Skip to content

Comments

operator: fix errors/warnings metric.#8

Open
MitchLewis930 wants to merge 1 commit intopr_048_beforefrom
pr_048_after
Open

operator: fix errors/warnings metric.#8
MitchLewis930 wants to merge 1 commit intopr_048_beforefrom
pr_048_after

Conversation

@MitchLewis930
Copy link

PR_048

This was broken during transition of pkg/metrics to integrate with Hive where relevant operator metrics where never initialized.
This adds a init func specific for operator and cleans up the "flush" logic used as a work around for errors/warnings emitted prior to agent starting (in the case of the operator).

Addresses: cilium#29525

Signed-off-by: Tom Hadlaw <tom.hadlaw@isovalent.com>
@MitchLewis930 MitchLewis930 requested a review from Copilot January 31, 2026 01:14
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the errors/warnings metric initialization to support proper registration in both the agent and operator contexts. The changes extract the metric creation into a shared helper function and introduce explicit initialization and flushing mechanisms for the operator.

Changes:

  • Extracted errors/warnings metric creation into a shared newErrorsWarningsMetric() helper function
  • Added InitOperatorMetrics() function to initialize operator-specific metrics
  • Introduced FlushLoggingMetrics() to encapsulate the metrics flushing logic using sync.Once

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
pkg/metrics/metrics.go Refactored ErrorsWarnings metric to use new helper function and added InitOperatorMetrics()
pkg/metrics/logging_hook.go Added FlushLoggingMetrics() function with sync.Once pattern for thread-safe flushing
pkg/metrics/cell.go Updated to use new FlushLoggingMetrics() function
operator/metrics/metrics.go Added operator metric initialization and flushing calls

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +19 to +26
flushMetrics = sync.Once{}
)

// FlushLoggingMetrics will cause all logging hook metrics accumulated prior
// to the errors_warnings metrics being registered with the Prometheus collector
// to be incremented to their respective errors_warnings metrics tuple.
func FlushLoggingMetrics() {
flushMetrics.Do(func() {
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

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

The variable flushMetrics should be named with a noun rather than a verb. Consider renaming it to flushMetricsOnce to better reflect that it's a sync.Once object and follow Go naming conventions.

Suggested change
flushMetrics = sync.Once{}
)
// FlushLoggingMetrics will cause all logging hook metrics accumulated prior
// to the errors_warnings metrics being registered with the Prometheus collector
// to be incremented to their respective errors_warnings metrics tuple.
func FlushLoggingMetrics() {
flushMetrics.Do(func() {
flushMetricsOnce = sync.Once{}
)
// FlushLoggingMetrics will cause all logging hook metrics accumulated prior
// to the errors_warnings metrics being registered with the Prometheus collector
// to be incremented to their respective errors_warnings metrics tuple.
func FlushLoggingMetrics() {
flushMetricsOnce.Do(func() {

Copilot uses AI. Check for mistakes.
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.

2 participants