operator: fix errors/warnings metric.#8
Open
MitchLewis930 wants to merge 1 commit intopr_048_beforefrom
Open
Conversation
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>
There was a problem hiding this comment.
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 usingsync.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() { |
There was a problem hiding this comment.
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() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR_048