[RHOAIENG-31975] - Onboard metrics to the centralized metrics platform#370
[RHOAIENG-31975] - Onboard metrics to the centralized metrics platform#370spolti wants to merge 1 commit intoopendatahub-io:mainfrom
Conversation
chore: Add the `monitoring.opendatahub.io/scrape: "true"` anntation to
Pod and Service monitors so the metrics can be collected by the
Centralized RHOAI Observability platform.
Signed-off-by: Spolti <fspolti@redhat.com>
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: spolti The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
WalkthroughAdds a new rhoaiObservabilityLabel constant and applies it to ServiceMonitor creation by adding a scrape label ("monitoring.opendatahub.io/scrape": "true") in ObjectMeta within reconcileServiceMonitor. Minor constant alignment/formatting. No exported/public API changes. Changes
Sequence Diagram(s)sequenceDiagram
participant R as Reconciler
participant SM as ServiceMonitor (object)
participant K8s as Kubernetes API
R->>R: reconcileServiceMonitor()
R->>SM: Instantiate ServiceMonitor spec
R->>SM: Set metadata.labels["monitoring.opendatahub.io/scrape"] = "true"
note right of SM: Label ensures scraping by observability stack
R->>K8s: Create/Update ServiceMonitor with labels
K8s-->>R: Status/Result
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.2.2)Error: can't load config: unsupported version of the configuration: "" See https://golangci-lint.run/product/migration-guide for migration instructions Tip 🔌 Remote MCP (Model Context Protocol) integration is now available!Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats. ✨ Finishing Touches
🧪 Generate unit tests
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (2)
controllers/service_controller.go (2)
52-55: Confirm intent: label vs annotation and target resource(s).PR description says “add the annotation … to Pods and Services”, but this change adds a label to the ServiceMonitor. If the centralized Prometheus instance selects ServiceMonitors by label (common pattern), this is correct. If the requirement is to annotate Pods/Services for scraping, this file doesn’t do that.
- Please confirm which is required:
- ServiceMonitor label monitoring.opendatahub.io/scrape = "true" (what this change attempts), or
- Pod/Service annotations/labels, and on which resources.
- If Services also need the label, we can add rhoaiObservabilityLabel to labelMap in reconcileService.
I can push a small follow-up change once you confirm the contract with RHOAI Observability.
379-384: Nit: ‘changed’ flag logic is inverted.You set changed := reflect.DeepEqual(...). That sets changed to true when owner refs did not change. In practice this causes unnecessary updates or hides actual changes depending on later mutations.
Recommend:
- changed := reflect.DeepEqual(crBefore, sm.GetOwnerReferences()) + changed := !reflect.DeepEqual(crBefore, sm.GetOwnerReferences())
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
controllers/service_controller.go(2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Analyze (go)
| Labels: map[string]string{ | ||
| rhoaiObservabilityLabel: "true", | ||
| }, | ||
| }, |
There was a problem hiding this comment.
Bug: Newly added ServiceMonitor label is immediately overwritten (net effect = no label).
You add the RHOAI Observability label in ObjectMeta on construct, but a few lines later you overwrite sm.Labels with owner.Labels, which drops the added label both on create and update. The centralized Prometheus will not see the label.
Fix by merging owner labels with the required rhoai label instead of overwriting:
- Labels: map[string]string{
- rhoaiObservabilityLabel: "true",
- },
+ Labels: map[string]string{
+ rhoaiObservabilityLabel: "true",
+ },
@@
- if !reflect.DeepEqual(sm.Labels, owner.Labels) {
- sm.Labels = owner.Labels
- changed = true
- }
+ // Merge owner labels with the required RHOAI Observability scrape label
+ merged := map[string]string{}
+ for k, v := range owner.Labels {
+ merged[k] = v
+ }
+ merged[rhoaiObservabilityLabel] = "true"
+ if !reflect.DeepEqual(sm.Labels, merged) {
+ sm.Labels = merged
+ changed = true
+ }Also applies to: 385-388
🤖 Prompt for AI Agents
In controllers/service_controller.go around lines 351-354 (and similarly at
385-388), the newly added rhoaiObservabilityLabel is being overwritten because
sm.Labels is replaced with owner.Labels; instead merge owner.Labels into
sm.Labels while ensuring rhoaiObservabilityLabel="true" is present. Concretely,
create or keep a labels map for sm, copy all key/values from owner.Labels into
it, then set labels[rhoaiObservabilityLabel] = "true", and assign that merged
map to sm.Labels so the required label is not lost on create or update.
chore: Add the
monitoring.opendatahub.io/scrape: "true"anntation toPod and Service monitors so the metrics can be collected by the
Centralized RHOAI Observability platform.
Motivation
Modifications
Result
PR checklist
Checklist items below are applicable for development targeted to both fast and stable branches/tags
Checklist items below are applicable for development targeted to both fast and stable branches/tags
Summary by CodeRabbit