diff --git a/translator/config/defaultConfig_test.go b/translator/config/defaultConfig_test.go index 76078fb99e..99d8610c67 100644 --- a/translator/config/defaultConfig_test.go +++ b/translator/config/defaultConfig_test.go @@ -42,6 +42,9 @@ func TestDefaultJSONConfigFor_OtelK8s(t *testing.T) { assert.JSONEq(t, defaultOtelK8sConfig, cfg) assert.Contains(t, cfg, "container_insights") assert.NotContains(t, cfg, "host_metrics") + // On Kubernetes the role comes from the pod's AWS_ROLE_ARN (web identity on + // AKS, IRSA on EKS), so the config must not carry a role_arn of its own. + assert.NotContains(t, cfg, "role_arn") } func TestDefaultJSONConfigFor_OtelECS(t *testing.T) { diff --git a/translator/config/defaults/otel_k8s.json b/translator/config/defaults/otel_k8s.json index bc95c13bb4..f829976fb4 100644 --- a/translator/config/defaults/otel_k8s.json +++ b/translator/config/defaults/otel_k8s.json @@ -1,9 +1,4 @@ { - "agent": { - "credentials": { - "role_arn": "${CWAGENT_ROLE_ARN}" - } - }, "opentelemetry": { "collect": { "container_insights": {}, diff --git a/translator/tocwconfig/sampleConfig/opentelemetry/combined_v1_v2_eks_config.yaml b/translator/tocwconfig/sampleConfig/opentelemetry/combined_v1_v2_eks_config.yaml index aa3dd72d17..01fe2c457c 100644 --- a/translator/tocwconfig/sampleConfig/opentelemetry/combined_v1_v2_eks_config.yaml +++ b/translator/tocwconfig/sampleConfig/opentelemetry/combined_v1_v2_eks_config.yaml @@ -1378,8 +1378,10 @@ processors: - set(resource.attributes["service.name"], resource.attributes["k8s.pod.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.pod.name"] != nil - set(resource.attributes["service.name"], resource.attributes["k8s.container.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.container.name"] != nil - set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil - - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" - - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["azure.resourcegroup.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.region"] != nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" + - set(resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["azure.resourcegroup.name"]) where resource.attributes["cloud.platform"] == "azure_aks" and resource.attributes["azure.resourcegroup.name"] != nil + - replace_pattern(resource.attributes["_tmp.azure.resourcegroup.name"], "^MC_(.+)_TestCluster_[^_]+$", "$$$1") where resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["_tmp.azure.resourcegroup.name"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.deployment.name"]) where resource.attributes["k8s.deployment.name"] != nil - set(resource.attributes["k8s.workload.type"], "Deployment") where resource.attributes["k8s.deployment.name"] != nil and resource.attributes["k8s.workload.type"] == nil - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.statefulset.name"]) where resource.attributes["k8s.workload.name"] == nil and resource.attributes["k8s.statefulset.name"] != nil @@ -1404,6 +1406,7 @@ processors: - delete_key(resource.attributes, "app.kubernetes.io/instance") - delete_key(resource.attributes, "app.kubernetes.io/name") - delete_key(resource.attributes, "app.kubernetes.io/version") + - delete_key(resource.attributes, "_tmp.azure.resourcegroup.name") metric_statements: - context: resource error_mode: ignore @@ -1420,8 +1423,10 @@ processors: - set(resource.attributes["service.name"], resource.attributes["k8s.pod.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.pod.name"] != nil - set(resource.attributes["service.name"], resource.attributes["k8s.container.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.container.name"] != nil - set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil - - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" - - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["azure.resourcegroup.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.region"] != nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" + - set(resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["azure.resourcegroup.name"]) where resource.attributes["cloud.platform"] == "azure_aks" and resource.attributes["azure.resourcegroup.name"] != nil + - replace_pattern(resource.attributes["_tmp.azure.resourcegroup.name"], "^MC_(.+)_TestCluster_[^_]+$", "$$$1") where resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["_tmp.azure.resourcegroup.name"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.deployment.name"]) where resource.attributes["k8s.deployment.name"] != nil - set(resource.attributes["k8s.workload.type"], "Deployment") where resource.attributes["k8s.deployment.name"] != nil and resource.attributes["k8s.workload.type"] == nil - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.statefulset.name"]) where resource.attributes["k8s.workload.name"] == nil and resource.attributes["k8s.statefulset.name"] != nil @@ -1446,6 +1451,7 @@ processors: - delete_key(resource.attributes, "app.kubernetes.io/instance") - delete_key(resource.attributes, "app.kubernetes.io/name") - delete_key(resource.attributes, "app.kubernetes.io/version") + - delete_key(resource.attributes, "_tmp.azure.resourcegroup.name") trace_statements: - context: resource error_mode: ignore @@ -1462,8 +1468,10 @@ processors: - set(resource.attributes["service.name"], resource.attributes["k8s.pod.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.pod.name"] != nil - set(resource.attributes["service.name"], resource.attributes["k8s.container.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.container.name"] != nil - set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil - - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" - - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["azure.resourcegroup.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.region"] != nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" + - set(resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["azure.resourcegroup.name"]) where resource.attributes["cloud.platform"] == "azure_aks" and resource.attributes["azure.resourcegroup.name"] != nil + - replace_pattern(resource.attributes["_tmp.azure.resourcegroup.name"], "^MC_(.+)_TestCluster_[^_]+$", "$$$1") where resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["_tmp.azure.resourcegroup.name"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.deployment.name"]) where resource.attributes["k8s.deployment.name"] != nil - set(resource.attributes["k8s.workload.type"], "Deployment") where resource.attributes["k8s.deployment.name"] != nil and resource.attributes["k8s.workload.type"] == nil - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.statefulset.name"]) where resource.attributes["k8s.workload.name"] == nil and resource.attributes["k8s.statefulset.name"] != nil @@ -1488,6 +1496,7 @@ processors: - delete_key(resource.attributes, "app.kubernetes.io/instance") - delete_key(resource.attributes, "app.kubernetes.io/name") - delete_key(resource.attributes, "app.kubernetes.io/version") + - delete_key(resource.attributes, "_tmp.azure.resourcegroup.name") transform/logs_cleanup: error_mode: ignore flatten_data: false diff --git a/translator/tocwconfig/sampleConfig/opentelemetry/container_insights_config.yaml b/translator/tocwconfig/sampleConfig/opentelemetry/container_insights_config.yaml index b8cf369ca7..a71e4eadec 100644 --- a/translator/tocwconfig/sampleConfig/opentelemetry/container_insights_config.yaml +++ b/translator/tocwconfig/sampleConfig/opentelemetry/container_insights_config.yaml @@ -781,8 +781,10 @@ processors: - set(resource.attributes["service.name"], resource.attributes["k8s.pod.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.pod.name"] != nil - set(resource.attributes["service.name"], resource.attributes["k8s.container.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.container.name"] != nil - set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil - - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" - - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["azure.resourcegroup.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.region"] != nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" + - set(resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["azure.resourcegroup.name"]) where resource.attributes["cloud.platform"] == "azure_aks" and resource.attributes["azure.resourcegroup.name"] != nil + - replace_pattern(resource.attributes["_tmp.azure.resourcegroup.name"], "^MC_(.+)_TestCluster_[^_]+$", "$$$1") where resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["_tmp.azure.resourcegroup.name"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.deployment.name"]) where resource.attributes["k8s.deployment.name"] != nil - set(resource.attributes["k8s.workload.type"], "Deployment") where resource.attributes["k8s.deployment.name"] != nil and resource.attributes["k8s.workload.type"] == nil - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.statefulset.name"]) where resource.attributes["k8s.workload.name"] == nil and resource.attributes["k8s.statefulset.name"] != nil @@ -807,6 +809,7 @@ processors: - delete_key(resource.attributes, "app.kubernetes.io/instance") - delete_key(resource.attributes, "app.kubernetes.io/name") - delete_key(resource.attributes, "app.kubernetes.io/version") + - delete_key(resource.attributes, "_tmp.azure.resourcegroup.name") metric_statements: - context: resource error_mode: ignore @@ -823,8 +826,10 @@ processors: - set(resource.attributes["service.name"], resource.attributes["k8s.pod.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.pod.name"] != nil - set(resource.attributes["service.name"], resource.attributes["k8s.container.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.container.name"] != nil - set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil - - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" - - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["azure.resourcegroup.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.region"] != nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" + - set(resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["azure.resourcegroup.name"]) where resource.attributes["cloud.platform"] == "azure_aks" and resource.attributes["azure.resourcegroup.name"] != nil + - replace_pattern(resource.attributes["_tmp.azure.resourcegroup.name"], "^MC_(.+)_TestCluster_[^_]+$", "$$$1") where resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["_tmp.azure.resourcegroup.name"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.deployment.name"]) where resource.attributes["k8s.deployment.name"] != nil - set(resource.attributes["k8s.workload.type"], "Deployment") where resource.attributes["k8s.deployment.name"] != nil and resource.attributes["k8s.workload.type"] == nil - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.statefulset.name"]) where resource.attributes["k8s.workload.name"] == nil and resource.attributes["k8s.statefulset.name"] != nil @@ -849,6 +854,7 @@ processors: - delete_key(resource.attributes, "app.kubernetes.io/instance") - delete_key(resource.attributes, "app.kubernetes.io/name") - delete_key(resource.attributes, "app.kubernetes.io/version") + - delete_key(resource.attributes, "_tmp.azure.resourcegroup.name") trace_statements: - context: resource error_mode: ignore @@ -865,8 +871,10 @@ processors: - set(resource.attributes["service.name"], resource.attributes["k8s.pod.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.pod.name"] != nil - set(resource.attributes["service.name"], resource.attributes["k8s.container.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.container.name"] != nil - set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil - - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" - - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["azure.resourcegroup.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.region"] != nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" + - set(resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["azure.resourcegroup.name"]) where resource.attributes["cloud.platform"] == "azure_aks" and resource.attributes["azure.resourcegroup.name"] != nil + - replace_pattern(resource.attributes["_tmp.azure.resourcegroup.name"], "^MC_(.+)_TestCluster_[^_]+$", "$$$1") where resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["_tmp.azure.resourcegroup.name"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.deployment.name"]) where resource.attributes["k8s.deployment.name"] != nil - set(resource.attributes["k8s.workload.type"], "Deployment") where resource.attributes["k8s.deployment.name"] != nil and resource.attributes["k8s.workload.type"] == nil - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.statefulset.name"]) where resource.attributes["k8s.workload.name"] == nil and resource.attributes["k8s.statefulset.name"] != nil @@ -891,6 +899,7 @@ processors: - delete_key(resource.attributes, "app.kubernetes.io/instance") - delete_key(resource.attributes, "app.kubernetes.io/name") - delete_key(resource.attributes, "app.kubernetes.io/version") + - delete_key(resource.attributes, "_tmp.azure.resourcegroup.name") transform/set_cluster_name: error_mode: ignore flatten_data: false diff --git a/translator/tocwconfig/sampleConfig/opentelemetry/default_otel_config_aks.yaml b/translator/tocwconfig/sampleConfig/opentelemetry/default_otel_config_aks.yaml index 9853b6613a..feb4c5b094 100644 --- a/translator/tocwconfig/sampleConfig/opentelemetry/default_otel_config_aks.yaml +++ b/translator/tocwconfig/sampleConfig/opentelemetry/default_otel_config_aks.yaml @@ -141,7 +141,6 @@ extensions: num_workers: 8 region: ${AWS_REGION} request_timeout_seconds: 10 - role_arn: ${CWAGENT_ROLE_ARN} headers_setter/logs: additional_auth: awscloudwatchlogsprovisioner headers: @@ -163,7 +162,6 @@ extensions: num_workers: 8 region: ${AWS_REGION} request_timeout_seconds: 30 - role_arn: ${CWAGENT_ROLE_ARN} service: logs sigv4auth/monitoring: assume_role: {} @@ -172,7 +170,6 @@ extensions: num_workers: 8 region: ${AWS_REGION} request_timeout_seconds: 30 - role_arn: ${CWAGENT_ROLE_ARN} service: monitoring sigv4auth/xray: assume_role: {} @@ -181,7 +178,6 @@ extensions: num_workers: 8 region: ${AWS_REGION} request_timeout_seconds: 30 - role_arn: ${CWAGENT_ROLE_ARN} service: xray processors: attributestocontext/opentelemetry: @@ -930,8 +926,10 @@ processors: - set(resource.attributes["service.name"], resource.attributes["k8s.pod.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.pod.name"] != nil - set(resource.attributes["service.name"], resource.attributes["k8s.container.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.container.name"] != nil - set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil - - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" - - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["azure.resourcegroup.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.region"] != nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" + - set(resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["azure.resourcegroup.name"]) where resource.attributes["cloud.platform"] == "azure_aks" and resource.attributes["azure.resourcegroup.name"] != nil + - replace_pattern(resource.attributes["_tmp.azure.resourcegroup.name"], "^MC_(.+)_test-cluster_[^_]+$", "$$$1") where resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["_tmp.azure.resourcegroup.name"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.deployment.name"]) where resource.attributes["k8s.deployment.name"] != nil - set(resource.attributes["k8s.workload.type"], "Deployment") where resource.attributes["k8s.deployment.name"] != nil and resource.attributes["k8s.workload.type"] == nil - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.statefulset.name"]) where resource.attributes["k8s.workload.name"] == nil and resource.attributes["k8s.statefulset.name"] != nil @@ -956,6 +954,7 @@ processors: - delete_key(resource.attributes, "app.kubernetes.io/instance") - delete_key(resource.attributes, "app.kubernetes.io/name") - delete_key(resource.attributes, "app.kubernetes.io/version") + - delete_key(resource.attributes, "_tmp.azure.resourcegroup.name") metric_statements: - context: resource error_mode: ignore @@ -972,8 +971,10 @@ processors: - set(resource.attributes["service.name"], resource.attributes["k8s.pod.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.pod.name"] != nil - set(resource.attributes["service.name"], resource.attributes["k8s.container.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.container.name"] != nil - set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil - - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" - - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["azure.resourcegroup.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.region"] != nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" + - set(resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["azure.resourcegroup.name"]) where resource.attributes["cloud.platform"] == "azure_aks" and resource.attributes["azure.resourcegroup.name"] != nil + - replace_pattern(resource.attributes["_tmp.azure.resourcegroup.name"], "^MC_(.+)_test-cluster_[^_]+$", "$$$1") where resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["_tmp.azure.resourcegroup.name"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.deployment.name"]) where resource.attributes["k8s.deployment.name"] != nil - set(resource.attributes["k8s.workload.type"], "Deployment") where resource.attributes["k8s.deployment.name"] != nil and resource.attributes["k8s.workload.type"] == nil - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.statefulset.name"]) where resource.attributes["k8s.workload.name"] == nil and resource.attributes["k8s.statefulset.name"] != nil @@ -998,6 +999,7 @@ processors: - delete_key(resource.attributes, "app.kubernetes.io/instance") - delete_key(resource.attributes, "app.kubernetes.io/name") - delete_key(resource.attributes, "app.kubernetes.io/version") + - delete_key(resource.attributes, "_tmp.azure.resourcegroup.name") trace_statements: - context: resource error_mode: ignore @@ -1014,8 +1016,10 @@ processors: - set(resource.attributes["service.name"], resource.attributes["k8s.pod.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.pod.name"] != nil - set(resource.attributes["service.name"], resource.attributes["k8s.container.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.container.name"] != nil - set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil - - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" - - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["azure.resourcegroup.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.region"] != nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" + - set(resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["azure.resourcegroup.name"]) where resource.attributes["cloud.platform"] == "azure_aks" and resource.attributes["azure.resourcegroup.name"] != nil + - replace_pattern(resource.attributes["_tmp.azure.resourcegroup.name"], "^MC_(.+)_test-cluster_[^_]+$", "$$$1") where resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["_tmp.azure.resourcegroup.name"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.deployment.name"]) where resource.attributes["k8s.deployment.name"] != nil - set(resource.attributes["k8s.workload.type"], "Deployment") where resource.attributes["k8s.deployment.name"] != nil and resource.attributes["k8s.workload.type"] == nil - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.statefulset.name"]) where resource.attributes["k8s.workload.name"] == nil and resource.attributes["k8s.statefulset.name"] != nil @@ -1040,6 +1044,7 @@ processors: - delete_key(resource.attributes, "app.kubernetes.io/instance") - delete_key(resource.attributes, "app.kubernetes.io/name") - delete_key(resource.attributes, "app.kubernetes.io/version") + - delete_key(resource.attributes, "_tmp.azure.resourcegroup.name") transform/logs_cleanup: error_mode: ignore flatten_data: false diff --git a/translator/tocwconfig/sampleConfig/opentelemetry/default_otel_config_windows.yaml b/translator/tocwconfig/sampleConfig/opentelemetry/default_otel_config_windows.yaml index dee49bd45c..3d3a2f5320 100644 --- a/translator/tocwconfig/sampleConfig/opentelemetry/default_otel_config_windows.yaml +++ b/translator/tocwconfig/sampleConfig/opentelemetry/default_otel_config_windows.yaml @@ -531,8 +531,8 @@ processors: statements: - set(resource.attributes["aws.log.group.name"], Concat(["/aws/cwagent", resource.attributes["aws.log.source"]], "/")) where resource.attributes["aws.log.group.name"] == nil and resource.attributes["aws.log.source"] != nil - set(resource.attributes["aws.log.group.name"], "/aws/cwagent/default") where resource.attributes["aws.log.group.name"] == nil - - set(resource.attributes["aws.log.stream.name"], Concat([resource.attributes["host.id"], resource.attributes["aws.log.channel"]], "/")) where resource.attributes["aws.log.stream.name"] == nil and resource.attributes["host.id"] != nil and resource.attributes["aws.log.channel"] != nil - - set(resource.attributes["aws.log.stream.name"], Concat([resource.attributes["host.name"], resource.attributes["aws.log.channel"]], "/")) where resource.attributes["aws.log.stream.name"] == nil and resource.attributes["host.name"] != nil and resource.attributes["aws.log.channel"] != nil + - set(resource.attributes["aws.log.stream.name"], Concat([resource.attributes["host.id"], resource.attributes["aws.log.channel"]], "/")) where resource.attributes["aws.log.stream.name"] == nil and resource.attributes["aws.log.source"] == "windows_events" and resource.attributes["host.id"] != nil and resource.attributes["aws.log.channel"] != nil + - set(resource.attributes["aws.log.stream.name"], Concat([resource.attributes["host.name"], resource.attributes["aws.log.channel"]], "/")) where resource.attributes["aws.log.stream.name"] == nil and resource.attributes["aws.log.source"] == "windows_events" and resource.attributes["host.name"] != nil and resource.attributes["aws.log.channel"] != nil - set(resource.attributes["aws.log.stream.name"], Concat([resource.attributes["host.id"], resource.attributes["log.file.name"]], "/")) where resource.attributes["aws.log.stream.name"] == nil and resource.attributes["aws.log.source"] == "files" and resource.attributes["host.id"] != nil and resource.attributes["log.file.name"] != nil - set(resource.attributes["aws.log.stream.name"], Concat([resource.attributes["host.name"], resource.attributes["log.file.name"]], "/")) where resource.attributes["aws.log.stream.name"] == nil and resource.attributes["aws.log.source"] == "files" and resource.attributes["host.name"] != nil and resource.attributes["log.file.name"] != nil - set(resource.attributes["aws.log.stream.name"], Concat([resource.attributes["host.id"], resource.attributes["service.namespace"], resource.attributes["service.name"]], "/")) where resource.attributes["aws.log.stream.name"] == nil and resource.attributes["host.id"] != nil and resource.attributes["service.namespace"] != nil and resource.attributes["service.name"] != nil and resource.attributes["service.name"] != "unknown_service" diff --git a/translator/tocwconfig/sampleConfig/opentelemetry/host_metrics_aks_config.yaml b/translator/tocwconfig/sampleConfig/opentelemetry/host_metrics_aks_config.yaml index e327fdfdcb..b6bacf2036 100644 --- a/translator/tocwconfig/sampleConfig/opentelemetry/host_metrics_aks_config.yaml +++ b/translator/tocwconfig/sampleConfig/opentelemetry/host_metrics_aks_config.yaml @@ -423,8 +423,10 @@ processors: - set(resource.attributes["service.name"], resource.attributes["k8s.pod.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.pod.name"] != nil - set(resource.attributes["service.name"], resource.attributes["k8s.container.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.container.name"] != nil - set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil - - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" - - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["azure.resourcegroup.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.region"] != nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" + - set(resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["azure.resourcegroup.name"]) where resource.attributes["cloud.platform"] == "azure_aks" and resource.attributes["azure.resourcegroup.name"] != nil + - replace_pattern(resource.attributes["_tmp.azure.resourcegroup.name"], "^MC_(.+)_TestCluster_[^_]+$", "$$$1") where resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["_tmp.azure.resourcegroup.name"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.deployment.name"]) where resource.attributes["k8s.deployment.name"] != nil - set(resource.attributes["k8s.workload.type"], "Deployment") where resource.attributes["k8s.deployment.name"] != nil and resource.attributes["k8s.workload.type"] == nil - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.statefulset.name"]) where resource.attributes["k8s.workload.name"] == nil and resource.attributes["k8s.statefulset.name"] != nil @@ -449,6 +451,7 @@ processors: - delete_key(resource.attributes, "app.kubernetes.io/instance") - delete_key(resource.attributes, "app.kubernetes.io/name") - delete_key(resource.attributes, "app.kubernetes.io/version") + - delete_key(resource.attributes, "_tmp.azure.resourcegroup.name") metric_statements: - context: resource error_mode: ignore @@ -465,8 +468,10 @@ processors: - set(resource.attributes["service.name"], resource.attributes["k8s.pod.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.pod.name"] != nil - set(resource.attributes["service.name"], resource.attributes["k8s.container.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.container.name"] != nil - set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil - - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" - - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["azure.resourcegroup.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.region"] != nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" + - set(resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["azure.resourcegroup.name"]) where resource.attributes["cloud.platform"] == "azure_aks" and resource.attributes["azure.resourcegroup.name"] != nil + - replace_pattern(resource.attributes["_tmp.azure.resourcegroup.name"], "^MC_(.+)_TestCluster_[^_]+$", "$$$1") where resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["_tmp.azure.resourcegroup.name"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.deployment.name"]) where resource.attributes["k8s.deployment.name"] != nil - set(resource.attributes["k8s.workload.type"], "Deployment") where resource.attributes["k8s.deployment.name"] != nil and resource.attributes["k8s.workload.type"] == nil - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.statefulset.name"]) where resource.attributes["k8s.workload.name"] == nil and resource.attributes["k8s.statefulset.name"] != nil @@ -491,6 +496,7 @@ processors: - delete_key(resource.attributes, "app.kubernetes.io/instance") - delete_key(resource.attributes, "app.kubernetes.io/name") - delete_key(resource.attributes, "app.kubernetes.io/version") + - delete_key(resource.attributes, "_tmp.azure.resourcegroup.name") trace_statements: - context: resource error_mode: ignore @@ -507,8 +513,10 @@ processors: - set(resource.attributes["service.name"], resource.attributes["k8s.pod.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.pod.name"] != nil - set(resource.attributes["service.name"], resource.attributes["k8s.container.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.container.name"] != nil - set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil - - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" - - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["azure.resourcegroup.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.region"] != nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" + - set(resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["azure.resourcegroup.name"]) where resource.attributes["cloud.platform"] == "azure_aks" and resource.attributes["azure.resourcegroup.name"] != nil + - replace_pattern(resource.attributes["_tmp.azure.resourcegroup.name"], "^MC_(.+)_TestCluster_[^_]+$", "$$$1") where resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["_tmp.azure.resourcegroup.name"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.deployment.name"]) where resource.attributes["k8s.deployment.name"] != nil - set(resource.attributes["k8s.workload.type"], "Deployment") where resource.attributes["k8s.deployment.name"] != nil and resource.attributes["k8s.workload.type"] == nil - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.statefulset.name"]) where resource.attributes["k8s.workload.name"] == nil and resource.attributes["k8s.statefulset.name"] != nil @@ -533,6 +541,25 @@ processors: - delete_key(resource.attributes, "app.kubernetes.io/instance") - delete_key(resource.attributes, "app.kubernetes.io/name") - delete_key(resource.attributes, "app.kubernetes.io/version") + - delete_key(resource.attributes, "_tmp.azure.resourcegroup.name") + transform/set_cluster_name: + error_mode: ignore + flatten_data: false + log_statements: + - context: resource + error_mode: ignore + statements: + - set(resource.attributes["k8s.cluster.name"], "TestCluster") + metric_statements: + - context: resource + error_mode: ignore + statements: + - set(resource.attributes["k8s.cluster.name"], "TestCluster") + trace_statements: + - context: resource + error_mode: ignore + statements: + - set(resource.attributes["k8s.cluster.name"], "TestCluster") receivers: hostmetrics/opentelemetry: collection_interval: 10s @@ -588,6 +615,7 @@ service: processors: - resourcedetection/opentelemetry - k8sattributes/opentelemetry + - transform/set_cluster_name - transform/identity - batch/opentelemetry_metrics receivers: diff --git a/translator/tocwconfig/sampleConfig/opentelemetry/otlp_otel_eks_config.yaml b/translator/tocwconfig/sampleConfig/opentelemetry/otlp_otel_eks_config.yaml index b0d4d4bf18..074e5e7219 100644 --- a/translator/tocwconfig/sampleConfig/opentelemetry/otlp_otel_eks_config.yaml +++ b/translator/tocwconfig/sampleConfig/opentelemetry/otlp_otel_eks_config.yaml @@ -538,8 +538,10 @@ processors: - set(resource.attributes["service.name"], resource.attributes["k8s.pod.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.pod.name"] != nil - set(resource.attributes["service.name"], resource.attributes["k8s.container.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.container.name"] != nil - set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil - - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" - - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["azure.resourcegroup.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.region"] != nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" + - set(resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["azure.resourcegroup.name"]) where resource.attributes["cloud.platform"] == "azure_aks" and resource.attributes["azure.resourcegroup.name"] != nil + - replace_pattern(resource.attributes["_tmp.azure.resourcegroup.name"], "^MC_(.+)_TestCluster_[^_]+$", "$$$1") where resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["_tmp.azure.resourcegroup.name"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.deployment.name"]) where resource.attributes["k8s.deployment.name"] != nil - set(resource.attributes["k8s.workload.type"], "Deployment") where resource.attributes["k8s.deployment.name"] != nil and resource.attributes["k8s.workload.type"] == nil - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.statefulset.name"]) where resource.attributes["k8s.workload.name"] == nil and resource.attributes["k8s.statefulset.name"] != nil @@ -564,6 +566,7 @@ processors: - delete_key(resource.attributes, "app.kubernetes.io/instance") - delete_key(resource.attributes, "app.kubernetes.io/name") - delete_key(resource.attributes, "app.kubernetes.io/version") + - delete_key(resource.attributes, "_tmp.azure.resourcegroup.name") metric_statements: - context: resource error_mode: ignore @@ -580,8 +583,10 @@ processors: - set(resource.attributes["service.name"], resource.attributes["k8s.pod.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.pod.name"] != nil - set(resource.attributes["service.name"], resource.attributes["k8s.container.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.container.name"] != nil - set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil - - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" - - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["azure.resourcegroup.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.region"] != nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" + - set(resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["azure.resourcegroup.name"]) where resource.attributes["cloud.platform"] == "azure_aks" and resource.attributes["azure.resourcegroup.name"] != nil + - replace_pattern(resource.attributes["_tmp.azure.resourcegroup.name"], "^MC_(.+)_TestCluster_[^_]+$", "$$$1") where resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["_tmp.azure.resourcegroup.name"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.deployment.name"]) where resource.attributes["k8s.deployment.name"] != nil - set(resource.attributes["k8s.workload.type"], "Deployment") where resource.attributes["k8s.deployment.name"] != nil and resource.attributes["k8s.workload.type"] == nil - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.statefulset.name"]) where resource.attributes["k8s.workload.name"] == nil and resource.attributes["k8s.statefulset.name"] != nil @@ -606,6 +611,7 @@ processors: - delete_key(resource.attributes, "app.kubernetes.io/instance") - delete_key(resource.attributes, "app.kubernetes.io/name") - delete_key(resource.attributes, "app.kubernetes.io/version") + - delete_key(resource.attributes, "_tmp.azure.resourcegroup.name") trace_statements: - context: resource error_mode: ignore @@ -622,8 +628,10 @@ processors: - set(resource.attributes["service.name"], resource.attributes["k8s.pod.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.pod.name"] != nil - set(resource.attributes["service.name"], resource.attributes["k8s.container.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.container.name"] != nil - set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil - - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" - - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["azure.resourcegroup.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.region"] != nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" + - set(resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["azure.resourcegroup.name"]) where resource.attributes["cloud.platform"] == "azure_aks" and resource.attributes["azure.resourcegroup.name"] != nil + - replace_pattern(resource.attributes["_tmp.azure.resourcegroup.name"], "^MC_(.+)_TestCluster_[^_]+$", "$$$1") where resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["_tmp.azure.resourcegroup.name"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.deployment.name"]) where resource.attributes["k8s.deployment.name"] != nil - set(resource.attributes["k8s.workload.type"], "Deployment") where resource.attributes["k8s.deployment.name"] != nil and resource.attributes["k8s.workload.type"] == nil - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.statefulset.name"]) where resource.attributes["k8s.workload.name"] == nil and resource.attributes["k8s.statefulset.name"] != nil @@ -648,6 +656,7 @@ processors: - delete_key(resource.attributes, "app.kubernetes.io/instance") - delete_key(resource.attributes, "app.kubernetes.io/name") - delete_key(resource.attributes, "app.kubernetes.io/version") + - delete_key(resource.attributes, "_tmp.azure.resourcegroup.name") transform/logs_cleanup: error_mode: ignore flatten_data: false @@ -707,6 +716,24 @@ processors: statements: - set(scope.attributes["cloudwatch.source"], "cloudwatch-agent") - set(scope.attributes["cloudwatch.solution"], "otel-otlp") + transform/set_cluster_name: + error_mode: ignore + flatten_data: false + log_statements: + - context: resource + error_mode: ignore + statements: + - set(resource.attributes["k8s.cluster.name"], "TestCluster") + metric_statements: + - context: resource + error_mode: ignore + statements: + - set(resource.attributes["k8s.cluster.name"], "TestCluster") + trace_statements: + - context: resource + error_mode: ignore + statements: + - set(resource.attributes["k8s.cluster.name"], "TestCluster") receivers: otlp/grpc_127_0_0_1_4317: protocols: @@ -746,6 +773,7 @@ service: processors: - resourcedetection/opentelemetry - k8sattributes/opentelemetry + - transform/set_cluster_name - transform/identity - transform/logs_routing - attributestocontext/opentelemetry @@ -768,6 +796,7 @@ service: processors: - resourcedetection/opentelemetry - k8sattributes/opentelemetry + - transform/set_cluster_name - transform/identity - batch/opentelemetry_metrics receivers: @@ -786,6 +815,7 @@ service: processors: - resourcedetection/opentelemetry - k8sattributes/opentelemetry + - transform/set_cluster_name - transform/identity - batch/opentelemetry_traces receivers: diff --git a/translator/tocwconfig/sampleConfig/opentelemetry/prometheus_otel_pipeline_eks_config.yaml b/translator/tocwconfig/sampleConfig/opentelemetry/prometheus_otel_pipeline_eks_config.yaml index 389f4de660..538ef69bd0 100644 --- a/translator/tocwconfig/sampleConfig/opentelemetry/prometheus_otel_pipeline_eks_config.yaml +++ b/translator/tocwconfig/sampleConfig/opentelemetry/prometheus_otel_pipeline_eks_config.yaml @@ -414,8 +414,10 @@ processors: - set(resource.attributes["service.name"], resource.attributes["k8s.pod.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.pod.name"] != nil - set(resource.attributes["service.name"], resource.attributes["k8s.container.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.container.name"] != nil - set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil - - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" - - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["azure.resourcegroup.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.region"] != nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" + - set(resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["azure.resourcegroup.name"]) where resource.attributes["cloud.platform"] == "azure_aks" and resource.attributes["azure.resourcegroup.name"] != nil + - replace_pattern(resource.attributes["_tmp.azure.resourcegroup.name"], "^MC_(.+)_TestCluster_[^_]+$", "$$$1") where resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["_tmp.azure.resourcegroup.name"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.deployment.name"]) where resource.attributes["k8s.deployment.name"] != nil - set(resource.attributes["k8s.workload.type"], "Deployment") where resource.attributes["k8s.deployment.name"] != nil and resource.attributes["k8s.workload.type"] == nil - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.statefulset.name"]) where resource.attributes["k8s.workload.name"] == nil and resource.attributes["k8s.statefulset.name"] != nil @@ -440,6 +442,7 @@ processors: - delete_key(resource.attributes, "app.kubernetes.io/instance") - delete_key(resource.attributes, "app.kubernetes.io/name") - delete_key(resource.attributes, "app.kubernetes.io/version") + - delete_key(resource.attributes, "_tmp.azure.resourcegroup.name") metric_statements: - context: resource error_mode: ignore @@ -456,8 +459,10 @@ processors: - set(resource.attributes["service.name"], resource.attributes["k8s.pod.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.pod.name"] != nil - set(resource.attributes["service.name"], resource.attributes["k8s.container.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.container.name"] != nil - set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil - - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" - - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["azure.resourcegroup.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.region"] != nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" + - set(resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["azure.resourcegroup.name"]) where resource.attributes["cloud.platform"] == "azure_aks" and resource.attributes["azure.resourcegroup.name"] != nil + - replace_pattern(resource.attributes["_tmp.azure.resourcegroup.name"], "^MC_(.+)_TestCluster_[^_]+$", "$$$1") where resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["_tmp.azure.resourcegroup.name"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.deployment.name"]) where resource.attributes["k8s.deployment.name"] != nil - set(resource.attributes["k8s.workload.type"], "Deployment") where resource.attributes["k8s.deployment.name"] != nil and resource.attributes["k8s.workload.type"] == nil - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.statefulset.name"]) where resource.attributes["k8s.workload.name"] == nil and resource.attributes["k8s.statefulset.name"] != nil @@ -482,6 +487,7 @@ processors: - delete_key(resource.attributes, "app.kubernetes.io/instance") - delete_key(resource.attributes, "app.kubernetes.io/name") - delete_key(resource.attributes, "app.kubernetes.io/version") + - delete_key(resource.attributes, "_tmp.azure.resourcegroup.name") trace_statements: - context: resource error_mode: ignore @@ -498,8 +504,10 @@ processors: - set(resource.attributes["service.name"], resource.attributes["k8s.pod.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.pod.name"] != nil - set(resource.attributes["service.name"], resource.attributes["k8s.container.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.container.name"] != nil - set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil - - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" - - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["azure.resourcegroup.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.region"] != nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" + - set(resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["azure.resourcegroup.name"]) where resource.attributes["cloud.platform"] == "azure_aks" and resource.attributes["azure.resourcegroup.name"] != nil + - replace_pattern(resource.attributes["_tmp.azure.resourcegroup.name"], "^MC_(.+)_TestCluster_[^_]+$", "$$$1") where resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["_tmp.azure.resourcegroup.name"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.deployment.name"]) where resource.attributes["k8s.deployment.name"] != nil - set(resource.attributes["k8s.workload.type"], "Deployment") where resource.attributes["k8s.deployment.name"] != nil and resource.attributes["k8s.workload.type"] == nil - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.statefulset.name"]) where resource.attributes["k8s.workload.name"] == nil and resource.attributes["k8s.statefulset.name"] != nil @@ -524,6 +532,7 @@ processors: - delete_key(resource.attributes, "app.kubernetes.io/instance") - delete_key(resource.attributes, "app.kubernetes.io/name") - delete_key(resource.attributes, "app.kubernetes.io/version") + - delete_key(resource.attributes, "_tmp.azure.resourcegroup.name") transform/prometheus_scope: error_mode: ignore flatten_data: false diff --git a/translator/tocwconfig/sampleConfig/opentelemetry/windows_events_config.yaml b/translator/tocwconfig/sampleConfig/opentelemetry/windows_events_config.yaml index 71a72586ae..3d3eaaeba8 100644 --- a/translator/tocwconfig/sampleConfig/opentelemetry/windows_events_config.yaml +++ b/translator/tocwconfig/sampleConfig/opentelemetry/windows_events_config.yaml @@ -427,8 +427,8 @@ processors: statements: - set(resource.attributes["aws.log.group.name"], Concat(["/aws/cwagent", resource.attributes["aws.log.source"]], "/")) where resource.attributes["aws.log.group.name"] == nil and resource.attributes["aws.log.source"] != nil - set(resource.attributes["aws.log.group.name"], "/aws/cwagent/default") where resource.attributes["aws.log.group.name"] == nil - - set(resource.attributes["aws.log.stream.name"], Concat([resource.attributes["host.id"], resource.attributes["aws.log.channel"]], "/")) where resource.attributes["aws.log.stream.name"] == nil and resource.attributes["host.id"] != nil and resource.attributes["aws.log.channel"] != nil - - set(resource.attributes["aws.log.stream.name"], Concat([resource.attributes["host.name"], resource.attributes["aws.log.channel"]], "/")) where resource.attributes["aws.log.stream.name"] == nil and resource.attributes["host.name"] != nil and resource.attributes["aws.log.channel"] != nil + - set(resource.attributes["aws.log.stream.name"], Concat([resource.attributes["host.id"], resource.attributes["aws.log.channel"]], "/")) where resource.attributes["aws.log.stream.name"] == nil and resource.attributes["aws.log.source"] == "windows_events" and resource.attributes["host.id"] != nil and resource.attributes["aws.log.channel"] != nil + - set(resource.attributes["aws.log.stream.name"], Concat([resource.attributes["host.name"], resource.attributes["aws.log.channel"]], "/")) where resource.attributes["aws.log.stream.name"] == nil and resource.attributes["aws.log.source"] == "windows_events" and resource.attributes["host.name"] != nil and resource.attributes["aws.log.channel"] != nil - set(resource.attributes["aws.log.stream.name"], Concat([resource.attributes["host.id"], resource.attributes["log.file.name"]], "/")) where resource.attributes["aws.log.stream.name"] == nil and resource.attributes["aws.log.source"] == "files" and resource.attributes["host.id"] != nil and resource.attributes["log.file.name"] != nil - set(resource.attributes["aws.log.stream.name"], Concat([resource.attributes["host.name"], resource.attributes["log.file.name"]], "/")) where resource.attributes["aws.log.stream.name"] == nil and resource.attributes["aws.log.source"] == "files" and resource.attributes["host.name"] != nil and resource.attributes["log.file.name"] != nil - set(resource.attributes["aws.log.stream.name"], Concat([resource.attributes["host.id"], resource.attributes["service.namespace"], resource.attributes["service.name"]], "/")) where resource.attributes["aws.log.stream.name"] == nil and resource.attributes["host.id"] != nil and resource.attributes["service.namespace"] != nil and resource.attributes["service.name"] != nil and resource.attributes["service.name"] != "unknown_service" diff --git a/translator/tocwconfig/tocwconfig_test.go b/translator/tocwconfig/tocwconfig_test.go index e7439441b2..db15f0c1bc 100644 --- a/translator/tocwconfig/tocwconfig_test.go +++ b/translator/tocwconfig/tocwconfig_test.go @@ -431,6 +431,7 @@ func TestOtlpOtelEKSConfig(t *testing.T) { resetContext(t) context.CurrentContext().SetMode(config.ModeEC2) context.CurrentContext().SetKubernetesMode(config.ModeEKS) + t.Setenv("K8S_CLUSTER_NAME", "TestCluster") checkTranslation(t, "opentelemetry/otlp_otel_eks_config", "linux", nil, "") } @@ -1063,6 +1064,11 @@ func resetContext(t *testing.T) { ecsutil.GetECSUtilSingleton().Region = "" context.ResetContext() + // agent.Global_Config is package-level state carried over from whichever test + // ran last, so a config that omits a field (e.g. credentials.role_arn) would + // otherwise inherit the previous test's value. + agent.Global_Config = agent.Agent{} + // Clear OTLP config cache to avoid conflicts between tests otlp.ClearConfigCache() diff --git a/translator/tocwconfig/tocwconfig_unix_test.go b/translator/tocwconfig/tocwconfig_unix_test.go index 8691a71937..17e5dea224 100644 --- a/translator/tocwconfig/tocwconfig_unix_test.go +++ b/translator/tocwconfig/tocwconfig_unix_test.go @@ -292,6 +292,7 @@ func TestAKSHostMetricsConfig(t *testing.T) { // AKS nodes are Azure VMs, so DetectAgentMode resolves host mode to AzureVM; mirror that here. context.CurrentContext().SetMode(config.ModeAzureVM) context.CurrentContext().SetKubernetesMode(config.ModeAKS) + t.Setenv("K8S_CLUSTER_NAME", "TestCluster") checkTranslation(t, "opentelemetry/host_metrics_aks_config", "linux", nil, "") } diff --git a/translator/translate/otel/pipeline/opentelemetry/windowsevents/translators.go b/translator/translate/otel/pipeline/opentelemetry/windowsevents/translators.go index d651845430..ca8cecc622 100644 --- a/translator/translate/otel/pipeline/opentelemetry/windowsevents/translators.go +++ b/translator/translate/otel/pipeline/opentelemetry/windowsevents/translators.go @@ -12,7 +12,9 @@ import ( translatorconfig "github.com/aws/amazon-cloudwatch-agent/translator/config" translatorcontext "github.com/aws/amazon-cloudwatch-agent/translator/context" + globallogs "github.com/aws/amazon-cloudwatch-agent/translator/translate/logs" "github.com/aws/amazon-cloudwatch-agent/translator/translate/otel/common" + logsutil "github.com/aws/amazon-cloudwatch-agent/translator/translate/util" ) const ( @@ -70,7 +72,13 @@ func parseEntries(conf *confmap.Conf) []eventEntry { } logGroupName, _ := m[logGroupNameKey].(string) + if logGroupName != "" { + logGroupName = logsutil.ResolvePlaceholder(logGroupName, globallogs.GlobalLogConfig.MetadataInfo) + } logStreamName, _ := m[logStreamNameKey].(string) + if logStreamName != "" { + logStreamName = logsutil.ResolvePlaceholder(logStreamName, globallogs.GlobalLogConfig.MetadataInfo) + } var levels []string if rawLevels, ok := m[eventLevelsKey].([]any); ok { diff --git a/translator/translate/otel/pipeline/opentelemetry/windowsevents/translators_test.go b/translator/translate/otel/pipeline/opentelemetry/windowsevents/translators_test.go index bb4b162809..d5182ab640 100644 --- a/translator/translate/otel/pipeline/opentelemetry/windowsevents/translators_test.go +++ b/translator/translate/otel/pipeline/opentelemetry/windowsevents/translators_test.go @@ -12,6 +12,7 @@ import ( translatorconfig "github.com/aws/amazon-cloudwatch-agent/translator/config" translatorcontext "github.com/aws/amazon-cloudwatch-agent/translator/context" + globallogs "github.com/aws/amazon-cloudwatch-agent/translator/translate/logs" ) func TestNewTranslators_Disabled(t *testing.T) { @@ -92,6 +93,56 @@ func TestParseEntries(t *testing.T) { assert.Equal(t, []string{"WARNING"}, entries[2].eventLevels) } +func TestParseEntries_ResolvesPlaceholders(t *testing.T) { + globallogs.GlobalLogConfig.MetadataInfo = map[string]string{ + "{hostname}": "EC2AMAZ-ABC123", + "{instance_id}": "i-abcdef1234567890", + "{ip_address}": "172.31.0.1", + } + conf := confmap.NewFromStringMap(map[string]any{ + "opentelemetry": map[string]any{ + "collect": map[string]any{ + "windows_events": map[string]any{ + "collect_list": []any{ + map[string]any{ + "event_name": "System", + "log_group_name": "logs-{instance_id}", + "log_stream_name": "{hostname}/{ip_address}", + }, + }, + }, + }, + }, + }) + entries := parseEntries(conf) + require.Len(t, entries, 1) + assert.Equal(t, "logs-i-abcdef1234567890", entries[0].logGroupName) + assert.Equal(t, "EC2AMAZ-ABC123/172.31.0.1", entries[0].logStreamName) +} + +// Empty names must skip resolution: ResolvePlaceholder defaults an empty input +// to {instance_id} rather than leaving it empty. +func TestParseEntries_EmptyNamesSkipPlaceholderResolution(t *testing.T) { + globallogs.GlobalLogConfig.MetadataInfo = map[string]string{ + "{instance_id}": "i-abcdef1234567890", + } + conf := confmap.NewFromStringMap(map[string]any{ + "opentelemetry": map[string]any{ + "collect": map[string]any{ + "windows_events": map[string]any{ + "collect_list": []any{ + map[string]any{"event_name": "System"}, + }, + }, + }, + }, + }) + entries := parseEntries(conf) + require.Len(t, entries, 1) + assert.Equal(t, "", entries[0].logGroupName) + assert.Equal(t, "", entries[0].logStreamName) +} + func TestParseEntries_ReceiverNames(t *testing.T) { conf := confmap.NewFromStringMap(map[string]any{ "opentelemetry": map[string]any{ diff --git a/translator/translate/otel/processor/transformprocessor/transform_identity_k8s.yaml b/translator/translate/otel/processor/transformprocessor/transform_identity_k8s.yaml index 9764871466..de3268e588 100644 --- a/translator/translate/otel/processor/transformprocessor/transform_identity_k8s.yaml +++ b/translator/translate/otel/processor/transformprocessor/transform_identity_k8s.yaml @@ -18,9 +18,13 @@ trace_statements: - set(resource.attributes["service.name"], resource.attributes["k8s.container.name"]) where resource.attributes["service.name"] == nil and resource.attributes["k8s.container.name"] != nil - set(resource.attributes["service.name"], "unknown_service") where resource.attributes["service.name"] == nil # cloud.resource_id: EKS cluster ARN - - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" - # cloud.resource_id: AKS managed cluster resource ID - - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["azure.resourcegroup.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("arn:aws:eks:%s:%s:cluster/%s", [resource.attributes["cloud.region"], resource.attributes["cloud.account.id"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.region"] != nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "aws_eks" + # cloud.resource_id: AKS managed cluster resource ID. azure.resourcegroup.name is the node's RG + # (MC___); extract the cluster's RG into a temp attribute (cluster + # name injected as a regex literal at translate time), build the ID, then drop the temp. + - set(resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["azure.resourcegroup.name"]) where resource.attributes["cloud.platform"] == "azure_aks" and resource.attributes["azure.resourcegroup.name"] != nil + - replace_pattern(resource.attributes["_tmp.azure.resourcegroup.name"], "^MC_(.+)_%CLUSTER_NAME%_[^_]+$", "$$$1") where resource.attributes["cloud.platform"] == "azure_aks" + - set(resource.attributes["cloud.resource_id"], Format("/subscriptions/%s/resourceGroups/%s/providers/Microsoft.ContainerService/managedClusters/%s", [resource.attributes["cloud.account.id"], resource.attributes["_tmp.azure.resourcegroup.name"], resource.attributes["k8s.cluster.name"]])) where resource.attributes["cloud.resource_id"] == nil and resource.attributes["cloud.account.id"] != nil and resource.attributes["_tmp.azure.resourcegroup.name"] != nil and resource.attributes["k8s.cluster.name"] != nil and resource.attributes["cloud.platform"] == "azure_aks" # k8s.workload.name/type - set(resource.attributes["k8s.workload.name"], resource.attributes["k8s.deployment.name"]) where resource.attributes["k8s.deployment.name"] != nil - set(resource.attributes["k8s.workload.type"], "Deployment") where resource.attributes["k8s.deployment.name"] != nil and resource.attributes["k8s.workload.type"] == nil @@ -50,6 +54,7 @@ trace_statements: - delete_key(resource.attributes, "app.kubernetes.io/instance") - delete_key(resource.attributes, "app.kubernetes.io/name") - delete_key(resource.attributes, "app.kubernetes.io/version") + - delete_key(resource.attributes, "_tmp.azure.resourcegroup.name") metric_statements: - error_mode: ignore context: resource diff --git a/translator/translate/otel/processor/transformprocessor/transform_logs_routing_host_windows.yaml b/translator/translate/otel/processor/transformprocessor/transform_logs_routing_host_windows.yaml index bcd1022052..f4cd651b6f 100644 --- a/translator/translate/otel/processor/transformprocessor/transform_logs_routing_host_windows.yaml +++ b/translator/translate/otel/processor/transformprocessor/transform_logs_routing_host_windows.yaml @@ -7,8 +7,8 @@ log_statements: - set(resource.attributes["aws.log.group.name"], Concat(["/aws/cwagent", resource.attributes["aws.log.source"]], "/")) where resource.attributes["aws.log.group.name"] == nil and resource.attributes["aws.log.source"] != nil - set(resource.attributes["aws.log.group.name"], "/aws/cwagent/default") where resource.attributes["aws.log.group.name"] == nil # Log stream: host.{id,name}/{channel} for windows events - - set(resource.attributes["aws.log.stream.name"], Concat([resource.attributes["host.id"], resource.attributes["aws.log.channel"]], "/")) where resource.attributes["aws.log.stream.name"] == nil and resource.attributes["host.id"] != nil and resource.attributes["aws.log.channel"] != nil - - set(resource.attributes["aws.log.stream.name"], Concat([resource.attributes["host.name"], resource.attributes["aws.log.channel"]], "/")) where resource.attributes["aws.log.stream.name"] == nil and resource.attributes["host.name"] != nil and resource.attributes["aws.log.channel"] != nil + - set(resource.attributes["aws.log.stream.name"], Concat([resource.attributes["host.id"], resource.attributes["aws.log.channel"]], "/")) where resource.attributes["aws.log.stream.name"] == nil and resource.attributes["aws.log.source"] == "windows_events" and resource.attributes["host.id"] != nil and resource.attributes["aws.log.channel"] != nil + - set(resource.attributes["aws.log.stream.name"], Concat([resource.attributes["host.name"], resource.attributes["aws.log.channel"]], "/")) where resource.attributes["aws.log.stream.name"] == nil and resource.attributes["aws.log.source"] == "windows_events" and resource.attributes["host.name"] != nil and resource.attributes["aws.log.channel"] != nil # Log stream: host.{id,name}/{file.name} for file log collection - set(resource.attributes["aws.log.stream.name"], Concat([resource.attributes["host.id"], resource.attributes["log.file.name"]], "/")) where resource.attributes["aws.log.stream.name"] == nil and resource.attributes["aws.log.source"] == "files" and resource.attributes["host.id"] != nil and resource.attributes["log.file.name"] != nil - set(resource.attributes["aws.log.stream.name"], Concat([resource.attributes["host.name"], resource.attributes["log.file.name"]], "/")) where resource.attributes["aws.log.stream.name"] == nil and resource.attributes["aws.log.source"] == "files" and resource.attributes["host.name"] != nil and resource.attributes["log.file.name"] != nil diff --git a/translator/translate/otel/processor/transformprocessor/translator.go b/translator/translate/otel/processor/transformprocessor/translator.go index 101ebef84c..41d039a534 100644 --- a/translator/translate/otel/processor/transformprocessor/translator.go +++ b/translator/translate/otel/processor/transformprocessor/translator.go @@ -201,7 +201,7 @@ func (t *translator) Translate(conf *confmap.Conf) (component.Config, error) { } if t.name == common.Identity { if context.CurrentContext().KubernetesMode() != "" { - return common.GetYamlFileToYamlConfig(cfg, transformIdentityK8sConfig) + return common.GetYamlFileToYamlConfig(cfg, injectClusterName(conf)) } if ecsutil.GetECSUtilSingleton().IsECS() { return common.GetYamlFileToYamlConfig(cfg, transformIdentityECSConfig) @@ -226,6 +226,18 @@ func (t *translator) Translate(conf *confmap.Conf) (component.Config, error) { return cfg, nil } +// injectClusterName bakes the cluster name into the AKS cloud.resource_id regex literal. +// replace_pattern's regex is compiled at load time (not a runtime getter), so the name must be a +// literal here to anchor the node RG's MC___ split. Falls back to a single +// underscore-free segment when unset. No escaping: ValidateClusterName already bars regex metacharacters. +func injectClusterName(conf *confmap.Conf) string { + clusterNameRegex := "[^_]+" + if clusterName := common.GetClusterName(conf, common.OtelClusterNameKey); clusterName != "" { + clusterNameRegex = clusterName + } + return strings.ReplaceAll(transformIdentityK8sConfig, "%CLUSTER_NAME%", clusterNameRegex) +} + func buildResourceStatements(statements []string, errorMode string) map[string]any { stmts := make([]any, len(statements)) for i, s := range statements { diff --git a/translator/translate/otel/processor/transformprocessor/translator_test.go b/translator/translate/otel/processor/transformprocessor/translator_test.go index 0dbeab7248..340b3a94d3 100644 --- a/translator/translate/otel/processor/transformprocessor/translator_test.go +++ b/translator/translate/otel/processor/transformprocessor/translator_test.go @@ -5,6 +5,7 @@ package transformprocessor import ( _ "embed" + "fmt" "os" "path/filepath" "sort" @@ -278,6 +279,59 @@ func TestLogsRoutingWindowsSync(t *testing.T) { "Windows routing YAML must have exactly 2 channel-routing statements") assert.Equal(t, baseStmts, sharedStmts, "Windows routing YAML shared statements must match base") + + // Channel routing must be gated on the source the agent itself sets, or an + // OTLP client sending aws.log.channel could dictate its own stream name. + guard := fmt.Sprintf(`resource.attributes["aws.log.source"] == %q`, common.WindowsEventsKey) + for _, stmt := range channelStmts { + assert.Contains(t, stmt, guard, + "channel-routing statement must be guarded by aws.log.source") + } +} + +// TestLogsRoutingSourceGuards asserts that every stream-name rule keying off an +// attribute the agent itself attaches per source is gated on aws.log.source. +// Without the guard an OTLP client can set that attribute and choose its own log +// stream. Covers both source-specific attributes in both host routing YAMLs. +func TestLogsRoutingSourceGuards(t *testing.T) { + type routingConfig struct { + LogStatements []struct { + Statements []string `yaml:"statements"` + } `yaml:"log_statements"` + } + + // attribute -> the aws.log.source value that must gate rules using it + sourceAttrs := map[string]string{ + "log.file.name": common.FilesKey, + "aws.log.channel": common.WindowsEventsKey, + } + + for _, path := range []string{"transform_logs_routing_host.yaml", "transform_logs_routing_host_windows.yaml"} { + t.Run(path, func(t *testing.T) { + b, err := os.ReadFile(path) + require.NoError(t, err) + var cfg routingConfig + require.NoError(t, yaml.Unmarshal(b, &cfg)) + require.Len(t, cfg.LogStatements, 1) + + var guarded int + for _, stmt := range cfg.LogStatements[0].Statements { + if !strings.Contains(stmt, `set(resource.attributes["aws.log.stream.name"]`) { + continue + } + for attr, source := range sourceAttrs { + if !strings.Contains(stmt, fmt.Sprintf(`resource.attributes[%q]`, attr)) { + continue + } + assert.Contains(t, stmt, fmt.Sprintf(`resource.attributes["aws.log.source"] == %q`, source), + "stream rule using %q must be guarded by aws.log.source == %q", attr, source) + guarded++ + } + } + // Guard against the assertions passing vacuously if the rules are renamed. + assert.NotZero(t, guarded, "expected at least one source-specific stream rule") + }) + } } // TestIdentityTransformSemconvValues asserts that the semconv constants used by @@ -307,3 +361,43 @@ func TestIdentityTransformSemconvValues(t *testing.T) { assert.Equal(t, "service.instance.id", semconv.AttributeServiceInstanceID) assert.Equal(t, "service.version", semconv.AttributeServiceVersion) } + +// TestAKSClusterResourceIDDerivation guards the AKS cloud.resource_id fix: the k8s identity transform +// must derive the cluster's resource group from the node's MC___ RG rather +// than using azure.resourcegroup.name (the node RG) directly, and the Azure VM transform must NOT -- +// there the detected RG is the correct VM identity. +func TestAKSClusterResourceIDDerivation(t *testing.T) { + // The derivation lives only in the k8s transform. + assert.Contains(t, transformIdentityK8sConfig, `replace_pattern(resource.attributes["_tmp.azure.resourcegroup.name"]`, + "k8s identity transform must derive the cluster RG via replace_pattern") + assert.Contains(t, transformIdentityK8sConfig, `delete_key(resource.attributes, "_tmp.azure.resourcegroup.name")`, + "k8s identity transform must clean up the temp attribute") + assert.NotContains(t, transformIdentityAzureVMConfig, "_tmp.azure.resourcegroup.name", + "Azure VM transform must use the detected RG directly, not derive it") + + // Every %s in the AKS Format is nil-guarded (a nil arg would render a corrupt %!s() ID). + for _, attr := range []string{"cloud.account.id", "_tmp.azure.resourcegroup.name", "k8s.cluster.name"} { + assert.Contains(t, transformIdentityK8sConfig, + fmt.Sprintf(`resource.attributes[%q] != nil`, attr), + "AKS resource_id statement must guard %q", attr) + } +} + +// TestResolveK8sIdentityConfig asserts the cluster name is injected into the regex literal at +// translate time (replace_pattern's regex is compile-time, so it cannot read the attribute at runtime). +func TestResolveK8sIdentityConfig(t *testing.T) { + // No cluster name configured -> underscore-free fallback segment. + got := injectClusterName(confmap.New()) + assert.NotContains(t, got, "%CLUSTER_NAME%", "placeholder must be substituted") + assert.Contains(t, got, `"^MC_(.+)_[^_]+_[^_]+$"`, "empty cluster name should fall back to [^_]+") + + // Configured cluster name -> injected verbatim into the regex literal. ValidateClusterName + // (enforced on every path reaching this transform) restricts names to [A-Za-z0-9-_], none of + // which are regex metacharacters, so no escaping is needed. + conf := confmap.NewFromStringMap(map[string]any{ + "opentelemetry": map[string]any{"cluster_name": "my_cluster"}, + }) + got = injectClusterName(conf) + assert.NotContains(t, got, "%CLUSTER_NAME%") + assert.Contains(t, got, `"^MC_(.+)_my_cluster_[^_]+$"`, "cluster name must be injected into the regex literal") +}