mirror of https://github.com/prometheus/prometheus
Rename to keep_identifying_resource_attributes
Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>pull/15448/head
parent
ffabc04829
commit
174f828d70
|
@ -1431,7 +1431,7 @@ var (
|
|||
type OTLPConfig struct {
|
||||
PromoteResourceAttributes []string `yaml:"promote_resource_attributes,omitempty"`
|
||||
TranslationStrategy translationStrategyOption `yaml:"translation_strategy,omitempty"`
|
||||
ServiceNameInTargetInfo bool `yaml:"service_name_in_target_info,omitempty"`
|
||||
KeepIdentifyingResourceAttributes bool `yaml:"keep_identifying_resource_attributes,omitempty"`
|
||||
}
|
||||
|
||||
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
||||
|
|
|
@ -1556,7 +1556,7 @@ func TestOTLPSanitizeResourceAttributes(t *testing.T) {
|
|||
|
||||
func TestOTLPAllowServiceNameInTargetInfo(t *testing.T) {
|
||||
t.Run("good config", func(t *testing.T) {
|
||||
want, err := LoadFile(filepath.Join("testdata", "otlp_allow_service_name_in_target_info.good.yml"), false, promslog.NewNopLogger())
|
||||
want, err := LoadFile(filepath.Join("testdata", "otlp_allow_keep_identifying_resource_attributes.good.yml"), false, promslog.NewNopLogger())
|
||||
require.NoError(t, err)
|
||||
|
||||
out, err := yaml.Marshal(want)
|
||||
|
@ -1564,7 +1564,7 @@ func TestOTLPAllowServiceNameInTargetInfo(t *testing.T) {
|
|||
var got Config
|
||||
require.NoError(t, yaml.UnmarshalStrict(out, &got))
|
||||
|
||||
require.Equal(t, true, got.OTLPConfig.ServiceNameInTargetInfo)
|
||||
require.Equal(t, true, got.OTLPConfig.KeepIdentifyingResourceAttributes)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
otlp:
|
||||
keep_identifying_resource_attributes: true
|
|
@ -1,2 +0,0 @@
|
|||
otlp:
|
||||
service_name_in_target_info: true
|
|
@ -600,7 +600,7 @@ func addResourceTargetInfo(resource pcommon.Resource, settings Settings, timesta
|
|||
}
|
||||
|
||||
settings.PromoteResourceAttributes = nil
|
||||
if settings.ServiceNameInTargetInfo {
|
||||
if settings.KeepIdentifyingResourceAttributes {
|
||||
// Do not pass identifying attributes as ignoreAttrs below.
|
||||
identifyingAttrs = nil
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ type Settings struct {
|
|||
AddMetricSuffixes bool
|
||||
AllowUTF8 bool
|
||||
PromoteResourceAttributes []string
|
||||
ServiceNameInTargetInfo bool
|
||||
KeepIdentifyingResourceAttributes bool
|
||||
}
|
||||
|
||||
// PrometheusConverter converts from OTel write format to Prometheus remote write format.
|
||||
|
|
|
@ -35,8 +35,8 @@ import (
|
|||
|
||||
func TestFromMetrics(t *testing.T) {
|
||||
|
||||
for _, serviceNameInTargetInfo := range []bool{false, true} {
|
||||
t.Run(fmt.Sprintf("successful/keepIdentifyingAttributes=%v", serviceNameInTargetInfo), func(t *testing.T) {
|
||||
for _, keepIdentifyingResourceAttributes := range []bool{false, true} {
|
||||
t.Run(fmt.Sprintf("successful/keepIdentifyingAttributes=%v", keepIdentifyingResourceAttributes), func(t *testing.T) {
|
||||
converter := NewPrometheusConverter()
|
||||
payload := createExportRequest(5, 128, 128, 2, 0)
|
||||
var expMetadata []prompb.MetricMetadata
|
||||
|
@ -61,7 +61,7 @@ func TestFromMetrics(t *testing.T) {
|
|||
annots, err := converter.FromMetrics(
|
||||
context.Background(),
|
||||
payload.Metrics(),
|
||||
Settings{ServiceNameInTargetInfo: serviceNameInTargetInfo},
|
||||
Settings{KeepIdentifyingResourceAttributes: keepIdentifyingResourceAttributes},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
require.Empty(t, annots)
|
||||
|
@ -81,7 +81,7 @@ func TestFromMetrics(t *testing.T) {
|
|||
target_info_count++
|
||||
require.Equal(t, "test-namespace/test-service", lbls.Get("job"))
|
||||
require.Equal(t, "id1234", lbls.Get("instance"))
|
||||
if serviceNameInTargetInfo {
|
||||
if keepIdentifyingResourceAttributes {
|
||||
require.Equal(t, "test-service", lbls.Get("service_name"))
|
||||
require.Equal(t, "test-namespace", lbls.Get("service_namespace"))
|
||||
require.Equal(t, "id1234", lbls.Get("service_instance_id"))
|
||||
|
|
|
@ -515,7 +515,7 @@ func (h *otlpWriteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
|||
AddMetricSuffixes: true,
|
||||
AllowUTF8: otlpCfg.TranslationStrategy == config.NoUTF8EscapingWithSuffixes,
|
||||
PromoteResourceAttributes: otlpCfg.PromoteResourceAttributes,
|
||||
ServiceNameInTargetInfo: otlpCfg.ServiceNameInTargetInfo,
|
||||
KeepIdentifyingResourceAttributes: otlpCfg.KeepIdentifyingResourceAttributes,
|
||||
})
|
||||
if err != nil {
|
||||
h.logger.Warn("Error translating OTLP metrics to Prometheus write request", "err", err)
|
||||
|
|
Loading…
Reference in New Issue