diff --git a/src/cpp/ext/csm/metadata_exchange.cc b/src/cpp/ext/csm/metadata_exchange.cc index 8329d2b4cbc..567de4b6d5a 100644 --- a/src/cpp/ext/csm/metadata_exchange.cc +++ b/src/cpp/ext/csm/metadata_exchange.cc @@ -59,9 +59,7 @@ namespace { // The keys that will be used in the Metadata Exchange between local and remote. constexpr absl::string_view kMetadataExchangeTypeKey = "type"; -constexpr absl::string_view kMetadataExchangePodNameKey = "pod_name"; -constexpr absl::string_view kMetadataExchangeContainerNameKey = - "container_name"; +constexpr absl::string_view kMetadataExchangeWorkloadNameKey = "workload_name"; constexpr absl::string_view kMetadataExchangeNamespaceNameKey = "namespace_name"; constexpr absl::string_view kMetadataExchangeClusterNameKey = "cluster_name"; @@ -70,13 +68,13 @@ constexpr absl::string_view kMetadataExchangeProjectIdKey = "project_id"; constexpr absl::string_view kMetadataExchangeCanonicalServiceKey = "canonical_service"; // The keys that will be used for the local attributes when recording metrics. +constexpr absl::string_view kCanonicalServiceAttribute = + "csm.workload_canonical_service"; constexpr absl::string_view kMeshIdAttribute = "csm.mesh_id"; // The keys that will be used for the peer attributes when recording metrics. constexpr absl::string_view kPeerTypeAttribute = "csm.remote_workload_type"; -constexpr absl::string_view kPeerPodNameAttribute = - "csm.remote_workload_pod_name"; -constexpr absl::string_view kPeerContainerNameAttribute = - "csm.remote_workload_container_name"; +constexpr absl::string_view kPeerWorkloadNameAttribute = + "csm.remote_workload_name"; constexpr absl::string_view kPeerNamespaceNameAttribute = "csm.remote_workload_namespace_name"; constexpr absl::string_view kPeerClusterNameAttribute = @@ -270,10 +268,9 @@ class MeshLabelsIterable : public LabelsIterable { google_protobuf_Struct* struct_pb = nullptr; }; - static constexpr std::array kGkeAttributeList = { - GkeAttribute{kPeerPodNameAttribute, kMetadataExchangePodNameKey}, - GkeAttribute{kPeerContainerNameAttribute, - kMetadataExchangeContainerNameKey}, + static constexpr std::array kGkeAttributeList = { + GkeAttribute{kPeerWorkloadNameAttribute, + kMetadataExchangeWorkloadNameKey}, GkeAttribute{kPeerNamespaceNameAttribute, kMetadataExchangeNamespaceNameKey}, GkeAttribute{kPeerClusterNameAttribute, kMetadataExchangeClusterNameKey}, @@ -311,7 +308,7 @@ class MeshLabelsIterable : public LabelsIterable { uint32_t pos_ = 0; }; -constexpr std::array +constexpr std::array MeshLabelsIterable::kGkeAttributeList; } // namespace @@ -348,11 +345,8 @@ ServiceMeshLabelsInjector::ServiceMeshLabelsInjector( // Assume kubernetes for now absl::string_view type_value = GetStringValueFromAttributeMap( map, opentelemetry::sdk::resource::SemanticConventions::kCloudPlatform); - absl::string_view pod_name_value = GetStringValueFromAttributeMap( - map, opentelemetry::sdk::resource::SemanticConventions::kK8sPodName); - absl::string_view container_name_value = GetStringValueFromAttributeMap( - map, - opentelemetry::sdk::resource::SemanticConventions::kK8sContainerName); + std::string workload_name_value = + grpc_core::GetEnv("CSM_WORKLOAD_NAME").value_or("unknown"); absl::string_view namespace_value = GetStringValueFromAttributeMap( map, opentelemetry::sdk::resource::SemanticConventions::kK8sNamespaceName); @@ -369,16 +363,14 @@ ServiceMeshLabelsInjector::ServiceMeshLabelsInjector( absl::string_view project_id_value = GetStringValueFromAttributeMap( map, opentelemetry::sdk::resource::SemanticConventions::kCloudAccountId); std::string canonical_service_value = - grpc_core::GetEnv("GSM_CANONICAL_SERVICE_NAME").value_or("unknown"); + grpc_core::GetEnv("CSM_CANONICAL_SERVICE_NAME").value_or("unknown"); // Create metadata to be sent over wire. AddStringKeyValueToStructProto(metadata, kMetadataExchangeTypeKey, type_value, arena.ptr()); // Only handle GKE for now if (type_value == kGkeType) { - AddStringKeyValueToStructProto(metadata, kMetadataExchangePodNameKey, - pod_name_value, arena.ptr()); - AddStringKeyValueToStructProto(metadata, kMetadataExchangeContainerNameKey, - container_name_value, arena.ptr()); + AddStringKeyValueToStructProto(metadata, kMetadataExchangeWorkloadNameKey, + workload_name_value, arena.ptr()); AddStringKeyValueToStructProto(metadata, kMetadataExchangeNamespaceNameKey, namespace_value, arena.ptr()); AddStringKeyValueToStructProto(metadata, kMetadataExchangeClusterNameKey, @@ -399,6 +391,8 @@ ServiceMeshLabelsInjector::ServiceMeshLabelsInjector( absl::Base64Escape(absl::string_view(output, output_length))); // Fill up local labels map. The rest we get from the detected Resource and // from the peer. + local_labels_.emplace_back(kCanonicalServiceAttribute, + canonical_service_value); local_labels_.emplace_back(kMeshIdAttribute, GetMeshId()); } diff --git a/test/cpp/ext/csm/metadata_exchange_test.cc b/test/cpp/ext/csm/metadata_exchange_test.cc index 7f3a6ac15e7..7e202b54165 100644 --- a/test/cpp/ext/csm/metadata_exchange_test.cc +++ b/test/cpp/ext/csm/metadata_exchange_test.cc @@ -150,18 +150,18 @@ class MetadataExchangeTest const std::map& attributes) { + EXPECT_EQ( + absl::get(attributes.at("csm.workload_canonical_service")), + "canonical_service"); EXPECT_EQ(absl::get(attributes.at("csm.mesh_id")), "mesh-id"); switch (GetParam().type()) { case TestScenario::ResourceType::kGke: EXPECT_EQ( absl::get(attributes.at("csm.remote_workload_type")), "gcp_kubernetes_engine"); - EXPECT_EQ(absl::get( - attributes.at("csm.remote_workload_pod_name")), - "pod"); - EXPECT_EQ(absl::get( - attributes.at("csm.remote_workload_container_name")), - "container"); + EXPECT_EQ( + absl::get(attributes.at("csm.remote_workload_name")), + "workload"); EXPECT_EQ(absl::get( attributes.at("csm.remote_workload_namespace_name")), "namespace"); @@ -307,6 +307,7 @@ INSTANTIATE_TEST_SUITE_P( int main(int argc, char** argv) { grpc::testing::TestEnvironment env(&argc, argv); ::testing::InitGoogleTest(&argc, argv); - grpc_core::SetEnv("GSM_CANONICAL_SERVICE_NAME", "canonical_service"); + grpc_core::SetEnv("CSM_WORKLOAD_NAME", "workload"); + grpc_core::SetEnv("CSM_CANONICAL_SERVICE_NAME", "canonical_service"); return RUN_ALL_TESTS(); }