@@ -184,8 +184,15 @@ func (c *MonitoringCollector) reportMonitoringMetrics(ch chan<- prometheus.Metri
184
184
go func (metricDescriptor * monitoring.MetricDescriptor , ch chan <- prometheus.Metric ) {
185
185
defer wg .Done ()
186
186
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
+ }
187
194
timeSeriesListCall := c .monitoringService .Projects .TimeSeries .List (utils .ProjectResource (c .projectID )).
188
- Filter (fmt . Sprintf ( "metric.type= \" %s \" " , metricDescriptor . Type ) ).
195
+ Filter (filter ).
189
196
IntervalStartTime (startTime .Format (time .RFC3339Nano )).
190
197
IntervalEndTime (endTime .Format (time .RFC3339Nano ))
191
198
@@ -229,8 +236,15 @@ func (c *MonitoringCollector) reportMonitoringMetrics(ch chan<- prometheus.Metri
229
236
defer wg .Done ()
230
237
log .Debugf ("Listing Google Stackdriver Monitoring metric descriptors starting with `%s`..." , metricsTypePrefix )
231
238
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
+ }
232
246
if err := c .monitoringService .Projects .MetricDescriptors .List (utils .ProjectResource (c .projectID )).
233
- Filter (fmt . Sprintf ( "metric.type = starts_with( \" %s \" )" , metricsTypePrefix ) ).
247
+ Filter (filter ).
234
248
Pages (ctx , metricDescriptorsFunction ); err != nil {
235
249
errChannel <- err
236
250
}
0 commit comments