Make external metrics request window configurable (currently hardcoded to 5 minutes)
Problem
The custom-metrics-stackdriver-adapter uses a fixed 5-minute window when querying Cloud Monitoring for external metrics:
// adapter.go line ~250
metricsProvider, translator := cmd.makeProviderOrDie(&serverOptions, 5*time.Minute, 1*time.Minute)
This rateInterval becomes reqWindow in the Translator and is used in query_builder.go:
startTime := endTime.Add(-t.reqWindow)
So the Cloud Monitoring query always uses [now - 5 min, now].
Impact
Metrics that are exported less often than every 5 minutes (e.g. every 10 minutes) often fall outside this window. When that happens, the adapter returns no data, the External Metrics API returns empty, and HPAs using these metrics cannot scale.
Proposed solution
Add a configurable flag, e.g. --external-metrics-request-window, with a default of 5 minutes for backward compatibility. This would allow users with sparse metrics to use a longer window (e.g. 1 hour) without forking the adapter.
Environment
- GKE with custom-metrics-stackdriver-adapter
- Metrics emitted via OTLP to Cloud Monitoring
- HPA using external metric
workload.googleapis.com|long_running_jobs_scheduled
Make external metrics request window configurable (currently hardcoded to 5 minutes)
Problem
The custom-metrics-stackdriver-adapter uses a fixed 5-minute window when querying Cloud Monitoring for external metrics:
This
rateIntervalbecomesreqWindowin the Translator and is used inquery_builder.go:So the Cloud Monitoring query always uses
[now - 5 min, now].Impact
Metrics that are exported less often than every 5 minutes (e.g. every 10 minutes) often fall outside this window. When that happens, the adapter returns no data, the External Metrics API returns empty, and HPAs using these metrics cannot scale.
Proposed solution
Add a configurable flag, e.g.
--external-metrics-request-window, with a default of 5 minutes for backward compatibility. This would allow users with sparse metrics to use a longer window (e.g. 1 hour) without forking the adapter.Environment
workload.googleapis.com|long_running_jobs_scheduled