diff --git a/collectors/monitoring_collector.go b/collectors/monitoring_collector.go index 4f9ddb30..25a4d01a 100644 --- a/collectors/monitoring_collector.go +++ b/collectors/monitoring_collector.go @@ -42,6 +42,7 @@ type MonitoringCollector struct { metricsTypePrefixes []string metricsFilters []MetricFilter metricsInterval time.Duration + metricsDelay time.Duration metricsOffset time.Duration metricsIngestDelay bool monitoringService *monitoring.Service @@ -70,6 +71,9 @@ type MonitoringCollectorOptions struct { // RequestInterval is the time interval used in each request to get metrics. If there are many data points returned // during this interval, only the latest will be reported. RequestInterval time.Duration + // RequestDelay is the time interval between each subsequent request to get metrics. If you are receiving a rateLimited + // error, this can be increased. + RequestDelay time.Duration // RequestOffset is used to offset the requested interval into the past. RequestOffset time.Duration // IngestDelay decides if the ingestion delay specified in the metrics metadata is used when calculating the @@ -198,6 +202,7 @@ func NewMonitoringCollector(projectID string, monitoringService *monitoring.Serv metricsTypePrefixes: opts.MetricTypePrefixes, metricsFilters: opts.ExtraFilters, metricsInterval: opts.RequestInterval, + metricsDelay: opts.RequestDelay, metricsOffset: opts.RequestOffset, metricsIngestDelay: opts.IngestDelay, monitoringService: monitoringService, @@ -340,6 +345,9 @@ func (c *MonitoringCollector) reportMonitoringMetrics(ch chan<- prometheus.Metri timeSeriesListCall.PageToken(page.NextPageToken) } }(metricDescriptor, ch, startTime, endTime) + if c.metricsDelay != 0 { + time.Sleep(c.metricsDelay) + } } wg.Wait() diff --git a/stackdriver_exporter.go b/stackdriver_exporter.go index f71c4f43..0b21be8a 100644 --- a/stackdriver_exporter.go +++ b/stackdriver_exporter.go @@ -93,6 +93,10 @@ var ( "monitoring.metrics-interval", "Interval to request the Google Stackdriver Monitoring Metrics for. Only the most recent data point is used.", ).Default("5m").Duration() + monitoringMetricsDelay = kingpin.Flag( + "monitoring.metrics-delay", "Interval delay between metrics requests to the Google Stackdriver Monitoring.", + ).Default("0s").Duration() + monitoringMetricsOffset = kingpin.Flag( "monitoring.metrics-offset", "Offset for the Google Stackdriver Monitoring Metrics interval into the past.", ).Default("0s").Duration() @@ -215,6 +219,7 @@ func (h *handler) innerHandler(filters map[string]bool) http.Handler { MetricTypePrefixes: h.filterMetricTypePrefixes(filters), ExtraFilters: h.metricsExtraFilters, RequestInterval: *monitoringMetricsInterval, + RequestDelay: *monitoringMetricsDelay, RequestOffset: *monitoringMetricsOffset, IngestDelay: *monitoringMetricsIngestDelay, FillMissingLabels: *collectorFillMissingLabels,