Skip to content

Add check for prometheus cluster name #1663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions translator/translate/logs/util/get_eks_cluster_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package util

import (
"log"
"os"
"strings"
"time"

Expand Down Expand Up @@ -34,6 +35,12 @@ func GetEKSClusterName(sectionKey string, input map[string]interface{}) string {
//The key is in current input instance, use the value in JSON.
clusterName = val.(string)
}
if clusterName == "" {
envVarClusterName := os.Getenv("K8S_CLUSTER_NAME")
if envVarClusterName != "" {
clusterName = envVarClusterName
}
}
if clusterName == "" {
clusterName = GetClusterNameFromEc2Tagger()
}
Expand Down
11 changes: 8 additions & 3 deletions translator/translate/otel/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,9 +486,14 @@ func KueueContainerInsightsEnabled(conf *confmap.Conf) bool {
}

func GetClusterName(conf *confmap.Conf) string {
val, ok := GetString(conf, ConfigKey(LogsKey, MetricsCollectedKey, KubernetesKey, "cluster_name"))
if ok && val != "" {
return val
val1, ok1 := GetString(conf, ConfigKey(LogsKey, MetricsCollectedKey, KubernetesKey, "cluster_name"))
if ok1 && val1 != "" {
return val1
}

val2, ok2 := GetString(conf, ConfigKey(LogsKey, MetricsCollectedKey, PrometheusKey, "cluster_name"))
if ok2 && val2 != "" {
return val2
}

envVarClusterName := os.Getenv("K8S_CLUSTER_NAME")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ func TestTranslate(t *testing.T) {
"kubernetes": map[string]interface{}{
"cluster_name": "ci-logs",
},
"prometheus": map[string]interface{}{
"cluster_name": "ci-prometheus",
},
},
}},
mode: config.ModeEC2,
Expand All @@ -99,6 +102,9 @@ func TestTranslate(t *testing.T) {
"kubernetes": map[string]interface{}{
"cluster_name": "ci-logs",
},
"prometheus": map[string]interface{}{
"cluster_name": "ci-prometheus",
},
},
},
},
Expand All @@ -111,6 +117,43 @@ func TestTranslate(t *testing.T) {
Platform: config.ModeEC2,
},
},
"PrometheusUnderLogs": {
input: map[string]interface{}{
"logs": map[string]interface{}{
"metrics_collected": map[string]interface{}{
"prometheus": map[string]interface{}{
"cluster_name": "ci-prometheus",
},
},
},
},
mode: config.ModeEC2,
kubernetesMode: config.ModeEKS,
want: &awsentity.Config{
ClusterName: "ci-prometheus",
KubernetesMode: config.ModeEKS,
Platform: config.ModeEC2,
},
},
"PrometheusPrecedence": {
input: map[string]interface{}{
"logs": map[string]interface{}{
"metrics_collected": map[string]interface{}{
"prometheus": map[string]interface{}{
"cluster_name": "ci-prometheus",
},
},
},
},
mode: config.ModeEC2,
kubernetesMode: config.ModeEKS,
envClusterName: "env-cluster",
want: &awsentity.Config{
ClusterName: "ci-prometheus",
KubernetesMode: config.ModeEKS,
Platform: config.ModeEC2,
},
},
"ECS": {
input: map[string]interface{}{},
mode: config.ModeECS,
Expand Down