Skip to content

✨: Add custom Prometheus metrics for controller observability - #3108

Open
MaxRink wants to merge 1 commit into
metal3-io:mainfrom
MaxRink:metrics
Open

✨: Add custom Prometheus metrics for controller observability#3108
MaxRink wants to merge 1 commit into
metal3-io:mainfrom
MaxRink:metrics

Conversation

@MaxRink

@MaxRink MaxRink commented Jan 23, 2026

Copy link
Copy Markdown
Contributor

What this PR does

Adds custom Prometheus metrics to all CAPM3 controllers, addressing the lack of visibility into provisioning times, error rates, and controller performance.

Why we need it

Previously, CAPM3 only exposed default controller-runtime metrics, making it difficult to:

  • Monitor provisioning success rates and durations
  • Debug slow BMH associations
  • Track error rates by controller type
  • Set up meaningful alerts for operational issues

Changes

New files

  • internal/metrics/metrics.go - Central metrics package with 22 Prometheus metrics
  • internal/metrics/metrics_test.go - Unit tests for all helper functions (14 tests)
  • docs/metrics.md - Comprehensive documentation with PromQL examples

Modified controllers

All controllers instrumented with reconcile metrics:

  • metal3machine_controller.go - Also tracks BMH association and provisioning duration
  • metal3cluster_controller.go
  • metal3data_controller.go
  • metal3datatemplate_controller.go
  • metal3remediation_controller.go
  • metal3machinetemplate_controller.go
  • metal3labelsync_controller.go

Metrics overview

Category Metrics
Reconcile performance Counter + duration histogram per controller
BMH association capm3_bmh_association_total, capm3_bmh_association_duration_seconds
Provisioning capm3_metal3machine_provisioning_duration_seconds (creation → Ready)
Errors capm3_reconcile_errors_total by controller
Phase tracking capm3_metal3machine_phase_transitions_total

How to test

make test  # Runs generate + lint + unit tests

@metal3-io-bot metal3-io-bot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Jan 23, 2026
@metal3-io-bot

Copy link
Copy Markdown
Contributor

Hi @MaxRink. Thanks for your PR.

I'm waiting for a metal3-io 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.

@MaxRink MaxRink changed the title feat: Add custom Prometheus metrics for controller observability ✨: Add custom Prometheus metrics for controller observability Jan 23, 2026

@tuminoid tuminoid left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/ok-to-test

I think @fmuyassarov had something like this brewing as well?
/cc @lentzi90 @adilGhaffarDev @kashifest @fmuyassarov

@metal3-io-bot metal3-io-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 Jan 23, 2026
@MaxRink
MaxRink force-pushed the metrics branch 2 times, most recently from 180f512 to 2224fa7 Compare January 23, 2026 11:31
@metal3-io-bot metal3-io-bot added the needs-rebase Indicates that a PR cannot be merged because it has merge conflicts with HEAD. label Feb 5, 2026
@fmuyassarov

Copy link
Copy Markdown
Member

/ok-to-test

I think @fmuyassarov had something like this brewing as well? /cc @lentzi90 @adilGhaffarDev @kashifest @fmuyassarov

Yes, I was doing some custom metrics addition. But this might be a good start. I will take a look today/tomorrow at this patch.

@fmuyassarov

Copy link
Copy Markdown
Member

Can you rebase before we start reviewing?

@fmuyassarov

Copy link
Copy Markdown
Member

ping @MaxRink

Copilot AI review requested due to automatic review settings April 13, 2026 23:20
@metal3-io-bot metal3-io-bot removed the needs-rebase Indicates that a PR cannot be merged because it has merge conflicts with HEAD. label Apr 13, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds a centralized custom Prometheus metrics package and instruments CAPM3 controllers to improve observability into reconcile performance, provisioning workflows, and error rates.

Changes:

  • Introduces internal/metrics with CAPM3-specific counters/histograms/gauges and helper recording functions.
  • Instruments multiple controllers to record reconcile duration/result metrics, plus additional Metal3Machine provisioning and BMH association metrics.
  • Adds metrics documentation (docs/metrics.md) and basic unit tests for metric helper functions.

Reviewed changes

