Reviewer comments

pull/35631/head
Yash Tibrewal 1 year ago
parent e3710e086c
commit e0b80d01a2
  1. 2
      test/cpp/ext/csm/metadata_exchange_test.cc
  2. 64
      test/cpp/ext/otel/otel_plugin_test.cc
  3. 5
      test/cpp/ext/otel/otel_test_library.cc
  4. 169
      test/cpp/ext/otel/otel_test_library.h

@ -147,7 +147,7 @@ class MetadataExchangeTest
break; break;
} }
OpenTelemetryPluginEnd2EndTest::Init(std::move( OpenTelemetryPluginEnd2EndTest::Init(std::move(
OpenTelemetryPluginTestConfiguration() Options()
.set_metric_names(std::move(metric_names)) .set_metric_names(std::move(metric_names))
.set_labels_injector( .set_labels_injector(
std::make_unique<grpc::internal::ServiceMeshLabelsInjector>( std::make_unique<grpc::internal::ServiceMeshLabelsInjector>(

@ -51,9 +51,9 @@ TEST(OpenTelemetryPluginBuildTest, Basic) {
} }
TEST_F(OpenTelemetryPluginEnd2EndTest, ClientAttemptStarted) { TEST_F(OpenTelemetryPluginEnd2EndTest, ClientAttemptStarted) {
Init(std::move(OpenTelemetryPluginTestConfiguration().set_metric_names( Init(std::move(
{grpc::OpenTelemetryPluginBuilder:: Options().set_metric_names({grpc::OpenTelemetryPluginBuilder::
kClientAttemptStartedInstrumentName}))); kClientAttemptStartedInstrumentName})));
SendRPC(); SendRPC();
const char* kMetricName = "grpc.client.attempt.started"; const char* kMetricName = "grpc.client.attempt.started";
auto data = ReadCurrentMetricsData( auto data = ReadCurrentMetricsData(
@ -81,9 +81,9 @@ TEST_F(OpenTelemetryPluginEnd2EndTest, ClientAttemptStarted) {
} }
TEST_F(OpenTelemetryPluginEnd2EndTest, ClientAttemptDuration) { TEST_F(OpenTelemetryPluginEnd2EndTest, ClientAttemptDuration) {
Init(std::move(OpenTelemetryPluginTestConfiguration().set_metric_names( Init(std::move(
{grpc::OpenTelemetryPluginBuilder:: Options().set_metric_names({grpc::OpenTelemetryPluginBuilder::
kClientAttemptDurationInstrumentName}))); kClientAttemptDurationInstrumentName})));
SendRPC(); SendRPC();
const char* kMetricName = "grpc.client.attempt.duration"; const char* kMetricName = "grpc.client.attempt.duration";
auto data = ReadCurrentMetricsData( auto data = ReadCurrentMetricsData(
@ -115,7 +115,7 @@ TEST_F(OpenTelemetryPluginEnd2EndTest, ClientAttemptDuration) {
TEST_F(OpenTelemetryPluginEnd2EndTest, TEST_F(OpenTelemetryPluginEnd2EndTest,
ClientAttemptSentTotalCompressedMessageSize) { ClientAttemptSentTotalCompressedMessageSize) {
Init(std::move(OpenTelemetryPluginTestConfiguration().set_metric_names( Init(std::move(Options().set_metric_names(
{grpc::OpenTelemetryPluginBuilder:: {grpc::OpenTelemetryPluginBuilder::
kClientAttemptSentTotalCompressedMessageSizeInstrumentName}))); kClientAttemptSentTotalCompressedMessageSizeInstrumentName})));
SendRPC(); SendRPC();
@ -151,7 +151,7 @@ TEST_F(OpenTelemetryPluginEnd2EndTest,
TEST_F(OpenTelemetryPluginEnd2EndTest, TEST_F(OpenTelemetryPluginEnd2EndTest,
ClientAttemptRcvdTotalCompressedMessageSize) { ClientAttemptRcvdTotalCompressedMessageSize) {
Init(std::move(OpenTelemetryPluginTestConfiguration().set_metric_names( Init(std::move(Options().set_metric_names(
{grpc::OpenTelemetryPluginBuilder:: {grpc::OpenTelemetryPluginBuilder::
kClientAttemptRcvdTotalCompressedMessageSizeInstrumentName}))); kClientAttemptRcvdTotalCompressedMessageSizeInstrumentName})));
SendRPC(); SendRPC();
@ -186,7 +186,7 @@ TEST_F(OpenTelemetryPluginEnd2EndTest,
} }
TEST_F(OpenTelemetryPluginEnd2EndTest, ServerCallStarted) { TEST_F(OpenTelemetryPluginEnd2EndTest, ServerCallStarted) {
Init(std::move(OpenTelemetryPluginTestConfiguration().set_metric_names( Init(std::move(Options().set_metric_names(
{grpc::OpenTelemetryPluginBuilder::kServerCallStartedInstrumentName}))); {grpc::OpenTelemetryPluginBuilder::kServerCallStartedInstrumentName})));
SendRPC(); SendRPC();
const char* kMetricName = "grpc.server.call.started"; const char* kMetricName = "grpc.server.call.started";
@ -211,7 +211,7 @@ TEST_F(OpenTelemetryPluginEnd2EndTest, ServerCallStarted) {
} }
TEST_F(OpenTelemetryPluginEnd2EndTest, ServerCallDuration) { TEST_F(OpenTelemetryPluginEnd2EndTest, ServerCallDuration) {
Init(std::move(OpenTelemetryPluginTestConfiguration().set_metric_names( Init(std::move(Options().set_metric_names(
{grpc::OpenTelemetryPluginBuilder::kServerCallDurationInstrumentName}))); {grpc::OpenTelemetryPluginBuilder::kServerCallDurationInstrumentName})));
SendRPC(); SendRPC();
const char* kMetricName = "grpc.server.call.duration"; const char* kMetricName = "grpc.server.call.duration";
@ -240,7 +240,7 @@ TEST_F(OpenTelemetryPluginEnd2EndTest, ServerCallDuration) {
TEST_F(OpenTelemetryPluginEnd2EndTest, TEST_F(OpenTelemetryPluginEnd2EndTest,
ServerCallSentTotalCompressedMessageSize) { ServerCallSentTotalCompressedMessageSize) {
Init(std::move(OpenTelemetryPluginTestConfiguration().set_metric_names( Init(std::move(Options().set_metric_names(
{grpc::OpenTelemetryPluginBuilder:: {grpc::OpenTelemetryPluginBuilder::
kServerCallSentTotalCompressedMessageSizeInstrumentName}))); kServerCallSentTotalCompressedMessageSizeInstrumentName})));
SendRPC(); SendRPC();
@ -272,7 +272,7 @@ TEST_F(OpenTelemetryPluginEnd2EndTest,
TEST_F(OpenTelemetryPluginEnd2EndTest, TEST_F(OpenTelemetryPluginEnd2EndTest,
ServerCallRcvdTotalCompressedMessageSize) { ServerCallRcvdTotalCompressedMessageSize) {
Init(std::move(OpenTelemetryPluginTestConfiguration().set_metric_names( Init(std::move(Options().set_metric_names(
{grpc::OpenTelemetryPluginBuilder:: {grpc::OpenTelemetryPluginBuilder::
kServerCallRcvdTotalCompressedMessageSizeInstrumentName}))); kServerCallRcvdTotalCompressedMessageSizeInstrumentName})));
SendRPC(); SendRPC();
@ -305,17 +305,17 @@ TEST_F(OpenTelemetryPluginEnd2EndTest,
// Make sure that no meter provider results in normal operations. // Make sure that no meter provider results in normal operations.
TEST_F(OpenTelemetryPluginEnd2EndTest, NoMeterProviderRegistered) { TEST_F(OpenTelemetryPluginEnd2EndTest, NoMeterProviderRegistered) {
Init( Init(
std::move(OpenTelemetryPluginTestConfiguration() std::move(Options()
.set_metric_names({grpc::OpenTelemetryPluginBuilder:: .set_metric_names({grpc::OpenTelemetryPluginBuilder::
kClientAttemptStartedInstrumentName}) kClientAttemptStartedInstrumentName})
.set_test_no_meter_provider(true))); .set_use_meter_provider(false)));
SendRPC(); SendRPC();
} }
// Test that a channel selector returning true records metrics on the channel. // Test that a channel selector returning true records metrics on the channel.
TEST_F(OpenTelemetryPluginEnd2EndTest, TargetSelectorReturnsTrue) { TEST_F(OpenTelemetryPluginEnd2EndTest, TargetSelectorReturnsTrue) {
Init( Init(
std::move(OpenTelemetryPluginTestConfiguration() std::move(Options()
.set_metric_names({grpc::OpenTelemetryPluginBuilder:: .set_metric_names({grpc::OpenTelemetryPluginBuilder::
kClientAttemptStartedInstrumentName}) kClientAttemptStartedInstrumentName})
.set_target_selector( .set_target_selector(
@ -350,7 +350,7 @@ TEST_F(OpenTelemetryPluginEnd2EndTest, TargetSelectorReturnsTrue) {
// channel. // channel.
TEST_F(OpenTelemetryPluginEnd2EndTest, TargetSelectorReturnsFalse) { TEST_F(OpenTelemetryPluginEnd2EndTest, TargetSelectorReturnsFalse) {
Init( Init(
std::move(OpenTelemetryPluginTestConfiguration() std::move(Options()
.set_metric_names({grpc::OpenTelemetryPluginBuilder:: .set_metric_names({grpc::OpenTelemetryPluginBuilder::
kClientAttemptStartedInstrumentName}) kClientAttemptStartedInstrumentName})
.set_target_selector( .set_target_selector(
@ -366,7 +366,7 @@ TEST_F(OpenTelemetryPluginEnd2EndTest, TargetSelectorReturnsFalse) {
// Test that a server selector returning true records metrics on the server. // Test that a server selector returning true records metrics on the server.
TEST_F(OpenTelemetryPluginEnd2EndTest, ServerSelectorReturnsTrue) { TEST_F(OpenTelemetryPluginEnd2EndTest, ServerSelectorReturnsTrue) {
Init(std::move(OpenTelemetryPluginTestConfiguration() Init(std::move(Options()
.set_metric_names({grpc::OpenTelemetryPluginBuilder:: .set_metric_names({grpc::OpenTelemetryPluginBuilder::
kServerCallDurationInstrumentName}) kServerCallDurationInstrumentName})
.set_server_selector( .set_server_selector(
@ -392,7 +392,7 @@ TEST_F(OpenTelemetryPluginEnd2EndTest, ServerSelectorReturnsTrue) {
// Test that a server selector returning false does not record metrics on the // Test that a server selector returning false does not record metrics on the
// server. // server.
TEST_F(OpenTelemetryPluginEnd2EndTest, ServerSelectorReturnsFalse) { TEST_F(OpenTelemetryPluginEnd2EndTest, ServerSelectorReturnsFalse) {
Init(std::move(OpenTelemetryPluginTestConfiguration() Init(std::move(Options()
.set_metric_names({grpc::OpenTelemetryPluginBuilder:: .set_metric_names({grpc::OpenTelemetryPluginBuilder::
kServerCallDurationInstrumentName}) kServerCallDurationInstrumentName})
.set_server_selector( .set_server_selector(
@ -412,7 +412,7 @@ TEST_F(OpenTelemetryPluginEnd2EndTest, ServerSelectorReturnsFalse) {
// target as is on the channel. // target as is on the channel.
TEST_F(OpenTelemetryPluginEnd2EndTest, TargetAttributeFilterReturnsTrue) { TEST_F(OpenTelemetryPluginEnd2EndTest, TargetAttributeFilterReturnsTrue) {
Init( Init(
std::move(OpenTelemetryPluginTestConfiguration() std::move(Options()
.set_metric_names({grpc::OpenTelemetryPluginBuilder:: .set_metric_names({grpc::OpenTelemetryPluginBuilder::
kClientAttemptStartedInstrumentName}) kClientAttemptStartedInstrumentName})
.set_target_attribute_filter( .set_target_attribute_filter(
@ -447,7 +447,7 @@ TEST_F(OpenTelemetryPluginEnd2EndTest, TargetAttributeFilterReturnsTrue) {
// target as "other". // target as "other".
TEST_F(OpenTelemetryPluginEnd2EndTest, TargetAttributeFilterReturnsFalse) { TEST_F(OpenTelemetryPluginEnd2EndTest, TargetAttributeFilterReturnsFalse) {
Init( Init(
std::move(OpenTelemetryPluginTestConfiguration() std::move(Options()
.set_metric_names({grpc::OpenTelemetryPluginBuilder:: .set_metric_names({grpc::OpenTelemetryPluginBuilder::
kClientAttemptStartedInstrumentName}) kClientAttemptStartedInstrumentName})
.set_target_attribute_filter( .set_target_attribute_filter(
@ -480,9 +480,9 @@ TEST_F(OpenTelemetryPluginEnd2EndTest, TargetAttributeFilterReturnsFalse) {
// Test that generic method names are scrubbed properly on the client side. // Test that generic method names are scrubbed properly on the client side.
TEST_F(OpenTelemetryPluginEnd2EndTest, GenericClientRpc) { TEST_F(OpenTelemetryPluginEnd2EndTest, GenericClientRpc) {
Init(std::move(OpenTelemetryPluginTestConfiguration().set_metric_names( Init(std::move(
{grpc::OpenTelemetryPluginBuilder:: Options().set_metric_names({grpc::OpenTelemetryPluginBuilder::
kClientAttemptStartedInstrumentName}))); kClientAttemptStartedInstrumentName})));
SendGenericRPC(); SendGenericRPC();
const char* kMetricName = "grpc.client.attempt.started"; const char* kMetricName = "grpc.client.attempt.started";
auto data = ReadCurrentMetricsData( auto data = ReadCurrentMetricsData(
@ -514,7 +514,7 @@ TEST_F(OpenTelemetryPluginEnd2EndTest, GenericClientRpc) {
TEST_F(OpenTelemetryPluginEnd2EndTest, TEST_F(OpenTelemetryPluginEnd2EndTest,
GenericClientRpcWithMethodAttributeFilterReturningFalse) { GenericClientRpcWithMethodAttributeFilterReturningFalse) {
Init(std::move( Init(std::move(
OpenTelemetryPluginTestConfiguration() Options()
.set_metric_names({grpc::OpenTelemetryPluginBuilder:: .set_metric_names({grpc::OpenTelemetryPluginBuilder::
kClientAttemptStartedInstrumentName}) kClientAttemptStartedInstrumentName})
.set_generic_method_attribute_filter( .set_generic_method_attribute_filter(
@ -550,7 +550,7 @@ TEST_F(OpenTelemetryPluginEnd2EndTest,
TEST_F(OpenTelemetryPluginEnd2EndTest, TEST_F(OpenTelemetryPluginEnd2EndTest,
GenericClientRpcWithMethodAttributeFilterReturningTrue) { GenericClientRpcWithMethodAttributeFilterReturningTrue) {
Init(std::move( Init(std::move(
OpenTelemetryPluginTestConfiguration() Options()
.set_metric_names({grpc::OpenTelemetryPluginBuilder:: .set_metric_names({grpc::OpenTelemetryPluginBuilder::
kClientAttemptStartedInstrumentName}) kClientAttemptStartedInstrumentName})
.set_generic_method_attribute_filter( .set_generic_method_attribute_filter(
@ -583,7 +583,7 @@ TEST_F(OpenTelemetryPluginEnd2EndTest,
// Test that generic method names are scrubbed properly on the server side. // Test that generic method names are scrubbed properly on the server side.
TEST_F(OpenTelemetryPluginEnd2EndTest, GenericServerRpc) { TEST_F(OpenTelemetryPluginEnd2EndTest, GenericServerRpc) {
Init(std::move(OpenTelemetryPluginTestConfiguration().set_metric_names( Init(std::move(Options().set_metric_names(
{grpc::OpenTelemetryPluginBuilder::kServerCallDurationInstrumentName}))); {grpc::OpenTelemetryPluginBuilder::kServerCallDurationInstrumentName})));
SendGenericRPC(); SendGenericRPC();
const char* kMetricName = "grpc.server.call.duration"; const char* kMetricName = "grpc.server.call.duration";
@ -615,7 +615,7 @@ TEST_F(OpenTelemetryPluginEnd2EndTest, GenericServerRpc) {
TEST_F(OpenTelemetryPluginEnd2EndTest, TEST_F(OpenTelemetryPluginEnd2EndTest,
GenericServerRpcWithMethodAttributeFilterReturningFalse) { GenericServerRpcWithMethodAttributeFilterReturningFalse) {
Init(std::move( Init(std::move(
OpenTelemetryPluginTestConfiguration() Options()
.set_metric_names({grpc::OpenTelemetryPluginBuilder:: .set_metric_names({grpc::OpenTelemetryPluginBuilder::
kServerCallDurationInstrumentName}) kServerCallDurationInstrumentName})
.set_generic_method_attribute_filter( .set_generic_method_attribute_filter(
@ -650,7 +650,7 @@ TEST_F(OpenTelemetryPluginEnd2EndTest,
TEST_F(OpenTelemetryPluginEnd2EndTest, TEST_F(OpenTelemetryPluginEnd2EndTest,
GenericServerRpcWithMethodAttributeFilterReturningTrue) { GenericServerRpcWithMethodAttributeFilterReturningTrue) {
Init(std::move( Init(std::move(
OpenTelemetryPluginTestConfiguration() Options()
.set_metric_names({grpc::OpenTelemetryPluginBuilder:: .set_metric_names({grpc::OpenTelemetryPluginBuilder::
kServerCallDurationInstrumentName}) kServerCallDurationInstrumentName})
.set_generic_method_attribute_filter( .set_generic_method_attribute_filter(
@ -780,7 +780,7 @@ TEST_F(OpenTelemetryPluginOptionEnd2EndTest, Basic) {
/*enabled_on_client*/ true, /*enabled_on_server*/ true, /*enabled_on_client*/ true, /*enabled_on_server*/ true,
std::make_pair("key", "value"))); std::make_pair("key", "value")));
Init( Init(
std::move(OpenTelemetryPluginTestConfiguration() std::move(Options()
.set_metric_names({grpc::OpenTelemetryPluginBuilder:: .set_metric_names({grpc::OpenTelemetryPluginBuilder::
kClientAttemptDurationInstrumentName, kClientAttemptDurationInstrumentName,
grpc::OpenTelemetryPluginBuilder:: grpc::OpenTelemetryPluginBuilder::
@ -817,7 +817,7 @@ TEST_F(OpenTelemetryPluginOptionEnd2EndTest, ClientOnlyPluginOption) {
/*enabled_on_client*/ true, /*enabled_on_server*/ false, /*enabled_on_client*/ true, /*enabled_on_server*/ false,
std::make_pair("key", "value"))); std::make_pair("key", "value")));
Init( Init(
std::move(OpenTelemetryPluginTestConfiguration() std::move(Options()
.set_metric_names({grpc::OpenTelemetryPluginBuilder:: .set_metric_names({grpc::OpenTelemetryPluginBuilder::
kClientAttemptDurationInstrumentName, kClientAttemptDurationInstrumentName,
grpc::OpenTelemetryPluginBuilder:: grpc::OpenTelemetryPluginBuilder::
@ -855,7 +855,7 @@ TEST_F(OpenTelemetryPluginOptionEnd2EndTest, ServerOnlyPluginOption) {
/*enabled_on_client*/ false, /*enabled_on_server*/ true, /*enabled_on_client*/ false, /*enabled_on_server*/ true,
std::make_pair("key", "value"))); std::make_pair("key", "value")));
Init( Init(
std::move(OpenTelemetryPluginTestConfiguration() std::move(Options()
.set_metric_names({grpc::OpenTelemetryPluginBuilder:: .set_metric_names({grpc::OpenTelemetryPluginBuilder::
kClientAttemptDurationInstrumentName, kClientAttemptDurationInstrumentName,
grpc::OpenTelemetryPluginBuilder:: grpc::OpenTelemetryPluginBuilder::
@ -907,7 +907,7 @@ TEST_F(OpenTelemetryPluginOptionEnd2EndTest,
/*enabled_on_client*/ false, /*enabled_on_server*/ true, /*enabled_on_client*/ false, /*enabled_on_server*/ true,
std::make_pair("key5", "value5"))); std::make_pair("key5", "value5")));
Init( Init(
std::move(OpenTelemetryPluginTestConfiguration() std::move(Options()
.set_metric_names({grpc::OpenTelemetryPluginBuilder:: .set_metric_names({grpc::OpenTelemetryPluginBuilder::
kClientAttemptDurationInstrumentName, kClientAttemptDurationInstrumentName,
grpc::OpenTelemetryPluginBuilder:: grpc::OpenTelemetryPluginBuilder::

@ -82,8 +82,7 @@ const grpc_channel_filter AddServiceLabelsFilter::kFilter =
grpc_core::FilterEndpoint::kClient>( grpc_core::FilterEndpoint::kClient>(
"add_service_labels_filter"); "add_service_labels_filter");
void OpenTelemetryPluginEnd2EndTest::Init( void OpenTelemetryPluginEnd2EndTest::Init(Options config) {
OpenTelemetryPluginTestConfiguration config) {
// We are resetting the MeterProvider and OpenTelemetry plugin at the start // We are resetting the MeterProvider and OpenTelemetry plugin at the start
// of each test to avoid test results from one test carrying over to another // of each test to avoid test results from one test carrying over to another
// test. (Some measurements can get arbitrarily delayed.) // test. (Some measurements can get arbitrarily delayed.)
@ -99,7 +98,7 @@ void OpenTelemetryPluginEnd2EndTest::Init(
for (const auto& metric_name : config.metric_names) { for (const auto& metric_name : config.metric_names) {
ot_builder.EnableMetric(metric_name); ot_builder.EnableMetric(metric_name);
} }
if (!config.test_no_meter_provider) { if (config.use_meter_provider) {
auto meter_provider = auto meter_provider =
std::make_shared<opentelemetry::sdk::metrics::MeterProvider>(); std::make_shared<opentelemetry::sdk::metrics::MeterProvider>();
reader_.reset(new grpc::testing::MockMetricReader); reader_.reset(new grpc::testing::MockMetricReader);

@ -54,94 +54,93 @@ class MockMetricReader : public opentelemetry::sdk::metrics::MetricReader {
void OnInitialized() noexcept override {} void OnInitialized() noexcept override {}
}; };
struct OpenTelemetryPluginTestConfiguration {
public:
OpenTelemetryPluginTestConfiguration& set_metric_names(
absl::flat_hash_set<absl::string_view> names) {
metric_names = std::move(names);
return *this;
}
OpenTelemetryPluginTestConfiguration& set_resource(
const opentelemetry::sdk::resource::Resource& res) {
resource = res;
return *this;
}
OpenTelemetryPluginTestConfiguration& set_labels_injector(
std::unique_ptr<grpc::internal::LabelsInjector> injector) {
labels_injector = std::move(injector);
return *this;
}
OpenTelemetryPluginTestConfiguration& set_test_no_meter_provider(bool flag) {
test_no_meter_provider = flag;
return *this;
}
OpenTelemetryPluginTestConfiguration& set_labels_to_inject(
std::map<std::string, std::string> labels) {
labels_to_inject = std::move(labels);
return *this;
}
OpenTelemetryPluginTestConfiguration& set_target_selector(
absl::AnyInvocable<bool(absl::string_view /*target*/) const> func) {
target_selector = std::move(func);
return *this;
}
OpenTelemetryPluginTestConfiguration& set_server_selector(
absl::AnyInvocable<bool(const grpc_core::ChannelArgs& /*channel_args*/)
const>
func) {
server_selector = std::move(func);
return *this;
}
OpenTelemetryPluginTestConfiguration& set_target_attribute_filter(
absl::AnyInvocable<bool(absl::string_view /*target*/) const> func) {
target_attribute_filter = std::move(func);
return *this;
}
OpenTelemetryPluginTestConfiguration& set_generic_method_attribute_filter(
absl::AnyInvocable<bool(absl::string_view /*generic_method*/) const>
func) {
generic_method_attribute_filter = std::move(func);
return *this;
}
OpenTelemetryPluginTestConfiguration& set_plugin_options(
std::vector<
std::unique_ptr<grpc::internal::InternalOpenTelemetryPluginOption>>
options) {
plugin_options = std::move(options);
return *this;
}
absl::flat_hash_set<absl::string_view> metric_names;
opentelemetry::sdk::resource::Resource resource =
opentelemetry::sdk::resource::Resource::Create({});
std::unique_ptr<grpc::internal::LabelsInjector> labels_injector;
bool test_no_meter_provider = false;
std::map<std::string, std::string> labels_to_inject;
absl::AnyInvocable<bool(absl::string_view /*target*/) const> target_selector;
absl::AnyInvocable<bool(const grpc_core::ChannelArgs& /*channel_args*/) const>
server_selector;
absl::AnyInvocable<bool(absl::string_view /*target*/) const>
target_attribute_filter;
absl::AnyInvocable<bool(absl::string_view /*generic_method*/) const>
generic_method_attribute_filter;
std::vector<
std::unique_ptr<grpc::internal::InternalOpenTelemetryPluginOption>>
plugin_options;
};
class OpenTelemetryPluginEnd2EndTest : public ::testing::Test { class OpenTelemetryPluginEnd2EndTest : public ::testing::Test {
protected: protected:
struct Options {
public:
Options& set_metric_names(absl::flat_hash_set<absl::string_view> names) {
metric_names = std::move(names);
return *this;
}
Options& set_resource(const opentelemetry::sdk::resource::Resource& res) {
resource = res;
return *this;
}
Options& set_labels_injector(
std::unique_ptr<grpc::internal::LabelsInjector> injector) {
labels_injector = std::move(injector);
return *this;
}
Options& set_use_meter_provider(bool flag) {
use_meter_provider = flag;
return *this;
}
Options& set_labels_to_inject(std::map<std::string, std::string> labels) {
labels_to_inject = std::move(labels);
return *this;
}
Options& set_target_selector(
absl::AnyInvocable<bool(absl::string_view /*target*/) const> func) {
target_selector = std::move(func);
return *this;
}
Options& set_server_selector(
absl::AnyInvocable<bool(const grpc_core::ChannelArgs& /*channel_args*/)
const>
func) {
server_selector = std::move(func);
return *this;
}
Options& set_target_attribute_filter(
absl::AnyInvocable<bool(absl::string_view /*target*/) const> func) {
target_attribute_filter = std::move(func);
return *this;
}
Options& set_generic_method_attribute_filter(
absl::AnyInvocable<bool(absl::string_view /*generic_method*/) const>
func) {
generic_method_attribute_filter = std::move(func);
return *this;
}
Options& set_plugin_options(
std::vector<
std::unique_ptr<grpc::internal::InternalOpenTelemetryPluginOption>>
options) {
plugin_options = std::move(options);
return *this;
}
absl::flat_hash_set<absl::string_view> metric_names;
opentelemetry::sdk::resource::Resource resource =
opentelemetry::sdk::resource::Resource::Create({});
std::unique_ptr<grpc::internal::LabelsInjector> labels_injector;
bool use_meter_provider = true;
std::map<std::string, std::string> labels_to_inject;
absl::AnyInvocable<bool(absl::string_view /*target*/) const>
target_selector;
absl::AnyInvocable<bool(const grpc_core::ChannelArgs& /*channel_args*/)
const>
server_selector;
absl::AnyInvocable<bool(absl::string_view /*target*/) const>
target_attribute_filter;
absl::AnyInvocable<bool(absl::string_view /*generic_method*/) const>
generic_method_attribute_filter;
std::vector<
std::unique_ptr<grpc::internal::InternalOpenTelemetryPluginOption>>
plugin_options;
};
// Note that we can't use SetUp() here since we want to send in parameters. // Note that we can't use SetUp() here since we want to send in parameters.
void Init(OpenTelemetryPluginTestConfiguration config); void Init(Options config);
void TearDown() override; void TearDown() override;

Loading…
Cancel
Save