operator: fix errors/warnings metric.#8
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>
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
||||||||||||
User description
PR_048
PR Type
Bug fix
Description
Fix errors/warnings metric initialization in operator
Extract metric creation into reusable function
Implement flush mechanism for pre-initialization metrics
Ensure metrics registered before agent startup
Diagram Walkthrough
File Walkthrough
metrics.go
Initialize operator metrics and flush logsoperator/metrics/metrics.go
InitOperatorMetrics()during operator metric registrationErrorsWarningsmetric with Prometheus registryFlushLoggingMetrics()to emit pre-initialization metricscell.go
Refactor metric flush logicpkg/metrics/cell.go
FlushLoggingMetrics()calllogging_hook.go
Add flush function for logging metricspkg/metrics/logging_hook.go
sync.Oncevariable to ensure flush executes only onceFlushLoggingMetrics()function to handle metric flushingmetrics.go
Extract and initialize errors/warnings metricpkg/metrics/metrics.go
ErrorsWarningsmetric creation intonewErrorsWarningsMetric()helper function
InitOperatorMetrics()function to initialize operator-specificmetrics