-
Notifications
You must be signed in to change notification settings - Fork 585
Add prometheusConfig API #2653
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
base: master
Are you sure you want to change the base?
Add prometheusConfig API #2653
Conversation
This commit introduces a new API to be introduced as a part of the migration in CMO from ConfigMap to CRDs Signed-off-by: Mario Fernandez <[email protected]> Signed-off-by: Daniel Mellado <[email protected]>
|
Pipeline controller notification For optional jobs, comment This repository is configured in: LGTM mode |
|
Hello @marioferh! Some important instructions when contributing to openshift/api: |
|
Note Reviews pausedUse the following commands to manage reviews:
📝 WalkthroughWalkthroughThis pull request introduces comprehensive Prometheus platform configuration capabilities to the cluster monitoring API. It adds multiple new public types for Prometheus settings, including support for remote write endpoints, TLS configuration, authorization, metric relabeling, retention policies, and scheduling constraints. The changes include auto-generated implementations for deep-copy operations and OpenAPI/Swagger documentation. Three ClusterMonitoring CRD variants are updated with a new prometheusConfig field, and Alertmanager volumeClaimTemplate descriptions are refined across all CRD files. 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.5.0)Error: build linters: unable to load custom analyzer "kubeapilinter": tools/_output/bin/kube-api-linter.so, plugin: not implemented Comment |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
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.
Actionable comments posted: 5
🤖 Fix all issues with AI agents
In `@config/v1alpha1/types_cluster_monitoring.go`:
- Around line 734-736: The RelabelAction enum is missing valid Prometheus
actions (Lowercase, Uppercase, KeepEqual, DropEqual) referenced by the
RelabelConfig XValidation rules; update the RelabelAction enum to include these
four values and ensure the RelabelConfig.action field documentation (and any
comment on targetLabel) lists them so the enum validation and XValidation rules
align with each other and with Prometheus semantics.
In `@openapi/generated_openapi/zz_generated.openapi.go`:
- Around line 24259-24333: The RelabelConfig OpenAPI definition generated in
function schema_openshift_api_config_v1alpha1_RelabelConfig has an incomplete
"action" description; update the description string for the "action" property to
list all 11 valid Prometheus actions (Replace, Keep, Drop, HashMod, LabelMap,
LabelDrop, LabelKeep, Lowercase, Uppercase, KeepEqual, DropEqual) and then
regenerate the OpenAPI output from the canonical source type so the change
persists; verify and correct the source Go type or its swagger tags that define
RelabelConfig's Action documentation before re-running the generator.
In
`@payload-manifests/crds/0000_10_config-operator_01_clustermonitorings-CustomNoUpgrade.crd.yaml`:
- Around line 1803-1811: The action enum for RelabelConfig currently lists
Replace, Keep, Drop, HashMod, LabelMap, LabelDrop, LabelKeep but the targetLabel
description and its validation rule mention Lowercase, Uppercase, KeepEqual,
DropEqual; update either the enum or the docs/validation so they match: either
add the missing actions (Lowercase, Uppercase, KeepEqual, DropEqual) to the
action enum or remove/replace those action names from the targetLabel
description and the validation pattern so they only reference the existing enum
values; locate the enum block named "action" and the "targetLabel"
description/validation in this CRD and make the change consistently across both
sections.
In
`@payload-manifests/crds/0000_10_config-operator_01_clustermonitorings-DevPreviewNoUpgrade.crd.yaml`:
- Around line 1803-1811: The CRD's action enum for the field named "action" is
missing values referenced elsewhere (Lowercase, Uppercase, KeepEqual,
DropEqual), causing an enum/validation/description mismatch; fix by either
adding those four values to the action enum (so enum contains Replace, Keep,
Drop, HashMod, LabelMap, LabelDrop, LabelKeep, Lowercase, Uppercase, KeepEqual,
DropEqual) or by removing all references to those four actions from the
validation rule and the description text that mentions them; update the enum
block for "action" and the corresponding validation rule/description (the same
section around the existing action enum and the validation referenced)
consistently so they match, and repeat the same change for the other occurrence
noted (the block spanning lines ~1873-1894).
In
`@payload-manifests/crds/0000_10_config-operator_01_clustermonitorings-TechPreviewNoUpgrade.crd.yaml`:
- Around line 1803-1894: The action enum for the relabel configuration is
missing four valid Prometheus actions; update the enum under the "action" field
to include "Lowercase", "Uppercase", "KeepEqual", and "DropEqual" so those
values are accepted by validation. Edit the enum list (the token named action in
this CRD) to append these four strings and leave the existing
x-kubernetes-validations rules (the rule that requires targetLabel for Replace,
HashMod, Lowercase, Uppercase, KeepEqual, DropEqual and the replacement rule)
intact so targetLabel and replacement semantics continue to be enforced.
🧹 Nitpick comments (3)
openapi/openapi.json (3)
4575-4587: Consider encodingAcceptRisk.namelength constraints in schema.The description calls out non-empty and ≤256 chars, but the schema doesn’t enforce
minLength/maxLength. If you want API-server validation, add kubebuilder validation tags on the Go type so OpenAPI reflects the constraint.
12164-12208: Add schema validation for documented constraints (scheme/pathPrefix/staticConfigs).The doc specifies allowed values and structural constraints (e.g., scheme values, pathPrefix format, staticConfigs min/max), but the schema doesn’t encode them. If you want server-side validation, add kubebuilder
Enum,Pattern, andMinItems/MaxItemstags in the Go types so OpenAPI enforces these rules.
13178-13380: Align schema validation with documented constraints.Several fields document enums or size limits (e.g.,
collectionProfile,logLevel,externalLabels,remoteWrite,tolerations,topologySpreadConstraints), but the schema doesn’t encode those rules. If enforcement is intended, add kubebuilder validations to the Go types so the OpenAPI includesenum,minItems/maxItems, and relevantmin/maxconstraints.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Cache: Disabled due to data retention organization setting
Knowledge base: Disabled due to data retention organization setting
⛔ Files ignored due to path filters (4)
config/v1alpha1/zz_generated.crd-manifests/0000_10_config-operator_01_clustermonitorings-CustomNoUpgrade.crd.yamlis excluded by!**/zz_generated.crd-manifests/*config/v1alpha1/zz_generated.crd-manifests/0000_10_config-operator_01_clustermonitorings-DevPreviewNoUpgrade.crd.yamlis excluded by!**/zz_generated.crd-manifests/*config/v1alpha1/zz_generated.crd-manifests/0000_10_config-operator_01_clustermonitorings-TechPreviewNoUpgrade.crd.yamlis excluded by!**/zz_generated.crd-manifests/*config/v1alpha1/zz_generated.featuregated-crd-manifests/clustermonitorings.config.openshift.io/ClusterMonitoringConfig.yamlis excluded by!**/zz_generated.featuregated-crd-manifests/**
📒 Files selected for processing (8)
config/v1alpha1/types_cluster_monitoring.goconfig/v1alpha1/zz_generated.deepcopy.goconfig/v1alpha1/zz_generated.swagger_doc_generated.goopenapi/generated_openapi/zz_generated.openapi.goopenapi/openapi.jsonpayload-manifests/crds/0000_10_config-operator_01_clustermonitorings-CustomNoUpgrade.crd.yamlpayload-manifests/crds/0000_10_config-operator_01_clustermonitorings-DevPreviewNoUpgrade.crd.yamlpayload-manifests/crds/0000_10_config-operator_01_clustermonitorings-TechPreviewNoUpgrade.crd.yaml
🧰 Additional context used
🧬 Code graph analysis (3)
config/v1alpha1/zz_generated.deepcopy.go (2)
config/v1alpha1/types_cluster_monitoring.go (10)
AdditionalAlertmanagerConfig(615-676)TLSConfig(814-842)AuthorizationConfig(869-882)PrometheusConfig(434-601)Label(679-693)RemoteWriteSpec(696-732)ContainerResource(305-335)Retention(907-928)RelabelConfig(737-807)SecretKeySelector(886-903)config/v1alpha1/zz_generated.swagger_doc_generated.go (10)
AdditionalAlertmanagerConfig(132-134)TLSConfig(333-335)AuthorizationConfig(176-178)PrometheusConfig(273-275)Label(238-240)RemoteWriteSpec(300-302)ContainerResource(228-230)Retention(310-312)RelabelConfig(288-290)SecretKeySelector(320-322)
config/v1alpha1/types_cluster_monitoring.go (1)
config/v1alpha1/zz_generated.swagger_doc_generated.go (5)
PrometheusConfig(273-275)AdditionalAlertmanagerConfig(132-134)Label(238-240)Retention(310-312)SecretKeySelector(320-322)
config/v1alpha1/zz_generated.swagger_doc_generated.go (1)
config/v1alpha1/types_cluster_monitoring.go (9)
AdditionalAlertmanagerConfig(615-676)AuthorizationConfig(869-882)Label(679-693)PrometheusConfig(434-601)RelabelConfig(737-807)RemoteWriteSpec(696-732)Retention(907-928)SecretKeySelector(886-903)TLSConfig(814-842)
🔇 Additional comments (54)
config/v1alpha1/zz_generated.deepcopy.go (1)
1-1274: Autogenerated deep copy implementations look correct.This file is marked as autogenerated (
Code generated by codegen. DO NOT EDIT.). The deep copy semantics are correctly implemented:
- Slices of structs with nested pointers/slices (e.g.,
AdditionalAlertmanagerConfigs,RemoteWrite,WriteRelabelConfigs) use element-wiseDeepCopyInto- Slices of value types (e.g.,
ExternalLabels,StaticConfigs) usecopy()- Pointer fields (e.g.,
Replacement *string,VolumeClaimTemplate *PVC) are properly allocated and deep copied- Value-only structs (e.g.,
Retention,SecretKeySelector,TLSConfig) correctly use shallow copypayload-manifests/crds/0000_10_config-operator_01_clustermonitorings-TechPreviewNoUpgrade.crd.yaml (4)
455-456: Description refinement looks good.The updated description appropriately focuses on the practical configuration aspects (storage class and volume size) while removing redundant "This field is optional." text that's conveyed elsewhere in the schema.
1285-1298: Well-designed API surface for Prometheus configuration.The
prometheusConfigfield provides a comprehensive configuration interface with clear documentation and appropriate defaults. The use ofminProperties: 1ensures the field is meaningful when specified.
1592-1596: Good mutual TLS validation constraint.The CEL rule ensures that
certandkeymust both be specified together for mutual TLS, or both be omitted. This prevents invalid partial configurations.
2259-2668: PrometheusvolumeClaimTemplatemirrors Alertmanager configuration appropriately.The schema for Prometheus persistent storage follows the same pattern as
alertmanagerConfig.volumeClaimTemplate, ensuring consistent UX across the API. The description correctly notes that data will not persist without this configuration.payload-manifests/crds/0000_10_config-operator_01_clustermonitorings-CustomNoUpgrade.crd.yaml (4)
455-456: LGTM!The updated description is clearer and more actionable, guiding users on what the field configures.
1300-1606: Well-designed additional Alertmanager configuration.The
additionalAlertmanagerConfigsstructure is comprehensive with:
- Proper
x-kubernetes-list-map-keysusingnamefor server-side apply- Consistent secret reference patterns with appropriate validation
- TLS mutual auth validation ensuring cert/key are specified together
- Sensible defaults (HTTP scheme, 10s timeout)
1706-1736: Well-designed queryLogFile path validation.The validation rules effectively prevent security issues:
- Restricts
/dev/paths to only stdout, stderr, and null- Prevents path traversal with
..check- Disallows consecutive slashes and trailing slashes
- Allows both absolute paths and simple filenames
This is a thoughtful security-conscious design.
1285-1298: Comprehensive prometheusConfig API addition.The new
prometheusConfigfield provides extensive customization options for the platform Prometheus instance. The design follows established patterns:
- Consistent validation rules across similar field types
- Proper use of
x-kubernetes-list-type(map for keyed lists, atomic for ordered lists, set for unique items)- Clear default value documentation in descriptions
minProperties: 1ensures meaningful configuration when the field is presentpayload-manifests/crds/0000_10_config-operator_01_clustermonitorings-DevPreviewNoUpgrade.crd.yaml (7)
455-458: LGTM - Description refinement is clear and consistent.The updated description appropriately focuses on the purpose of
volumeClaimTemplatewhile the "If omitted" clause still conveys optionality.
1285-1298: LGTM - Well-structured prometheusConfig introduction.The prometheusConfig field is well-documented with clear use cases (pod scheduling, resource allocation, retention policies, external integrations). The
minProperties: 1constraint correctly ensures at least one property is set when the field is specified.
1300-1606: LGTM - additionalAlertmanagerConfigs is well-designed.Good use of:
- Server-side apply with
x-kubernetes-list-type: mapkeyed byname- CEL validation for mutual TLS (cert and key must both be present or both omitted)
- CEL validation for bearer token requirement based on auth type
- Clever use of
isURL('http://' + self)to validate host:port format in staticConfigs
1986-2016: LGTM - Retention configuration is well-defined.Clear constraints with appropriate ranges (1-365 days for duration, 1-16384 GiB for size). The
minProperties: 1ensures at least one setting is specified when the field is used.
1706-1736: LGTM - queryLogFile validation is comprehensive and security-conscious.The CEL validation rules properly:
- Allow absolute paths or simple filenames
- Restrict
/dev/paths to only stdout/stderr/null- Prevent path traversal with
..and/..checks- Prevent malformed paths with
//and trailing/checks
2259-2264: LGTM - volumeClaimTemplate structure is consistent.The Prometheus volumeClaimTemplate mirrors the Alertmanager volumeClaimTemplate structure, maintaining API consistency across the CRD.
1635-1673: LGTM - externalLabels design supports multi-controller management.Good use of
x-kubernetes-list-type: mapkeyed bykeyallows multiple controllers to independently manage their labels via server-side apply. The constraints (max 50 labels, 128 char limit per key/value) are reasonable.openapi/generated_openapi/zz_generated.openapi.go (10)
22321-22397: LGTM - AdditionalAlertmanagerConfig schema is well-structured.The schema properly defines required fields (
name,staticConfigs) and documents validation constraints in descriptions. The use ofx-kubernetes-list-type: setfor staticConfigs is appropriate for ensuring uniqueness.
22543-22548: LGTM - Improved documentation clarity.The updated description clearly explains the consequence of omitting
volumeClaimTemplate(ephemeral storage, data loss on restarts).
22578-22618: LGTM - AuthorizationConfig uses proper discriminated union pattern.The schema correctly implements the Kubernetes discriminated union pattern with
x-kubernetes-unions, ensuringbearerTokenis only applicable whentypeisBearerToken.
23055-23074: LGTM - prometheusConfig field properly integrated.The field is appropriately optional with a comprehensive description covering scheduling, resources, retention, and external integrations. Dependencies are correctly updated.
23656-23682: LGTM - Label schema is straightforward.Both
keyandvalueare correctly marked as required. Character length constraints documented in descriptions would be enforced via CRD validation markers in the source types.
24057-24257: LGTM - PrometheusConfig schema is comprehensive.The schema covers all expected Prometheus configuration aspects including scheduling (
nodeSelector,tolerations,topologySpreadConstraints), resources, retention, and external integrations (remoteWrite,additionalAlertmanagerConfigs). List types are correctly specified for server-side apply compatibility.
24335-24392: LGTM - RemoteWriteSpec schema is well-defined.The
urlfield is correctly marked as required. ThewriteRelabelConfigsuses map list type withnameas the key, enabling proper server-side apply behavior.
24394-24419: LGTM - Retention schema is appropriately flexible.Both fields are optional with sensible documented defaults (15 days, no size limit). The constraints (1-365 days, 1-16384 GiB) are clearly documented.
24515-24546: LGTM - SecretKeySelector schema is correct.Both
nameandkeyare properly required. Thex-kubernetes-map-type: atomicannotation is appropriate for this reference type, and the namespace scoping (openshift-monitoring) is clearly documented.
24578-24626: No changes needed. The TLSConfig validation constraints described in the schema are properly implemented in the source type definition via kubebuilder markers:
+kubebuilder:validation:MinProperties=1enforces at least one TLS configuration option must be specified+kubebuilder:validation:XValidationenforces the cert/key mutual dependencyThe OpenAPI schema correctly reflects the descriptions without requiring explicit Required fields, as the validation rules are enforced at the CRD/admission level.
config/v1alpha1/zz_generated.swagger_doc_generated.go (1)
121-335: LGTM! Swagger documentation entries for new types are correctly generated.The swagger documentation maps for the new Prometheus configuration types (
PrometheusConfig,AdditionalAlertmanagerConfig,Label,RemoteWriteSpec,RelabelConfig,TLSConfig,AuthorizationConfig,SecretKeySelector,Retention) are consistent with the corresponding struct definitions intypes_cluster_monitoring.go.config/v1alpha1/types_cluster_monitoring.go (8)
92-104: LGTM! Well-documented addition of prometheusConfig field.The new
prometheusConfigfield is properly documented with clear explanations of what can be configured (scheduling, resources, retention, external integrations). The field follows the same optional pattern as other config fields in the spec.
260-265: LGTM! VolumeClaimTemplate field improvements.The refined description is clearer, and adding
omitzeroto the JSON tag is appropriate for optional pointer fields to ensure empty structs are omitted from serialization.
430-601: LGTM! Comprehensive PrometheusConfig struct with thorough validation.The struct is well-designed with:
- Appropriate
listTypeannotations (mapfor unique keys,setfor unique items,atomicfor tolerations)- Reasonable validation bounds (e.g., 10kB-1GB for body size limit, 1-10 items for lists)
- Composite list map keys for
topologySpreadConstraintsmatching the pattern used inAlertmanagerCustomConfig- Clear documentation for each field including defaults and behavior when omitted
809-842: LGTM! Well-designed TLSConfig with proper mTLS validation.The struct has good validation:
MinProperties=1ensures meaningful configuration when TLSConfig is specified- XValidation rule properly enforces that
certandkeymust both be present or both absent for mutual TLS- DNS subdomain validation on
serverNameis appropriate
866-882: LGTM! Proper union pattern for AuthorizationConfig.The struct correctly implements the Kubernetes union pattern with:
+unionmarker on the struct+unionDiscriminatoron thetypefield- XValidation rule ensuring
bearerTokenis required when type isBearerTokenand forbidden otherwise
884-903: LGTM! SecretKeySelector with appropriate atomic struct type.The
+structType=atomicmarker is appropriate for this simple reference type. Both fields have proper validation constraints for Kubernetes secret naming conventions.
612-676: LGTM! Well-structured AdditionalAlertmanagerConfig.The struct has thorough validation:
- Clever
staticConfigsvalidation using URL parsing to validatehost:portformat- Proper path prefix validation preventing query strings and fragments
- Reasonable timeout bounds (1-600 seconds)
- Default scheme of
HTTPwith explicit HTTPS option
678-732: LGTM! Supporting types are well-defined.
Label: Appropriate length constraints (1-128 chars) for key/value pairsRemoteWriteSpec: Proper URL validation with http/https scheme enforcementRetention:MinProperties=1ensures meaningful configuration; reasonable bounds (1-365 days, 1-16384 GiB)CollectionProfile: Clear enum values (Full/Minimal) with good documentationAlso applies to: 905-961
openapi/openapi.json (19)
5875-5886: No issues noted.
6094-6102: No issues noted.
6129-6140: No issues noted.
6351-6354: No issues noted.
8537-8539: No issues noted.
8815-8817: No issues noted.
9745-9747: No issues noted.
11323-11326: No issues noted.
11334-11353: No issues noted.
11639-11650: No issues noted.
11685-11686: No issues noted.
12288-12290: No issues noted.
12306-12331: No issues noted.
12586-12590: No issues noted.
12938-12954: No issues noted.
13446-13464: No issues noted.
13483-13510: No issues noted.
29305-29307: No issues noted.
29954-29957: No issues noted.
✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.
| // RelabelConfig represents a relabeling rule. | ||
| // +kubebuilder:validation:XValidation:rule="self.action in ['Replace', 'HashMod', 'Lowercase', 'Uppercase', 'KeepEqual', 'DropEqual'] ? (has(self.targetLabel) && size(self.targetLabel) > 0) : !has(self.targetLabel)",message="targetLabel is required when action is Replace, HashMod, Lowercase, Uppercase, KeepEqual or DropEqual, and forbidden otherwise" | ||
| // +kubebuilder:validation:XValidation:rule="self.action in ['Replace', 'LabelMap'] || !has(self.replacement)",message="replacement is only valid when action is Replace or LabelMap" |
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.
Missing relabel actions in enum causes validation mismatch.
The XValidation rules on RelabelConfig (lines 735-736) reference actions Lowercase, Uppercase, KeepEqual, and DropEqual, but these are not included in the RelabelAction enum (lines 930-949).
This creates a mismatch:
- The enum validation will reject these valid Prometheus relabel actions
- The XValidation rules for
targetLabelrequirement will never apply to these actions - The comment on
targetLabel(line 781) references actions users cannot actually use
These are valid Prometheus relabel actions that should be supported.
🔧 Proposed fix: Add missing actions to the enum
-// +kubebuilder:validation:Enum=Replace;Keep;Drop;HashMod;LabelMap;LabelDrop;LabelKeep
+// +kubebuilder:validation:Enum=Replace;Keep;Drop;HashMod;LabelMap;LabelDrop;LabelKeep;Lowercase;Uppercase;KeepEqual;DropEqual
type RelabelAction string
const (
// RelabelActionReplace replaces the target label with the replacement value.
RelabelActionReplace RelabelAction = "Replace"
// RelabelActionKeep keeps metrics that match the regex.
RelabelActionKeep RelabelAction = "Keep"
// RelabelActionDrop drops metrics that match the regex.
RelabelActionDrop RelabelAction = "Drop"
// RelabelActionHashMod sets the target label to the modulus of a hash of the source labels.
RelabelActionHashMod RelabelAction = "HashMod"
// RelabelActionLabelMap maps label names based on regex matching.
RelabelActionLabelMap RelabelAction = "LabelMap"
// RelabelActionLabelDrop removes labels that match the regex.
RelabelActionLabelDrop RelabelAction = "LabelDrop"
// RelabelActionLabelKeep removes labels that do not match the regex.
RelabelActionLabelKeep RelabelAction = "LabelKeep"
+ // RelabelActionLowercase lowercases the concatenated source labels and writes to target label.
+ RelabelActionLowercase RelabelAction = "Lowercase"
+ // RelabelActionUppercase uppercases the concatenated source labels and writes to target label.
+ RelabelActionUppercase RelabelAction = "Uppercase"
+ // RelabelActionKeepEqual drops targets where concatenated source labels do not match target label.
+ RelabelActionKeepEqual RelabelAction = "KeepEqual"
+ // RelabelActionDropEqual drops targets where concatenated source labels match target label.
+ RelabelActionDropEqual RelabelAction = "DropEqual"
)Also update the action field documentation (lines 796-804) to include these actions.
Also applies to: 930-949
🤖 Prompt for AI Agents
In `@config/v1alpha1/types_cluster_monitoring.go` around lines 734 - 736, The
RelabelAction enum is missing valid Prometheus actions (Lowercase, Uppercase,
KeepEqual, DropEqual) referenced by the RelabelConfig XValidation rules; update
the RelabelAction enum to include these four values and ensure the
RelabelConfig.action field documentation (and any comment on targetLabel) lists
them so the enum validation and XValidation rules align with each other and with
Prometheus semantics.
| func schema_openshift_api_config_v1alpha1_RelabelConfig(ref common.ReferenceCallback) common.OpenAPIDefinition { | ||
| return common.OpenAPIDefinition{ | ||
| Schema: spec.Schema{ | ||
| SchemaProps: spec.SchemaProps{ | ||
| Description: "RelabelConfig represents a relabeling rule.", | ||
| Type: []string{"object"}, | ||
| Properties: map[string]spec.Schema{ | ||
| "name": { | ||
| SchemaProps: spec.SchemaProps{ | ||
| Description: "name is a unique identifier for this relabel configuration. Must contain only alphanumeric characters, hyphens, and underscores. Must be between 1 and 63 characters in length.", | ||
| Type: []string{"string"}, | ||
| Format: "", | ||
| }, | ||
| }, | ||
| "sourceLabels": { | ||
| VendorExtensible: spec.VendorExtensible{ | ||
| Extensions: spec.Extensions{ | ||
| "x-kubernetes-list-type": "set", | ||
| }, | ||
| }, | ||
| SchemaProps: spec.SchemaProps{ | ||
| Description: "sourceLabels specifies which label names to extract from each series for this relabeling rule. Each entry must be a valid label name (non-empty). The values of these labels are joined together using the configured separator, and the resulting string is then matched against the regular expression for the replace, keep, or drop actions. If a referenced label does not exist on a series, Prometheus substitutes an empty string. When omitted, the rule operates without extracting source labels (useful for actions like labelmap). Minimum of 1 and maximum of 10 source labels can be specified, each between 1 and 128 characters. Each entry must be unique.", | ||
| Type: []string{"array"}, | ||
| Items: &spec.SchemaOrArray{ | ||
| Schema: &spec.Schema{ | ||
| SchemaProps: spec.SchemaProps{ | ||
| Default: "", | ||
| Type: []string{"string"}, | ||
| Format: "", | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| "separator": { | ||
| SchemaProps: spec.SchemaProps{ | ||
| Description: "separator is the character sequence used to join source label values. Common examples: \";\", \",\", \"::\", \"|||\". When omitted, this means no opinion and the platform is left to choose a reasonable default, which is subject to change over time. The default value is \";\". Must be between 1 and 5 characters in length when specified.", | ||
| Type: []string{"string"}, | ||
| Format: "", | ||
| }, | ||
| }, | ||
| "regex": { | ||
| SchemaProps: spec.SchemaProps{ | ||
| Description: "regex is the regular expression to match against the concatenated source label values. Must be a valid RE2 regular expression (https://github.com/google/re2/wiki/Syntax). When omitted, this means no opinion and the platform is left to choose a reasonable default, which is subject to change over time. The default value is \"(.*)\" to match everything. Must be between 1 and 1000 characters in length when specified.", | ||
| Type: []string{"string"}, | ||
| Format: "", | ||
| }, | ||
| }, | ||
| "targetLabel": { | ||
| SchemaProps: spec.SchemaProps{ | ||
| Description: "targetLabel is the target label name where the result is written. Required for `Replace`, `HashMod`, `Lowercase`, `Uppercase`,`KeepEqual` and `DropEqual` actions. Must be between 1 and 128 characters in length when specified.", | ||
| Type: []string{"string"}, | ||
| Format: "", | ||
| }, | ||
| }, | ||
| "replacement": { | ||
| SchemaProps: spec.SchemaProps{ | ||
| Description: "replacement value against which a Replace action is performed if the regular expression matches. Regex capture groups are available (e.g., $1, $2). When omitted, this means no opinion and the platform is left to choose a reasonable default, which is subject to change over time. The default value is \"$1\" (the first capture group). Setting to an empty string (\"\") explicitly clears the target label value. Must be at most 255 characters in length.", | ||
| Type: []string{"string"}, | ||
| Format: "", | ||
| }, | ||
| }, | ||
| "action": { | ||
| SchemaProps: spec.SchemaProps{ | ||
| Description: "action is the action to perform on the matched labels. Valid actions are:\n - Replace: Replaces the value of targetLabel with replacement, using regex capture groups.\n - Keep: Keeps only metrics where regex matches the source labels.\n - Drop: Drops metrics where regex matches the source labels.\n - HashMod: Sets targetLabel to the hash modulus of the source labels.\n - LabelMap: Copies labels matching regex to new label names derived from replacement.\n - LabelDrop: Drops labels matching regex.\n - LabelKeep: Keeps only labels matching regex.", | ||
| Type: []string{"string"}, | ||
| Format: "", | ||
| }, | ||
| }, | ||
| }, | ||
| Required: []string{"name", "action"}, | ||
| }, | ||
| }, | ||
| } | ||
| } |
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.
🧩 Analysis chain
🏁 Script executed:
#!/bin/bash
# Search for the source RelabelConfig type definition to verify action values
fd -e go -E 'zz_generated*' | xargs rg -l 'RelabelConfig' | head -10Repository: openshift/api
Length of output: 170
🌐 Web query:
Prometheus relabel_config action valid values documentation
💡 Result:
Valid relabel_config action values (Prometheus):
- replace (default) — set/replace a label. (prometheus.io)
- keep — keep objects that match regex. (prometheus.io)
- drop — drop objects that match regex. (prometheus.io)
- hashmod — store hash%modulus in target_label (for sharding). (training.promlabs.com)
- labelmap — map label names by regex. (prometheus.io)
- labeldrop — drop labels by name regex. (prometheus.io)
- labelkeep — keep only labels matching name regex. (prometheus.io)
- keepequal — keep if source_labels equal target_label (added in v2.41). (training.promlabs.com)
- dropequal — drop if source_labels equal target_label (added in v2.41). (training.promlabs.com)
- lowercase — lower-case label value (requires Prometheus ≥ v2.36). (deckhouse.io)
- uppercase — upper-case label value (requires Prometheus ≥ v2.36). (deckhouse.io)
Notes: regex is required/used for many actions (replace, keep, drop, labelmap, labeldrop, labelkeep); default action is replace. See Prometheus configuration docs and relabeling guide for details and examples. (prometheus.io)
Citations:
- 1: https://prometheus.io/docs/prometheus/latest/configuration/configuration/?utm_source=openai
- 2: https://prometheus.io/docs/prometheus/latest/configuration/configuration/?utm_source=openai
- 3: https://prometheus.io/docs/prometheus/latest/configuration/configuration/?utm_source=openai
- 4: https://training.promlabs.com/training/relabeling/writing-relabeling-rules/hashing-and-sharding-on-label-values/?utm_source=openai
- 5: https://prometheus.io/docs/prometheus/latest/configuration/configuration/?utm_source=openai
- 6: https://prometheus.io/docs/prometheus/latest/configuration/configuration/?utm_source=openai
- 7: https://prometheus.io/docs/prometheus/latest/configuration/configuration/?utm_source=openai
- 8: https://training.promlabs.com/training/relabeling/writing-relabeling-rules/keeping-and-dropping-objects/?utm_source=openai
- 9: https://training.promlabs.com/training/relabeling/writing-relabeling-rules/keeping-and-dropping-objects/?utm_source=openai
- 10: https://deckhouse.io/modules/operator-prometheus/cr.html?utm_source=openai
- 11: https://deckhouse.io/modules/operator-prometheus/cr.html?utm_source=openai
- 12: https://prometheus.io/docs/prometheus/latest/configuration/configuration/?utm_source=openai
Incomplete action values in RelabelConfig schema.
The action field description lists only 7 valid values: Replace, Keep, Drop, HashMod, LabelMap, LabelDrop, LabelKeep. However, it omits Lowercase, Uppercase, KeepEqual, and DropEqual—all of which are valid Prometheus relabel actions also mentioned in the targetLabel field description and supported in Prometheus v2.36+.
Update the action description to include all 11 valid actions: Replace, Keep, Drop, HashMod, LabelMap, LabelDrop, LabelKeep, Lowercase, Uppercase, KeepEqual, DropEqual.
Since this is generated code, verify and fix the source type definitions.
🤖 Prompt for AI Agents
In `@openapi/generated_openapi/zz_generated.openapi.go` around lines 24259 -
24333, The RelabelConfig OpenAPI definition generated in function
schema_openshift_api_config_v1alpha1_RelabelConfig has an incomplete "action"
description; update the description string for the "action" property to list all
11 valid Prometheus actions (Replace, Keep, Drop, HashMod, LabelMap, LabelDrop,
LabelKeep, Lowercase, Uppercase, KeepEqual, DropEqual) and then regenerate the
OpenAPI output from the canonical source type so the change persists; verify and
correct the source Go type or its swagger tags that define RelabelConfig's
Action documentation before re-running the generator.
| enum: | ||
| - Replace | ||
| - Keep | ||
| - Drop | ||
| - HashMod | ||
| - LabelMap | ||
| - LabelDrop | ||
| - LabelKeep | ||
| type: string |
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.
Mismatch between RelabelConfig action enum and validation/description.
The action enum (lines 1803-1810) includes: Replace, Keep, Drop, HashMod, LabelMap, LabelDrop, LabelKeep.
However, the targetLabel description (line 1876) and validation rule (lines 1889-1891) reference additional actions: Lowercase, Uppercase, KeepEqual, DropEqual — which are not in the enum.
This inconsistency will not cause runtime failures (since invalid actions are rejected at the enum level), but it creates confusing documentation and suggests an incomplete implementation.
Either add the missing actions to the enum if they should be supported, or update the description and validation rule to only reference the actions that exist in the enum.
🔧 Suggested fix: Update validation rule to match enum
If the additional actions are not intended to be supported, update the validation:
x-kubernetes-validations:
- message: targetLabel is required when action is Replace,
- HashMod, Lowercase, Uppercase, KeepEqual or DropEqual,
+ HashMod, LabelMap, LabelDrop, or LabelKeep,
and forbidden otherwise
- rule: 'self.action in [''Replace'', ''HashMod'', ''Lowercase'',
- ''Uppercase'', ''KeepEqual'', ''DropEqual''] ? (has(self.targetLabel)
+ rule: 'self.action in [''Replace'', ''HashMod''] ? (has(self.targetLabel)
&& size(self.targetLabel) > 0) : !has(self.targetLabel)'And update the description at line 1876 accordingly.
Alternatively, if Lowercase, Uppercase, KeepEqual, DropEqual should be supported, add them to the enum.
Also applies to: 1873-1891
🤖 Prompt for AI Agents
In
`@payload-manifests/crds/0000_10_config-operator_01_clustermonitorings-CustomNoUpgrade.crd.yaml`
around lines 1803 - 1811, The action enum for RelabelConfig currently lists
Replace, Keep, Drop, HashMod, LabelMap, LabelDrop, LabelKeep but the targetLabel
description and its validation rule mention Lowercase, Uppercase, KeepEqual,
DropEqual; update either the enum or the docs/validation so they match: either
add the missing actions (Lowercase, Uppercase, KeepEqual, DropEqual) to the
action enum or remove/replace those action names from the targetLabel
description and the validation pattern so they only reference the existing enum
values; locate the enum block named "action" and the "targetLabel"
description/validation in this CRD and make the change consistently across both
sections.
| enum: | ||
| - Replace | ||
| - Keep | ||
| - Drop | ||
| - HashMod | ||
| - LabelMap | ||
| - LabelDrop | ||
| - LabelKeep | ||
| type: string |
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.
Inconsistency between enum values and validation rule.
The action enum (lines 1803-1810) includes only: Replace, Keep, Drop, HashMod, LabelMap, LabelDrop, LabelKeep.
However, the validation rule (lines 1889-1891) and description (lines 1876-1877) reference additional actions: Lowercase, Uppercase, KeepEqual, DropEqual.
This inconsistency means:
- Users cannot select these actions (they're not in the enum)
- The validation rule references non-selectable values
- The description is misleading
Either add the missing actions to the enum, or remove references to them from the validation and description.
#!/bin/bash
# Verify if other CRD variants have the same inconsistency
rg -n "Lowercase|Uppercase|KeepEqual|DropEqual" payload-manifests/crds/*clustermonitoring*.yaml | head -30Also applies to: 1873-1894
🤖 Prompt for AI Agents
In
`@payload-manifests/crds/0000_10_config-operator_01_clustermonitorings-DevPreviewNoUpgrade.crd.yaml`
around lines 1803 - 1811, The CRD's action enum for the field named "action" is
missing values referenced elsewhere (Lowercase, Uppercase, KeepEqual,
DropEqual), causing an enum/validation/description mismatch; fix by either
adding those four values to the action enum (so enum contains Replace, Keep,
Drop, HashMod, LabelMap, LabelDrop, LabelKeep, Lowercase, Uppercase, KeepEqual,
DropEqual) or by removing all references to those four actions from the
validation rule and the description text that mentions them; update the enum
block for "action" and the corresponding validation rule/description (the same
section around the existing action enum and the validation referenced)
consistently so they match, and repeat the same change for the other occurrence
noted (the block spanning lines ~1873-1894).
| enum: | ||
| - Replace | ||
| - Keep | ||
| - Drop | ||
| - HashMod | ||
| - LabelMap | ||
| - LabelDrop | ||
| - LabelKeep | ||
| type: string | ||
| name: | ||
| description: |- | ||
| name is a unique identifier for this relabel configuration. | ||
| Must contain only alphanumeric characters, hyphens, and underscores. | ||
| Must be between 1 and 63 characters in length. | ||
| maxLength: 63 | ||
| minLength: 1 | ||
| type: string | ||
| x-kubernetes-validations: | ||
| - message: must contain only alphanumeric characters, | ||
| hyphens, and underscores | ||
| rule: self.matches('^[a-zA-Z0-9_-]+$') | ||
| regex: | ||
| description: |- | ||
| regex is the regular expression to match against the concatenated source label values. | ||
| Must be a valid RE2 regular expression (https://github.com/google/re2/wiki/Syntax). | ||
| When omitted, this means no opinion and the platform is left to choose a reasonable default, which is subject to change over time. | ||
| The default value is "(.*)" to match everything. | ||
| Must be between 1 and 1000 characters in length when specified. | ||
| maxLength: 1000 | ||
| minLength: 1 | ||
| type: string | ||
| replacement: | ||
| description: |- | ||
| replacement value against which a Replace action is performed if the | ||
| regular expression matches. Regex capture groups are available (e.g., $1, $2). | ||
| When omitted, this means no opinion and the platform is left to choose a reasonable default, which is subject to change over time. | ||
| The default value is "$1" (the first capture group). | ||
| Setting to an empty string ("") explicitly clears the target label value. | ||
| Must be at most 255 characters in length. | ||
| maxLength: 255 | ||
| type: string | ||
| separator: | ||
| description: |- | ||
| separator is the character sequence used to join source label values. | ||
| Common examples: ";", ",", "::", "|||". | ||
| When omitted, this means no opinion and the platform is left to choose a reasonable default, which is subject to change over time. | ||
| The default value is ";". | ||
| Must be between 1 and 5 characters in length when specified. | ||
| maxLength: 5 | ||
| minLength: 1 | ||
| type: string | ||
| sourceLabels: | ||
| description: |- | ||
| sourceLabels specifies which label names to extract from each series for this relabeling rule. | ||
| Each entry must be a valid label name (non-empty). | ||
| The values of these labels are joined together using the configured separator, | ||
| and the resulting string is then matched against the regular expression for | ||
| the replace, keep, or drop actions. | ||
| If a referenced label does not exist on a series, Prometheus substitutes an empty string. | ||
| When omitted, the rule operates without extracting source labels (useful for actions like labelmap). | ||
| Minimum of 1 and maximum of 10 source labels can be specified, each between 1 and 128 characters. | ||
| Each entry must be unique. | ||
| items: | ||
| maxLength: 128 | ||
| minLength: 1 | ||
| type: string | ||
| maxItems: 10 | ||
| minItems: 1 | ||
| type: array | ||
| x-kubernetes-list-type: set | ||
| targetLabel: | ||
| description: |- | ||
| targetLabel is the target label name where the result is written. | ||
| Required for `Replace`, `HashMod`, `Lowercase`, `Uppercase`,`KeepEqual` and `DropEqual` actions. | ||
| Must be between 1 and 128 characters in length when specified. | ||
| maxLength: 128 | ||
| minLength: 1 | ||
| type: string | ||
| required: | ||
| - action | ||
| - name | ||
| type: object | ||
| x-kubernetes-validations: | ||
| - message: targetLabel is required when action is Replace, | ||
| HashMod, Lowercase, Uppercase, KeepEqual or DropEqual, | ||
| and forbidden otherwise | ||
| rule: 'self.action in [''Replace'', ''HashMod'', ''Lowercase'', | ||
| ''Uppercase'', ''KeepEqual'', ''DropEqual''] ? (has(self.targetLabel) | ||
| && size(self.targetLabel) > 0) : !has(self.targetLabel)' | ||
| - message: replacement is only valid when action is Replace | ||
| or LabelMap | ||
| rule: self.action in ['Replace', 'LabelMap'] || !has(self.replacement) |
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.
🧩 Analysis chain
🌐 Web query:
Prometheus relabeling actions Lowercase Uppercase KeepEqual DropEqual targetLabel requirements
💡 Result:
Summary — what each action does, targetLabel requirement, and Prometheus version notes:
-
Lowercase / Uppercase: write the concatenated source_labels (joined by separator) in lower- or upper-case into target_label. target_label is required for these actions. (Prometheus docs). [1][2]
-
KeepEqual / DropEqual: compare the concatenated source_labels to the value of target_label and keep or drop the target accordingly:
- keepequal: keep only when concatenated source_labels == target_label (drop otherwise).
- dropequal: drop when concatenated source_labels == target_label.
Both actions require target_label. (Prometheus docs). [1][2]
-
Keep / Drop (for comparison): keep/drop based on whether regex matches the concatenated source_labels (these do not use target_label). [1]
-
Replace / HashMod / LabelMap / LabelDrop / LabelKeep / etc.: standard relabel actions — Replace and HashMod require target_label; other label-wide actions behave differently (see docs). [1]
Version/requirements:
- Uppercase and Lowercase require Prometheus >= 2.36.0.
- KeepEqual and DropEqual require Prometheus >= 2.41.0.
- Replace and HashMod also require target_label when used. [2][3]
References:
- Prometheus configuration — relabel_config (actions, semantics). [1]
- Provider / API docs noting targetLabel is mandatory for Replace, HashMod, Lowercase, Uppercase, KeepEqual, DropEqual and version notes. [2][3]
🏁 Script executed:
# First, locate and examine the CRD file
find . -name "*clustermonitorings*TechPreviewNoUpgrade.crd.yaml" -type fRepository: openshift/api
Length of output: 278
🏁 Script executed:
# Read the specific section of the CRD file
sed -n '1803,1894p' ./payload-manifests/crds/0000_10_config-operator_01_clustermonitorings-TechPreviewNoUpgrade.crd.yaml | cat -nRepository: openshift/api
Length of output: 7152
🏁 Script executed:
# Verify no other validation or enum definitions exist for action elsewhere
grep -n "action:" ./payload-manifests/crds/0000_10_config-operator_01_clustermonitorings-TechPreviewNoUpgrade.crd.yaml | head -20Repository: openshift/api
Length of output: 99
Add missing relabel actions to enum.
The action enum (lines 1803-1811) is missing four valid Prometheus relabeling actions: Lowercase, Uppercase, KeepEqual, and DropEqual. These actions exist in Prometheus 2.36+ (Lowercase, Uppercase) and 2.41+ (KeepEqual, DropEqual) and all require targetLabel, which is already correctly documented in the field description and enforced by the validation rule. However, users cannot use these actions because the enum validation will reject them.
Add the four missing actions to the enum:
Suggested fix
enum:
- Replace
- Keep
- Drop
- HashMod
- LabelMap
- LabelDrop
- LabelKeep
+ - Lowercase
+ - Uppercase
+ - KeepEqual
+ - DropEqual
type: string🤖 Prompt for AI Agents
In
`@payload-manifests/crds/0000_10_config-operator_01_clustermonitorings-TechPreviewNoUpgrade.crd.yaml`
around lines 1803 - 1894, The action enum for the relabel configuration is
missing four valid Prometheus actions; update the enum under the "action" field
to include "Lowercase", "Uppercase", "KeepEqual", and "DropEqual" so those
values are accepted by validation. Edit the enum list (the token named action in
this CRD) to append these four strings and leave the existing
x-kubernetes-validations rules (the rule that requires targetLabel for Replace,
HashMod, Lowercase, Uppercase, KeepEqual, DropEqual and the replacement rule)
intact so targetLabel and replacement semantics continue to be enforced.
|
@CodeRabbit ignore |
✅ Actions performedReviews paused. |
|
@marioferh: all tests passed! Full PR test history. Your PR dashboard. DetailsInstructions 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. |
This commit introduces a new API to be introduced as a part of the migration in CMO from ConfigMap to CRDs
This pr replaces #2630 because is broken