Skip to content

[RHOAIENG-31975] - Onboard metrics to the centralized metrics platform#370

Closed
spolti wants to merge 1 commit intoopendatahub-io:mainfrom
spolti:RHOAIENG-31975
Closed

[RHOAIENG-31975] - Onboard metrics to the centralized metrics platform#370
spolti wants to merge 1 commit intoopendatahub-io:mainfrom
spolti:RHOAIENG-31975

Conversation

@spolti
Copy link
Member

@spolti spolti commented Aug 20, 2025

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.

Motivation

Modifications

Result

PR checklist

Checklist items below are applicable for development targeted to both fast and stable branches/tags

  • Unit tests pass locally
  • FVT tests pass locally
  • If the PR adds a new container image or updates the tag of an existing image (not build within cpaas), is the corresponding change made in live-builder and cpaas-midstream to add/update the image tag in the operator CSV? Link the PRs if applicable

Checklist items below are applicable for development targeted to both fast and stable branches/tags

  • Tested modelmesh serving deployment with odh-manifests and ran odh-manifests-e2e tests locally

Summary by CodeRabbit

  • New Features
    • Enables automatic metrics scraping by labeling ServiceMonitor resources, improving default observability.
    • Monitoring systems now detect and collect metrics without manual configuration, enhancing dashboards and alerts availability.
    • Provides more reliable visibility into service health and performance across deployments.

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>
@openshift-ci
Copy link

openshift-ci bot commented Aug 20, 2025

[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

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

@coderabbitai
Copy link

coderabbitai bot commented Aug 20, 2025

Walkthrough

Adds 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

Cohort / File(s) Summary
ServiceMonitor labeling and constants
controllers/service_controller.go
Added rhoaiObservabilityLabel constant; updated reconcileServiceMonitor to set Labels with rhoaiObservabilityLabel: "true"; minor formatting alignment of constants.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

A rabbit taps keys in the dew-lit night,
Adds a tiny label—oh what delight!
“Scrape me,” it squeaks, to metrics that flow,
Through ServiceMonitors watching below.
Small hop, big graphs, dashboards in sight—
Carrots for logs, and charts shining bright.

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
The command is terminated due to an 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 Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

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.

📥 Commits

Reviewing files that changed from the base of the PR and between 7e8b60b and 4f4b54c.

📒 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)

Comment on lines +351 to 354
Labels: map[string]string{
rhoaiObservabilityLabel: "true",
},
},
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

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.

@spolti spolti closed this Aug 21, 2025
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.

1 participant