1
0
Fork 0
mirror of https://github.com/prometheus-operator/prometheus-operator.git synced 2025-04-16 01:06:27 +00:00

change: define enableFeatures list as a set

It allows different actors to manipulate the list of enabled features
using server-side apply.

Signed-off-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
Simon Pasquier 2024-04-04 12:30:08 +02:00
parent d70313bd17
commit 3e0d0f86f2
16 changed files with 65 additions and 17 deletions

32
Documentation/api.md generated
View file

@ -1868,10 +1868,13 @@ For more information see <a href="https://prometheus.io/docs/prometheus/latest/q
<td> <td>
<code>enableFeatures</code><br/> <code>enableFeatures</code><br/>
<em> <em>
[]string <a href="#monitoring.coreos.com/v1.EnableFeature">
[]EnableFeature
</a>
</em> </em>
</td> </td>
<td> <td>
<em>(Optional)</em>
<p>Enable access to Prometheus feature flags. By default, no features are enabled.</p> <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 <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 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> <td>
<code>enableFeatures</code><br/> <code>enableFeatures</code><br/>
<em> <em>
[]string <a href="#monitoring.coreos.com/v1.EnableFeature">
[]EnableFeature
</a>
</em> </em>
</td> </td>
<td> <td>
<em>(Optional)</em>
<p>Enable access to Prometheus feature flags. By default, no features are enabled.</p> <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 <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 scope of what the maintainers will support and by doing so, you accept
@ -7892,6 +7898,13 @@ Kubernetes core/v1.PersistentVolumeClaimStatus
</tr> </tr>
</tbody> </tbody>
</table> </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 id="monitoring.coreos.com/v1.Endpoint">Endpoint
</h3> </h3>
<p> <p>
@ -10488,10 +10501,13 @@ For more information see <a href="https://prometheus.io/docs/prometheus/latest/q
<td> <td>
<code>enableFeatures</code><br/> <code>enableFeatures</code><br/>
<em> <em>
[]string <a href="#monitoring.coreos.com/v1.EnableFeature">
[]EnableFeature
</a>
</em> </em>
</td> </td>
<td> <td>
<em>(Optional)</em>
<p>Enable access to Prometheus feature flags. By default, no features are enabled.</p> <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 <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 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> <td>
<code>enableFeatures</code><br/> <code>enableFeatures</code><br/>
<em> <em>
[]string <a href="#monitoring.coreos.com/v1.EnableFeature">
[]EnableFeature
</a>
</em> </em>
</td> </td>
<td> <td>
<em>(Optional)</em>
<p>Enable access to Prometheus feature flags. By default, no features are enabled.</p> <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 <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 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> <td>
<code>enableFeatures</code><br/> <code>enableFeatures</code><br/>
<em> <em>
[]string <a href="#monitoring.coreos.com/v1.EnableFeature">
[]EnableFeature
</a>
</em> </em>
</td> </td>
<td> <td>
<em>(Optional)</em>
<p>Enable access to Prometheus feature flags. By default, no features are enabled.</p> <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 <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 scope of what the maintainers will support and by doing so, you accept

4
bundle.yaml generated
View file

@ -17684,8 +17684,10 @@ spec:
will support and by doing so, you accept that this behaviour may 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/" break at any time without notice. \n For more information see https://prometheus.io/docs/prometheus/latest/feature_flags/"
items: items:
minLength: 1
type: string type: string
type: array type: array
x-kubernetes-list-type: set
enableRemoteWriteReceiver: enableRemoteWriteReceiver:
description: "Enable Prometheus to be used as a receiver for the Prometheus description: "Enable Prometheus to be used as a receiver for the Prometheus
remote write protocol. \n WARNING: This is not considered an efficient 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 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/" break at any time without notice. \n For more information see https://prometheus.io/docs/prometheus/latest/feature_flags/"
items: items:
minLength: 1
type: string type: string
type: array type: array
x-kubernetes-list-type: set
enableRemoteWriteReceiver: enableRemoteWriteReceiver:
description: "Enable Prometheus to be used as a receiver for the Prometheus description: "Enable Prometheus to be used as a receiver for the Prometheus
remote write protocol. \n WARNING: This is not considered an efficient remote write protocol. \n WARNING: This is not considered an efficient

View file

