GoogleCloudPlatform / GoogleCloudPlatform/k8s-stackdriver
Make external metrics request window configurable (currently hardcoded to 5 minutes)
- Dominant language
- Go
- Stars
- 409
- Forks
- 236
- Avg merge
- 2h 34m
- Merged PRs (30d)
- 9
Description
# 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:
```go
// 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`:
```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`
Contributor guide
Assessment
This issue has not been assessed yet.