Rename to keep_identifying_resource_attributes

Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>
pull/15448/head
György Krajcsovits 2024-11-29 15:19:14 +01:00
parent ffabc04829
commit 174f828d70
8 changed files with 24 additions and 24 deletions

View File

@ -1429,9 +1429,9 @@ var (
// OTLPConfig is the configuration for writing to the OTLP endpoint.
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"`
PromoteResourceAttributes []string `yaml:"promote_resource_attributes,omitempty"`
TranslationStrategy translationStrategyOption `yaml:"translation_strategy,omitempty"`
KeepIdentifyingResourceAttributes bool `yaml:"keep_identifying_resource_attributes,omitempty"`
}
// UnmarshalYAML implements the yaml.Unmarshaler interface.

View File

@ -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)
})
}

View File

@ -0,0 +1,2 @@
otlp:
keep_identifying_resource_attributes: true

View File

@ -1,2 +0,0 @@
otlp:
service_name_in_target_info: true

View File

@ -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
}

View File

@ -32,14 +32,14 @@ import (
)
type Settings struct {
Namespace string
ExternalLabels map[string]string
DisableTargetInfo bool
ExportCreatedMetric bool
AddMetricSuffixes bool
AllowUTF8 bool
PromoteResourceAttributes []string
ServiceNameInTargetInfo bool
Namespace string
ExternalLabels map[string]string
DisableTargetInfo bool
ExportCreatedMetric bool
AddMetricSuffixes bool
AllowUTF8 bool
PromoteResourceAttributes []string
KeepIdentifyingResourceAttributes bool
}
// PrometheusConverter converts from OTel write format to Prometheus remote write format.

View File

@ -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"))

View File

@ -512,10 +512,10 @@ func (h *otlpWriteHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
converter := otlptranslator.NewPrometheusConverter()
annots, err := converter.FromMetrics(r.Context(), req.Metrics(), otlptranslator.Settings{
AddMetricSuffixes: true,
AllowUTF8: otlpCfg.TranslationStrategy == config.NoUTF8EscapingWithSuffixes,
PromoteResourceAttributes: otlpCfg.PromoteResourceAttributes,
ServiceNameInTargetInfo: otlpCfg.ServiceNameInTargetInfo,
AddMetricSuffixes: true,
AllowUTF8: otlpCfg.TranslationStrategy == config.NoUTF8EscapingWithSuffixes,
PromoteResourceAttributes: otlpCfg.PromoteResourceAttributes,
KeepIdentifyingResourceAttributes: otlpCfg.KeepIdentifyingResourceAttributes,
})
if err != nil {
h.logger.Warn("Error translating OTLP metrics to Prometheus write request", "err", err)