Copilot reviewed 12 out of 12 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
internal/metrics/metrics.go Defines and registers CAPM3 Prometheus metrics plus helper recording functions.
internal/metrics/metrics_test.go Adds unit tests covering metric helper entrypoints.
docs/metrics.md Documents exposed metrics, labels, and example PromQL queries.
go.mod Promotes prometheus/client_golang to a direct dependency.
controllers/metal3machine_controller.go Adds reconcile + BMH association + provisioning duration instrumentation.
controllers/metal3machine_controller_test.go Updates mocks/calls to accommodate additional provisioning/metrics logic.
controllers/metal3cluster_controller.go Adds reconcile + error instrumentation.
controllers/metal3data_controller.go Adds reconcile + error instrumentation.
controllers/metal3datatemplate_controller.go Adds reconcile + error instrumentation.
controllers/metal3remediation_controller.go Adds reconcile + error instrumentation.
controllers/metal3machinetemplate_controller.go Adds reconcile + error instrumentation.
controllers/metal3labelsync_controller.go Adds reconcile instrumentation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread controllers/metal3data_controller.go Outdated
Comment thread controllers/metal3datatemplate_controller.go Outdated
Comment thread internal/metrics/metrics.go
Comment thread controllers/metal3labelsync_controller.go Outdated
Comment thread docs/metrics.md Outdated
Comment thread docs/metrics.md Outdated
Comment thread docs/metrics.md Outdated
Comment thread internal/metrics/metrics_test.go Outdated
Comment thread docs/metrics.md Outdated
Comment thread controllers/metal3machine_controller.go Outdated
@metal3-io-bot metal3-io-bot added the needs-rebase Indicates that a PR cannot be merged because it has merge conflicts with HEAD. label Apr 16, 2026
@metal3-io-bot metal3-io-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed needs-rebase Indicates that a PR cannot be merged because it has merge conflicts with HEAD. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Apr 23, 2026
@Sunnatillo

Copy link
Copy Markdown
Member

@fmuyassarov needs your review

@MaxRink
MaxRink force-pushed the metrics branch 2 times, most recently from 98d3a43 to 8d8e2d2 Compare June 8, 2026 17:26
@tuminoid

Copy link
Copy Markdown
Member

/cc @fmuyassarov @lentzi90

@adilGhaffarDev adilGhaffarDev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/approved
thanks @MaxRink
One minor comment but not a blocker.
/hold
holding so others can review.

Comment thread controllers/metal3machine_controller.go Outdated
@metal3-io-bot metal3-io-bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jun 18, 2026
@metal3-io-bot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adilGhaffarDev

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

@metal3-io-bot metal3-io-bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 18, 2026

@adilGhaffarDev adilGhaffarDev left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks good.

@metal3-io-bot metal3-io-bot added the needs-rebase Indicates that a PR cannot be merged because it has merge conflicts with HEAD. label Jun 23, 2026
@metal3-io-bot metal3-io-bot removed the needs-rebase Indicates that a PR cannot be merged because it has merge conflicts with HEAD. label Jun 23, 2026
@MaxRink
MaxRink force-pushed the metrics branch 2 times, most recently from 8404827 to 4e0dc65 Compare June 24, 2026 13:37
@lentzi90

Copy link
Copy Markdown
Member

/test metal3-centos-e2e-integration-test-main metal3-ubuntu-e2e-integration-test-main

@lentzi90 lentzi90 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking good overall! I have a couple of comments on passing through the function to record reconciliation errors. This I would like to get rid of so we just do it with the defer. What do you think about this?

Comment thread controllers/metal3datatemplate_controller.go Outdated
Comment thread controllers/metal3machine_controller.go Outdated
@metal3-io-bot metal3-io-bot added the needs-rebase Indicates that a PR cannot be merged because it has merge conflicts with HEAD. label Jun 30, 2026
@metal3-io-bot metal3-io-bot removed the needs-rebase Indicates that a PR cannot be merged because it has merge conflicts with HEAD. label Jul 31, 2026

@lentzi90 lentzi90 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you please squash the commits?

@lentzi90

Copy link
Copy Markdown
Member

/test metal3-ubuntu-e2e-integration-test-main metal3-centos-e2e-integration-test-main

@lentzi90 lentzi90 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

/lgtm

@@ -0,0 +1,460 @@
/*
Copyright 2024 The Kubernetes Authors.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: 2026

@@ -0,0 +1,275 @@
/*
Copyright 2024 The Kubernetes Authors.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: 2026

@metal3-io-bot metal3-io-bot added the lgtm Indicates that a PR is ready to be merged. label Aug 19, 2026
Add comprehensive Prometheus metrics to all CAPM3 controllers for
visibility into reconciliation performance, provisioning workflows,
and error rates.

Metrics added:
- Reconcile counters and duration histograms for all 7 controllers
- BMH association duration tracking
- Machine provisioning duration (creation to Ready)
- Phase transition counters
- Error counters by controller type

Also adds metrics documentation with example PromQL queries and
alerting rules.

Signed-off-by: Maximilian Rink <maximilian.rink@telekom.de>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@metal3-io-bot metal3-io-bot removed the lgtm Indicates that a PR is ready to be merged. label Aug 28, 2026
@metal3-io-bot

Copy link
Copy Markdown
Contributor

New changes are detected. LGTM label has been removed.

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. do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants