|
|
|
@ -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<EnvParsingTestType> { |
|
|
|
|
~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<EnvParsingTestType> { |
|
|
|
|
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); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|