Skip to content

make ExternalMetricsRequestWindow configurable#1117

Open
tav-pw wants to merge 1 commit intoGoogleCloudPlatform:masterfrom
tav-pw:config-external-metrics
Open

make ExternalMetricsRequestWindow configurable#1117
tav-pw wants to merge 1 commit intoGoogleCloudPlatform:masterfrom
tav-pw:config-external-metrics

Conversation

@tav-pw
Copy link

@tav-pw tav-pw commented Mar 18, 2026

Add configurable --external-metrics-request-window flag

Summary

Add a --external-metrics-request-window flag to make the Cloud Monitoring query window configurable. Currently hardcoded to 5 minutes, which causes HPAs to receive no metrics when using sparse metrics (e.g. exported every 10 minutes).

Problem

The adapter queries Cloud Monitoring with a fixed 5-minute window ([now - 5 min, now]). Metrics exported less frequently often fall outside this window, so the External Metrics API returns empty and HPAs cannot scale.

Relevant code:

Solution

Add a configurable flag with default 5m for backward compatibility. Users with sparse metrics can set --external-metrics-request-window=1h (or similar).

Changes

  • Add ExternalMetricsRequestWindow time.Duration to stackdriverAdapterServerOptions
  • Set default to 5*time.Minute in serverOptions
  • Add flags.DurationVar for --external-metrics-request-window
  • Pass serverOptions.ExternalMetricsRequestWindow to makeProviderOrDie instead of 5*time.Minute

Testing

  • Default behavior unchanged (5m window)
  • With --external-metrics-request-window=1h, sparse metrics should be returned reliably

@google-cla
Copy link

google-cla bot commented Mar 18, 2026

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant