Skip to content

Commit

Permalink
Replaced collector host & port with base_url (rnburn#50)
Browse files Browse the repository at this point in the history
This is useful if the collector is using https.
  • Loading branch information
poear committed Jun 8, 2022
1 parent f695931 commit d973173
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 38 deletions.
7 changes: 2 additions & 5 deletions zipkin/include/zipkin/tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,11 @@ typedef std::unique_ptr<Reporter> ReporterPtr;
/**
* Construct a Reporter that sends spans to a Zipkin service via HTTP.
*
* @param collector_host The host to use when sending spans to the Zipkin
* service.
* @param collector_port The port to use when sending spans to the Zipkin
* service.
* @param collector_base_url The base url of the collector. eg. http://localhost:9411
* @return a Reporter object.
*/
ReporterPtr makeHttpReporter(
const char *collector_host, uint32_t collector_port,
const char *collector_base_url,
std::chrono::milliseconds collector_timeout = DEFAULT_TRANSPORT_TIMEOUT,
SteadyClock::duration reporting_period = DEFAULT_REPORTING_PERIOD,
size_t max_buffered_spans = DEFAULT_SPAN_BUFFER_SIZE);
Expand Down
15 changes: 6 additions & 9 deletions zipkin/src/zipkin_http_transporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,15 @@
#include <iostream>

namespace zipkin {
static std::string getUrl(const char *collector_host, uint32_t collector_port) {
return std::string{"http://"} + collector_host + ":" +
std::to_string(collector_port) +
static std::string getUrl(const char *collector_base_url) {
return collector_base_url+
ZipkinCoreConstants::get().DEFAULT_COLLECTOR_ENDPOINT;
}

ZipkinHttpTransporter::ZipkinHttpTransporter(const char *collector_host,
uint32_t collector_port,
ZipkinHttpTransporter::ZipkinHttpTransporter(const char *collector_base_url,
std::chrono::milliseconds collector_timeout) {
auto rcode = curl_easy_setopt(handle_, CURLOPT_URL,
getUrl(collector_host, collector_port).c_str());
getUrl(collector_base_url).c_str());
if (rcode != CURLE_OK) {
throw CurlError{rcode};
}
Expand Down Expand Up @@ -57,13 +55,12 @@ void ZipkinHttpTransporter::transportSpans(SpanBuffer &spans) try {
// Drop spans
}

ReporterPtr makeHttpReporter(const char *collector_host,
uint32_t collector_port,
ReporterPtr makeHttpReporter(const char *collector_base_url,
std::chrono::milliseconds collector_timeout,
SteadyClock::duration reporting_period,
size_t max_buffered_spans) try {
std::unique_ptr<Transporter> transporter{
new ZipkinHttpTransporter{collector_host, collector_port, collector_timeout}};
new ZipkinHttpTransporter{collector_base_url, collector_timeout}};
std::unique_ptr<Reporter> reporter{new ReporterImpl{
std::move(transporter), reporting_period, max_buffered_spans}};
return reporter;
Expand Down
6 changes: 2 additions & 4 deletions zipkin/src/zipkin_http_transporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,12 @@ class ZipkinHttpTransporter : public Transporter {
/**
* Constructor.
*
* @param collector_host The host to use when sending spans to the Zipkin
* service.
* @param collector_port The port to use when sending spans to the Zipkin service.
* @param collector_base_url The base url of the collector. eg. http://localhost:9411
* @param collector_timeout Timeout for http requests
*
* Throws CurlError if the handle can't be initialized.
*/
ZipkinHttpTransporter(const char *collector_host, uint32_t collector_port,
ZipkinHttpTransporter(const char *collector_base_url,
std::chrono::milliseconds collector_timeout = DEFAULT_TRANSPORT_TIMEOUT);

/**
Expand Down
3 changes: 1 addition & 2 deletions zipkin_opentracing/include/zipkin/opentracing.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@

namespace zipkin {
struct ZipkinOtTracerOptions {
std::string collector_host = "localhost";
uint32_t collector_port = 9411;
std::string collector_base_url = "http://localhost:9411";
std::chrono::milliseconds collector_timeout = DEFAULT_TRANSPORT_TIMEOUT;
SteadyClock::duration reporting_period = DEFAULT_REPORTING_PERIOD;
size_t max_buffered_spans = DEFAULT_SPAN_BUFFER_SIZE;
Expand Down
2 changes: 1 addition & 1 deletion zipkin_opentracing/src/opentracing.cc
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ makeZipkinOtTracer(const ZipkinOtTracerOptions &options,
std::shared_ptr<ot::Tracer>
makeZipkinOtTracer(const ZipkinOtTracerOptions &options) {
auto reporter =
makeHttpReporter(options.collector_host.c_str(), options.collector_port,
makeHttpReporter(options.collector_base_url.c_str(),
options.collector_timeout, options.reporting_period,
options.max_buffered_spans);
return makeZipkinOtTracer(options, std::move(reporter));
Expand Down
7 changes: 2 additions & 5 deletions zipkin_opentracing/src/tracer_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,8 @@ OtTracerFactory::MakeTracer(const char *configuration,
options.service_address =
IpAddress{IpVersion::v4, document["service_address"].GetString()};
}
if (document.HasMember("collector_host")) {
options.collector_host = document["collector_host"].GetString();
}
if (document.HasMember("collector_port")) {
options.collector_port = document["collector_port"].GetInt();
if (document.HasMember("collector_base_url")) {
options.collector_base_url = document["collector_base_url"].GetString();
}
if (document.HasMember("collector_timeout")) {
options.collector_timeout =
Expand Down
6 changes: 2 additions & 4 deletions zipkin_opentracing/test/ot_tracer_factory_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ TEST_CASE("OtTracerFactory") {
"fails.") {
const char *configuration = R"(
{
"service_name": "abc",
"collector_port": 0
"service_name": "abc"
})";
auto tracer_maybe = tracer_factory.MakeTracer(configuration, error_message);
CHECK(error_message != "");
Expand All @@ -35,8 +34,7 @@ TEST_CASE("OtTracerFactory") {
const char *configuration = R"(
{
"service_name": "abc",
"collector_port": 80,
"collector_host": "foo.bar",
"collector_base_url": "http://foo.bar:80",
"sample_rate": 0.1
})";
auto tracer_maybe = tracer_factory.MakeTracer(configuration, error_message);
Expand Down
10 changes: 2 additions & 8 deletions zipkin_opentracing/tracer_configuration.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,9 @@
"type": "string",
"description": "IP address to use with the default Zipkin endpoint annotation"
},
"collector_host": {
"collector_base_url": {
"type": "string",
"description": "Host to use when connecting to Zipkin's collector"
},
"collector_port": {
"type": "integer",
"minimum": 1,
"maximum": 65535,
"description": "Port to use when connecting to Zipkin's collector"
"description": "Base url to use when connecting to Zipkin's collector"
},
"reporting_period": {
"type": "integer",
Expand Down

0 comments on commit d973173

Please sign in to comment.