Skip to content

Commit

Permalink
Fix style and benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
owent committed Nov 16, 2023
1 parent 1862010 commit 5fef32a
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 16 deletions.
4 changes: 3 additions & 1 deletion api/include/opentelemetry/common/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
// GCC 9 has likely attribute but do not support declare it at the beginning of statement
# if defined(__has_cpp_attribute) && (defined(__clang__) || !defined(__GNUC__) || __GNUC__ > 9)
# if __has_cpp_attribute(likely)
# define OPENTELEMETRY_LIKELY_IF(...) if (__VA_ARGS__) [[likely]]
# define OPENTELEMETRY_LIKELY_IF(...) \
if (__VA_ARGS__) \
[[likely]]

# endif
# endif
Expand Down
4 changes: 3 additions & 1 deletion exporters/otlp/src/otlp_grpc_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ static sdk::common::ExportResult InternalDelegateAsyncExport(

++async_data->start_request_counter;
++async_data->running_requests;
# if (GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039
# if defined(GRPC_CPP_VERSION_MAJOR) && \
(GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039
stub->async()
# else
stub->experimental_async()
Expand Down Expand Up @@ -289,6 +290,7 @@ std::shared_ptr<grpc::Channel> OtlpGrpcClient::MakeChannel(const OtlpGrpcClientO
options.ssl_client_key_string);
ssl_opts.pem_cert_chain = GetFileContentsOrInMemoryContents(options.ssl_client_cert_path,
options.ssl_client_cert_string);

#endif
channel =
grpc::CreateCustomChannel(grpc_target, grpc::SslCredentials(ssl_opts), grpc_arguments);
Expand Down
74 changes: 66 additions & 8 deletions exporters/otlp/test/otlp_grpc_exporter_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,28 +49,86 @@ const trace_api::SpanContext kSpanContext{
// Create a fake service stub to avoid dependency on gmock
class FakeServiceStub : public proto::collector::trace::v1::TraceService::StubInterface
{
public:
#if defined(GRPC_CPP_VERSION_MAJOR) && \
(GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039
using async_interface_base =
proto::collector::trace::v1::TraceService::StubInterface::async_interface;
#else
using async_interface_base =
proto::collector::trace::v1::TraceService::StubInterface::experimental_async_interface;
#endif

FakeServiceStub() : async_interface_(this) {}

class async_interface : public async_interface_base
{
public:
async_interface(FakeServiceStub *owner) : stub_(owner) {}

virtual ~async_interface() {}

void Export(
::grpc::ClientContext *context,
const ::opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest *request,
::opentelemetry::proto::collector::trace::v1::ExportTraceServiceResponse *response,
std::function<void(::grpc::Status)> callback) override
{
callback(stub_->Export(context, *request, response));
}

#if defined(GRPC_CPP_VERSION_MAJOR) && \
(GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 || \
defined(GRPC_CALLBACK_API_NONEXPERIMENTAL)
void Export(
::grpc::ClientContext * /*context*/,
const ::opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest * /*request*/,
::opentelemetry::proto::collector::trace::v1::ExportTraceServiceResponse * /*response*/,
::grpc::ClientUnaryReactor * /*reactor*/) override
{}
#else
void Export(
::grpc::ClientContext * /*context*/,
const ::opentelemetry::proto::collector::trace::v1::ExportTraceServiceRequest * /*request*/,
::opentelemetry::proto::collector::trace::v1::ExportTraceServiceResponse * /*response*/,
::grpc::experimental::ClientUnaryReactor * /*reactor*/)
{}
#endif

private:
FakeServiceStub *stub_;
};

async_interface_base *async() { return &async_interface_; }
async_interface_base *experimental_async() { return &async_interface_; }

grpc::Status Export(grpc::ClientContext *,
const proto::collector::trace::v1::ExportTraceServiceRequest &,
proto::collector::trace::v1::ExportTraceServiceResponse *) override
{
return grpc::Status::OK;
}

grpc::ClientAsyncResponseReaderInterface<proto::collector::trace::v1::ExportTraceServiceResponse>
*AsyncExportRaw(grpc::ClientContext *,
const proto::collector::trace::v1::ExportTraceServiceRequest &,
grpc::CompletionQueue *) override
grpc::ClientAsyncResponseReaderInterface<
proto::collector::trace::v1::ExportTraceServiceResponse> *
AsyncExportRaw(grpc::ClientContext *,
const proto::collector::trace::v1::ExportTraceServiceRequest &,
grpc::CompletionQueue *) override
{
return nullptr;
}

grpc::ClientAsyncResponseReaderInterface<proto::collector::trace::v1::ExportTraceServiceResponse>
*PrepareAsyncExportRaw(grpc::ClientContext *,
const proto::collector::trace::v1::ExportTraceServiceRequest &,
grpc::CompletionQueue *) override
grpc::ClientAsyncResponseReaderInterface<
proto::collector::trace::v1::ExportTraceServiceResponse> *
PrepareAsyncExportRaw(grpc::ClientContext *,
const proto::collector::trace::v1::ExportTraceServiceRequest &,
grpc::CompletionQueue *) override
{
return nullptr;
}

private:
async_interface async_interface_;
};

// OtlpGrpcExporterTestPeer is a friend class of OtlpGrpcExporter
Expand Down
6 changes: 4 additions & 2 deletions exporters/otlp/test/otlp_grpc_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ namespace
class OtlpMockTraceServiceStub : public proto::collector::trace::v1::MockTraceServiceStub
{
public:
# if (GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039
# if defined(GRPC_CPP_VERSION_MAJOR) && \
(GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039
using async_interface_base =
proto::collector::trace::v1::TraceService::StubInterface::async_interface;
# else
Expand All @@ -78,7 +79,8 @@ class OtlpMockTraceServiceStub : public proto::collector::trace::v1::MockTraceSe
callback(stub_->last_async_status_);
}

# if (GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 || \
# if defined(GRPC_CPP_VERSION_MAJOR) && \
(GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 || \
defined(GRPC_CALLBACK_API_NONEXPERIMENTAL)
void Export(
::grpc::ClientContext * /*context*/,
Expand Down
12 changes: 8 additions & 4 deletions exporters/otlp/test/otlp_grpc_log_record_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ namespace
class OtlpMockTraceServiceStub : public proto::collector::trace::v1::MockTraceServiceStub
{
public:
#if (GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039
#if defined(GRPC_CPP_VERSION_MAJOR) && \
(GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039
using async_interface_base =
proto::collector::trace::v1::TraceService::StubInterface::async_interface;
#else
Expand All @@ -74,7 +75,8 @@ class OtlpMockTraceServiceStub : public proto::collector::trace::v1::MockTraceSe
callback(stub_->last_async_status_);
}

#if (GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 || \
#if defined(GRPC_CPP_VERSION_MAJOR) && \
(GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 || \
defined(GRPC_CALLBACK_API_NONEXPERIMENTAL)
void Export(
::grpc::ClientContext * /*context*/,
Expand Down Expand Up @@ -108,7 +110,8 @@ class OtlpMockTraceServiceStub : public proto::collector::trace::v1::MockTraceSe
class OtlpMockLogsServiceStub : public proto::collector::logs::v1::MockLogsServiceStub
{
public:
#if (GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039
#if defined(GRPC_CPP_VERSION_MAJOR) && \
(GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039
using async_interface_base =
proto::collector::logs::v1::LogsService::StubInterface::async_interface;
#else
Expand All @@ -135,7 +138,8 @@ class OtlpMockLogsServiceStub : public proto::collector::logs::v1::MockLogsServi
callback(stub_->last_async_status_);
}

#if (GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 || \
#if defined(GRPC_CPP_VERSION_MAJOR) && \
(GRPC_CPP_VERSION_MAJOR * 1000 + GRPC_CPP_VERSION_MINOR) >= 1039 || \
defined(GRPC_CALLBACK_API_NONEXPERIMENTAL)
void Export(
::grpc::ClientContext * /*context*/,
Expand Down

0 comments on commit 5fef32a

Please sign in to comment.