mirror of
https://github.com/prometheus-operator/prometheus-operator.git
synced 2025-04-15 16:56:24 +00:00
feat: support new otlp
receiver configuration (#6780)
--------- Signed-off-by: dongjiang1989 <dongjiang1989@126.com> Co-authored-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
parent
698a8923fd
commit
304ca66537
19 changed files with 471 additions and 0 deletions
105
Documentation/api.md
generated
105
Documentation/api.md
generated
|
@ -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">
|
||||
|
|
30
bundle.yaml
generated
30
bundle.yaml
generated
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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"`
|
||||
}
|
||||
|
|
25
pkg/apis/monitoring/v1/zz_generated.deepcopy.go
generated
25
pkg/apis/monitoring/v1/zz_generated.deepcopy.go
generated
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
39
pkg/client/applyconfiguration/monitoring/v1/otlpconfig.go
Normal file
39
pkg/client/applyconfiguration/monitoring/v1/otlpconfig.go
Normal file
|
@ -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
|
||||
}
|
|
@ -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.
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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"):
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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 {
|
||||
|
|
9
pkg/prometheus/testdata/OTLPConfig_Config_empty_attributes.golden
generated
vendored
Normal file
9
pkg/prometheus/testdata/OTLPConfig_Config_empty_attributes.golden
generated
vendored
Normal file
|
@ -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: []
|
12
pkg/prometheus/testdata/OTLPConfig_Config_promote_resource_attributes.golden
generated
vendored
Normal file
12
pkg/prometheus/testdata/OTLPConfig_Config_promote_resource_attributes.golden
generated
vendored
Normal file
|
@ -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
|
Loading…
Add table
Reference in a new issue