-
Notifications
You must be signed in to change notification settings - Fork 399
MON-4115: expose label metrics for jobs and cronjobs #2553
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| // DO NOT EDIT THE CONTENT IN THIS FILE. It is automatically generated from the | ||
| // source code for the Cluster Monitoring Operator. Any changes made to this | ||
| // file will be overwritten when the content is re-generated. If you wish to | ||
| // make edits, read the docgen utility instructions in the source code for the | ||
| // CMO. | ||
| :_content-type: ASSEMBLY | ||
|
|
||
| == ResourceLabels | ||
|
|
||
| === Description | ||
|
|
||
| The `ResourceLabels` resource defines which Kubernetes labels to expose as metrics for a given resource type. | ||
|
|
||
| === Required | ||
| * `resource` | ||
| * `labels` | ||
|
|
||
|
|
||
| Appears in: link:kubestatemetricsconfig.adoc[KubeStateMetricsConfig] | ||
|
|
||
| [options="header"] | ||
| |=== | ||
| | Property | Type | Description | ||
| |resource|string|Defines the Kubernetes resource name (for example, `jobs` or `cronjobs`). | ||
|
|
||
| |labels|[]string|Defines the list of Kubernetes labels to expose as metrics for this resource. Use `*` to expose all labels. | ||
|
|
||
| |=== | ||
|
|
||
| link:../index.adoc[Back to TOC] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -363,9 +363,50 @@ func NewConfigFromString(content string) (*Config, error) { | |
| ) | ||
| } | ||
|
|
||
| // Validate additional resource labels for KSM. | ||
| if err := validateAdditionalResourceLabels(c.ClusterMonitoringConfiguration.KubeStateMetricsConfig); err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| return &c, nil | ||
| } | ||
|
|
||
| var supportedResourceLabelsResources = []string{"jobs", "cronjobs"} | ||
|
|
||
| func validateAdditionalResourceLabels(ksm *KubeStateMetricsConfig) error { | ||
| if ksm == nil { | ||
| return nil | ||
| } | ||
|
|
||
| seenResources := map[string]bool{} | ||
| for _, rl := range ksm.AdditionalResourceLabels { | ||
| if rl.Resource == "" { | ||
| return fmt.Errorf("%w: additionalResourceLabels: resource name must not be empty", ErrConfigValidation) | ||
| } | ||
| if !slices.Contains(supportedResourceLabelsResources, rl.Resource) { | ||
| return fmt.Errorf("%w: additionalResourceLabels: unsupported resource %q, supported resources are: %v", ErrConfigValidation, rl.Resource, supportedResourceLabelsResources) | ||
| } | ||
| if seenResources[rl.Resource] { | ||
| return fmt.Errorf("%w: additionalResourceLabels: duplicate resource %q", ErrConfigValidation, rl.Resource) | ||
| } | ||
| seenResources[rl.Resource] = true | ||
| if len(rl.Labels) == 0 { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we also check for non-empty values?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added checks for empty and duplicate non-empty labels. |
||
| return fmt.Errorf("%w: additionalResourceLabels: resource %q must have at least one label", ErrConfigValidation, rl.Resource) | ||
| } | ||
| if slices.Contains(rl.Labels, "") { | ||
| return fmt.Errorf("%w: additionalResourceLabels: resource %q has an empty label value", ErrConfigValidation, rl.Resource) | ||
| } | ||
| seenLabels := map[string]bool{} | ||
| for _, l := range rl.Labels { | ||
| if seenLabels[l] { | ||
| return fmt.Errorf("%w: additionalResourceLabels: resource %q has duplicate label %q", ErrConfigValidation, rl.Resource, l) | ||
| } | ||
| seenLabels[l] = true | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func (c *Config) applyDefaults() { | ||
| if c.Images == nil { | ||
| c.Images = &Images{} | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -182,6 +182,16 @@ type DedicatedServiceMonitors struct { | |
| Enabled bool `json:"enabled,omitempty"` | ||
| } | ||
|
|
||
| // The `ResourceLabels` resource defines which Kubernetes labels to expose | ||
| // as metrics for a given resource type. | ||
| type ResourceLabels struct { | ||
| // Defines the Kubernetes resource name (for example, `jobs` or `cronjobs`). | ||
| Resource string `json:"resource"` | ||
| // Defines the list of Kubernetes labels to expose as metrics for this | ||
| // resource. Use `*` to expose all labels. | ||
| Labels []string `json:"labels"` | ||
| } | ||
|
|
||
| // The `KubeStateMetricsConfig` resource defines settings for the | ||
| // `kube-state-metrics` agent. | ||
| type KubeStateMetricsConfig struct { | ||
|
|
@@ -193,6 +203,11 @@ type KubeStateMetricsConfig struct { | |
| Tolerations []v1.Toleration `json:"tolerations,omitempty"` | ||
| // Defines a pod's topology spread constraints. | ||
| TopologySpreadConstraints []v1.TopologySpreadConstraint `json:"topologySpreadConstraints,omitempty"` | ||
| // Defines additional resource labels to expose as metrics in addition to | ||
| // 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"` | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please note, this was renamed from |
||
| } | ||
|
|
||
| // The `PrometheusK8sConfig` resource defines settings for the Prometheus | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)