diff --git a/Documentation/api.md b/Documentation/api.md index c077a2a99..be899233e 100644 --- a/Documentation/api.md +++ b/Documentation/api.md @@ -1868,10 +1868,13 @@ For more information see <a href="https://prometheus.io/docs/prometheus/latest/q <td> <code>enableFeatures</code><br/> <em> -[]string +<a href="#monitoring.coreos.com/v1.EnableFeature"> +[]EnableFeature +</a> </em> </td> <td> +<em>(Optional)</em> <p>Enable access to Prometheus feature flags. By default, no features are enabled.</p> <p>Enabling features which are disabled by default is entirely outside the scope of what the maintainers will support and by doing so, you accept @@ -6388,10 +6391,13 @@ For more information see <a href="https://prometheus.io/docs/prometheus/latest/q <td> <code>enableFeatures</code><br/> <em> -[]string +<a href="#monitoring.coreos.com/v1.EnableFeature"> +[]EnableFeature +</a> </em> </td> <td> +<em>(Optional)</em> <p>Enable access to Prometheus feature flags. By default, no features are enabled.</p> <p>Enabling features which are disabled by default is entirely outside the scope of what the maintainers will support and by doing so, you accept @@ -7892,6 +7898,13 @@ Kubernetes core/v1.PersistentVolumeClaimStatus </tr> </tbody> </table> +<h3 id="monitoring.coreos.com/v1.EnableFeature">EnableFeature +(<code>string</code> alias)</h3> +<p> +(<em>Appears on:</em><a href="#monitoring.coreos.com/v1.CommonPrometheusFields">CommonPrometheusFields</a>) +</p> +<div> +</div> <h3 id="monitoring.coreos.com/v1.Endpoint">Endpoint </h3> <p> @@ -10488,10 +10501,13 @@ For more information see <a href="https://prometheus.io/docs/prometheus/latest/q <td> <code>enableFeatures</code><br/> <em> -[]string +<a href="#monitoring.coreos.com/v1.EnableFeature"> +[]EnableFeature +</a> </em> </td> <td> +<em>(Optional)</em> <p>Enable access to Prometheus feature flags. By default, no features are enabled.</p> <p>Enabling features which are disabled by default is entirely outside the scope of what the maintainers will support and by doing so, you accept @@ -16411,10 +16427,13 @@ For more information see <a href="https://prometheus.io/docs/prometheus/latest/q <td> <code>enableFeatures</code><br/> <em> -[]string +<a href="#monitoring.coreos.com/v1.EnableFeature"> +[]EnableFeature +</a> </em> </td> <td> +<em>(Optional)</em> <p>Enable access to Prometheus feature flags. By default, no features are enabled.</p> <p>Enabling features which are disabled by default is entirely outside the scope of what the maintainers will support and by doing so, you accept @@ -22466,10 +22485,13 @@ For more information see <a href="https://prometheus.io/docs/prometheus/latest/q <td> <code>enableFeatures</code><br/> <em> -[]string +<a href="#monitoring.coreos.com/v1.EnableFeature"> +[]EnableFeature +</a> </em> </td> <td> +<em>(Optional)</em> <p>Enable access to Prometheus feature flags. By default, no features are enabled.</p> <p>Enabling features which are disabled by default is entirely outside the scope of what the maintainers will support and by doing so, you accept diff --git a/bundle.yaml b/bundle.yaml index 5898b0d9e..58f130e52 100644 --- a/bundle.yaml +++ b/bundle.yaml @@ -17684,8 +17684,10 @@ spec: will support and by doing so, you accept that this behaviour may break at any time without notice. \n For more information see https://prometheus.io/docs/prometheus/latest/feature_flags/" items: + minLength: 1 type: string type: array + x-kubernetes-list-type: set enableRemoteWriteReceiver: description: "Enable Prometheus to be used as a receiver for the Prometheus remote write protocol. \n WARNING: This is not considered an efficient @@ -27231,8 +27233,10 @@ spec: will support and by doing so, you accept that this behaviour may break at any time without notice. \n For more information see https://prometheus.io/docs/prometheus/latest/feature_flags/" items: + minLength: 1 type: string type: array + x-kubernetes-list-type: set enableRemoteWriteReceiver: description: "Enable Prometheus to be used as a receiver for the Prometheus remote write protocol. \n WARNING: This is not considered an efficient diff --git a/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheusagents.yaml b/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheusagents.yaml index 0bf84838a..7e54c6b5c 100644 --- a/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheusagents.yaml +++ b/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheusagents.yaml @@ -2688,8 +2688,10 @@ spec: will support and by doing so, you accept that this behaviour may break at any time without notice. \n For more information see https://prometheus.io/docs/prometheus/latest/feature_flags/" items: + minLength: 1 type: string type: array + x-kubernetes-list-type: set enableRemoteWriteReceiver: description: "Enable Prometheus to be used as a receiver for the Prometheus remote write protocol. \n WARNING: This is not considered an efficient diff --git a/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheuses.yaml b/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheuses.yaml index 1c8a4464e..b4497676a 100644 --- a/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheuses.yaml +++ b/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheuses.yaml @@ -3100,8 +3100,10 @@ spec: will support and by doing so, you accept that this behaviour may break at any time without notice. \n For more information see https://prometheus.io/docs/prometheus/latest/feature_flags/" items: + minLength: 1 type: string type: array + x-kubernetes-list-type: set enableRemoteWriteReceiver: description: "Enable Prometheus to be used as a receiver for the Prometheus remote write protocol. \n WARNING: This is not considered an efficient diff --git a/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml b/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml index 2dc7554d7..9fe3d5926 100644 --- a/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml +++ b/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml @@ -2689,8 +2689,10 @@ spec: will support and by doing so, you accept that this behaviour may break at any time without notice. \n For more information see https://prometheus.io/docs/prometheus/latest/feature_flags/" items: + minLength: 1 type: string type: array + x-kubernetes-list-type: set enableRemoteWriteReceiver: description: "Enable Prometheus to be used as a receiver for the Prometheus remote write protocol. \n WARNING: This is not considered an efficient diff --git a/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml b/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml index cdd97c162..0d89bf7b6 100644 --- a/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml +++ b/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml @@ -3101,8 +3101,10 @@ spec: will support and by doing so, you accept that this behaviour may break at any time without notice. \n For more information see https://prometheus.io/docs/prometheus/latest/feature_flags/" items: + minLength: 1 type: string type: array + x-kubernetes-list-type: set enableRemoteWriteReceiver: description: "Enable Prometheus to be used as a receiver for the Prometheus remote write protocol. \n WARNING: This is not considered an efficient diff --git a/jsonnet/prometheus-operator/prometheusagents-crd.json b/jsonnet/prometheus-operator/prometheusagents-crd.json index 3c25c2ce1..7d213ba71 100644 --- a/jsonnet/prometheus-operator/prometheusagents-crd.json +++ b/jsonnet/prometheus-operator/prometheusagents-crd.json @@ -2336,9 +2336,11 @@ "enableFeatures": { "description": "Enable access to Prometheus feature flags. By default, no features are enabled. \n Enabling features which are disabled by default is entirely outside the scope of what the maintainers will support and by doing so, you accept that this behaviour may break at any time without notice. \n For more information see https://prometheus.io/docs/prometheus/latest/feature_flags/", "items": { + "minLength": 1, "type": "string" }, - "type": "array" + "type": "array", + "x-kubernetes-list-type": "set" }, "enableRemoteWriteReceiver": { "description": "Enable Prometheus to be used as a receiver for the Prometheus remote write protocol. \n WARNING: This is not considered an efficient way of ingesting samples. Use it with caution for specific low-volume use cases. It is not suitable for replacing the ingestion via scraping and turning Prometheus into a push-based metrics collection system. For more information see https://prometheus.io/docs/prometheus/latest/querying/api/#remote-write-receiver \n It requires Prometheus >= v2.33.0.", diff --git a/jsonnet/prometheus-operator/prometheuses-crd.json b/jsonnet/prometheus-operator/prometheuses-crd.json index 22bcc6989..0e4c72a91 100644 --- a/jsonnet/prometheus-operator/prometheuses-crd.json +++ b/jsonnet/prometheus-operator/prometheuses-crd.json @@ -2757,9 +2757,11 @@ "enableFeatures": { "description": "Enable access to Prometheus feature flags. By default, no features are enabled. \n Enabling features which are disabled by default is entirely outside the scope of what the maintainers will support and by doing so, you accept that this behaviour may break at any time without notice. \n For more information see https://prometheus.io/docs/prometheus/latest/feature_flags/", "items": { + "minLength": 1, "type": "string" }, - "type": "array" + "type": "array", + "x-kubernetes-list-type": "set" }, "enableRemoteWriteReceiver": { "description": "Enable Prometheus to be used as a receiver for the Prometheus remote write protocol. \n WARNING: This is not considered an efficient way of ingesting samples. Use it with caution for specific low-volume use cases. It is not suitable for replacing the ingestion via scraping and turning Prometheus into a push-based metrics collection system. For more information see https://prometheus.io/docs/prometheus/latest/querying/api/#remote-write-receiver \n It requires Prometheus >= v2.33.0.", diff --git a/pkg/apis/monitoring/v1/prometheus_types.go b/pkg/apis/monitoring/v1/prometheus_types.go index 4953225cb..47af1b460 100644 --- a/pkg/apis/monitoring/v1/prometheus_types.go +++ b/pkg/apis/monitoring/v1/prometheus_types.go @@ -88,6 +88,9 @@ type TopologySpreadConstraint struct { AdditionalLabelSelectors *AdditionalLabelSelectors `json:"additionalLabelSelectors,omitempty"` } +// +kubebuilder:validation:MinLength:=1 +type EnableFeature string + // CommonPrometheusFields are the options available to both the Prometheus server and agent. // +k8s:deepcopy-gen=true type CommonPrometheusFields struct { @@ -302,7 +305,10 @@ type CommonPrometheusFields struct { // that this behaviour may break at any time without notice. // // For more information see https://prometheus.io/docs/prometheus/latest/feature_flags/ - EnableFeatures []string `json:"enableFeatures,omitempty"` + // + // +listType:=set + // +optional + EnableFeatures []EnableFeature `json:"enableFeatures,omitempty"` // The external URL under which the Prometheus service is externally // available. This is necessary to generate correct URLs (for instance if diff --git a/pkg/apis/monitoring/v1/zz_generated.deepcopy.go b/pkg/apis/monitoring/v1/zz_generated.deepcopy.go index dc1e7a2a7..7e8790077 100644 --- a/pkg/apis/monitoring/v1/zz_generated.deepcopy.go +++ b/pkg/apis/monitoring/v1/zz_generated.deepcopy.go @@ -700,7 +700,7 @@ func (in *CommonPrometheusFields) DeepCopyInto(out *CommonPrometheusFields) { } if in.EnableFeatures != nil { in, out := &in.EnableFeatures, &out.EnableFeatures - *out = make([]string, len(*in)) + *out = make([]EnableFeature, len(*in)) copy(*out, *in) } if in.Storage != nil { diff --git a/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go b/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go index cb8ec67d4..47132da99 100644 --- a/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go +++ b/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go @@ -51,7 +51,7 @@ type CommonPrometheusFieldsApplyConfiguration struct { ScrapeProtocols []monitoringv1.ScrapeProtocol `json:"scrapeProtocols,omitempty"` ExternalLabels map[string]string `json:"externalLabels,omitempty"` EnableRemoteWriteReceiver *bool `json:"enableRemoteWriteReceiver,omitempty"` - EnableFeatures []string `json:"enableFeatures,omitempty"` + EnableFeatures []monitoringv1.EnableFeature `json:"enableFeatures,omitempty"` ExternalURL *string `json:"externalUrl,omitempty"` RoutePrefix *string `json:"routePrefix,omitempty"` Storage *StorageSpecApplyConfiguration `json:"storage,omitempty"` @@ -327,7 +327,7 @@ func (b *CommonPrometheusFieldsApplyConfiguration) WithEnableRemoteWriteReceiver // WithEnableFeatures adds the given value to the EnableFeatures field in the declarative configuration // and returns the receiver, so that objects can be build by chaining "With" function invocations. // If called multiple times, values provided by each call will be appended to the EnableFeatures field. -func (b *CommonPrometheusFieldsApplyConfiguration) WithEnableFeatures(values ...string) *CommonPrometheusFieldsApplyConfiguration { +func (b *CommonPrometheusFieldsApplyConfiguration) WithEnableFeatures(values ...monitoringv1.EnableFeature) *CommonPrometheusFieldsApplyConfiguration { for i := range values { b.EnableFeatures = append(b.EnableFeatures, values[i]) } diff --git a/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go b/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go index 5dfe9f39b..fedbab4cb 100644 --- a/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go +++ b/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go @@ -270,7 +270,7 @@ func (b *PrometheusSpecApplyConfiguration) WithEnableRemoteWriteReceiver(value b // WithEnableFeatures adds the given value to the EnableFeatures field in the declarative configuration // and returns the receiver, so that objects can be build by chaining "With" function invocations. // If called multiple times, values provided by each call will be appended to the EnableFeatures field. -func (b *PrometheusSpecApplyConfiguration) WithEnableFeatures(values ...string) *PrometheusSpecApplyConfiguration { +func (b *PrometheusSpecApplyConfiguration) WithEnableFeatures(values ...monitoringv1.EnableFeature) *PrometheusSpecApplyConfiguration { for i := range values { b.EnableFeatures = append(b.EnableFeatures, values[i]) } diff --git a/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go b/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go index 4a311b80b..894ed96bf 100644 --- a/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go +++ b/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go @@ -249,7 +249,7 @@ func (b *PrometheusAgentSpecApplyConfiguration) WithEnableRemoteWriteReceiver(va // WithEnableFeatures adds the given value to the EnableFeatures field in the declarative configuration // and returns the receiver, so that objects can be build by chaining "With" function invocations. // If called multiple times, values provided by each call will be appended to the EnableFeatures field. -func (b *PrometheusAgentSpecApplyConfiguration) WithEnableFeatures(values ...string) *PrometheusAgentSpecApplyConfiguration { +func (b *PrometheusAgentSpecApplyConfiguration) WithEnableFeatures(values ...monitoringv1.EnableFeature) *PrometheusAgentSpecApplyConfiguration { for i := range values { b.EnableFeatures = append(b.EnableFeatures, values[i]) } diff --git a/pkg/prometheus/server/statefulset_test.go b/pkg/prometheus/server/statefulset_test.go index 35b899649..c77503e04 100644 --- a/pkg/prometheus/server/statefulset_test.go +++ b/pkg/prometheus/server/statefulset_test.go @@ -1888,7 +1888,7 @@ func TestEnableFeaturesWithOneFeature(t *testing.T) { sset, err := makeStatefulSetFromPrometheus(monitoringv1.Prometheus{ Spec: monitoringv1.PrometheusSpec{ CommonPrometheusFields: monitoringv1.CommonPrometheusFields{ - EnableFeatures: []string{"exemplar-storage"}, + EnableFeatures: []monitoringv1.EnableFeature{"exemplar-storage"}, }, }, }) @@ -1910,7 +1910,7 @@ func TestEnableFeaturesWithMultipleFeature(t *testing.T) { sset, err := makeStatefulSetFromPrometheus(monitoringv1.Prometheus{ Spec: monitoringv1.PrometheusSpec{ CommonPrometheusFields: monitoringv1.CommonPrometheusFields{ - EnableFeatures: []string{"exemplar-storage1", "exemplar-storage2"}, + EnableFeatures: []monitoringv1.EnableFeature{"exemplar-storage1", "exemplar-storage2"}, }, }, }) diff --git a/pkg/prometheus/statefulset.go b/pkg/prometheus/statefulset.go index 71f1d81d1..4dcbc256c 100644 --- a/pkg/prometheus/statefulset.go +++ b/pkg/prometheus/statefulset.go @@ -222,7 +222,11 @@ func BuildCommonPrometheusArgs(cpf monitoringv1.CommonPrometheusFields, cg *Conf } if len(cpf.EnableFeatures) > 0 { - promArgs = cg.WithMinimumVersion("2.25.0").AppendCommandlineArgument(promArgs, monitoringv1.Argument{Name: "enable-feature", Value: strings.Join(cpf.EnableFeatures[:], ",")}) + efs := make([]string, len(cpf.EnableFeatures)) + for i := range cpf.EnableFeatures { + efs[i] = string(cpf.EnableFeatures[i]) + } + promArgs = cg.WithMinimumVersion("2.25.0").AppendCommandlineArgument(promArgs, monitoringv1.Argument{Name: "enable-feature", Value: strings.Join(efs, ",")}) } if cpf.ExternalURL != "" { diff --git a/test/framework/prometheus.go b/test/framework/prometheus.go index cd0bddf9c..dee9a436e 100644 --- a/test/framework/prometheus.go +++ b/test/framework/prometheus.go @@ -285,7 +285,7 @@ func (prwtc PromRemoteWriteTestConfig) AddRemoteWriteWithTLSToPrometheus(p *moni } func (f *Framework) EnableRemoteWriteReceiverWithTLS(p *monitoringv1.Prometheus) { - p.Spec.EnableFeatures = []string{"remote-write-receiver"} + p.Spec.EnableFeatures = []monitoringv1.EnableFeature{"remote-write-receiver"} p.Spec.Web = &monitoringv1.PrometheusWebSpec{ WebConfigFileFields: monitoringv1.WebConfigFileFields{