Skip to content

Commit 7acb80a

Browse files
committed
fix cluster name resolved path
1 parent 80a20a9 commit 7acb80a

11 files changed

Lines changed: 20 additions & 14 deletions

File tree

translator/translate/otel/common/common.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -556,9 +556,9 @@ func SanitizeName(input string) string {
556556
}, strings.ToLower(input))
557557
}
558558

559-
func GetClusterName(conf *confmap.Conf) string {
560-
val, ok := GetString(conf, ConfigKey(LogsKey, MetricsCollectedKey, KubernetesKey, "cluster_name"))
561-
if ok && val != "" {
559+
func GetClusterName(conf *confmap.Conf, key string) string {
560+
// Check any config keys passed
561+
if val, ok := GetString(conf, key); ok && val != "" {
562562
return val
563563
}
564564

@@ -598,3 +598,6 @@ func EscapeDollarDigit(s string) string {
598598

599599
// OtelClusterNameKey is the config key for the root-level cluster name under opentelemetry.
600600
var OtelClusterNameKey = ConfigKey(OpenTelemetryKey, ClusterNameKey)
601+
602+
// LegacyClusterNameKey is the config key for the cluster name in the V1 config path.
603+
var LegacyClusterNameKey = ConfigKey(LogsKey, MetricsCollectedKey, KubernetesKey, ClusterNameKey)

translator/translate/otel/exporter/awsemf/prometheus.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func setPrometheusLogGroup(conf *confmap.Conf, cfg *awsemfexporter.Config) error
3939
}
4040
} else {
4141

42-
if clusterName := common.GetClusterName(conf); clusterName != "" {
42+
if clusterName := common.GetClusterName(conf, common.LegacyClusterNameKey); clusterName != "" {
4343
cfg.LogGroupName = fmt.Sprintf(eksDefaultLogGroupFormat, clusterName)
4444
}
4545
}

translator/translate/otel/pipeline/opentelemetry/containerinsights/common.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ func (t *yamlComponentTranslator) Translate(_ *confmap.Conf) (component.Config,
7575
}
7676

7777
func getClusterName(conf *confmap.Conf) (string, error) {
78-
name, _ := common.GetString(conf, common.OtelClusterNameKey)
78+
name := common.GetClusterName(conf, common.OtelClusterNameKey)
7979
if name == "" {
80-
return "", fmt.Errorf("cluster_name is required for container_insights: set opentelemetry::cluster_name in config")
80+
return "", fmt.Errorf("cluster_name is required for container_insights: set opentelemetry::cluster_name in config or K8S_CLUSTER_NAME environment variable")
8181
}
8282
return name, nil
8383
}

translator/translate/otel/pipeline/opentelemetry/translator_logs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,8 @@ func (t *baseLogsTranslator) Translate(conf *confmap.Conf) (*common.ComponentTra
113113
processors.Set(k8sattributesprocessor.NewTranslator(common.OpenTelemetryKey))
114114
}
115115
// Apply root-level cluster name if set
116-
if clusterName, ok := common.GetString(conf, common.OtelClusterNameKey); ok && clusterName != "" {
116+
clusterName := common.GetClusterName(conf, common.OtelClusterNameKey)
117+
if clusterName != "" {
117118
stmt := fmt.Sprintf(`set(resource.attributes["k8s.cluster.name"], "%s")`, clusterName)
118119
processors.Set(transformprocessor.NewTranslatorWithName("set_cluster_name",
119120
transformprocessor.WithMetricResourceStatements([]string{stmt}),

translator/translate/otel/pipeline/opentelemetry/translator_metrics.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ func (t *baseMetricsTranslator) Translate(conf *confmap.Conf) (*common.Component
6464
processors.Set(k8sattributesprocessor.NewTranslator(common.OpenTelemetryKey))
6565
}
6666
// Apply root-level cluster name if set
67-
if clusterName, ok := common.GetString(conf, common.OtelClusterNameKey); ok && clusterName != "" {
67+
clusterName := common.GetClusterName(conf, common.OtelClusterNameKey)
68+
if clusterName != "" {
6869
stmt := fmt.Sprintf(`set(resource.attributes["k8s.cluster.name"], "%s")`, clusterName)
6970
processors.Set(transformprocessor.NewTranslatorWithName("set_cluster_name",
7071
transformprocessor.WithMetricResourceStatements([]string{stmt}),

translator/translate/otel/pipeline/opentelemetry/translator_traces.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ func (t *baseTracesTranslator) Translate(conf *confmap.Conf) (*common.ComponentT
5959
processors.Set(k8sattributesprocessor.NewTranslator(common.OpenTelemetryKey))
6060
}
6161
// Apply root-level cluster name if set
62-
if clusterName, ok := common.GetString(conf, common.OtelClusterNameKey); ok && clusterName != "" {
62+
clusterName := common.GetClusterName(conf, common.OtelClusterNameKey)
63+
if clusterName != "" {
6364
stmt := fmt.Sprintf(`set(resource.attributes["k8s.cluster.name"], "%s")`, clusterName)
6465
processors.Set(transformprocessor.NewTranslatorWithName("set_cluster_name",
6566
transformprocessor.WithMetricResourceStatements([]string{stmt}),

translator/translate/otel/processor/awsapplicationsignals/translator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (t *translator) Translate(conf *confmap.Conf) (component.Config, error) {
6767
hostedIn, hostedInConfigured := common.GetHostedIn(conf)
6868
if common.IsAppSignalsKubernetes() {
6969
if !hostedInConfigured {
70-
hostedIn = common.GetClusterName(conf)
70+
hostedIn = common.GetClusterName(conf, common.LegacyClusterNameKey)
7171
}
7272
}
7373

translator/translate/otel/processor/awsentity/translator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (t *translator) Translate(conf *confmap.Conf) (component.Config, error) {
103103
clusterName, clusterNameConfigured := common.GetHostedIn(conf)
104104

105105
if !clusterNameConfigured {
106-
clusterName = common.GetClusterName(conf)
106+
clusterName = common.GetClusterName(conf, common.LegacyClusterNameKey)
107107
}
108108

109109
cfg.ClusterName = clusterName

translator/translate/otel/processor/resourceprocessor/translator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (t *translator) getJMXAttributes(conf *confmap.Conf) []any {
137137
}
138138

139139
func (t *translator) getContainerInsightsJMXAttributes(conf *confmap.Conf) []any {
140-
clusterName := common.GetClusterName(conf)
140+
clusterName := common.GetClusterName(conf, common.LegacyClusterNameKey)
141141
nodeName := os.Getenv(config.HOST_NAME)
142142
return []any{
143143
map[string]any{

translator/translate/otel/receiver/awscontainerinsight/translator.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ func (t *translator) Translate(conf *confmap.Conf) (component.Config, error) {
130130
}
131131

132132
func (t *translator) setClusterName(conf *confmap.Conf, cfg *awscontainerinsightreceiver.Config) error {
133-
cfg.ClusterName = common.GetClusterName(conf)
133+
cfg.ClusterName = common.GetClusterName(conf, common.LegacyClusterNameKey)
134134

135135
if cfg.ClusterName == "" {
136136
return errors.New("cluster name is not provided and was not auto-detected from EC2 tags")

0 commit comments

Comments
 (0)