@ -2688,8 +2688,10 @@ spec:
will support and by doing so, you accept that this behaviour may 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/" break at any time without notice. \n For more information see https://prometheus.io/docs/prometheus/latest/feature_flags/"
items: items:
minLength: 1
type: string type: string
type: array type: array
x-kubernetes-list-type: set
enableRemoteWriteReceiver: enableRemoteWriteReceiver:
description: "Enable Prometheus to be used as a receiver for the Prometheus description: "Enable Prometheus to be used as a receiver for the Prometheus
remote write protocol. \n WARNING: This is not considered an efficient remote write protocol. \n WARNING: This is not considered an efficient

View file

@ -3100,8 +3100,10 @@ spec:
will support and by doing so, you accept that this behaviour may 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/" break at any time without notice. \n For more information see https://prometheus.io/docs/prometheus/latest/feature_flags/"
items: items:
minLength: 1
type: string type: string
type: array type: array
x-kubernetes-list-type: set
enableRemoteWriteReceiver: enableRemoteWriteReceiver:
description: "Enable Prometheus to be used as a receiver for the Prometheus description: "Enable Prometheus to be used as a receiver for the Prometheus
remote write protocol. \n WARNING: This is not considered an efficient remote write protocol. \n WARNING: This is not considered an efficient

View file

@ -2689,8 +2689,10 @@ spec:
will support and by doing so, you accept that this behaviour may 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/" break at any time without notice. \n For more information see https://prometheus.io/docs/prometheus/latest/feature_flags/"
items: items:
minLength: 1
type: string type: string
type: array type: array
x-kubernetes-list-type: set
enableRemoteWriteReceiver: enableRemoteWriteReceiver:
description: "Enable Prometheus to be used as a receiver for the Prometheus description: "Enable Prometheus to be used as a receiver for the Prometheus
remote write protocol. \n WARNING: This is not considered an efficient remote write protocol. \n WARNING: This is not considered an efficient

View file

@ -3101,8 +3101,10 @@ spec:
will support and by doing so, you accept that this behaviour may 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/" break at any time without notice. \n For more information see https://prometheus.io/docs/prometheus/latest/feature_flags/"
items: items:
minLength: 1
type: string type: string
type: array type: array
x-kubernetes-list-type: set
enableRemoteWriteReceiver: enableRemoteWriteReceiver:
description: "Enable Prometheus to be used as a receiver for the Prometheus description: "Enable Prometheus to be used as a receiver for the Prometheus
remote write protocol. \n WARNING: This is not considered an efficient remote write protocol. \n WARNING: This is not considered an efficient

View file

