diff --git a/Documentation/api.md b/Documentation/api.md index 39a7d821d..08d6fe350 100644 --- a/Documentation/api.md +++ b/Documentation/api.md @@ -2135,6 +2135,21 @@ Kubernetes core/v1.Affinity </tr> <tr> <td> +<code>otlp</code><br/> +<em> +<a href="#monitoring.coreos.com/v1.OTLPConfig"> +OTLPConfig +</a> +</em> +</td> +<td> +<em>(Optional)</em> +<p>Settings related to the OTLP receiver feature. +It requires Prometheus >= v2.54.0.</p> +</td> +</tr> +<tr> +<td> <code>securityContext</code><br/> <em> <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#podsecuritycontext-v1-core"> @@ -6869,6 +6884,21 @@ Kubernetes core/v1.Affinity </tr> <tr> <td> +<code>otlp</code><br/> +<em> +<a href="#monitoring.coreos.com/v1.OTLPConfig"> +OTLPConfig +</a> +</em> +</td> +<td> +<em>(Optional)</em> +<p>Settings related to the OTLP receiver feature. +It requires Prometheus >= v2.54.0.</p> +</td> +</tr> +<tr> +<td> <code>securityContext</code><br/> <em> <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#podsecuritycontext-v1-core"> @@ -9219,6 +9249,36 @@ string </tr> </tbody> </table> +<h3 id="monitoring.coreos.com/v1.OTLPConfig">OTLPConfig +</h3> +<p> +(<em>Appears on:</em><a href="#monitoring.coreos.com/v1.CommonPrometheusFields">CommonPrometheusFields</a>) +</p> +<div> +<p>OTLPConfig is the configuration for writing to the OTLP endpoint.</p> +</div> +<table> +<thead> +<tr> +<th>Field</th> +<th>Description</th> +</tr> +</thead> +<tbody> +<tr> +<td> +<code>promoteResourceAttributes</code><br/> +<em> +[]string +</em> +</td> +<td> +<em>(Optional)</em> +<p>List of OpenTelemetry Attributes that should be promoted to metric labels, defaults to none.</p> +</td> +</tr> +</tbody> +</table> <h3 id="monitoring.coreos.com/v1.ObjectReference">ObjectReference </h3> <p> @@ -11133,6 +11193,21 @@ Kubernetes core/v1.Affinity </tr> <tr> <td> +<code>otlp</code><br/> +<em> +<a href="#monitoring.coreos.com/v1.OTLPConfig"> +OTLPConfig +</a> +</em> +</td> +<td> +<em>(Optional)</em> +<p>Settings related to the OTLP receiver feature. +It requires Prometheus >= v2.54.0.</p> +</td> +</tr> +<tr> +<td> <code>securityContext</code><br/> <em> <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#podsecuritycontext-v1-core"> @@ -17384,6 +17459,21 @@ Kubernetes core/v1.Affinity </tr> <tr> <td> +<code>otlp</code><br/> +<em> +<a href="#monitoring.coreos.com/v1.OTLPConfig"> +OTLPConfig +</a> +</em> +</td> +<td> +<em>(Optional)</em> +<p>Settings related to the OTLP receiver feature. +It requires Prometheus >= v2.54.0.</p> +</td> +</tr> +<tr> +<td> <code>securityContext</code><br/> <em> <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#podsecuritycontext-v1-core"> @@ -24729,6 +24819,21 @@ Kubernetes core/v1.Affinity </tr> <tr> <td> +<code>otlp</code><br/> +<em> +<a href="#monitoring.coreos.com/v1.OTLPConfig"> +OTLPConfig +</a> +</em> +</td> +<td> +<em>(Optional)</em> +<p>Settings related to the OTLP receiver feature. +It requires Prometheus >= v2.54.0.</p> +</td> +</tr> +<tr> +<td> <code>securityContext</code><br/> <em> <a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.24/#podsecuritycontext-v1-core"> diff --git a/bundle.yaml b/bundle.yaml index 9207840ac..63036fe0d 100644 --- a/bundle.yaml +++ b/bundle.yaml @@ -25802,6 +25802,21 @@ spec: type: string description: Defines on which Nodes the Pods are scheduled. type: object + otlp: + description: |- + Settings related to the OTLP receiver feature. + It requires Prometheus >= v2.54.0. + properties: + promoteResourceAttributes: + description: List of OpenTelemetry Attributes that should be promoted + to metric labels, defaults to none. + items: + minLength: 1 + type: string + minItems: 1 + type: array + x-kubernetes-list-type: set + type: object overrideHonorLabels: description: |- When true, Prometheus resolves label conflicts by renaming the labels in the scraped data @@ -37286,6 +37301,21 @@ spec: type: string description: Defines on which Nodes the Pods are scheduled. type: object + otlp: + description: |- + Settings related to the OTLP receiver feature. + It requires Prometheus >= v2.54.0. + properties: + promoteResourceAttributes: + description: List of OpenTelemetry Attributes that should be promoted + to metric labels, defaults to none. + items: + minLength: 1 + type: string + minItems: 1 + type: array + x-kubernetes-list-type: set + type: object overrideHonorLabels: description: |- When true, Prometheus resolves label conflicts by renaming the labels in the scraped data 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 4724bd2fa..e8d9854ea 100644 --- a/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheusagents.yaml +++ b/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheusagents.yaml @@ -4757,6 +4757,21 @@ spec: type: string description: Defines on which Nodes the Pods are scheduled. type: object + otlp: + description: |- + Settings related to the OTLP receiver feature. + It requires Prometheus >= v2.54.0. + properties: + promoteResourceAttributes: + description: List of OpenTelemetry Attributes that should be promoted + to metric labels, defaults to none. + items: + minLength: 1 + type: string + minItems: 1 + type: array + x-kubernetes-list-type: set + type: object overrideHonorLabels: description: |- When true, Prometheus resolves label conflicts by renaming the labels in the scraped data 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 ffb1aa20c..4e950feca 100644 --- a/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheuses.yaml +++ b/example/prometheus-operator-crd-full/monitoring.coreos.com_prometheuses.yaml @@ -5526,6 +5526,21 @@ spec: type: string description: Defines on which Nodes the Pods are scheduled. type: object + otlp: + description: |- + Settings related to the OTLP receiver feature. + It requires Prometheus >= v2.54.0. + properties: + promoteResourceAttributes: + description: List of OpenTelemetry Attributes that should be promoted + to metric labels, defaults to none. + items: + minLength: 1 + type: string + minItems: 1 + type: array + x-kubernetes-list-type: set + type: object overrideHonorLabels: description: |- When true, Prometheus resolves label conflicts by renaming the labels in the scraped data diff --git a/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml b/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml index db3585a6f..2a679415d 100644 --- a/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml +++ b/example/prometheus-operator-crd/monitoring.coreos.com_prometheusagents.yaml @@ -4758,6 +4758,21 @@ spec: type: string description: Defines on which Nodes the Pods are scheduled. type: object + otlp: + description: |- + Settings related to the OTLP receiver feature. + It requires Prometheus >= v2.54.0. + properties: + promoteResourceAttributes: + description: List of OpenTelemetry Attributes that should be promoted + to metric labels, defaults to none. + items: + minLength: 1 + type: string + minItems: 1 + type: array + x-kubernetes-list-type: set + type: object overrideHonorLabels: description: |- When true, Prometheus resolves label conflicts by renaming the labels in the scraped data diff --git a/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml b/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml index e76801813..35cfd21b6 100644 --- a/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml +++ b/example/prometheus-operator-crd/monitoring.coreos.com_prometheuses.yaml @@ -5527,6 +5527,21 @@ spec: type: string description: Defines on which Nodes the Pods are scheduled. type: object + otlp: + description: |- + Settings related to the OTLP receiver feature. + It requires Prometheus >= v2.54.0. + properties: + promoteResourceAttributes: + description: List of OpenTelemetry Attributes that should be promoted + to metric labels, defaults to none. + items: + minLength: 1 + type: string + minItems: 1 + type: array + x-kubernetes-list-type: set + type: object overrideHonorLabels: description: |- When true, Prometheus resolves label conflicts by renaming the labels in the scraped data diff --git a/jsonnet/prometheus-operator/prometheusagents-crd.json b/jsonnet/prometheus-operator/prometheusagents-crd.json index 43168a99d..38ed7dec9 100644 --- a/jsonnet/prometheus-operator/prometheusagents-crd.json +++ b/jsonnet/prometheus-operator/prometheusagents-crd.json @@ -3952,6 +3952,22 @@ "description": "Defines on which Nodes the Pods are scheduled.", "type": "object" }, + "otlp": { + "description": "Settings related to the OTLP receiver feature.\nIt requires Prometheus >= v2.54.0.", + "properties": { + "promoteResourceAttributes": { + "description": "List of OpenTelemetry Attributes that should be promoted to metric labels, defaults to none.", + "items": { + "minLength": 1, + "type": "string" + }, + "minItems": 1, + "type": "array", + "x-kubernetes-list-type": "set" + } + }, + "type": "object" + }, "overrideHonorLabels": { "description": "When true, Prometheus resolves label conflicts by renaming the labels in the scraped data\n to “exported_” for all targets created from ServiceMonitor, PodMonitor and\nScrapeConfig objects. Otherwise the HonorLabels field of the service or pod monitor applies.\nIn practice,`overrideHonorLaels:true` enforces `honorLabels:false`\nfor all ServiceMonitor, PodMonitor and ScrapeConfig objects.", "type": "boolean" diff --git a/jsonnet/prometheus-operator/prometheuses-crd.json b/jsonnet/prometheus-operator/prometheuses-crd.json index f9165626d..49ec6079c 100644 --- a/jsonnet/prometheus-operator/prometheuses-crd.json +++ b/jsonnet/prometheus-operator/prometheuses-crd.json @@ -4553,6 +4553,22 @@ "description": "Defines on which Nodes the Pods are scheduled.", "type": "object" }, + "otlp": { + "description": "Settings related to the OTLP receiver feature.\nIt requires Prometheus >= v2.54.0.", + "properties": { + "promoteResourceAttributes": { + "description": "List of OpenTelemetry Attributes that should be promoted to metric labels, defaults to none.", + "items": { + "minLength": 1, + "type": "string" + }, + "minItems": 1, + "type": "array", + "x-kubernetes-list-type": "set" + } + }, + "type": "object" + }, "overrideHonorLabels": { "description": "When true, Prometheus resolves label conflicts by renaming the labels in the scraped data\n to “exported_” for all targets created from ServiceMonitor, PodMonitor and\nScrapeConfig objects. Otherwise the HonorLabels field of the service or pod monitor applies.\nIn practice,`overrideHonorLaels:true` enforces `honorLabels:false`\nfor all ServiceMonitor, PodMonitor and ScrapeConfig objects.", "type": "boolean" diff --git a/pkg/apis/monitoring/v1/prometheus_types.go b/pkg/apis/monitoring/v1/prometheus_types.go index b3baf2482..c2f555d1d 100644 --- a/pkg/apis/monitoring/v1/prometheus_types.go +++ b/pkg/apis/monitoring/v1/prometheus_types.go @@ -391,6 +391,12 @@ type CommonPrometheusFields struct { // +optional RemoteWrite []RemoteWriteSpec `json:"remoteWrite,omitempty"` + // Settings related to the OTLP receiver feature. + // It requires Prometheus >= v2.54.0. + // + // +optional + OTLP *OTLPConfig `json:"otlp,omitempty"` + // SecurityContext holds pod-level security attributes and common container settings. // This defaults to the default PodSecurityContext. // +optional @@ -2011,3 +2017,16 @@ type ScrapeClass struct { // +optional AttachMetadata *AttachMetadata `json:"attachMetadata,omitempty"` } + +// OTLPConfig is the configuration for writing to the OTLP endpoint. +// +// +k8s:openapi-gen=true +type OTLPConfig struct { + // List of OpenTelemetry Attributes that should be promoted to metric labels, defaults to none. + // + // +kubebuilder:validation:MinItems=1 + // +kubebuilder:validation:items:MinLength=1 + // +listType=set + // +optional + PromoteResourceAttributes []string `json:"promoteResourceAttributes,omitempty"` +} diff --git a/pkg/apis/monitoring/v1/zz_generated.deepcopy.go b/pkg/apis/monitoring/v1/zz_generated.deepcopy.go index bf72f1451..333e687b9 100644 --- a/pkg/apis/monitoring/v1/zz_generated.deepcopy.go +++ b/pkg/apis/monitoring/v1/zz_generated.deepcopy.go @@ -825,6 +825,11 @@ func (in *CommonPrometheusFields) DeepCopyInto(out *CommonPrometheusFields) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.OTLP != nil { + in, out := &in.OTLP, &out.OTLP + *out = new(OTLPConfig) + (*in).DeepCopyInto(*out) + } if in.SecurityContext != nil { in, out := &in.SecurityContext, &out.SecurityContext *out = new(corev1.PodSecurityContext) @@ -1455,6 +1460,26 @@ func (in *OAuth2ValidationError) DeepCopy() *OAuth2ValidationError { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *OTLPConfig) DeepCopyInto(out *OTLPConfig) { + *out = *in + if in.PromoteResourceAttributes != nil { + in, out := &in.PromoteResourceAttributes, &out.PromoteResourceAttributes + *out = make([]string, len(*in)) + copy(*out, *in) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OTLPConfig. +func (in *OTLPConfig) DeepCopy() *OTLPConfig { + if in == nil { + return nil + } + out := new(OTLPConfig) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ObjectReference) DeepCopyInto(out *ObjectReference) { *out = *in diff --git a/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go b/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go index 83380f257..50ebf9d1b 100644 --- a/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go +++ b/pkg/client/applyconfiguration/monitoring/v1/commonprometheusfields.go @@ -69,6 +69,7 @@ type CommonPrometheusFieldsApplyConfiguration struct { Tolerations []corev1.Toleration `json:"tolerations,omitempty"` TopologySpreadConstraints []TopologySpreadConstraintApplyConfiguration `json:"topologySpreadConstraints,omitempty"` RemoteWrite []RemoteWriteSpecApplyConfiguration `json:"remoteWrite,omitempty"` + OTLP *OTLPConfigApplyConfiguration `json:"otlp,omitempty"` SecurityContext *corev1.PodSecurityContext `json:"securityContext,omitempty"` ListenLocal *bool `json:"listenLocal,omitempty"` Containers []corev1.Container `json:"containers,omitempty"` @@ -498,6 +499,14 @@ func (b *CommonPrometheusFieldsApplyConfiguration) WithRemoteWrite(values ...*Re return b } +// WithOTLP sets the OTLP field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the OTLP field is set to the value of the last call. +func (b *CommonPrometheusFieldsApplyConfiguration) WithOTLP(value *OTLPConfigApplyConfiguration) *CommonPrometheusFieldsApplyConfiguration { + b.OTLP = value + return b +} + // WithSecurityContext sets the SecurityContext field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the SecurityContext field is set to the value of the last call. diff --git a/pkg/client/applyconfiguration/monitoring/v1/otlpconfig.go b/pkg/client/applyconfiguration/monitoring/v1/otlpconfig.go new file mode 100644 index 000000000..6e1101d07 --- /dev/null +++ b/pkg/client/applyconfiguration/monitoring/v1/otlpconfig.go @@ -0,0 +1,39 @@ +// Copyright The prometheus-operator Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1 + +// OTLPConfigApplyConfiguration represents an declarative configuration of the OTLPConfig type for use +// with apply. +type OTLPConfigApplyConfiguration struct { + PromoteResourceAttributes []string `json:"promoteResourceAttributes,omitempty"` +} + +// OTLPConfigApplyConfiguration constructs an declarative configuration of the OTLPConfig type for use with +// apply. +func OTLPConfig() *OTLPConfigApplyConfiguration { + return &OTLPConfigApplyConfiguration{} +} + +// WithPromoteResourceAttributes adds the given value to the PromoteResourceAttributes 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 PromoteResourceAttributes field. +func (b *OTLPConfigApplyConfiguration) WithPromoteResourceAttributes(values ...string) *OTLPConfigApplyConfiguration { + for i := range values { + b.PromoteResourceAttributes = append(b.PromoteResourceAttributes, values[i]) + } + return b +} diff --git a/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go b/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go index 03f4bec94..ba90eb722 100644 --- a/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go +++ b/pkg/client/applyconfiguration/monitoring/v1/prometheusspec.go @@ -439,6 +439,14 @@ func (b *PrometheusSpecApplyConfiguration) WithRemoteWrite(values ...*RemoteWrit return b } +// WithOTLP sets the OTLP field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the OTLP field is set to the value of the last call. +func (b *PrometheusSpecApplyConfiguration) WithOTLP(value *OTLPConfigApplyConfiguration) *PrometheusSpecApplyConfiguration { + b.OTLP = value + return b +} + // WithSecurityContext sets the SecurityContext field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the SecurityContext field is set to the value of the last call. diff --git a/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go b/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go index 56d73ca0c..5ae6d27dc 100644 --- a/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go +++ b/pkg/client/applyconfiguration/monitoring/v1alpha1/prometheusagentspec.go @@ -427,6 +427,14 @@ func (b *PrometheusAgentSpecApplyConfiguration) WithRemoteWrite(values ...*v1.Re return b } +// WithOTLP sets the OTLP field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the OTLP field is set to the value of the last call. +func (b *PrometheusAgentSpecApplyConfiguration) WithOTLP(value *v1.OTLPConfigApplyConfiguration) *PrometheusAgentSpecApplyConfiguration { + b.OTLP = value + return b +} + // WithSecurityContext sets the SecurityContext field in the declarative configuration to the given value // and returns the receiver, so that objects can be built by chaining "With" function invocations. // If called multiple times, the SecurityContext field is set to the value of the last call. diff --git a/pkg/client/applyconfiguration/utils.go b/pkg/client/applyconfiguration/utils.go index 0bed8a9ca..12fe17ed2 100644 --- a/pkg/client/applyconfiguration/utils.go +++ b/pkg/client/applyconfiguration/utils.go @@ -99,6 +99,8 @@ func ForKind(kind schema.GroupVersionKind) interface{} { return &monitoringv1.OAuth2ApplyConfiguration{} case v1.SchemeGroupVersion.WithKind("ObjectReference"): return &monitoringv1.ObjectReferenceApplyConfiguration{} + case v1.SchemeGroupVersion.WithKind("OTLPConfig"): + return &monitoringv1.OTLPConfigApplyConfiguration{} case v1.SchemeGroupVersion.WithKind("PodMetricsEndpoint"): return &monitoringv1.PodMetricsEndpointApplyConfiguration{} case v1.SchemeGroupVersion.WithKind("PodMonitor"): diff --git a/pkg/prometheus/promcfg.go b/pkg/prometheus/promcfg.go index 350038b50..e15bddb67 100644 --- a/pkg/prometheus/promcfg.go +++ b/pkg/prometheus/promcfg.go @@ -786,6 +786,15 @@ func (cg *ConfigGenerator) GenerateServerConfiguration( cfg = append(cfg, cg.generateRemoteReadConfig(remoteRead, store)) } + // OTLP config + if cpf.OTLP != nil { + otlpcfg, err := cg.generateOTLPConfig() + if err != nil { + return nil, fmt.Errorf("generating OTLP configuration failed: %w", err) + } + cfg = append(cfg, otlpcfg) + } + if cpf.TracingConfig != nil { tracingcfg, err := cg.generateTracingConfig(store) @@ -2560,6 +2569,15 @@ func (cg *ConfigGenerator) GenerateAgentConfiguration( cfg = append(cfg, cg.generateRemoteWriteConfig(store)) } + // OTLP config + if cpf.OTLP != nil { + otlpcfg, err := cg.generateOTLPConfig() + if err != nil { + return nil, fmt.Errorf("generating OTLP configuration failed: %w", err) + } + cfg = append(cfg, otlpcfg) + } + if cpf.TracingConfig != nil { tracingcfg, err := cg.generateTracingConfig(store) if err != nil { @@ -4124,6 +4142,25 @@ func (cg *ConfigGenerator) generateScrapeConfig( return cfg, nil } +func (cg *ConfigGenerator) generateOTLPConfig() (yaml.MapItem, error) { + if cg.version.LT(semver.MustParse("2.54.0")) { + return yaml.MapItem{}, fmt.Errorf("OTLP configuration is only supported from Prometheus version 2.54.0") + } + + otlpConfig := cg.prom.GetCommonPrometheusFields().OTLP + + cfg := yaml.MapSlice{} + cfg = append(cfg, yaml.MapItem{ + Key: "promote_resource_attributes", + Value: otlpConfig.PromoteResourceAttributes, + }) + + return yaml.MapItem{ + Key: "otlp", + Value: cfg, + }, nil +} + func (cg *ConfigGenerator) generateTracingConfig(store *assets.StoreBuilder) (yaml.MapItem, error) { cfg := yaml.MapSlice{} objMeta := cg.prom.GetObjectMeta() diff --git a/pkg/prometheus/promcfg_test.go b/pkg/prometheus/promcfg_test.go index d8f17114d..c0a2688c9 100644 --- a/pkg/prometheus/promcfg_test.go +++ b/pkg/prometheus/promcfg_test.go @@ -8105,6 +8105,82 @@ func TestScrapeConfigSpecConfigWithHetznerSD(t *testing.T) { } } +func TestOTLPConfig(t *testing.T) { + testCases := []struct { + otlpConfig *monitoringv1.OTLPConfig + name string + version string + expectedErr bool + golden string + }{ + { + name: "Config promote resource attributes", + version: "v2.54.0", + otlpConfig: &monitoringv1.OTLPConfig{ + PromoteResourceAttributes: []string{"aa", "bb", "cc"}, + }, + golden: "OTLPConfig_Config_promote_resource_attributes.golden", + expectedErr: false, + }, + { + name: "Config promote resource attributes with old version", + version: "v2.53.0", + otlpConfig: &monitoringv1.OTLPConfig{ + PromoteResourceAttributes: []string{"aa", "bb", "cc"}, + }, + expectedErr: true, + }, + { + name: "Config Empty attributes", + version: "v2.54.0", + otlpConfig: &monitoringv1.OTLPConfig{ + PromoteResourceAttributes: []string{}, + }, + expectedErr: false, + golden: "OTLPConfig_Config_empty_attributes.golden", + }, + } + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + store := assets.NewTestStoreBuilder() + p := defaultPrometheus() + + if tc.version != "" { + p.Spec.CommonPrometheusFields.Version = tc.version + } + + p.Spec.CommonPrometheusFields.OTLP = tc.otlpConfig + + cg := mustNewConfigGenerator(t, p) + + cfg, err := cg.GenerateServerConfiguration( + p.Spec.EvaluationInterval, + p.Spec.QueryLogFile, + p.Spec.RuleSelector, + p.Spec.Exemplars, + p.Spec.TSDB, + p.Spec.Alerting, + p.Spec.RemoteRead, + nil, + nil, + nil, + nil, + store, + nil, + nil, + nil, + nil, + ) + if tc.expectedErr { + require.Error(t, err) + } else { + require.NoError(t, err) + golden.Assert(t, string(cfg), tc.golden) + } + }) + } +} + func TestTracingConfig(t *testing.T) { samplingTwo := resource.MustParse("0.5") testCases := []struct { diff --git a/pkg/prometheus/testdata/OTLPConfig_Config_empty_attributes.golden b/pkg/prometheus/testdata/OTLPConfig_Config_empty_attributes.golden new file mode 100644 index 000000000..15f3b4533 --- /dev/null +++ b/pkg/prometheus/testdata/OTLPConfig_Config_empty_attributes.golden @@ -0,0 +1,9 @@ +global: + evaluation_interval: 30s + scrape_interval: 30s + external_labels: + prometheus: default/test + prometheus_replica: $(POD_NAME) +scrape_configs: [] +otlp: + promote_resource_attributes: [] diff --git a/pkg/prometheus/testdata/OTLPConfig_Config_promote_resource_attributes.golden b/pkg/prometheus/testdata/OTLPConfig_Config_promote_resource_attributes.golden new file mode 100644 index 000000000..b1267111e --- /dev/null +++ b/pkg/prometheus/testdata/OTLPConfig_Config_promote_resource_attributes.golden @@ -0,0 +1,12 @@ +global: + evaluation_interval: 30s + scrape_interval: 30s + external_labels: + prometheus: default/test + prometheus_replica: $(POD_NAME) +scrape_configs: [] +otlp: + promote_resource_attributes: + - aa + - bb + - cc