fix: Add NetworkPolicy to allow Prometheus metrics scraping on port 8383 - #366
Conversation
The ocm-agent-operator creates a ServiceMonitor for Prometheus to scrape port 8383 metrics, but the existing NetworkPolicies only allow Alertmanager and MUO ingress. This causes TargetDown alerts because prometheus-k8s pods from openshift-monitoring cannot reach the ocm-agent metrics endpoint. Add a new NetworkPolicy that allows prometheus-k8s pods (selected by app.kubernetes.io/name=prometheus) from openshift-monitoring to reach the ocm-agent. The policy is created in both fleet and non-fleet modes since Prometheus scraping is needed in both. Uses the existing dispatch-key pattern (like NamespaceRHOBS) so NamespacePrometheus maps back to the real openshift-monitoring namespace via callerNamespace(). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Important
This repository does not receive automatic reviews because it has fewer than 10 stars. ⚙️ Run configurationConfiguration used: Repository YAML (base), Central YAML (inherited) Review profile: CHILL Plan: Team Run ID: Comment |
|
@redhat-chai-bot: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #366 +/- ##
==========================================
+ Coverage 65.39% 65.60% +0.21%
==========================================
Files 23 23
Lines 1598 1608 +10
==========================================
+ Hits 1045 1055 +10
Misses 473 473
Partials 80 80
🚀 New features to boost your workflow:
|
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: redhat-chai-bot, tkong-redhat 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 |
|
🤖 Finished Retro · ✅ Success · Started 12:26 AM UTC · Completed 12:38 AM UTC Commit: Runtime: claude · Model: opus → claude-opus-4-6 · Effort: high · Cost: $4.80 |
Retro: PR #366 — Add NetworkPolicy for Prometheus metrics scrapingTimeline
Why the review agent did not runThe Route job's
This meant a security-relevant change (NetworkPolicy modifications) received no automated review. Existing upstream coverageThis gap is well-tracked in
Code quality assessmentThe PR itself was well-executed: clean single-commit diff (+53/-12 across 3 files), follows existing dispatch-key patterns, includes Ginkgo BDD tests for the new Prometheus dispatch key, updates policy counts in both fleet and non-fleet test contexts, and provides a thorough PR description with root cause analysis and external references. Codecov reported 87.5% patch coverage. All Prow CI tests passed. No new proposalsThe primary improvement opportunity (ensuring review dispatch fires for trusted service-account PRs) is already tracked by the upstream issues listed above. No repo-level proposals are warranted — the code quality was high and the workflow gap is a platform-level routing issue. |
Summary
ocm-agent-operator creates a ServiceMonitor for Prometheus to scrape port 8383, but its NetworkPolicies only allow Alertmanager and MUO ingress. This causes
TargetDownalerts because Prometheus scrapes are silently dropped (context deadline exceededon:8383/metrics).This PR adds a NetworkPolicy allowing
prometheus-k8spods fromopenshift-monitoringto reach the OCM Agent on port 8383 for metrics scraping.Root Cause
In
ensureAllNetworkPolicies(), the onlyopenshift-monitoringNetworkPolicy targets Alertmanager pods (alertmanager: main). No policy exists for Prometheus pods, so the ServiceMonitor creates a scrape target that the NetworkPolicy blocks.PR #326 added granular pod selectors (OBO, RHOBS, MUO) but did not address the Prometheus gap.
Changes
pkg/consts/ocmagenthandler/ocmagenthandler.goOCMAgentPrometheusNetworkPolicySuffixfor the policy nameNamespacePrometheusdispatch key (not a literal namespace — follows the same pattern asNamespaceRHOBS)PrometheusPodLabelKey/PrometheusPodLabelValuefor pod selection (app.kubernetes.io/name: prometheus)pkg/ocmagenthandler/ocmagenthandler_networkpolicy.goNamespacePrometheuscase tobuildNetworkPolicyName()NamespacePrometheuscase tocallerPodSelector()returning Prometheus pod labelsNamespacePrometheuscase tocallerNamespace()mapping toNamespaceMonitorng(Prometheus runs in openshift-monitoring)NamespacePrometheusto both fleet and non-fleet namespace lists inensureAllNetworkPolicies()andensureAllNetworkPoliciesDeleted()pkg/ocmagenthandler/ocmagenthandler_networkpolicy_test.goValidation
go build ./...— passesgo test ./pkg/ocmagenthandler/— 78/78 specs passedReferences
AI-generated. Review for accuracy.
@joshbranham requested in Slack thread