kubernetes-sigs / kubernetes-sigs/node-readiness-controller

testing: Add Test Coverage for Prometheus Metrics

Open
#269 5 comments 0 reactions 1 assignee View on GitHub

@rawadhossain is already working on this.

Since Jun 20, 2026.

Dominant language
Go
Stars
164
Forks
75
Avg merge
8d 23h
Merged PRs (30d)
13

Description

Problem

We're exposing 5 Prometheus metrics from the controller, but only 1 of them (BootstrapCompleted) has test coverage. This makes it harder to catch regressions when metrics behavior changes.

Current Metrics Status

  • BootstrapCompleted - Has tests
  • RulesTotal - No tests
  • TaintOperations - No tests
  • Failures - No tests
  • EvaluationDuration - No tests (and not even used in code yet)

What Needs to Be Done

1. Add tests for RulesTotal metric

This gauge tracks the total number of active rules. We should test:

  • Value increases when a rule is added to the cache
  • Value decreases when a rule is removed from the cache
2. Add tests for TaintOperations metric

This counter tracks taint add/remove operations. We should test:

  • Counter increments when adding a taint (with labels: rule, operation="add")
  • Counter increments when removing a taint (with labels: rule, operation="remove")
3. Add tests for Failures metric

This counter tracks operational failures. We should test:

  • Counter increments on evaluation errors (label: reason="EvaluationError")
  • Counter increments on taint operation failures (labels: reason="AddTaintError" or reason="RemoveTaintError")
4. Implement and test EvaluationDuration metric

This histogram is defined but never used. We should:

  • Add instrumentation to the evaluateRuleForNode() function to record evaluation duration
  • Add tests to verify the histogram records evaluations

Acceptance Criteria

  • All 5 metrics have unit test coverage
  • Tests verify metrics behave correctly in both success and failure scenarios
  • All tests pass with make test

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.