@ -2336,9 +2336,11 @@
"enableFeatures": { "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/", "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": { "items": {
"minLength": 1,
"type": "string" "type": "string"
}, },
"type": "array" "type": "array",
"x-kubernetes-list-type": "set"
}, },
"enableRemoteWriteReceiver": { "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.", "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.",

View file

@ -2757,9 +2757,11 @@
"enableFeatures": { "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/", "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": { "items": {
"minLength": 1,
"type": "string" "type": "string"
}, },
"type": "array" "type": "array",
"x-kubernetes-list-type": "set"
}, },
"enableRemoteWriteReceiver": { "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.", "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.",

View file

@ -88,6 +88,9 @@ type TopologySpreadConstraint struct {
AdditionalLabelSelectors *AdditionalLabelSelectors `json:"additionalLabelSelectors,omitempty"` AdditionalLabelSelectors *AdditionalLabelSelectors `json:"additionalLabelSelectors,omitempty"`
} }
// +kubebuilder:validation:MinLength:=1
type EnableFeature string
// CommonPrometheusFields are the options available to both the Prometheus server and agent. // CommonPrometheusFields are the options available to both the Prometheus server and agent.
// +k8s:deepcopy-gen=true // +k8s:deepcopy-gen=true
type CommonPrometheusFields struct { type CommonPrometheusFields struct {
@ -302,7 +305,10 @@ type CommonPrometheusFields struct {
// that this behaviour may break at any time without notice. // that this behaviour may break at any time without notice.
// //
// For more information see https://prometheus.io/docs/prometheus/latest/feature_flags/ // 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 // The external URL under which the Prometheus service is externally
// available. This is necessary to generate correct URLs (for instance if // available. This is necessary to generate correct URLs (for instance if

View file

@ -700,7 +700,7 @@ func (in *CommonPrometheusFields) DeepCopyInto(out *CommonPrometheusFields) {
} }
if in.EnableFeatures != nil { if in.EnableFeatures != nil {
in, out := &in.EnableFeatures, &out.EnableFeatures in, out := &in.EnableFeatures, &out.EnableFeatures
*out = make([]string, len(*in)) *out = make([]EnableFeature, len(*in))
copy(*out, *in) copy(*out, *in)
} }
if in.Storage != nil { if in.Storage != nil {

View file

@ -51,7 +51,7 @@ type CommonPrometheusFieldsApplyConfiguration struct {
ScrapeProtocols []monitoringv1.ScrapeProtocol `json:"scrapeProtocols,omitempty"` ScrapeProtocols []monitoringv1.ScrapeProtocol `json:"scrapeProtocols,omitempty"`
ExternalLabels map[string]string `json:"externalLabels,omitempty"` ExternalLabels map[string]string `json:"externalLabels,omitempty"`
EnableRemoteWriteReceiver *bool `json:"enableRemoteWriteReceiver,omitempty"` EnableRemoteWriteReceiver *bool `json:"enableRemoteWriteReceiver,omitempty"`
EnableFeatures []string `json:"enableFeatures,omitempty"` EnableFeatures []monitoringv1.EnableFeature `json:"enableFeatures,omitempty"`
ExternalURL *string `json:"externalUrl,omitempty"` ExternalURL *string `json:"externalUrl,omitempty"`
RoutePrefix *string `json:"routePrefix,omitempty"` RoutePrefix *string `json:"routePrefix,omitempty"`
Storage *StorageSpecApplyConfiguration `json:"storage,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 // 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. // 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. // 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 { for i := range values {
b.EnableFeatures = append(b.EnableFeatures, values[i]) b.EnableFeatures = append(b.EnableFeatures, values[i])
} }

View file

@ -270,7 +270,7 @@ func (b *PrometheusSpecApplyConfiguration) WithEnableRemoteWriteReceiver(value b
// WithEnableFeatures adds the given value to the EnableFeatures field in the declarative configuration // 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. // 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. // 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 { for i := range values {
b.EnableFeatures = append(b.EnableFeatures, values[i]) b.EnableFeatures = append(b.EnableFeatures, values[i])
} }

View file

@ -249,7 +249,7 @@ func (b *PrometheusAgentSpecApplyConfiguration) WithEnableRemoteWriteReceiver(va
// WithEnableFeatures adds the given value to the EnableFeatures field in the declarative configuration // 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. // 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. // 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 { for i := range values {
b.EnableFeatures = append(b.EnableFeatures, values[i]) b.EnableFeatures = append(b.EnableFeatures, values[i])
} }

View file

@ -1888,7 +1888,7 @@ func TestEnableFeaturesWithOneFeature(t *testing.T) {
sset, err := makeStatefulSetFromPrometheus(monitoringv1.Prometheus{ sset, err := makeStatefulSetFromPrometheus(monitoringv1.Prometheus{
Spec: monitoringv1.PrometheusSpec{ Spec: monitoringv1.PrometheusSpec{
CommonPrometheusFields: monitoringv1.CommonPrometheusFields{ 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{ sset, err := makeStatefulSetFromPrometheus(monitoringv1.Prometheus{
Spec: monitoringv1.PrometheusSpec{ Spec: monitoringv1.PrometheusSpec{
CommonPrometheusFields: monitoringv1.CommonPrometheusFields{ CommonPrometheusFields: monitoringv1.CommonPrometheusFields{
EnableFeatures: []string{"exemplar-storage1", "exemplar-storage2"}, EnableFeatures: []monitoringv1.EnableFeature{"exemplar-storage1", "exemplar-storage2"},
}, },
}, },
}) })

View file

@ -222,7 +222,11 @@ func BuildCommonPrometheusArgs(cpf monitoringv1.CommonPrometheusFields, cg *Conf
} }
if len(cpf.EnableFeatures) > 0 { 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 != "" { if cpf.ExternalURL != "" {

View file

@ -285,7 +285,7 @@ func (prwtc PromRemoteWriteTestConfig) AddRemoteWriteWithTLSToPrometheus(p *moni
} }
func (f *Framework) EnableRemoteWriteReceiverWithTLS(p *monitoringv1.Prometheus) { 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{ p.Spec.Web = &monitoringv1.PrometheusWebSpec{
WebConfigFileFields: monitoringv1.WebConfigFileFields{ WebConfigFileFields: monitoringv1.WebConfigFileFields{