@@ -184,8 +184,15 @@ func (c *MonitoringCollector) reportMonitoringMetrics(ch chan<- prometheus.Metri
184184 go func (metricDescriptor * monitoring.MetricDescriptor , ch chan <- prometheus.Metric ) {
185185 defer wg .Done ()
186186 log .Debugf ("Retrieving Google Stackdriver Monitoring metrics for descriptor `%s`..." , metricDescriptor .Type )
187+ filter := fmt .Sprintf ("metric.type=\" %s\" " , metricDescriptor .Type )
188+ if c .monitoringDropDelegatedProjects {
189+ filter = fmt .Sprintf (
190+ "project=\" %s\" AND metric.type=\" %s\" " ,
191+ c .projectID ,
192+ metricDescriptor .Type )
193+ }
187194 timeSeriesListCall := c .monitoringService .Projects .TimeSeries .List (utils .ProjectResource (c .projectID )).
188- Filter (fmt . Sprintf ( "metric.type= \" %s \" " , metricDescriptor . Type ) ).
195+ Filter (filter ).
189196 IntervalStartTime (startTime .Format (time .RFC3339Nano )).
190197 IntervalEndTime (endTime .Format (time .RFC3339Nano ))
191198
@@ -229,8 +236,15 @@ func (c *MonitoringCollector) reportMonitoringMetrics(ch chan<- prometheus.Metri
229236 defer wg .Done ()
230237 log .Debugf ("Listing Google Stackdriver Monitoring metric descriptors starting with `%s`..." , metricsTypePrefix )
231238 ctx := context .Background ()
239+ filter := fmt .Sprintf ("metric.type = starts_with(\" %s\" )" , metricsTypePrefix )
240+ if c .monitoringDropDelegatedProjects {
241+ filter = fmt .Sprintf (
242+ "project = \" %s\" AND metric.type = starts_with(\" %s\" )" ,
243+ c .projectID ,
244+ metricsTypePrefix )
245+ }
232246 if err := c .monitoringService .Projects .MetricDescriptors .List (utils .ProjectResource (c .projectID )).
233- Filter (fmt . Sprintf ( "metric.type = starts_with( \" %s \" )" , metricsTypePrefix ) ).
247+ Filter (filter ).
234248 Pages (ctx , metricDescriptorsFunction ); err != nil {
235249 errChannel <- err
236250 }
0 commit comments