GcpObservability: Add config support for constant labels (#31710)

pull/31718/head
Yash Tibrewal 2 years ago committed by GitHub
parent f3fedae7c8
commit 0389940093
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      src/cpp/ext/gcp/observability_config.h
  2. 13
      test/cpp/ext/gcp/observability_config_test.cc

@ -97,6 +97,7 @@ struct GcpObservabilityConfig {
absl::optional<CloudMonitoring> cloud_monitoring;
absl::optional<CloudTrace> cloud_trace;
std::string project_id;
std::map<std::string, std::string> labels;
static const grpc_core::JsonLoaderInterface* JsonLoader(
const grpc_core::JsonArgs&) {
@ -108,6 +109,7 @@ struct GcpObservabilityConfig {
&GcpObservabilityConfig::cloud_monitoring)
.OptionalField("cloud_trace", &GcpObservabilityConfig::cloud_trace)
.OptionalField("project_id", &GcpObservabilityConfig::project_id)
.OptionalField("labels", &GcpObservabilityConfig::labels)
.Finish();
return loader;
}

@ -55,7 +55,12 @@ TEST(GcpObservabilityConfigJsonParsingTest, Basic) {
"cloud_trace": {
"sampling_rate": 0.05
},
"project_id": "project"
"project_id": "project",
"labels": {
"SOURCE_VERSION": "v1",
"SERVICE_NAME": "payment-service",
"DATA_CENTER": "us-west1-a"
}
})json";
auto json = grpc_core::Json::Parse(json_str);
ASSERT_TRUE(json.ok()) << json.status();
@ -88,6 +93,11 @@ TEST(GcpObservabilityConfigJsonParsingTest, Basic) {
EXPECT_TRUE(config.cloud_trace.has_value());
EXPECT_FLOAT_EQ(config.cloud_trace->sampling_rate, 0.05);
EXPECT_EQ(config.project_id, "project");
EXPECT_THAT(config.labels,
::testing::UnorderedElementsAre(
::testing::Pair("SOURCE_VERSION", "v1"),
::testing::Pair("SERVICE_NAME", "payment-service"),
::testing::Pair("DATA_CENTER", "us-west1-a")));
}
TEST(GcpObservabilityConfigJsonParsingTest, Defaults) {
@ -103,6 +113,7 @@ TEST(GcpObservabilityConfigJsonParsingTest, Defaults) {
EXPECT_FALSE(config.cloud_monitoring.has_value());
EXPECT_FALSE(config.cloud_trace.has_value());
EXPECT_TRUE(config.project_id.empty());
EXPECT_TRUE(config.labels.empty());
}
TEST(GcpObservabilityConfigJsonParsingTest, LoggingConfigMethodIllegalSlashes) {

Loading…
Cancel
Save