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

otlp gRPC log export should fail after shutdown #1064

Merged
merged 2 commits into from
Nov 15, 2021
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
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ class OtlpGrpcLogExporter : public opentelemetry::sdk::logs::LogExporter
* Shutdown this exporter.
* @param timeout The maximum time to wait for the shutdown method to return.
*/
bool Shutdown(std::chrono::microseconds timeout = std::chrono::microseconds(0)) noexcept override
{
return true;
}
bool Shutdown(
std::chrono::microseconds timeout = std::chrono::microseconds::max()) noexcept override;

private:
// Configuration options for the exporter
Expand All @@ -79,6 +77,7 @@ class OtlpGrpcLogExporter : public opentelemetry::sdk::logs::LogExporter
* @param stub the service stub to be used for exporting
*/
OtlpGrpcLogExporter(std::unique_ptr<proto::collector::logs::v1::LogsService::StubInterface> stub);
bool is_shutdown_ = false;
};

} // namespace otlp
Expand Down
11 changes: 11 additions & 0 deletions exporters/otlp/src/otlp_grpc_log_exporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ std::unique_ptr<opentelemetry::sdk::logs::Recordable> OtlpGrpcLogExporter::MakeR
opentelemetry::sdk::common::ExportResult OtlpGrpcLogExporter::Export(
const nostd::span<std::unique_ptr<opentelemetry::sdk::logs::Recordable>> &logs) noexcept
{
if (is_shutdown_)
{
OTEL_INTERNAL_LOG_ERROR("[OTLP gRPC log] Export failed, exporter is shutdown");
return sdk::common::ExportResult::kFailure;
}
proto::collector::logs::v1::ExportLogsServiceRequest request;
OtlpRecordableUtils::PopulateRequest(logs, &request);

Expand All @@ -150,6 +155,12 @@ opentelemetry::sdk::common::ExportResult OtlpGrpcLogExporter::Export(
return sdk::common::ExportResult::kSuccess;
}

bool OtlpGrpcLogExporter::Shutdown(std::chrono::microseconds timeout) noexcept
{
is_shutdown_ = true;
return true;
}

} // namespace otlp
} // namespace exporter
OPENTELEMETRY_END_NAMESPACE
Expand Down
6 changes: 2 additions & 4 deletions exporters/otlp/test/otlp_grpc_log_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ TEST_F(OtlpGrpcLogExporterTestPeer, ShutdownTest)
// exporter shuold not be shutdown by default
nostd::span<std::unique_ptr<sdk::logs::Recordable>> batch_1(&recordable_1, 1);
EXPECT_CALL(*mock_stub, Export(_, _, _))
.Times(Exactly(2))
.Times(Exactly(1))
.WillOnce(Return(grpc::Status::OK))
.WillOnce(Return(grpc::Status::CANCELLED));

Expand Down Expand Up @@ -132,11 +132,9 @@ TEST_F(OtlpGrpcLogExporterTestPeer, ExportIntegrationTest)

uint8_t trace_id_bin[opentelemetry::trace::TraceId::kSize] = {
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
char trace_id_hex[2 * opentelemetry::trace::TraceId::kSize] = {0};
opentelemetry::trace::TraceId trace_id{trace_id_bin};
uint8_t span_id_bin[opentelemetry::trace::SpanId::kSize] = {'7', '6', '5', '4',
uint8_t span_id_bin[opentelemetry::trace::SpanId::kSize] = {'7', '6', '5', '4',
'3', '2', '1', '0'};
char span_id_hex[2 * opentelemetry::trace::SpanId::kSize] = {0};
opentelemetry::trace::SpanId span_id{span_id_bin};

auto logger = provider->GetLogger("test");
Expand Down