diff --git a/src/cpp/ext/gcp/observability_config.cc b/src/cpp/ext/gcp/observability_config.cc index 1bf1e8a7450..28d8aed966f 100644 --- a/src/cpp/ext/gcp/observability_config.cc +++ b/src/cpp/ext/gcp/observability_config.cc @@ -48,12 +48,12 @@ namespace internal { namespace { // Loads the contents of the file pointed by env var -// GRPC_OBSERVABILITY_CONFIG_FILE. If unset, falls back to the contents of -// GRPC_OBSERVABILITY_CONFIG. +// GRPC_GCP_OBSERVABILITY_CONFIG_FILE. If unset, falls back to the contents of +// GRPC_GCP_OBSERVABILITY_CONFIG. absl::StatusOr GetGcpObservabilityConfigContents() { - // First, try GRPC_OBSERVABILITY_CONFIG_FILE + // First, try GRPC_GCP_OBSERVABILITY_CONFIG_FILE std::string contents_str; - auto path = grpc_core::GetEnv("GRPC_OBSERVABILITY_CONFIG_FILE"); + auto path = grpc_core::GetEnv("GRPC_GCP_OBSERVABILITY_CONFIG_FILE"); if (path.has_value()) { grpc_slice contents; grpc_error_handle error = @@ -67,15 +67,15 @@ absl::StatusOr GetGcpObservabilityConfigContents() { grpc_slice_unref(contents); return std::move(contents_str); } - // Next, try GRPC_OBSERVABILITY_CONFIG env var. - auto env_config = grpc_core::GetEnv("GRPC_OBSERVABILITY_CONFIG"); + // Next, try GRPC_GCP_OBSERVABILITY_CONFIG env var. + auto env_config = grpc_core::GetEnv("GRPC_GCP_OBSERVABILITY_CONFIG"); if (env_config.has_value()) { return std::move(*env_config); } // No observability config found. return absl::FailedPreconditionError( - "Environment variables GRPC_OBSERVABILITY_CONFIG_FILE or " - "GRPC_OBSERVABILITY_CONFIG " + "Environment variables GRPC_GCP_OBSERVABILITY_CONFIG_FILE or " + "GRPC_GCP_OBSERVABILITY_CONFIG " "not defined"); } diff --git a/src/cpp/ext/gcp/observability_config.h b/src/cpp/ext/gcp/observability_config.h index 0d5cc69c53f..6ed0755766a 100644 --- a/src/cpp/ext/gcp/observability_config.h +++ b/src/cpp/ext/gcp/observability_config.h @@ -116,9 +116,9 @@ struct GcpObservabilityConfig { } // Tries to load the contents of GcpObservabilityConfig from the file located - // by the value of environment variable `GRPC_OBSERVABILITY_CONFIG_FILE`. If - // `GRPC_OBSERVABILITY_CONFIG_FILE` is unset, falls back to - // `GRPC_OBSERVABILITY_CONFIG`. + // by the value of environment variable `GRPC_GCP_OBSERVABILITY_CONFIG_FILE`. + // If `GRPC_GCP_OBSERVABILITY_CONFIG_FILE` is unset, falls back to + // `GRPC_GCP_OBSERVABILITY_CONFIG`. static absl::StatusOr ReadFromEnv(); }; diff --git a/test/cpp/ext/gcp/observability_config_test.cc b/test/cpp/ext/gcp/observability_config_test.cc index 8c27b593ab6..a5f51b6592b 100644 --- a/test/cpp/ext/gcp/observability_config_test.cc +++ b/test/cpp/ext/gcp/observability_config_test.cc @@ -247,13 +247,13 @@ TEST(GcpEnvParsingTest, NoEnvironmentVariableSet) { auto config = GcpObservabilityConfig::ReadFromEnv(); EXPECT_EQ(config.status(), absl::FailedPreconditionError( - "Environment variables GRPC_OBSERVABILITY_CONFIG_FILE or " - "GRPC_OBSERVABILITY_CONFIG " + "Environment variables GRPC_GCP_OBSERVABILITY_CONFIG_FILE or " + "GRPC_GCP_OBSERVABILITY_CONFIG " "not defined")); } TEST(GcpEnvParsingTest, ConfigFileDoesNotExist) { - grpc_core::SetEnv("GRPC_OBSERVABILITY_CONFIG_FILE", + grpc_core::SetEnv("GRPC_GCP_OBSERVABILITY_CONFIG_FILE", "/tmp/gcp_observability_config_does_not_exist"); auto config = GcpObservabilityConfig::ReadFromEnv(); @@ -261,22 +261,22 @@ TEST(GcpEnvParsingTest, ConfigFileDoesNotExist) { EXPECT_EQ(config.status(), absl::FailedPreconditionError("Failed to load file")); - grpc_core::UnsetEnv("GRPC_OBSERVABILITY_CONFIG_FILE"); + grpc_core::UnsetEnv("GRPC_GCP_OBSERVABILITY_CONFIG_FILE"); } TEST(GcpEnvParsingTest, ProjectIdNotSet) { - grpc_core::SetEnv("GRPC_OBSERVABILITY_CONFIG", "{}"); + grpc_core::SetEnv("GRPC_GCP_OBSERVABILITY_CONFIG", "{}"); auto config = GcpObservabilityConfig::ReadFromEnv(); EXPECT_EQ(config.status(), absl::FailedPreconditionError("GCP Project ID not found.")); - grpc_core::UnsetEnv("GRPC_OBSERVABILITY_CONFIG"); + grpc_core::UnsetEnv("GRPC_GCP_OBSERVABILITY_CONFIG"); grpc_core::CoreConfiguration::Reset(); } TEST(GcpEnvParsingTest, ProjectIdFromGcpProjectEnvVar) { - grpc_core::SetEnv("GRPC_OBSERVABILITY_CONFIG", "{}"); + grpc_core::SetEnv("GRPC_GCP_OBSERVABILITY_CONFIG", "{}"); grpc_core::SetEnv("GCP_PROJECT", "gcp_project"); auto config = GcpObservabilityConfig::ReadFromEnv(); @@ -284,12 +284,12 @@ TEST(GcpEnvParsingTest, ProjectIdFromGcpProjectEnvVar) { EXPECT_EQ(config->project_id, "gcp_project"); grpc_core::UnsetEnv("GCP_PROJECT"); - grpc_core::UnsetEnv("GRPC_OBSERVABILITY_CONFIG"); + grpc_core::UnsetEnv("GRPC_GCP_OBSERVABILITY_CONFIG"); grpc_core::CoreConfiguration::Reset(); } TEST(GcpEnvParsingTest, ProjectIdFromGcloudProjectEnvVar) { - grpc_core::SetEnv("GRPC_OBSERVABILITY_CONFIG", "{}"); + grpc_core::SetEnv("GRPC_GCP_OBSERVABILITY_CONFIG", "{}"); grpc_core::SetEnv("GCLOUD_PROJECT", "gcloud_project"); auto config = GcpObservabilityConfig::ReadFromEnv(); @@ -297,12 +297,12 @@ TEST(GcpEnvParsingTest, ProjectIdFromGcloudProjectEnvVar) { EXPECT_EQ(config->project_id, "gcloud_project"); grpc_core::UnsetEnv("GCLOUD_PROJECT"); - grpc_core::UnsetEnv("GRPC_OBSERVABILITY_CONFIG"); + grpc_core::UnsetEnv("GRPC_GCP_OBSERVABILITY_CONFIG"); grpc_core::CoreConfiguration::Reset(); } TEST(GcpEnvParsingTest, ProjectIdFromGoogleCloudProjectEnvVar) { - grpc_core::SetEnv("GRPC_OBSERVABILITY_CONFIG", "{}"); + grpc_core::SetEnv("GRPC_GCP_OBSERVABILITY_CONFIG", "{}"); grpc_core::SetEnv("GOOGLE_CLOUD_PROJECT", "google_cloud_project"); auto config = GcpObservabilityConfig::ReadFromEnv(); @@ -310,7 +310,7 @@ TEST(GcpEnvParsingTest, ProjectIdFromGoogleCloudProjectEnvVar) { EXPECT_EQ(config->project_id, "google_cloud_project"); grpc_core::UnsetEnv("GOOGLE_CLOUD_PROJECT"); - grpc_core::UnsetEnv("GRPC_OBSERVABILITY_CONFIG"); + grpc_core::UnsetEnv("GRPC_GCP_OBSERVABILITY_CONFIG"); grpc_core::CoreConfiguration::Reset(); } @@ -352,13 +352,13 @@ class EnvParsingTest : public ::testing::TestWithParam { ~EnvParsingTest() override { if (GetParam().config_source() == EnvParsingTestType::ConfigSource::kFile) { if (tmp_file_name != nullptr) { - grpc_core::UnsetEnv("GRPC_OBSERVABILITY_CONFIG_FILE"); + grpc_core::UnsetEnv("GRPC_GCP_OBSERVABILITY_CONFIG_FILE"); remove(tmp_file_name); gpr_free(tmp_file_name); } } else if (GetParam().config_source() == EnvParsingTestType::ConfigSource::kEnvVar) { - grpc_core::UnsetEnv("GRPC_OBSERVABILITY_CONFIG"); + grpc_core::UnsetEnv("GRPC_GCP_OBSERVABILITY_CONFIG"); } } @@ -369,10 +369,10 @@ class EnvParsingTest : public ::testing::TestWithParam { gpr_tmpfile("gcp_observability_config", &tmp_file_name); fputs(json, tmp_config_file); fclose(tmp_config_file); - grpc_core::SetEnv("GRPC_OBSERVABILITY_CONFIG_FILE", tmp_file_name); + grpc_core::SetEnv("GRPC_GCP_OBSERVABILITY_CONFIG_FILE", tmp_file_name); } else if (GetParam().config_source() == EnvParsingTestType::ConfigSource::kEnvVar) { - grpc_core::SetEnv("GRPC_OBSERVABILITY_CONFIG", json); + grpc_core::SetEnv("GRPC_GCP_OBSERVABILITY_CONFIG", json); } } diff --git a/test/cpp/ext/gcp/observability_test.cc b/test/cpp/ext/gcp/observability_test.cc index 757e38a8cf3..c8c9c28f3ec 100644 --- a/test/cpp/ext/gcp/observability_test.cc +++ b/test/cpp/ext/gcp/observability_test.cc @@ -28,8 +28,8 @@ TEST(GcpObservabilityTest, RegistrationTest) { auto status = grpc::experimental::GcpObservabilityInit(); EXPECT_EQ(status, absl::FailedPreconditionError( - "Environment variables GRPC_OBSERVABILITY_CONFIG_FILE or " - "GRPC_OBSERVABILITY_CONFIG " + "Environment variables GRPC_GCP_OBSERVABILITY_CONFIG_FILE or " + "GRPC_GCP_OBSERVABILITY_CONFIG " "not defined")); grpc_core::CoreConfiguration::Reset();