Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: adding a new option to delay subsequent collections #320

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions collectors/monitoring_collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions stackdriver_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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,
Expand Down