mirror of
https://github.com/prometheus-operator/prometheus-operator.git
synced 2025-04-21 03:38:43 +00:00
feat: add support TranslationStrategy
option for OTLP receiver (#7112)
--------- Signed-off-by: dongjiang1989 <dongjiang1989@126.com> Co-authored-by: Simon Pasquier <spasquie@redhat.com>
This commit is contained in:
parent
0ef087d4e0
commit
0a5584367f
17 changed files with 222 additions and 18 deletions
Documentation
bundle.yamlexample
prometheus-operator-crd-full
prometheus-operator-crd
jsonnet/prometheus-operator
pkg
apis/monitoring/v1
client/applyconfiguration/monitoring/v1
prometheus
40
Documentation/api.md
generated
40
Documentation/api.md
generated
|
@ -9781,6 +9781,22 @@ string
|
|||
<p>List of OpenTelemetry Attributes that should be promoted to metric labels, defaults to none.</p>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<code>translationStrategy</code><br/>
|
||||
<em>
|
||||
<a href="#monitoring.coreos.com/v1.TranslationStrategyOption">
|
||||
TranslationStrategyOption
|
||||
</a>
|
||||
</em>
|
||||
</td>
|
||||
<td>
|
||||
<em>(Optional)</em>
|
||||
<p>Configures how the OTLP receiver endpoint translates the incoming metrics.
|
||||
If unset, Prometheus uses its default value.</p>
|
||||
<p>It requires Prometheus >= v3.0.0.</p>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h3 id="monitoring.coreos.com/v1.ObjectReference">ObjectReference
|
||||
|
@ -17226,6 +17242,30 @@ AdditionalLabelSelectors
|
|||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h3 id="monitoring.coreos.com/v1.TranslationStrategyOption">TranslationStrategyOption
|
||||
(<code>string</code> alias)</h3>
|
||||
<p>
|
||||
(<em>Appears on:</em><a href="#monitoring.coreos.com/v1.OTLPConfig">OTLPConfig</a>)
|
||||
</p>
|
||||
<div>
|
||||
<p>TranslationStrategyOption represents a translation strategy option for the OTLP endpoint.
|
||||
Supported values are:
|
||||
* <code>NoUTF8EscapingWithSuffixes</code>
|
||||
* <code>UnderscoreEscapingWithSuffixes</code></p>
|
||||
</div>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Value</th>
|
||||
<th>Description</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody><tr><td><p>"NoUTF8EscapingWithSuffixes"</p></td>
|
||||
<td></td>
|
||||
</tr><tr><td><p>"UnderscoreEscapingWithSuffixes"</p></td>
|
||||
<td></td>
|
||||
</tr></tbody>
|
||||
</table>
|
||||
<h3 id="monitoring.coreos.com/v1.WebConfigFileFields">WebConfigFileFields
|
||||
</h3>
|
||||
<p>
|
||||
|
|
20
bundle.yaml
generated
20
bundle.yaml
generated
|
@ -25680,6 +25680,16 @@ spec:
|
|||
minItems: 1
|
||||
type: array
|
||||
x-kubernetes-list-type: set
|
||||
translationStrategy:
|
||||
description: |-
|
||||
Configures how the OTLP receiver endpoint translates the incoming metrics.
|
||||
If unset, Prometheus uses its default value.
|
||||
|
||||
It requires Prometheus >= v3.0.0.
|
||||
enum:
|
||||
- NoUTF8EscapingWithSuffixes
|
||||
- UnderscoreEscapingWithSuffixes
|
||||
type: string
|
||||
type: object
|
||||
overrideHonorLabels:
|
||||
description: |-
|
||||
|
@ -37012,6 +37022,16 @@ spec:
|
|||
minItems: 1
|
||||
type: array
|
||||
x-kubernetes-list-type: set
|
||||
translationStrategy:
|
||||
description: |-
|
||||
Configures how the OTLP receiver endpoint translates the incoming metrics.
|
||||
If unset, Prometheus uses its default value.
|
||||
|
||||
It requires Prometheus >= v3.0.0.
|
||||
enum:
|
||||
- NoUTF8EscapingWithSuffixes
|
||||
- UnderscoreEscapingWithSuffixes
|
||||
type: string
|
||||
type: object
|
||||
overrideHonorLabels:
|
||||
description: |-
|
||||
|
|
|
@ -4737,6 +4737,16 @@ spec:
|
|||
minItems: 1
|
||||
type: array
|
||||
x-kubernetes-list-type: set
|
||||
translationStrategy:
|
||||
description: |-
|
||||
Configures how the OTLP receiver endpoint translates the incoming metrics.
|
||||
If unset, Prometheus uses its default value.
|
||||
|
||||
It requires Prometheus >= v3.0.0.
|
||||
enum:
|
||||
- NoUTF8EscapingWithSuffixes
|
||||
- UnderscoreEscapingWithSuffixes
|
||||
type: string
|
||||
type: object
|
||||
overrideHonorLabels:
|
||||
description: |-
|
||||
|
|
|
@ -5446,6 +5446,16 @@ spec:
|
|||
minItems: 1
|
||||
type: array
|
||||
x-kubernetes-list-type: set
|
||||
translationStrategy:
|
||||
description: |-
|
||||
Configures how the OTLP receiver endpoint translates the incoming metrics.
|
||||
If unset, Prometheus uses its default value.
|
||||
|
||||
It requires Prometheus >= v3.0.0.
|
||||
enum:
|
||||
- NoUTF8EscapingWithSuffixes
|
||||
- UnderscoreEscapingWithSuffixes
|
||||
type: string
|
||||
type: object
|
||||
overrideHonorLabels:
|
||||
description: |-
|
||||
|
|
|
@ -4738,6 +4738,16 @@ spec:
|
|||
minItems: 1
|
||||
type: array
|
||||
x-kubernetes-list-type: set
|
||||
translationStrategy:
|
||||
description: |-
|
||||
Configures how the OTLP receiver endpoint translates the incoming metrics.
|
||||
If unset, Prometheus uses its default value.
|
||||
|
||||
It requires Prometheus >= v3.0.0.
|
||||
enum:
|
||||
- NoUTF8EscapingWithSuffixes
|
||||
- UnderscoreEscapingWithSuffixes
|
||||
type: string
|
||||
type: object
|
||||
overrideHonorLabels:
|
||||
description: |-
|
||||
|
|
|
@ -5447,6 +5447,16 @@ spec:
|
|||
minItems: 1
|
||||
type: array
|
||||
x-kubernetes-list-type: set
|
||||
translationStrategy:
|
||||
description: |-
|
||||
Configures how the OTLP receiver endpoint translates the incoming metrics.
|
||||
If unset, Prometheus uses its default value.
|
||||
|
||||
It requires Prometheus >= v3.0.0.
|
||||
enum:
|
||||
- NoUTF8EscapingWithSuffixes
|
||||
- UnderscoreEscapingWithSuffixes
|
||||
type: string
|
||||
type: object
|
||||
overrideHonorLabels:
|
||||
description: |-
|
||||
|
|
|
@ -4038,6 +4038,14 @@
|
|||
"minItems": 1,
|
||||
"type": "array",
|
||||
"x-kubernetes-list-type": "set"
|
||||
},
|
||||
"translationStrategy": {
|
||||
"description": "Configures how the OTLP receiver endpoint translates the incoming metrics.\nIf unset, Prometheus uses its default value.\n\nIt requires Prometheus >= v3.0.0.",
|
||||
"enum": [
|
||||
"NoUTF8EscapingWithSuffixes",
|
||||
"UnderscoreEscapingWithSuffixes"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
|
|
|
@ -4639,6 +4639,14 @@
|
|||
"minItems": 1,
|
||||
"type": "array",
|
||||
"x-kubernetes-list-type": "set"
|
||||
},
|
||||
"translationStrategy": {
|
||||
"description": "Configures how the OTLP receiver endpoint translates the incoming metrics.\nIf unset, Prometheus uses its default value.\n\nIt requires Prometheus >= v3.0.0.",
|
||||
"enum": [
|
||||
"NoUTF8EscapingWithSuffixes",
|
||||
"UnderscoreEscapingWithSuffixes"
|
||||
],
|
||||
"type": "string"
|
||||
}
|
||||
},
|
||||
"type": "object"
|
||||
|
|
|
@ -2105,6 +2105,18 @@ type ScrapeClass struct {
|
|||
AttachMetadata *AttachMetadata `json:"attachMetadata,omitempty"`
|
||||
}
|
||||
|
||||
// TranslationStrategyOption represents a translation strategy option for the OTLP endpoint.
|
||||
// Supported values are:
|
||||
// * `NoUTF8EscapingWithSuffixes`
|
||||
// * `UnderscoreEscapingWithSuffixes`
|
||||
// +kubebuilder:validation:Enum=NoUTF8EscapingWithSuffixes;UnderscoreEscapingWithSuffixes
|
||||
type TranslationStrategyOption string
|
||||
|
||||
const (
|
||||
NoUTF8EscapingWithSuffixes TranslationStrategyOption = "NoUTF8EscapingWithSuffixes"
|
||||
UnderscoreEscapingWithSuffixes TranslationStrategyOption = "UnderscoreEscapingWithSuffixes"
|
||||
)
|
||||
|
||||
// OTLPConfig is the configuration for writing to the OTLP endpoint.
|
||||
//
|
||||
// +k8s:openapi-gen=true
|
||||
|
@ -2116,4 +2128,11 @@ type OTLPConfig struct {
|
|||
// +listType=set
|
||||
// +optional
|
||||
PromoteResourceAttributes []string `json:"promoteResourceAttributes,omitempty"`
|
||||
|
||||
// Configures how the OTLP receiver endpoint translates the incoming metrics.
|
||||
// If unset, Prometheus uses its default value.
|
||||
//
|
||||
// It requires Prometheus >= v3.0.0.
|
||||
// +optional
|
||||
TranslationStrategy *TranslationStrategyOption `json:"translationStrategy,omitempty"`
|
||||
}
|
||||
|
|
5
pkg/apis/monitoring/v1/zz_generated.deepcopy.go
generated
5
pkg/apis/monitoring/v1/zz_generated.deepcopy.go
generated
|
@ -1534,6 +1534,11 @@ func (in *OTLPConfig) DeepCopyInto(out *OTLPConfig) {
|
|||
*out = make([]string, len(*in))
|
||||
copy(*out, *in)
|
||||
}
|
||||
if in.TranslationStrategy != nil {
|
||||
in, out := &in.TranslationStrategy, &out.TranslationStrategy
|
||||
*out = new(TranslationStrategyOption)
|
||||
**out = **in
|
||||
}
|
||||
}
|
||||
|
||||
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OTLPConfig.
|
||||
|
|
|
@ -16,10 +16,15 @@
|
|||
|
||||
package v1
|
||||
|
||||
import (
|
||||
v1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
|
||||
)
|
||||
|
||||
// OTLPConfigApplyConfiguration represents a declarative configuration of the OTLPConfig type for use
|
||||
// with apply.
|
||||
type OTLPConfigApplyConfiguration struct {
|
||||
PromoteResourceAttributes []string `json:"promoteResourceAttributes,omitempty"`
|
||||
PromoteResourceAttributes []string `json:"promoteResourceAttributes,omitempty"`
|
||||
TranslationStrategy *v1.TranslationStrategyOption `json:"translationStrategy,omitempty"`
|
||||
}
|
||||
|
||||
// OTLPConfigApplyConfiguration constructs a declarative configuration of the OTLPConfig type for use with
|
||||
|
@ -37,3 +42,11 @@ func (b *OTLPConfigApplyConfiguration) WithPromoteResourceAttributes(values ...s
|
|||
}
|
||||
return b
|
||||
}
|
||||
|
||||
// WithTranslationStrategy sets the TranslationStrategy 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 TranslationStrategy field is set to the value of the last call.
|
||||
func (b *OTLPConfigApplyConfiguration) WithTranslationStrategy(value v1.TranslationStrategyOption) *OTLPConfigApplyConfiguration {
|
||||
b.TranslationStrategy = &value
|
||||
return b
|
||||
}
|
||||
|
|
|
@ -4496,17 +4496,25 @@ func (cg *ConfigGenerator) appendOTLPConfig(cfg yaml.MapSlice) (yaml.MapSlice, e
|
|||
return cfg, fmt.Errorf("OTLP configuration is only supported from Prometheus version 2.55.0")
|
||||
}
|
||||
|
||||
return append(
|
||||
cfg,
|
||||
yaml.MapItem{
|
||||
Key: "otlp",
|
||||
Value: yaml.MapSlice{
|
||||
{
|
||||
Key: "promote_resource_attributes",
|
||||
Value: otlpConfig.PromoteResourceAttributes,
|
||||
},
|
||||
},
|
||||
}), nil
|
||||
otlp := yaml.MapSlice{}
|
||||
|
||||
if len(otlpConfig.PromoteResourceAttributes) > 0 {
|
||||
otlp = cg.WithMinimumVersion("2.55.0").AppendMapItem(otlp,
|
||||
"promote_resource_attributes",
|
||||
otlpConfig.PromoteResourceAttributes)
|
||||
}
|
||||
|
||||
if otlpConfig.TranslationStrategy != nil {
|
||||
otlp = cg.WithMinimumVersion("3.0.0").AppendMapItem(otlp,
|
||||
"translation_strategy",
|
||||
otlpConfig.TranslationStrategy)
|
||||
}
|
||||
|
||||
if len(otlp) == 0 {
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
return cg.AppendMapItem(cfg, "otlp", otlp), nil
|
||||
}
|
||||
|
||||
func (cg *ConfigGenerator) appendTracingConfig(cfg yaml.MapSlice, s assets.StoreGetter) (yaml.MapSlice, error) {
|
||||
|
|
|
@ -8596,8 +8596,7 @@ func TestOTLPConfig(t *testing.T) {
|
|||
otlpConfig: &monitoringv1.OTLPConfig{
|
||||
PromoteResourceAttributes: []string{"aa", "bb", "cc"},
|
||||
},
|
||||
golden: "OTLPConfig_Config_promote_resource_attributes.golden",
|
||||
expectedErr: false,
|
||||
golden: "OTLPConfig_Config_promote_resource_attributes.golden",
|
||||
},
|
||||
{
|
||||
name: "Config promote resource attributes with old version",
|
||||
|
@ -8613,8 +8612,31 @@ func TestOTLPConfig(t *testing.T) {
|
|||
otlpConfig: &monitoringv1.OTLPConfig{
|
||||
PromoteResourceAttributes: []string{},
|
||||
},
|
||||
expectedErr: false,
|
||||
golden: "OTLPConfig_Config_empty_attributes.golden",
|
||||
golden: "OTLPConfig_Config_empty_attributes.golden",
|
||||
},
|
||||
{
|
||||
name: "Config otlp translation strategy",
|
||||
version: "v3.0.0",
|
||||
otlpConfig: &monitoringv1.OTLPConfig{
|
||||
TranslationStrategy: ptr.To(monitoringv1.UnderscoreEscapingWithSuffixes),
|
||||
},
|
||||
golden: "OTLPConfig_Config_translation_strategy.golden",
|
||||
},
|
||||
{
|
||||
name: "Config Empty translation strategy",
|
||||
version: "v3.0.0",
|
||||
otlpConfig: &monitoringv1.OTLPConfig{
|
||||
TranslationStrategy: nil,
|
||||
},
|
||||
golden: "OTLPConfig_Config_empty_translation_strategy.golden",
|
||||
},
|
||||
{
|
||||
name: "Config Empty translation strategy",
|
||||
version: "v2.55.0",
|
||||
otlpConfig: &monitoringv1.OTLPConfig{
|
||||
TranslationStrategy: ptr.To(monitoringv1.UnderscoreEscapingWithSuffixes),
|
||||
},
|
||||
golden: "OTLPConfig_Config_translation_strategy_with_unsupported_version.golden",
|
||||
},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
|
|
2
pkg/prometheus/testdata/OTLPConfig_Config_empty_attributes.golden
generated
vendored
2
pkg/prometheus/testdata/OTLPConfig_Config_empty_attributes.golden
generated
vendored
|
@ -5,5 +5,3 @@ global:
|
|||
prometheus_replica: $(POD_NAME)
|
||||
evaluation_interval: 30s
|
||||
scrape_configs: []
|
||||
otlp:
|
||||
promote_resource_attributes: []
|
||||
|
|
7
pkg/prometheus/testdata/OTLPConfig_Config_empty_translation_strategy.golden
generated
vendored
Normal file
7
pkg/prometheus/testdata/OTLPConfig_Config_empty_translation_strategy.golden
generated
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
global:
|
||||
scrape_interval: 30s
|
||||
external_labels:
|
||||
prometheus: default/test
|
||||
prometheus_replica: $(POD_NAME)
|
||||
evaluation_interval: 30s
|
||||
scrape_configs: []
|
9
pkg/prometheus/testdata/OTLPConfig_Config_translation_strategy.golden
generated
vendored
Normal file
9
pkg/prometheus/testdata/OTLPConfig_Config_translation_strategy.golden
generated
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
global:
|
||||
scrape_interval: 30s
|
||||
external_labels:
|
||||
prometheus: default/test
|
||||
prometheus_replica: $(POD_NAME)
|
||||
evaluation_interval: 30s
|
||||
scrape_configs: []
|
||||
otlp:
|
||||
translation_strategy: UnderscoreEscapingWithSuffixes
|
7
pkg/prometheus/testdata/OTLPConfig_Config_translation_strategy_with_unsupported_version.golden
generated
vendored
Normal file
7
pkg/prometheus/testdata/OTLPConfig_Config_translation_strategy_with_unsupported_version.golden
generated
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
global:
|
||||
scrape_interval: 30s
|
||||
external_labels:
|
||||
prometheus: default/test
|
||||
prometheus_replica: $(POD_NAME)
|
||||
evaluation_interval: 30s
|
||||
scrape_configs: []
|
Loading…
Add table
Add a link
Reference in a new issue