Skip to content

Commit

Permalink
Fix tests for lightstep_tracer_impl.
Browse files Browse the repository at this point in the history
Signed-off-by: Ryan Burn <ryan.burn@gmail.com>
  • Loading branch information
rnburn committed Feb 27, 2018
1 parent 8f7fa81 commit 5f2d430
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
8 changes: 6 additions & 2 deletions source/common/tracing/lightstep_tracer_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -64,20 +64,24 @@ void LightStepDriver::LightStepTransporter::onSuccess(Http::MessagePtr&& respons
active_request_ = nullptr;
Grpc::Common::validateResponse(*response);

Grpc::Common::chargeStat(*driver_.cluster(), lightstep::CollectorServiceFullName(),
lightstep::CollectorMethodName(), true);
// http://www.grpc.io/docs/guides/wire.html
// First 5 bytes contain the message header.
response->body()->drain(5);
Buffer::ZeroCopyInputStreamImpl stream{std::move(response->body())};
if (!active_response_->ParseFromZeroCopyStream(&stream)) {
throw EnvoyException("Failed to parse LightStep collector response");
}
Grpc::Common::chargeStat(*driver_.cluster(), lightstep::CollectorServiceFullName(),
lightstep::CollectorMethodName(), true);
active_callback_->OnSuccess();
} catch (const Grpc::Exception& ex) {
Grpc::Common::chargeStat(*driver_.cluster(), lightstep::CollectorServiceFullName(),
lightstep::CollectorMethodName(), false);
active_callback_->OnFailure(std::make_error_code(std::errc::network_down));
} catch (const EnvoyException& ex) {
Grpc::Common::chargeStat(*driver_.cluster(), lightstep::CollectorServiceFullName(),
lightstep::CollectorMethodName(), false);
active_callback_->OnFailure(std::make_error_code(std::errc::bad_message));
}
}

Expand Down
44 changes: 43 additions & 1 deletion test/common/tracing/lightstep_tracer_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -245,12 +245,54 @@ TEST_F(LightStepDriverTest, FlushOneFailure) {

first_span->finishSpan();

callback->onFailure(Http::AsyncClient::FailureReason::Reset);

EXPECT_EQ(1U, cm_.thread_local_cluster_.cluster_.info_->stats_store_
.counter("grpc.lightstep.collector.CollectorService.Report.failure")
.value());
EXPECT_EQ(1U, cm_.thread_local_cluster_.cluster_.info_->stats_store_
.counter("grpc.lightstep.collector.CollectorService.Report.total")
.value());
EXPECT_EQ(1U, stats_.counter("tracing.lightstep.spans_sent").value());
}

TEST_F(LightStepDriverTest, FlushOneInvalidResponse) {
setupValidDriver();

Http::MockAsyncClientRequest request(&cm_.async_client_);
Http::AsyncClient::Callbacks* callback;
const Optional<std::chrono::milliseconds> timeout(std::chrono::seconds(5));

EXPECT_CALL(cm_.async_client_, send_(_, _, timeout))
.WillOnce(
Invoke([&](Http::MessagePtr& message, Http::AsyncClient::Callbacks& callbacks,
const Optional<std::chrono::milliseconds>&) -> Http::AsyncClient::Request* {
callback = &callbacks;

EXPECT_STREQ("/lightstep.collector.CollectorService/Report",
message->headers().Path()->value().c_str());
EXPECT_STREQ("fake_cluster", message->headers().Host()->value().c_str());
EXPECT_STREQ("application/grpc", message->headers().ContentType()->value().c_str());

return &request;
}));

EXPECT_CALL(runtime_.snapshot_, getInteger("tracing.lightstep.min_flush_spans", 5))
.WillOnce(Return(1));
EXPECT_CALL(runtime_.snapshot_, getInteger("tracing.lightstep.request_timeout", 5000U))
.WillOnce(Return(5000U));

SpanPtr first_span = driver_->startSpan(config_, request_headers_, operation_name_, start_time_);

first_span->finishSpan();

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

msg->trailers(Http::HeaderMapPtr{new Http::TestHeaderMapImpl{{"grpc-status", "0"}}});
msg->body() = std::make_unique<Buffer::OwnedImpl>("invalidresponse");

callback->onFailure(Http::AsyncClient::FailureReason::Reset);
callback->onSuccess(std::move(msg));

EXPECT_EQ(1U, cm_.thread_local_cluster_.cluster_.info_->stats_store_
.counter("grpc.lightstep.collector.CollectorService.Report.failure")
Expand Down

0 comments on commit 5f2d430

Please sign in to comment.