Skip to content

Add Prometheus metrics to readiness condition reporter - #379

Merged
kubernetes-prow[bot] merged 4 commits into
kubernetes-sigs:mainfrom
rawadhossain:reporter
Aug 18, 2026
Merged

Add Prometheus metrics to readiness condition reporter#379
kubernetes-prow[bot] merged 4 commits into
kubernetes-sigs:mainfrom
rawadhossain:reporter

Conversation

@rawadhossain

@rawadhossain rawadhossain commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Description

Implements the Reporter metrics specified in the observability design

  • node_readiness_reporter_build_info
  • node_readiness_reporter_check_duration_seconds
  • node_readiness_reporter_checks_total
  • node_readiness_reporter_condition_writes_total

Also adds the Prometheus /metrics and /healthz endpoints to the readiness condition reporter.

Implementation choices

  • Single HTTP server for both /metrics and /healthz to keep the Reporter to one listener and port.
  • Dedicated Prometheus registry to keep the Reporter's metrics isolated and avoid registration conflicts in tests, following the same general pattern used by the controller metrics.
  • Port :9445 as the default metrics port because the Reporter runs with hostNetwork: true. The address is configurable through METRICS_BIND_ADDRESS.

Build fix

Updated Dockerfile.reporter to build the Reporter package instead of single file main.go, since the new metrics.go also needs to be included.

Fixes #380

Type of Change

/kind feature

Testing

  • Verified metrics scraping with a live kind cluster and Prometheus.
  • Verified graceful SIGTERM shutdown.
  • Verified the Reporter continues its normal check/condition-update loop when the metrics port is unavailable.

Checklist

  • make test passes
  • make lint passes

@kubernetes-prow kubernetes-prow Bot added the kind/feature Categorizes issue or PR as related to a new feature. label Aug 9, 2026
@netlify

netlify Bot commented Aug 9, 2026

Copy link
Copy Markdown

Deploy Preview for node-readiness-controller ready!

Name Link
🔨 Latest commit 2de0068
🔍 Latest deploy log https://app.netlify.com/projects/node-readiness-controller/deploys/6a84326f1f7e2800082aff28
😎 Deploy Preview https://deploy-preview-379--node-readiness-controller.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@kubernetes-prow
kubernetes-prow Bot requested review from dchen1107 and mrunalp August 9, 2026 10:59
@kubernetes-prow kubernetes-prow Bot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Aug 9, 2026
@kubernetes-prow

Copy link
Copy Markdown

Hi @rawadhossain. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

Instructions 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.

@kubernetes-prow kubernetes-prow Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 9, 2026
@ajaysundark

Copy link
Copy Markdown
Contributor

/cc @AvineshTripathi @ajaysundark

@ajaysundark

Copy link
Copy Markdown
Contributor

/ok-to-test

@kubernetes-prow kubernetes-prow Bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 10, 2026

@AvineshTripathi AvineshTripathi left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you for starting this PR! I have left some comments

