Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tracing: google grpc service support for ocagent/opencensus #9955

Merged
merged 16 commits into from
Feb 17, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions api/envoy/config/trace/v2/trace.proto
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ message DatadogConfig {
}

// Configuration for the OpenCensus tracer.
// [#next-free-field: 14]
// [#next-free-field: 15]
// [#extension: envoy.tracers.opencensus]
message OpenCensusConfig {
enum TraceContext {
Expand Down Expand Up @@ -196,14 +196,19 @@ message OpenCensusConfig {
// The URL to Zipkin, e.g. "http://127.0.0.1:9411/api/v2/spans"
string zipkin_url = 6;

// Enables the OpenCensus Agent exporter if set to true. The address must also
// be set.
// Enables the OpenCensus Agent exporter if set to true. The ocagent_address or
// ocagent_grpc_service must also be set.
bool ocagent_exporter_enabled = 11;

// The address of the OpenCensus Agent, if its exporter is enabled, in gRPC
// format: https://github.com/grpc/grpc/blob/master/doc/naming.md
// [#comment:TODO: deprecate this field]
string ocagent_address = 12;

// (optional) The gRPC server hosted by the OpenCensus Agent. Only Google gRPC is supported.
// This is only used if the ocagent_address is left empty.
api.v2.core.GrpcService ocagent_grpc_service = 14;

// List of incoming trace context headers we will accept. First one found
// wins.
repeated TraceContext incoming_trace_context = 8;
Expand Down
11 changes: 8 additions & 3 deletions api/envoy/config/trace/v3/trace.proto
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ message DatadogConfig {
}

// Configuration for the OpenCensus tracer.
// [#next-free-field: 14]
// [#next-free-field: 15]
// [#extension: envoy.tracers.opencensus]
message OpenCensusConfig {
option (udpa.annotations.versioning).previous_message_type =
Expand Down Expand Up @@ -219,14 +219,19 @@ message OpenCensusConfig {
// The URL to Zipkin, e.g. "http://127.0.0.1:9411/api/v2/spans"
string zipkin_url = 6;

// Enables the OpenCensus Agent exporter if set to true. The address must also
// be set.
// Enables the OpenCensus Agent exporter if set to true. The ocagent_address or
// ocagent_grpc_service must also be set.
bool ocagent_exporter_enabled = 11;

// The address of the OpenCensus Agent, if its exporter is enabled, in gRPC
// format: https://github.com/grpc/grpc/blob/master/doc/naming.md
// [#comment:TODO: deprecate this field]
string ocagent_address = 12;

// (optional) The gRPC server hosted by the OpenCensus Agent. Only Google gRPC is supported.
// This is only used if the ocagent_address is left empty.
core.v3.GrpcService ocagent_grpc_service = 14;

// List of incoming trace context headers we will accept. First one found
// wins.
repeated TraceContext incoming_trace_context = 8;
Expand Down
2 changes: 1 addition & 1 deletion docs/root/intro/version_history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Version history
* thrift_proxy: add router filter stats to docs.
* tracers: tracer extensions use the "envoy.tracers" name space. A mapping of extension names is
available in the :ref:`deprecated <deprecated>` documentation.
* tracing: added gRPC service configuration to the OpenCensus Stackdriver tracer.
* tracing: added gRPC service configuration to the OpenCensus Stackdriver and OpenCensus Agent tracers.
* upstream: combined HTTP/1 and HTTP/2 connection pool code. This means that circuit breaker
limits for both requests and connections apply to both pool types. Also, HTTP/2 now has
the option to limit concurrent requests on a connection, and allow multiple draining
Expand Down
11 changes: 8 additions & 3 deletions generated_api_shadow/envoy/config/trace/v2/trace.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions generated_api_shadow/envoy/config/trace/v3/trace.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion source/extensions/tracers/opencensus/opencensus_tracer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,17 @@ Driver::Driver(const envoy::config::trace::v3::OpenCensusConfig& oc_config,
}
if (oc_config.ocagent_exporter_enabled()) {
::opencensus::exporters::trace::OcAgentOptions opts;
opts.address = oc_config.ocagent_address();
if (!oc_config.ocagent_address().empty()) {
opts.address = oc_config.ocagent_address();
} else if (oc_config.has_ocagent_grpc_service()) {
if (!oc_config.ocagent_grpc_service().has_google_grpc()) {
throw EnvoyException("Opencensus ocagent tracer only supports GoogleGrpc.");
}
envoy::config::core::v3::GrpcService ocagent_service = oc_config.ocagent_grpc_service();
auto channel = Envoy::Grpc::GoogleGrpcUtils::createChannel(ocagent_service, api);
opts.trace_service_stub =
::opencensus::proto::agent::trace::v1::TraceService::NewStub(channel);
}
opts.service_name = local_info_.clusterName();
::opencensus::exporters::trace::OcAgentExporter::Register(std::move(opts));
}
Expand Down
40 changes: 40 additions & 0 deletions test/extensions/tracers/opencensus/config_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,46 @@ TEST(OpenCensusTracerConfigTest, OpenCensusHttpTracerWithTypedConfig) {
{32, 32, 128, 32, ::opencensus::trace::ProbabilitySampler(1e-4)});
}

TEST(OpenCensusTracerConfigTest, OpenCensusHttpTracerGrpc) {
NiceMock<Server::MockInstance> server;
const std::string yaml_string = R"EOF(
http:
name: envoy.tracers.opencensus
typed_config:
"@type": type.googleapis.com/envoy.config.trace.v2.OpenCensusConfig
trace_config:
rate_limiting_sampler:
qps: 123
max_number_of_attributes: 12
max_number_of_annotations: 34
max_number_of_message_events: 56
max_number_of_links: 78
ocagent_exporter_enabled: true
ocagent_grpc_service:
google_grpc:
target_uri: 127.0.0.1:55678
stat_prefix: test
incoming_trace_context: b3
incoming_trace_context: trace_context
incoming_trace_context: grpc_trace_bin
incoming_trace_context: cloud_trace_context
outgoing_trace_context: trace_context
)EOF";

envoy::config::trace::v3::Tracing configuration;
TestUtility::loadFromYaml(yaml_string, configuration);

OpenCensusTracerFactory factory;
auto message = Config::Utility::translateToFactoryConfig(
configuration.http(), ProtobufMessage::getStrictValidationVisitor(), factory);
Tracing::HttpTracerPtr tracer = factory.createHttpTracer(*message, server);
EXPECT_NE(nullptr, tracer);

// Reset TraceParams back to default.
::opencensus::trace::TraceConfig::SetCurrentTraceParams(
{32, 32, 128, 32, ::opencensus::trace::ProbabilitySampler(1e-4)});
}

TEST(OpenCensusTracerConfigTest, DoubleRegistrationTest) {
EXPECT_THROW_WITH_MESSAGE(
(Registry::RegisterFactory<OpenCensusTracerFactory, Server::Configuration::TracerFactory>()),
Expand Down
1 change: 1 addition & 0 deletions tools/spelling/spelling_dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -784,6 +784,7 @@ nullptr
num
numkeys
observability
ocagent
offsetof
oneof
oneway
Expand Down