Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
10 changes: 7 additions & 3 deletions source/common/http/conn_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,12 @@ ConnectionManagerImpl::ActiveStream::~ActiveStream() {
log_handler->log(request_headers_.get(), response_headers_.get(), request_info_);
}

if (active_span_ && !request_info_.healthCheck()) {
Tracing::HttpTracerUtility::finalizeSpan(*active_span_, request_info_);
if (active_span_) {
if (request_info_.healthCheck()) {
connection_manager_.config_.tracingStats().health_check_.inc();
} else {
Tracing::HttpTracerUtility::finalizeSpan(*active_span_, request_info_);
}
}
}

Expand Down Expand Up @@ -341,7 +345,7 @@ void ConnectionManagerImpl::ActiveStream::chargeTracingStats(
connection_manager_.config_.tracingStats().client_enabled_.inc();
break;
case Tracing::Reason::HealthCheck:
connection_manager_.config_.tracingStats().health_check_.inc();
// At this point we have not run any filters, including HC one, so this should not happen.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

then take this case statement out, add a default, and throw an invalid argument exception to crash (and add test to that effect).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

sounds good, need to rearrange stuff a little bit for this, should be easy

break;
case Tracing::Reason::NotTraceableRequestId:
connection_manager_.config_.tracingStats().not_traceable_.inc();
Expand Down
21 changes: 19 additions & 2 deletions test/common/http/conn_manager_impl_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,13 @@ TEST_F(HttpConnectionManagerImplTest, StartAndFinishSpanNormalFlow) {
setup(false, "");

NiceMock<Tracing::MockSpan>* span = new NiceMock<Tracing::MockSpan>();
EXPECT_CALL(tracer_, startSpan_(_, _, _)).WillOnce(Return(span));
EXPECT_CALL(tracer_, startSpan_(_, _, _))
.WillOnce(Invoke([&](const Tracing::Config& config, const Http::HeaderMap&,
const Http::AccessLog::RequestInfo&) -> Tracing::Span* {
EXPECT_EQ("operation", config.operationName());

return span;
}));
EXPECT_CALL(*span, finishSpan());
EXPECT_CALL(runtime_.snapshot_, featureEnabled("tracing.global_enabled", 100, _))
.WillOnce(Return(true));
Expand Down Expand Up @@ -240,6 +246,9 @@ TEST_F(HttpConnectionManagerImplTest, StartAndFinishSpanNormalFlow) {

Buffer::OwnedImpl fake_input("1234");
conn_manager_->onData(fake_input);

EXPECT_EQ(1UL, tracing_stats_.service_forced_.value());
EXPECT_EQ(0UL, tracing_stats_.random_sampling_.value());
}

TEST_F(HttpConnectionManagerImplTest, TestAccessLog) {
Expand Down Expand Up @@ -355,7 +364,7 @@ TEST_F(HttpConnectionManagerImplTest, StartSpanOnlyHealthCheckRequest) {
Http::HeaderMapPtr headers{
new TestHeaderMapImpl{{":authority", "host"},
{":path", "/healthcheck"},
{"x-request-id", "125a4afb-6f55-a4ba-ad80-413f09f48a28"}}};
{"x-request-id", "125a4afb-6f55-94ba-ad80-413f09f48a28"}}};
decoder->decodeHeaders(std::move(headers), true);

Http::HeaderMapPtr response_headers{new TestHeaderMapImpl{{":status", "200"}}};
Expand All @@ -366,6 +375,14 @@ TEST_F(HttpConnectionManagerImplTest, StartSpanOnlyHealthCheckRequest) {

Buffer::OwnedImpl fake_input("1234");
conn_manager_->onData(fake_input);

// Make destruction of active stream so that we can capture tracing HC stat.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

grammar

filter_callbacks_.connection_.dispatcher_.clearDeferredDeleteList();

// HC request, but was originally sampled, so check for two stats here.
EXPECT_EQ(1UL, tracing_stats_.random_sampling_.value());
EXPECT_EQ(1UL, tracing_stats_.health_check_.value());
EXPECT_EQ(0UL, tracing_stats_.service_forced_.value());
}

TEST_F(HttpConnectionManagerImplTest, NoPath) {
Expand Down