Comment thread cmd/readiness-condition-reporter/main.go Outdated
Comment thread cmd/readiness-condition-reporter/main.go Outdated
Comment thread cmd/readiness-condition-reporter/metrics.go Outdated
// reporterChecksTotal tracks total probe check results over time.
reporterChecksTotal = prometheus.NewCounterVec(
prometheus.CounterOpts{
Name: "node_readiness_reporter_checks_total",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

node_readiness_reporter_checks instead

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

but I see in #344 it says node_readiness_reporter_checks_total

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, was confused about this too, so kept it as in the design doc.

@ajaysundark ajaysundark Aug 11, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I followed https://prometheus.io/docs/practices/naming/#metric-names. The metrics convention suggests that an accumulating count has total as a suffix. Also on a similar note, https://www.robustperception.io/on-the-naming-of-things/ was a good read on why our node_readiness_rules_total (a gauge) metric could drop the suffix as can cause to confusions like this.

mux.HandleFunc("/healthz", func(w http.ResponseWriter, _ *http.Request) {
w.WriteHeader(http.StatusOK)
})
metricsServer := &http.Server{

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

why not using "sigs.k8s.io/controller-runtime/pkg/metrics/server"? We already have it as part of go.mod

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I looked into this one. It can run standalone without a full Manager setup, but I kept the current approach for a few reasons:

  • We use a dedicated registry for the Reporter, so the /metrics endpoint only exposes the metrics we explicitly register.
  • The current implementation gives us explicit control over the metrics server shutdown and keeps the existing klog setup.
  • Using metrics/server doesn't really make the implementation simpler once the registry and logging setup are included.

I also tested the current setup with a real SIGTERM against a live pod, and it shuts down cleanly in ~0.3s. So I kept the current implementation since it gives us the behavior we wanted and is already validated. Im okay to switch to metrics/server if you think that's preferable here.

Signed-off-by: Rawad Hossain <rawad.hossain00@gmail.com>
// reporterBuildInfo tracks the reporter binary version to track fleet version skew.
reporterBuildInfo = prometheus.NewGaugeVec(
prometheus.GaugeOpts{
Name: "node_readiness_reporter_build_info",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@rawadhossain just reviewed #406. Don't we need the ldFlags on this one?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we need it here too. Was planning to get #406 merged first and then follow up here. I’ll push the changes once #406 lands.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ajaysundark done with the idFlags changes now that #406 is merged. PTAL.

Signed-off-by: Rawad Hossain <rawad.hossain00@gmail.com>
@rawadhossain
rawadhossain force-pushed the reporter branch 2 times, most recently from 3613030 to 2e35f85 Compare August 14, 2026 23:10
@ajaysundark
ajaysundark requested review from AvineshTripathi and removed request for dchen1107 and mrunalp August 17, 2026 05:00
@AvineshTripathi

Copy link
Copy Markdown
Contributor

/lgtm

I think this is all good now. @ajaysundark can you take a final look

@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 17, 2026
prometheus.HistogramOpts{
Name: "node_readiness_reporter_check_duration_seconds",
Help: "Duration of health probe checks.",
Buckets: prometheus.DefBuckets,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

An AI review caught this as excessive, so I looked it up - https://pkg.go.dev/github.com/prometheus/client_golang/prometheus#pkg-variables. The default bucket seems to be 11 buckets from 0.005 granularity to 10s.

I wonder whether these many milliseconds accuracy is needed. May be we could keep it fewer to something like {0.1, 0.5, 1, 5, 10 }?

@rawadhossain rawadhossain Aug 18, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looked into this and I agree that the default buckets are more than we need here. Tested it by running the reporter against real traffic + some deliberate slow responses to see which buckets actually mattered.

So I ended up with {0.005, 0.1, 0.25, 0.5, 1, 2.5, 5, 10}. Kept a few more buckets since they were catching useful delays in testing.

Committed the changes. PTAL.

Comment thread cmd/readiness-condition-reporter/metrics.go Outdated
Comment thread cmd/readiness-condition-reporter/metrics.go Outdated
@ajaysundark

Copy link
Copy Markdown
Contributor

/lgtm

please address the comments when you get time before we could merge this.

@kubernetes-prow kubernetes-prow Bot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 18, 2026
@AvineshTripathi

Copy link
Copy Markdown
Contributor

/lgtm

Adding it again! Changes looks good

@kubernetes-prow kubernetes-prow Bot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 18, 2026
@ajaysundark

Copy link
Copy Markdown
Contributor

/approve

@kubernetes-prow

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ajaysundark, rawadhossain

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

@kubernetes-prow kubernetes-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 18, 2026
@kubernetes-prow
kubernetes-prow Bot merged commit 33bdbc9 into kubernetes-sigs:main Aug 18, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Reporter metrics

3 participants