Skip to content

MON-4115: expose label metrics for jobs and cronjobs#2553

Open
rexagod wants to merge 2 commits intoopenshift:mainfrom
rexagod:MON-4115
Open

MON-4115: expose label metrics for jobs and cronjobs#2553
rexagod wants to merge 2 commits intoopenshift:mainfrom
rexagod:MON-4115

Conversation

@rexagod
Copy link
Copy Markdown
Member

@rexagod rexagod commented Jan 8, 2025

Adds jobs and cronjobs to the exposed set of label metrics, i.e., --metric-labels-allowlist=pods=[*],nodes=[*],namespaces=[*],persistentvolumes=[*],persistentvolumeclaims=[*],poddisruptionbudgets=[*],jobs=[*],cronjobs=[*] by introducing a wrapper AdditionalResourceLabels field (see #2553 (comment) for details).

  • I added CHANGELOG entry for this change.
  • No user facing changes, so no entry in CHANGELOG was needed.

The linked issue is a feature request by a customer that requested these metrics to build their dashboards. I'm not sure what the qualifying factors were for the inclusion of the existing set of exposed label metrics --metric-labels-allowlist=pods=[*],nodes=[*],namespaces=[*],persistentvolumes=[*],persistentvolumeclaims=[*],poddisruptionbudgets=[*], but I'm assuming we do so when there's an explicit and reasonable request to expose them.

Nonetheless, I've opened this PR to set a ground for discussion if we want to incorporate this, or not.


TODO: Introduce this field in openshift/api#2778 once this is in.

@openshift-ci-robot
Copy link
Copy Markdown
Contributor

openshift-ci-robot commented Jan 8, 2025

@rexagod: This pull request references MON-4115 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the feature request to target the "4.19.0" version, but no target version was set.

Details

In response to this:

Adds jobs and cronjobs to the exposed set of label metrics:

  • --metric-labels-allowlist=pods=[*],nodes=[*],namespaces=[*],persistentvolumes=[*],persistentvolumeclaims=[*],poddisruptionbudgets=[*],jobs=[*],cronjobs=[*]
  • I added CHANGELOG entry for this change.
  • No user facing changes, so no entry in CHANGELOG was needed.

The linked issue is a feature request by a customer that requested these metrics to build their dashboards. I'm not sure what the qualifying factors were for the inclusion of the existing set of exposed label metrics --metric-labels-allowlist=pods=[*],nodes=[*],namespaces=[*],persistentvolumes=[*],persistentvolumeclaims=[*],poddisruptionbudgets=[*], but I'm assuming we do so when there's an explicit and reasonable request to expose them.

Nonetheless, I've opened this PR to set a ground for discussion if we want to incorporate this, or not.

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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-ci-robot openshift-ci-robot added the jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. label Jan 8, 2025
@openshift-ci openshift-ci bot requested review from danielmellado and jan--f January 8, 2025 11:37
@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 8, 2025
@rexagod
Copy link
Copy Markdown
Member Author

rexagod commented Jan 8, 2025

/jira refresh

@openshift-ci-robot
Copy link
Copy Markdown
Contributor

openshift-ci-robot commented Jan 8, 2025

@rexagod: This pull request references MON-4115 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the feature request to target the "4.19.0" version, but no target version was set.

Details

In response to this:

/jira refresh

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 openshift-eng/jira-lifecycle-plugin repository.

@rexagod
Copy link
Copy Markdown
Member Author

rexagod commented Jan 8, 2025

/jira refresh

@openshift-ci-robot
Copy link
Copy Markdown
Contributor

openshift-ci-robot commented Jan 8, 2025

@rexagod: This pull request references MON-4115 which is a valid jira issue.

Details

In response to this:

/jira refresh

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 openshift-eng/jira-lifecycle-plugin repository.

@rexagod rexagod force-pushed the MON-4115 branch 3 times, most recently from c25eb30 to 7ad69ad Compare January 8, 2025 22:07
@juzhao
Copy link
Copy Markdown
Contributor

juzhao commented Jan 9, 2025

/retest-required

@rexagod
Copy link
Copy Markdown
Member Author

rexagod commented Jan 9, 2025

I'm having some issues running make generate on macOS, it's a gift that keeps giving.

@juzhao
Copy link
Copy Markdown
Contributor

juzhao commented Jan 26, 2025

/retest

@juzhao
Copy link
Copy Markdown
Contributor

juzhao commented Jan 29, 2025

/label qe-approved

@openshift-ci openshift-ci bot added the qe-approved Signifies that QE has signed off on this PR label Jan 29, 2025
@openshift-ci-robot
Copy link
Copy Markdown
Contributor

openshift-ci-robot commented Jan 29, 2025

@rexagod: This pull request references MON-4115 which is a valid jira issue.

Details

In response to this:

Adds jobs and cronjobs to the exposed set of label metrics:

  • --metric-labels-allowlist=pods=[*],nodes=[*],namespaces=[*],persistentvolumes=[*],persistentvolumeclaims=[*],poddisruptionbudgets=[*],jobs=[*],cronjobs=[*]
  • I added CHANGELOG entry for this change.
  • No user facing changes, so no entry in CHANGELOG was needed.

The linked issue is a feature request by a customer that requested these metrics to build their dashboards. I'm not sure what the qualifying factors were for the inclusion of the existing set of exposed label metrics --metric-labels-allowlist=pods=[*],nodes=[*],namespaces=[*],persistentvolumes=[*],persistentvolumeclaims=[*],poddisruptionbudgets=[*], but I'm assuming we do so when there's an explicit and reasonable request to expose them.

Nonetheless, I've opened this PR to set a ground for discussion if we want to incorporate this, or not.

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 openshift-eng/jira-lifecycle-plugin repository.

@machine424
Copy link
Copy Markdown
Contributor

left a comment on the ticket.

@rexagod
Copy link
Copy Markdown
Member Author

rexagod commented Apr 10, 2025

[from the f2f] @machine424 suggested we have the default allowlist, in addition to a set of "allowed" resources that the users could choose to enable from. The allowlist itself will thus be customizable from CMO's config.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 10, 2025
@openshift-merge-robot openshift-merge-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 8, 2025
@rexagod
Copy link
Copy Markdown
Member Author

rexagod commented Jul 8, 2025

Support extending the labels-allowlist based on this discussion.

@openshift-merge-robot openshift-merge-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Sep 16, 2025
@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 1, 2026
// the default labels. Currently, only `jobs` and `cronjobs` resources are
// supported due to cardinality concerns. Each entry specifies a resource
// name and a list of label names (use `*` to expose all labels).
AdditionalResourceLabels []ResourceLabels `json:"additionalResourceLabels,omitempty"`
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Please note, this was renamed from AdditionalLabelsAllowList to this.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
pkg/manifests/manifests.go (1)

791-802: Mutate the deployment args directly instead of the ranged copy.

This works today only because the copied container.Args slice still aliases the live deployment args. That’s easy to break later with an append or re-slice and hard to spot in review.

Suggested refactor
 			additionalResourceLabels := f.config.ClusterMonitoringConfiguration.KubeStateMetricsConfig.AdditionalResourceLabels
 			if len(additionalResourceLabels) > 0 {
-				for j := range container.Args {
-					if strings.HasPrefix(container.Args[j], "--metric-labels-allowlist=") {
-						var parts []string
-						for _, rl := range additionalResourceLabels {
-							parts = append(parts, fmt.Sprintf("%s=[%s]", rl.Resource, strings.Join(rl.Labels, ",")))
-						}
-						container.Args[j] += "," + strings.Join(parts, ",")
-					}
-				}
+				parts := make([]string, 0, len(additionalResourceLabels))
+				for _, rl := range additionalResourceLabels {
+					parts = append(parts, fmt.Sprintf("%s=[%s]", rl.Resource, strings.Join(rl.Labels, ",")))
+				}
+
+				args := d.Spec.Template.Spec.Containers[i].Args
+				for j := range args {
+					if strings.HasPrefix(args[j], "--metric-labels-allowlist=") {
+						args[j] += "," + strings.Join(parts, ",")
+						break
+					}
+				}
+				d.Spec.Template.Spec.Containers[i].Args = args
 			}

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 59d001fb-5b7a-46cb-be1c-050ffcbf0f1b

📥 Commits

Reviewing files that changed from the base of the PR and between 58b8caa and 24b8d6b.

📒 Files selected for processing (9)
  • Documentation/api.md
  • Documentation/openshiftdocs/index.adoc
  • Documentation/openshiftdocs/modules/kubestatemetricsconfig.adoc
  • Documentation/openshiftdocs/modules/resourcelabels.adoc
  • pkg/manifests/config.go
  • pkg/manifests/config_test.go
  • pkg/manifests/manifests.go
  • pkg/manifests/manifests_test.go
  • pkg/manifests/types.go
✅ Files skipped from review due to trivial changes (2)
  • Documentation/openshiftdocs/index.adoc
  • Documentation/openshiftdocs/modules/resourcelabels.adoc
🚧 Files skipped from review as they are similar to previous changes (2)
  • Documentation/openshiftdocs/modules/kubestatemetricsconfig.adoc
  • pkg/manifests/config_test.go

@rexagod
Copy link
Copy Markdown
Member Author

rexagod commented Apr 1, 2026

/test golangci-lint

@rexagod
Copy link
Copy Markdown
Member Author

rexagod commented Apr 2, 2026

/retest-required

Adds `AdditionalResourceLabels` to KSM config. This works as follows:
```
additionalResourceLabels:
- resource: jobs
  labels:
  - foo
  - bar
 - resource: cronjobs
   labels:
   - *
```

Signed-off-by: Pranshu Srivastava <rexagod@gmail.com>
@rexagod
Copy link
Copy Markdown
Member Author

rexagod commented Apr 2, 2026

Updated commit and PR descriptions to reflect the newer field name.

@openshift-ci-robot
Copy link
Copy Markdown
Contributor

openshift-ci-robot commented Apr 2, 2026

@rexagod: This pull request references MON-4115 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the feature request to target either version "4.22." or "openshift-4.22.", but it targets "openshift-5.0" instead.

Details

In response to this:

Adds jobs and cronjobs to the exposed set of label metrics, i.e., --metric-labels-allowlist=pods=[*],nodes=[*],namespaces=[*],persistentvolumes=[*],persistentvolumeclaims=[*],poddisruptionbudgets=[*],jobs=[*],cronjobs=[*] by introducing a wrapper AdditionalResourceLabels field (see #2553 (comment) for details).

  • I added CHANGELOG entry for this change.
  • No user facing changes, so no entry in CHANGELOG was needed.

The linked issue is a feature request by a customer that requested these metrics to build their dashboards. I'm not sure what the qualifying factors were for the inclusion of the existing set of exposed label metrics --metric-labels-allowlist=pods=[*],nodes=[*],namespaces=[*],persistentvolumes=[*],persistentvolumeclaims=[*],poddisruptionbudgets=[*], but I'm assuming we do so when there's an explicit and reasonable request to expose them.

Nonetheless, I've opened this PR to set a ground for discussion if we want to incorporate this, or not.

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 openshift-eng/jira-lifecycle-plugin repository.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
pkg/manifests/manifests.go (1)

791-802: Mutate deployment args directly instead of relying on range-copy aliasing.

This block mutates container.Args from the range variable copy. It works today because of slice aliasing, but it’s fragile and harder to maintain. Write back through d.Spec.Template.Spec.Containers[i].Args explicitly.

Suggested refactor
 			additionalResourceLabels := f.config.ClusterMonitoringConfiguration.KubeStateMetricsConfig.AdditionalResourceLabels
 			if len(additionalResourceLabels) > 0 {
-				for j := range container.Args {
-					if strings.HasPrefix(container.Args[j], "--metric-labels-allowlist=") {
-						var parts []string
-						for _, rl := range additionalResourceLabels {
-							parts = append(parts, fmt.Sprintf("%s=[%s]", rl.Resource, strings.Join(rl.Labels, ",")))
-						}
-						container.Args[j] += "," + strings.Join(parts, ",")
-					}
-				}
+				var parts []string
+				for _, rl := range additionalResourceLabels {
+					parts = append(parts, fmt.Sprintf("%s=[%s]", rl.Resource, strings.Join(rl.Labels, ",")))
+				}
+
+				args := d.Spec.Template.Spec.Containers[i].Args
+				for j := range args {
+					if strings.HasPrefix(args[j], "--metric-labels-allowlist=") {
+						args[j] += "," + strings.Join(parts, ",")
+						break
+					}
+				}
+				d.Spec.Template.Spec.Containers[i].Args = args
 			}

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository YAML (base), Organization UI (inherited)

Review profile: CHILL

Plan: Pro

Run ID: 000b3f8e-c9b1-4bee-b54c-0b9e5c0cb35e

📥 Commits

Reviewing files that changed from the base of the PR and between 24b8d6b and 38c3c3a.

📒 Files selected for processing (9)
  • Documentation/api.md
  • Documentation/openshiftdocs/index.adoc
  • Documentation/openshiftdocs/modules/kubestatemetricsconfig.adoc
  • Documentation/openshiftdocs/modules/resourcelabels.adoc
  • pkg/manifests/config.go
  • pkg/manifests/config_test.go
  • pkg/manifests/manifests.go
  • pkg/manifests/manifests_test.go
  • pkg/manifests/types.go
✅ Files skipped from review due to trivial changes (4)
  • Documentation/openshiftdocs/modules/resourcelabels.adoc
  • pkg/manifests/config_test.go
  • Documentation/openshiftdocs/index.adoc
  • pkg/manifests/config.go
🚧 Files skipped from review as they are similar to previous changes (3)
  • Documentation/openshiftdocs/modules/kubestatemetricsconfig.adoc
  • pkg/manifests/types.go
  • pkg/manifests/manifests_test.go

Comment on lines +562 to +568
#### Description

The `ResourceLabels` resource defines which Kubernetes labels to expose as metrics for a given resource type.

#### Required
- ` resource `
- ` labels `
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Fix heading increment for markdownlint compliance.

Line 562 uses #### directly under a ## section, which triggers MD001. Since this file is generated, update the source code comments/templates so this renders as ### (and same for the paired “Required” heading).

🧰 Tools
🪛 markdownlint-cli2 (0.22.0)

[warning] 562-562: Heading levels should only increment by one level at a time
Expected: h3; Actual: h4

(MD001, heading-increment)


d, err := f.KubeStateMetricsDeployment()
if err != nil {
t.Fatal(err)
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.

(nit) can we use require.NoError(t, err) which is less verbose? Same for the other calls to t.Fatal(f).

return fmt.Errorf("%w: additionalResourceLabels: duplicate resource %q", ErrConfigValidation, rl.Resource)
}
seen[rl.Resource] = true
if len(rl.Labels) == 0 {
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.

should we also check for non-empty values?

Copy link
Copy Markdown
Member Author

@rexagod rexagod Apr 2, 2026

Choose a reason for hiding this comment

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

Added checks for empty and duplicate non-empty labels.

@rexagod
Copy link
Copy Markdown
Member Author

rexagod commented Apr 2, 2026

TODO: Introduce this field in openshift/api#2778 once this is in.

@openshift-ci-robot
Copy link
Copy Markdown
Contributor

openshift-ci-robot commented Apr 2, 2026

@rexagod: This pull request references MON-4115 which is a valid jira issue.

Warning: The referenced jira issue has an invalid target version for the target branch this PR targets: expected the feature request to target either version "4.22." or "openshift-4.22.", but it targets "openshift-5.0" instead.

Details

In response to this:

Adds jobs and cronjobs to the exposed set of label metrics, i.e., --metric-labels-allowlist=pods=[*],nodes=[*],namespaces=[*],persistentvolumes=[*],persistentvolumeclaims=[*],poddisruptionbudgets=[*],jobs=[*],cronjobs=[*] by introducing a wrapper AdditionalResourceLabels field (see #2553 (comment) for details).

  • I added CHANGELOG entry for this change.
  • No user facing changes, so no entry in CHANGELOG was needed.

The linked issue is a feature request by a customer that requested these metrics to build their dashboards. I'm not sure what the qualifying factors were for the inclusion of the existing set of exposed label metrics --metric-labels-allowlist=pods=[*],nodes=[*],namespaces=[*],persistentvolumes=[*],persistentvolumeclaims=[*],poddisruptionbudgets=[*], but I'm assuming we do so when there's an explicit and reasonable request to expose them.

Nonetheless, I've opened this PR to set a ground for discussion if we want to incorporate this, or not.


TODO: Introduce this field in openshift/api#2778 once this is in.

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 openshift-eng/jira-lifecycle-plugin repository.

@rexagod
Copy link
Copy Markdown
Member Author

rexagod commented Apr 2, 2026

/jira refresh

@openshift-ci-robot
Copy link
Copy Markdown
Contributor

openshift-ci-robot commented Apr 2, 2026

@rexagod: This pull request references MON-4115 which is a valid jira issue.

Details

In response to this:

/jira refresh

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 openshift-eng/jira-lifecycle-plugin repository.

Copy link
Copy Markdown
Contributor

@simonpasquier simonpasquier left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Apr 2, 2026
@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 2, 2026

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: rexagod, simonpasquier

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:
  • OWNERS [rexagod,simonpasquier]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@simonpasquier
Copy link
Copy Markdown
Contributor

/test e2e-aws-ovn-techpreview

1 similar comment
@simonpasquier
Copy link
Copy Markdown
Contributor

/test e2e-aws-ovn-techpreview

@rexagod
Copy link
Copy Markdown
Member Author

rexagod commented Apr 7, 2026

/verified by tests

@openshift-ci-robot openshift-ci-robot added the verified Signifies that the PR passed pre-merge verification criteria label Apr 7, 2026
@openshift-ci-robot
Copy link
Copy Markdown
Contributor

@rexagod: This PR has been marked as verified by tests.

Details

In response to this:

/verified by tests

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 openshift-eng/jira-lifecycle-plugin repository.

@openshift-merge-bot
Copy link
Copy Markdown
Contributor

/retest-required

Remaining retests: 0 against base HEAD 2e2c0aa and 2 for PR HEAD 3c57aca in total

@openshift-merge-bot
Copy link
Copy Markdown
Contributor

/retest-required

Remaining retests: 0 against base HEAD f6a7969 and 1 for PR HEAD 3c57aca in total

@rexagod
Copy link
Copy Markdown
Member Author

rexagod commented Apr 9, 2026

/test e2e-aws-ovn-techpreview

@openshift-ci
Copy link
Copy Markdown
Contributor

openshift-ci bot commented Apr 9, 2026

@rexagod: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
ci/prow/e2e-hypershift-conformance 3c57aca link unknown /test e2e-hypershift-conformance

Full PR test history. Your PR dashboard.

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. I understand the commands that are listed here.

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. jira/valid-reference Indicates that this PR references a valid Jira ticket of any type. lgtm Indicates that a PR is ready to be merged. qe-approved Signifies that QE has signed off on this PR verified Signifies that the PR passed pre-merge verification criteria

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants