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

Use collector service name and method from LightStep lib. #123

Merged
merged 3 commits into from
Oct 6, 2016
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
25 changes: 14 additions & 11 deletions source/common/tracing/http_tracer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "common/common/macros.h"
#include "common/common/utility.h"
#include "common/grpc/common.h"
#include "common/http/codes.h"
#include "common/http/headers.h"
#include "common/http/header_map_impl.h"
#include "common/http/message_impl.h"
Expand All @@ -11,9 +12,6 @@

namespace Tracing {

const std::string LightStepSink::LIGHTSTEP_SERVICE = "lightstep.collector.CollectorService";
const std::string LightStepSink::LIGHTSTEP_METHOD = "Report";

void HttpTracerUtility::mutateHeaders(Http::HeaderMap& request_headers, Runtime::Loader& runtime) {
std::string x_request_id = request_headers.get(Http::Headers::get().RequestId);

Expand Down Expand Up @@ -160,9 +158,9 @@ void LightStepRecorder::flushSpans() {
lightstep::collector::ReportRequest request;
std::swap(request, builder_.pending());

Http::MessagePtr message =
Grpc::Common::prepareHeaders(sink_.collectorCluster(), LightStepSink::LIGHTSTEP_SERVICE,
LightStepSink::LIGHTSTEP_METHOD);
Http::MessagePtr message = Grpc::Common::prepareHeaders(sink_.collectorCluster(),
lightstep::CollectorServiceFullName(),
lightstep::CollectorMethodName());

message->body(Grpc::Common::serializeBody(std::move(request)));

Expand Down Expand Up @@ -243,6 +241,11 @@ void LightStepSink::flushTrace(const Http::HeaderMap& request_headers, const Htt
lightstep::SetTag("node id", service_node_),
});

if (request_info.responseCode().valid() &&
Http::CodeUtility::is5xx(request_info.responseCode().value())) {
span.SetTag("error", "true");
}

if (request_headers.has(Http::Headers::get().ClientTraceId)) {
span.SetTag("join:x-client-trace-id", request_headers.get(Http::Headers::get().ClientTraceId));
}
Expand All @@ -252,7 +255,7 @@ void LightStepSink::flushTrace(const Http::HeaderMap& request_headers, const Htt

void LightStepRecorder::onFailure(Http::AsyncClient::FailureReason) {
Grpc::Common::chargeStat(sink_.statsStore(), sink_.collectorCluster(),
LightStepSink::LIGHTSTEP_SERVICE, LightStepSink::LIGHTSTEP_METHOD,
lightstep::CollectorServiceFullName(), lightstep::CollectorMethodName(),
false);
}

Expand All @@ -261,12 +264,12 @@ void LightStepRecorder::onSuccess(Http::MessagePtr&& msg) {
Grpc::Common::validateResponse(*msg);

Grpc::Common::chargeStat(sink_.statsStore(), sink_.collectorCluster(),
LightStepSink::LIGHTSTEP_SERVICE, LightStepSink::LIGHTSTEP_METHOD,
true);
lightstep::CollectorServiceFullName(),
lightstep::CollectorMethodName(), true);
} catch (const Grpc::Exception& ex) {
Grpc::Common::chargeStat(sink_.statsStore(), sink_.collectorCluster(),
LightStepSink::LIGHTSTEP_SERVICE, LightStepSink::LIGHTSTEP_METHOD,
false);
lightstep::CollectorServiceFullName(),
lightstep::CollectorMethodName(), false);
}
}

Expand Down
3 changes: 0 additions & 3 deletions source/common/tracing/http_tracer_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,6 @@ class LightStepSink : public HttpSink {
Stats::Store& statsStore() { return stats_store_; }
LightstepTracerStats& tracerStats() { return tracer_stats_; }

static const std::string LIGHTSTEP_SERVICE;
static const std::string LIGHTSTEP_METHOD;

private:
struct TlsLightStepTracer : ThreadLocal::ThreadLocalObject {
TlsLightStepTracer(lightstep::Tracer tracer, LightStepSink& sink);
Expand Down
22 changes: 9 additions & 13 deletions test/common/tracing/http_tracer_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ class LightStepSinkTest : public Test {
}

const Http::HeaderMapImpl empty_header_{};
const Http::HeaderMapImpl response_headers_{{":status", "500"}};

std::unique_ptr<LightStepSink> sink_;
NiceMock<Event::MockTimer>* timer_;
Expand Down Expand Up @@ -392,13 +393,8 @@ TEST_F(LightStepSinkTest, FlushSeveralSpans) {

SystemTime start_time;
EXPECT_CALL(request_info, startTime()).Times(2).WillRepeatedly(Return(start_time));
Optional<uint32_t> code_1(200);
Optional<uint32_t> code_2(503);
EXPECT_CALL(request_info, responseCode())
.WillOnce(ReturnRef(code_1))
.WillOnce(ReturnRef(code_1))
.WillOnce(ReturnRef(code_2))
.WillOnce(ReturnRef(code_2));
Optional<uint32_t> code(200);
EXPECT_CALL(request_info, responseCode()).WillRepeatedly(ReturnRef(code));

const std::string protocol = "http/1";
EXPECT_CALL(request_info, protocol()).Times(2).WillRepeatedly(ReturnRef(protocol));
Expand All @@ -408,8 +404,8 @@ TEST_F(LightStepSinkTest, FlushSeveralSpans) {
EXPECT_CALL(runtime_.snapshot_, getInteger("tracing.lightstep.request_timeout", 5000U))
.WillOnce(Return(5000U));

sink_->flushTrace(empty_header_, empty_header_, request_info);
sink_->flushTrace(empty_header_, empty_header_, request_info);
sink_->flushTrace(empty_header_, response_headers_, request_info);
sink_->flushTrace(empty_header_, response_headers_, request_info);

Http::MessagePtr msg(new Http::ResponseMessageImpl(
Http::HeaderMapPtr{new Http::HeaderMapImpl{{":status", "200"}}}));
Expand Down Expand Up @@ -452,14 +448,14 @@ TEST_F(LightStepSinkTest, FlushSpansTimer) {
SystemTime start_time;
EXPECT_CALL(request_info, startTime()).WillOnce(Return(start_time));
Optional<uint32_t> code(200);
EXPECT_CALL(request_info, responseCode()).Times(2).WillRepeatedly(ReturnRef(code));
EXPECT_CALL(request_info, responseCode()).WillRepeatedly(ReturnRef(code));

const std::string protocol = "http/1";
EXPECT_CALL(request_info, protocol()).WillOnce(ReturnRef(protocol));
EXPECT_CALL(runtime_.snapshot_, getInteger("tracing.lightstep.min_flush_spans", 5))
.WillOnce(Return(5));

sink_->flushTrace(empty_header_, empty_header_, request_info);
sink_->flushTrace(empty_header_, response_headers_, request_info);
// Timer should be re-enabled.
EXPECT_CALL(*timer_, enableTimer(std::chrono::milliseconds(1000)));
EXPECT_CALL(runtime_.snapshot_, getInteger("tracing.lightstep.request_timeout", 5000U))
Expand Down Expand Up @@ -498,7 +494,7 @@ TEST_F(LightStepSinkTest, FlushOneSpanGrpcFailure) {
SystemTime start_time;
EXPECT_CALL(request_info, startTime()).WillOnce(Return(start_time));
Optional<uint32_t> code(200);
EXPECT_CALL(request_info, responseCode()).WillOnce(ReturnRef(code)).WillOnce(ReturnRef(code));
EXPECT_CALL(request_info, responseCode()).WillRepeatedly(ReturnRef(code));

const std::string protocol = "http/1";
EXPECT_CALL(request_info, protocol()).WillOnce(ReturnRef(protocol));
Expand All @@ -507,7 +503,7 @@ TEST_F(LightStepSinkTest, FlushOneSpanGrpcFailure) {
EXPECT_CALL(runtime_.snapshot_, getInteger("tracing.lightstep.request_timeout", 5000U))
.WillOnce(Return(5000U));

sink_->flushTrace(empty_header_, empty_header_, request_info);
sink_->flushTrace(empty_header_, response_headers_, request_info);

Http::MessagePtr msg(new Http::ResponseMessageImpl(
Http::HeaderMapPtr{new Http::HeaderMapImpl{{":status", "200"}}}));
Expand Down