Skip to content

Add metrics for APIBinding and APIExport usage data#4147

Open
Elbehery wants to merge 5 commits into
kcp-dev:mainfrom
Elbehery:20260521_extend_metrics_usage_data
Open

Add metrics for APIBinding and APIExport usage data#4147
Elbehery wants to merge 5 commits into
kcp-dev:mainfrom
Elbehery:20260521_extend_metrics_usage_data

Conversation

@Elbehery
Copy link
Copy Markdown

Implements the metrics proposed in #4041. Adds five new Prometheus metrics to improve
observability of APIBinding and APIExport lifecycle and health, following the same
patterns already used for kcp_workspace_count and kcp_logicalcluster_count.

All metrics are system-wide aggregates with no per-resource labels to avoid cardinality
explosion.

New metrics

Metric Type Labels Description
kcp_apibinding_phase Gauge phase Number of APIBindings in each phase (Binding, Bound, or empty for newly created)
kcp_apibinding_condition_status Gauge condition, status Number of APIBindings with each condition type and status (True/False/Unknown)
kcp_apibinding_ready_duration_ms Histogram Milliseconds from APIBinding creation to reaching the Bound phase
kcp_apiexport_condition_status Gauge condition, status Number of APIExports with each condition type and status
kcp_apiexport_ready_duration_ms Histogram Milliseconds from APIExport creation to becoming fully operational (IdentityValid=True and VirtualWorkspaceURLsReady=True)

Implementation

  • Phase and condition state is tracked per resource key in a sync.Mutex-protected map
    in each controller; on update only the diff is applied to the gauges.
  • Histogram observations are idempotent — each resource contributes exactly one sample
    (guarded by a phase-transition check for bindings, a readyAPIExports set for exports)
    so controller restarts do not double-count.
  • Each metric is introduced in its own commit with unit tests covering add, update,
    delete, and concurrency cases.

cc @mjudeikis @ntnn @SimonTheLeg

@kcp-ci-bot
Copy link
Copy Markdown
Contributor

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

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.

@kcp-ci-bot kcp-ci-bot added the do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label May 22, 2026
@kcp-ci-bot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign mjudeikis 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

@kcp-ci-bot kcp-ci-bot added do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels May 22, 2026
@kcp-ci-bot
Copy link
Copy Markdown
Contributor

Hi @Elbehery. Thanks for your PR.

I'm waiting for a kcp-dev 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.

@kcp-ci-bot kcp-ci-bot added the dco-signoff: no Indicates the PR's author has not signed the DCO. label May 22, 2026
Elbehery added 5 commits May 22, 2026 12:45
Track the number of APIBindings in each phase (Binding, Bound, or empty
for newly created) via a system-wide GaugeVec with a single "phase"
label. Phase transitions are tracked in the apibinding controller event
handlers using a per-key map protected by a mutex, following the same
pattern used for kcp_workspace_count.

Signed-off-by: elbehery <elbeherymustafa@gmail.com>
Track the number of APIBindings with each condition type and status
(True, False, Unknown) via a GaugeVec with "condition" and "status"
labels. Per-binding condition snapshots are maintained in the controller
and diffed on update to keep the gauges accurate without cardinality
explosion from per-resource labels.

Signed-off-by: elbehery <elbeherymustafa@gmail.com>
Record the time in milliseconds from APIBinding creation to reaching the
Bound phase as a histogram. The observation is taken once in the phase
update handler on the Bound transition, so each binding contributes
exactly one sample. Buckets cover the expected range from sub-second to
5 minutes.

Signed-off-by: elbehery <elbeherymustafa@gmail.com>
Track the number of APIExports with each condition type and status
(True, False, Unknown) via a GaugeVec with "condition" and "status"
labels. Per-export condition snapshots are maintained in the apiexport
controller and diffed on update to keep the gauges accurate, mirroring
the approach used for kcp_apibinding_condition_status.

Signed-off-by: elbehery <elbeherymustafa@gmail.com>
Record the time in milliseconds from APIExport creation to becoming
fully operational (IdentityValid=True and VirtualWorkspaceURLsReady=True
both set) as a histogram. Each export contributes exactly one sample,
tracked via a per-key set that is cleaned up on delete. Buckets cover
the same range as the apibinding counterpart.

Signed-off-by: elbehery <elbeherymustafa@gmail.com>
@Elbehery Elbehery force-pushed the 20260521_extend_metrics_usage_data branch from 510e2d3 to 01b37f4 Compare May 22, 2026 10:45
@kcp-ci-bot kcp-ci-bot added dco-signoff: yes Indicates the PR's author has signed the DCO. and removed dco-signoff: no Indicates the PR's author has not signed the DCO. labels May 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the DCO. do-not-merge/needs-kind Indicates a PR lacks a `kind/foo` label and requires one. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. needs-ok-to-test Indicates a PR that requires an org member to verify it 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.

2 participants