Skip to content

feat(metrics): add per-resource reconcile condition gauge#4812

Open
gurpalw wants to merge 2 commits into
kubernetes-sigs:mainfrom
gurpalw:feat/reconcile-condition-metric
Open

feat(metrics): add per-resource reconcile condition gauge#4812
gurpalw wants to merge 2 commits into
kubernetes-sigs:mainfrom
gurpalw:feat/reconcile-condition-metric

Conversation

@gurpalw

@gurpalw gurpalw commented Jul 6, 2026

Copy link
Copy Markdown

Issue

Fixes #4808

Description

Adds a per-resource reconciliation-status metric so Prometheus alerts can identify which resource is failing to reconcile, not just that some reconcile in a controller is failing:

awslbc_controller_reconcile_condition{controller, namespace, name} = 1 | 0
  • 1 — the last reconcile of the resource succeeded; 0 — the resource is failing to reconcile.
  • The series is deleted when the resource is deleted (finalizer cleanup, NotFound on fetch, service no longer of LB type, or an ingress group losing its last member), so the metric never reports a frozen state and cardinality stays bounded to live resources.
  • Requeue errors (RequeueNeeded/RequeueNeededAfter) do not mark the resource as failing, matching the existing awslbc_controller_reconcile_errors_total semantics — an LB mid-provisioning is not a failure.
  • Wired into all five reconcilers that share the lbcmetrics.MetricCollector: ingress, service, targetGroupBinding, gateway (NLB/ALB), and globalAccelerator.

Implementation notes, following existing patterns in the repo:

  • This is the lower-cardinality single-gauge shape discussed in Expose per-resource reconciliation status as a Prometheus metric #4808 (one series per resource, no status label), mirroring the existing per-resource Set/Delete lifecycle of aws_target_group_info (pkg/metrics/aws/target_group.go).
  • For the ingress controller the series identity is the ingress group (the unit actually reconciled), exactly like awslbc_controller_top_talkers: implicit groups map 1:1 to the Ingress's namespace/name; explicit groups are cluster-scoped and emit an empty namespace label.
  • The failure/requeue classification lives in a new runtime.HandleReconcileErrorWithCondition helper next to the existing HandleReconcileError, so each reconciler's Reconcile() is a one-line change and future controllers get the metric for free.
  • ErrorWithMetrics gains an Unwrap() method so errors.As-based requeue detection (runtime.IsRequeueError) can see through it. Without this, requeue errors wrapped by NewErrorWithMetrics were opaque to errors.Is/errors.As; HandleReconcileError previously compensated with manual unwrapping (handleNestedError), which still works unchanged.
  • Corner cases covered: gateways owned by a different controller class drop any series recorded before ownership was known; deferred TGB reconciles and successful gateway dry-run passes clear a previously-failing condition; resources deleted before acquiring a finalizer have their series removed on the NotFound path.

Example alert query (also added to the docs): awslbc_controller_reconcile_condition == 0

Checklist

  • Added tests that cover your change (if possible)
  • Added/modified documentation as required (such as the README.md, or the docs directory)
  • Manually tested
  • Made sure the title of the PR is a good description that can go into the release notes

BONUS POINTS checklist: complete for good vibes and maybe prizes?! 🤯

  • Backfilled missing tests for code in same general area 🎉 (first metric-output tests for pkg/metrics/lbc using prometheus testutil)
  • Refactored something and made the world a better place 🌟

@kubernetes-prow kubernetes-prow Bot added the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Jul 6, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: gurpalw
Once this PR has been reviewed and has the lgtm label, please assign shuqz for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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 requested review from oliviassss and zac-nixon July 6, 2026 21:37
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Welcome @gurpalw!

It looks like this is your first PR to kubernetes-sigs/aws-load-balancer-controller 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/aws-load-balancer-controller has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@kubernetes-prow kubernetes-prow Bot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 6, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

Hi @gurpalw. 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.

Regular contributors should join the org to skip this step.

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 needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 6, 2026
@gurpalw
gurpalw force-pushed the feat/reconcile-condition-metric branch from d5ef8df to 6edf2ef Compare July 7, 2026 10:13
@kubernetes-prow kubernetes-prow Bot removed the do-not-merge/invalid-commit-message Indicates that a PR should not merge because it has an invalid commit message. label Jul 7, 2026
@shraddhabang

Copy link
Copy Markdown
Collaborator

/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 Jul 9, 2026
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 36.66667% with 57 lines in your changes missing coverage. Please review.
✅ Project coverage is 57.53%. Comparing base (82c3870) to head (6edf2ef).
⚠️ Report is 47 commits behind head on main.

Files with missing lines Patch % Lines
pkg/metrics/lbc/mockcollector.go 0.00% 15 Missing ⚠️
controllers/gateway/gateway_controller.go 0.00% 12 Missing ⚠️
controllers/aga/globalaccelerator_controller.go 0.00% 10 Missing ⚠️
controllers/elbv2/targetgroupbinding_controller.go 36.36% 7 Missing ⚠️
controllers/service/service_controller.go 14.28% 6 Missing ⚠️
controllers/ingress/group_controller.go 0.00% 5 Missing ⚠️
pkg/metrics/lbc/collector.go 88.23% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4812      +/-   ##
==========================================
+ Coverage   57.08%   57.53%   +0.45%     
==========================================
  Files         396      396              
  Lines       31572    31628      +56     
==========================================
+ Hits        18022    18197     +175     
+ Misses      12492    12369     -123     
- Partials     1058     1062       +4     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@kubernetes-prow kubernetes-prow Bot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 15, 2026
gurpalw added 2 commits July 17, 2026 21:07
Adds awslbc_controller_reconcile_condition{controller,namespace,name},
set to 1 when the last reconcile of a resource succeeded and 0 when it
is failing, so alerts can identify which resource is failing to
reconcile rather than only the controller. The series is deleted when
the resource is deleted (or an ingress group loses its last member) so
the metric stays bounded to live resources.

The failure/requeue classification lives in a new
runtime.HandleReconcileErrorWithCondition helper used by the ingress,
service, targetGroupBinding, gateway and globalAccelerator reconcilers.
ErrorWithMetrics gains an Unwrap method so errors.As-based requeue
detection can see through it and expected requeues are not reported as
failures.
Adds test coverage for the per-resource reconcile-condition gauge flagged
by Codecov as low patch coverage:

- lbc: exercise MockCollector condition set/delete recording
- service: NotFound-delete branch + condition assertions on reconcile
- targetGroupBinding: NotFound, cleanup-success, and deferred branches
- globalAccelerator: NotFound-delete branch (first tests for the package)
- gateway: NotFound-delete branch via the canonical NewMockCollector
- ingress: members-present (condition set) and empty-group (delete) branches
@gurpalw
gurpalw force-pushed the feat/reconcile-condition-metric branch from 32872ec to ad73c86 Compare July 17, 2026 20:16
@kubernetes-prow kubernetes-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose per-resource reconciliation status as a Prometheus metric

3 participants