Skip to content
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
6 changes: 5 additions & 1 deletion api/envoy/config/trace/v3/zipkin.proto
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ option (udpa.annotations.file_status).package_version_status = ACTIVE;

// Configuration for the Zipkin tracer.
// [#extension: envoy.tracers.zipkin]
// [#next-free-field: 6]
// [#next-free-field: 7]
message ZipkinConfig {
option (udpa.annotations.versioning).previous_message_type = "envoy.config.trace.v2.ZipkinConfig";

Expand Down Expand Up @@ -67,4 +67,8 @@ message ZipkinConfig {
// Determines the selected collector endpoint version. By default, the ``HTTP_JSON_V1`` will be
// used.
CollectorEndpointVersion collector_endpoint_version = 5;

// Optional hostname to use when sending spans to the collector_cluster. Useful for collectors
// that require a specific hostname. Defaults to `collector_cluster` above.
string collector_hostname = 6;
}
6 changes: 5 additions & 1 deletion api/envoy/extensions/tracers/zipkin/v4alpha/zipkin.proto

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

6 changes: 5 additions & 1 deletion generated_api_shadow/envoy/config/trace/v3/zipkin.proto

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

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

4 changes: 3 additions & 1 deletion source/extensions/tracers/zipkin/zipkin_tracer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ Driver::Driver(const envoy::config::trace::v3::ZipkinConfig& zipkin_config,
Config::Utility::checkCluster(TracerNames::get().Zipkin, zipkin_config.collector_cluster(), cm_,
/* allow_added_via_api */ true);
cluster_ = zipkin_config.collector_cluster();
hostname_ = !zipkin_config.collector_hostname().empty() ?
zipkin_config.collector_hostname() : zipkin_config.collector_cluster();
Comment on lines 80 to 81
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Huh. Is it worth reordering the ternary values here to ditch the leading !?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keeping it as it is, since either order is valid in its own way


CollectorInfo collector;
if (!zipkin_config.collector_endpoint().empty()) {
Expand Down Expand Up @@ -177,7 +179,7 @@ void ReporterImpl::flushSpans() {
Http::RequestMessagePtr message = std::make_unique<Http::RequestMessageImpl>();
message->headers().setReferenceMethod(Http::Headers::get().MethodValues.Post);
message->headers().setPath(collector_.endpoint_);
message->headers().setHost(driver_.cluster());
message->headers().setHost(driver_.hostname());
message->headers().setReferenceContentType(
collector_.version_ == envoy::config::trace::v3::ZipkinConfig::HTTP_PROTO
? Http::Headers::get().ContentTypeValues.Protobuf
Expand Down
2 changes: 2 additions & 0 deletions source/extensions/tracers/zipkin/zipkin_tracer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ class Driver : public Tracing::Driver {
// Getters to return the ZipkinDriver's key members.
Upstream::ClusterManager& clusterManager() { return cm_; }
const std::string& cluster() { return cluster_; }
const std::string& hostname() { return hostname_; }
Runtime::Loader& runtime() { return runtime_; }
ZipkinTracerStats& tracerStats() { return tracer_stats_; }

Expand All @@ -135,6 +136,7 @@ class Driver : public Tracing::Driver {

Upstream::ClusterManager& cm_;
std::string cluster_;
std::string hostname_;
ZipkinTracerStats tracer_stats_;
ThreadLocal::SlotPtr tls_;
Runtime::Loader& runtime_;
Expand Down
32 changes: 27 additions & 5 deletions test/extensions/tracers/zipkin/zipkin_tracer_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,31 @@ class ZipkinDriverTest : public testing::Test {
random_, time_source_);
}

void setupValidDriver(const std::string& version) {
void setupValidDriverWithHostname(const std::string& version, const std::string& hostname) {
EXPECT_CALL(cm_, get(Eq("fake_cluster"))).WillRepeatedly(Return(&cm_.thread_local_cluster_));

const std::string yaml_string = fmt::format(R"EOF(
std::string yaml_string = fmt::format(R"EOF(
collector_cluster: fake_cluster
collector_endpoint: /api/v1/spans
collector_endpoint_version: {}
)EOF",
version);
if (!hostname.empty()) {
yaml_string = yaml_string + fmt::format(R"EOF(
collector_hostname: {}
)EOF",
hostname);
}

envoy::config::trace::v3::ZipkinConfig zipkin_config;
TestUtility::loadFromYaml(yaml_string, zipkin_config);

setup(zipkin_config, true);
}

void expectValidFlushSeveralSpans(const std::string& version, const std::string& content_type) {
setupValidDriver(version);
void expectValidFlushSeveralSpansWithHostname(const std::string& version, const std::string& content_type,
const std::string& hostname) {
setupValidDriverWithHostname(version, hostname);

Http::MockAsyncClientRequest request(&cm_.async_client_);
Http::AsyncClient::Callbacks* callback;
Expand All @@ -90,8 +98,9 @@ class ZipkinDriverTest : public testing::Test {
const Http::AsyncClient::RequestOptions&) -> Http::AsyncClient::Request* {
callback = &callbacks;

const std::string& expected_hostname = !hostname.empty() ? hostname : "fake_cluster";
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here.

EXPECT_EQ("/api/v1/spans", message->headers().getPathValue());
EXPECT_EQ("fake_cluster", message->headers().getHostValue());
EXPECT_EQ(expected_hostname, message->headers().getHostValue());
EXPECT_EQ(content_type, message->headers().getContentTypeValue());

return &request;
Expand Down Expand Up @@ -127,6 +136,14 @@ class ZipkinDriverTest : public testing::Test {
EXPECT_EQ(1U, stats_.counter("tracing.zipkin.reports_failed").value());
}

void setupValidDriver(const std::string& version) {
setupValidDriverWithHostname(version, "");
}

void expectValidFlushSeveralSpans(const std::string& version, const std::string& content_type) {
expectValidFlushSeveralSpansWithHostname(version, content_type, "");
}

// TODO(#4160): Currently time_system_ is initialized from DangerousDeprecatedTestTime, which uses
// real time, not mock-time. When that is switched to use mock-time instead, I think
// generateRandom64() may not be as random as we want, and we'll need to inject entropy
Expand Down Expand Up @@ -217,6 +234,11 @@ TEST_F(ZipkinDriverTest, FlushSeveralSpansHttpJson) {
expectValidFlushSeveralSpans("HTTP_JSON", "application/json");
}

TEST_F(ZipkinDriverTest, FlushSeveralSpansHttpJsonWithHostname) {
expectValidFlushSeveralSpansWithHostname("HTTP_JSON", "application/json",
"zipkin.fakedomain.io");
}

TEST_F(ZipkinDriverTest, FlushSeveralSpansHttpProto) {
expectValidFlushSeveralSpans("HTTP_PROTO", "application/x-protobuf");
}
Expand Down