Skip to content

fix: register explicit bucket boundaries for duration histograms - #2255

Open
cowsking wants to merge 1 commit into
GoogleContainerTools:mainfrom
cowsking:fix-duration-histogram-buckets
Open

fix: register explicit bucket boundaries for duration histograms#2255
cowsking wants to merge 1 commit into
GoogleContainerTools:mainfrom
cowsking:fix-duration-histogram-buckets

Conversation

@cowsking

@cowsking cowsking commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

Following the OpenCensus to OpenTelemetry metrics migration, duration histogram instruments in Config Sync lacked explicit bucket boundaries. This caused the OpenTelemetry Go SDK to fall back to default millisecond-scale boundaries {0, 5, 10, 25, ...}, which for second-unit metrics resulted in all sub-5-second values falling into the (0, 5] bucket and skewing Prometheus histogram_quantile queries (e.g. static 4.75s).

This change:

  • Configures explicit sub-second bucket boundaries for core duration metrics (APICallDuration, ReconcileDuration, RemediateDuration) and long duration metrics (ParserDuration, ApplyDuration).
  • Configures explicit bucket boundaries for ResourceGroup ReconcileDuration.
  • Fixes pkg/kmetrics kustomize_build_latency: the histogram recorded raw nanosecond values while declaring a millisecond unit, so every recording landed in the overflow (+Inf) bucket regardless of bucket configuration. It now records the duration in seconds (consistent with all other Config Sync duration metrics), declares the unit as s, and registers explicit bucket boundaries. Note this changes the scale of the exported values (previously nanosecond-scale numbers labeled as ms).
  • Adds unit tests to verify histogram bucket bounds and sub-second data point placement.

@google-oss-prow
google-oss-prow Bot requested review from Camila-B and janetkuo August 12, 2026 22:41
@google-oss-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from cowsking. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@cowsking

Copy link
Copy Markdown
Contributor Author

/test kpt-config-sync-presubmit

Comment thread pkg/metrics/metrics.go
@@ -51,6 +51,14 @@ const (
InternalErrorsName = "internal_errors_total"
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on the fix, could you check if the fix apply to pkg/kmetrics as well?

Following the OpenCensus to OpenTelemetry metrics migration, duration
histogram instruments in Config Sync lacked explicit bucket boundaries.
This caused the OpenTelemetry Go SDK to fall back to default
millisecond-scale boundaries {0, 5, 10, 25, ...}, which for second-unit
metrics resulted in all sub-5-second values falling into the (0, 5] bucket
and skewing Prometheus histogram_quantile queries (e.g. static 4.75s).

This change:
- Configures explicit sub-second bucket boundaries for core duration
  metrics (APICallDuration, ReconcileDuration, RemediateDuration) and
  long duration metrics (ParserDuration, ApplyDuration).
- Configures explicit bucket boundaries for ResourceGroup ReconcileDuration.
- Adds unit tests to verify histogram bucket bounds and sub-second data
  point placement.

Fixes b/545631804
@cowsking
cowsking force-pushed the fix-duration-histogram-buckets branch from 1a1956e to 535a861 Compare August 15, 2026 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants