From a24488f43ba00c4bafb710a6bda565dab985309d Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 1 Dec 2022 14:26:01 -0800 Subject: [PATCH 1/3] Moved otlp_grpc_utils.cc to opentelemetry_exporter_otlp_grpc_client. (#1829) --- exporters/otlp/BUILD | 20 ++------------------ exporters/otlp/CMakeLists.txt | 5 +++-- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/exporters/otlp/BUILD b/exporters/otlp/BUILD index 8bb1ae2ff6..a75188e673 100644 --- a/exporters/otlp/BUILD +++ b/exporters/otlp/BUILD @@ -46,32 +46,17 @@ cc_library( ], ) -cc_library( - name = "otlp_grpc_utils", - srcs = [ - "src/otlp_grpc_utils.cc", - ], - hdrs = [ - "include/opentelemetry/exporters/otlp/otlp_grpc_utils.h", - ], - strip_include_prefix = "include", - tags = ["otlp"], - deps = [ - "//api", - "//sdk:headers", - "@com_github_grpc_grpc//:grpc++", - ], -) - cc_library( name = "otlp_grpc_client", srcs = [ "src/otlp_grpc_client.cc", + "src/otlp_grpc_utils.cc", ], hdrs = [ "include/opentelemetry/exporters/otlp/otlp_environment.h", "include/opentelemetry/exporters/otlp/otlp_grpc_client.h", "include/opentelemetry/exporters/otlp/otlp_grpc_exporter_options.h", + "include/opentelemetry/exporters/otlp/otlp_grpc_utils.h", "include/opentelemetry/exporters/otlp/protobuf_include_prefix.h", "include/opentelemetry/exporters/otlp/protobuf_include_suffix.h", ], @@ -111,7 +96,6 @@ cc_library( deps = [ ":otlp_recordable", ":otlp_grpc_client", - ":otlp_grpc_utils", "//ext:headers", "//sdk/src/trace", diff --git a/exporters/otlp/CMakeLists.txt b/exporters/otlp/CMakeLists.txt index a894af7374..7cecab0eca 100644 --- a/exporters/otlp/CMakeLists.txt +++ b/exporters/otlp/CMakeLists.txt @@ -2,7 +2,7 @@ add_library( opentelemetry_otlp_recordable src/otlp_log_recordable.cc src/otlp_recordable.cc src/otlp_populate_attribute_utils.cc src/otlp_recordable_utils.cc - src/otlp_metric_utils.cc src/otlp_grpc_utils.cc) + src/otlp_metric_utils.cc) set_target_properties(opentelemetry_otlp_recordable PROPERTIES EXPORT_NAME otlp_recordable) @@ -24,7 +24,8 @@ target_link_libraries(opentelemetry_otlp_recordable if(WITH_OTLP_GRPC) find_package(gRPC REQUIRED) - add_library(opentelemetry_exporter_otlp_grpc_client src/otlp_grpc_client.cc) + add_library(opentelemetry_exporter_otlp_grpc_client src/otlp_grpc_client.cc + src/otlp_grpc_utils.cc) set_target_properties(opentelemetry_exporter_otlp_grpc_client PROPERTIES EXPORT_NAME otlp_grpc_client) target_link_libraries( From 2accc77af1a7482db2a5246b12a44ca4f799782e Mon Sep 17 00:00:00 2001 From: Lalit Kumar Bhasin Date: Thu, 1 Dec 2022 15:32:41 -0800 Subject: [PATCH 2/3] Change default temporality as "Cumulative" for OTLP metrics exporters (#1828) --- .../otlp/otlp_grpc_metric_exporter_options.h | 2 +- .../otlp/otlp_http_metric_exporter_options.h | 2 +- .../test/otlp_http_metric_exporter_test.cc | 22 +++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h index 3d677c1a08..61828fd49e 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_grpc_metric_exporter_options.h @@ -22,7 +22,7 @@ struct OtlpGrpcMetricExporterOptions : public OtlpGrpcExporterOptions // Preferred Aggregation Temporality sdk::metrics::AggregationTemporality aggregation_temporality = - sdk::metrics::AggregationTemporality::kDelta; + sdk::metrics::AggregationTemporality::kCumulative; }; } // namespace otlp diff --git a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h index 7fbb000a34..140b5b886b 100644 --- a/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h +++ b/exporters/otlp/include/opentelemetry/exporters/otlp/otlp_http_metric_exporter_options.h @@ -51,7 +51,7 @@ struct OtlpHttpMetricExporterOptions // Preferred Aggregation Temporality sdk::metrics::AggregationTemporality aggregation_temporality = - sdk::metrics::AggregationTemporality::kDelta; + sdk::metrics::AggregationTemporality::kCumulative; #ifdef ENABLE_ASYNC_EXPORT // Concurrent requests diff --git a/exporters/otlp/test/otlp_http_metric_exporter_test.cc b/exporters/otlp/test/otlp_http_metric_exporter_test.cc index 5dbb4cc2a7..54abb88511 100644 --- a/exporters/otlp/test/otlp_http_metric_exporter_test.cc +++ b/exporters/otlp/test/otlp_http_metric_exporter_test.cc @@ -936,6 +936,28 @@ TEST_F(OtlpHttpMetricExporterTestPeer, DefaultEndpoint) EXPECT_EQ("http://localhost:4318/v1/metrics", GetOtlpDefaultMetricsEndpoint()); } +TEST_F(OtlpHttpMetricExporterTestPeer, CheckDefaultTemporality) +{ + std::unique_ptr exporter(new OtlpHttpMetricExporter()); + EXPECT_EQ( + opentelemetry::sdk::metrics::AggregationTemporality::kCumulative, + exporter->GetAggregationTemporality(opentelemetry::sdk::metrics::InstrumentType::kCounter)); + EXPECT_EQ( + opentelemetry::sdk::metrics::AggregationTemporality::kCumulative, + exporter->GetAggregationTemporality(opentelemetry::sdk::metrics::InstrumentType::kHistogram)); + EXPECT_EQ(opentelemetry::sdk::metrics::AggregationTemporality::kCumulative, + exporter->GetAggregationTemporality( + opentelemetry::sdk::metrics::InstrumentType::kUpDownCounter)); + EXPECT_EQ(opentelemetry::sdk::metrics::AggregationTemporality::kCumulative, + exporter->GetAggregationTemporality( + opentelemetry::sdk::metrics::InstrumentType::kObservableCounter)); + EXPECT_EQ(opentelemetry::sdk::metrics::AggregationTemporality::kCumulative, + exporter->GetAggregationTemporality( + opentelemetry::sdk::metrics::InstrumentType::kObservableGauge)); + EXPECT_EQ(opentelemetry::sdk::metrics::AggregationTemporality::kCumulative, + exporter->GetAggregationTemporality( + opentelemetry::sdk::metrics::InstrumentType::kObservableUpDownCounter)); +} #endif } // namespace otlp From f23c4a2e8915bb114656931f2cbc19008551e9b5 Mon Sep 17 00:00:00 2001 From: Flier Lu Date: Fri, 2 Dec 2022 15:24:29 +0800 Subject: [PATCH 3/3] fix enum-compare-switch warning (#1833) --- exporters/otlp/src/otlp_grpc_utils.cc | 34 +++++++++++++-------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/exporters/otlp/src/otlp_grpc_utils.cc b/exporters/otlp/src/otlp_grpc_utils.cc index 02094fb3f9..20bd8bd740 100644 --- a/exporters/otlp/src/otlp_grpc_utils.cc +++ b/exporters/otlp/src/otlp_grpc_utils.cc @@ -16,39 +16,39 @@ const char *grpc_status_code_to_string(::grpc::StatusCode status_code) { switch (status_code) { - case GRPC_STATUS_OK: + case ::grpc::StatusCode::OK: return "OK"; - case GRPC_STATUS_CANCELLED: + case ::grpc::StatusCode::CANCELLED: return "CANCELLED"; - case GRPC_STATUS_UNKNOWN: + case ::grpc::StatusCode::UNKNOWN: return "UNKNOWN"; - case GRPC_STATUS_INVALID_ARGUMENT: + case ::grpc::StatusCode::INVALID_ARGUMENT: return "INVALID_ARGUMENT"; - case GRPC_STATUS_DEADLINE_EXCEEDED: + case ::grpc::StatusCode::DEADLINE_EXCEEDED: return "DEADLINE_EXCEEDED"; - case GRPC_STATUS_NOT_FOUND: + case ::grpc::StatusCode::NOT_FOUND: return "NOT_FOUND"; - case GRPC_STATUS_ALREADY_EXISTS: + case ::grpc::StatusCode::ALREADY_EXISTS: return "ALREADY_EXISTS"; - case GRPC_STATUS_PERMISSION_DENIED: + case ::grpc::StatusCode::PERMISSION_DENIED: return "PERMISSION_DENIED"; - case GRPC_STATUS_UNAUTHENTICATED: + case ::grpc::StatusCode::UNAUTHENTICATED: return "UNAUTHENTICATED"; - case GRPC_STATUS_RESOURCE_EXHAUSTED: + case ::grpc::StatusCode::RESOURCE_EXHAUSTED: return "RESOURCE_EXHAUSTED"; - case GRPC_STATUS_FAILED_PRECONDITION: + case ::grpc::StatusCode::FAILED_PRECONDITION: return "FAILED_PRECONDITION"; - case GRPC_STATUS_ABORTED: + case ::grpc::StatusCode::ABORTED: return "ABORTED"; - case GRPC_STATUS_OUT_OF_RANGE: + case ::grpc::StatusCode::OUT_OF_RANGE: return "OUT_OF_RANGE"; - case GRPC_STATUS_UNIMPLEMENTED: + case ::grpc::StatusCode::UNIMPLEMENTED: return "UNIMPLEMENTED"; - case GRPC_STATUS_INTERNAL: + case ::grpc::StatusCode::INTERNAL: return "INTERNAL"; - case GRPC_STATUS_UNAVAILABLE: + case ::grpc::StatusCode::UNAVAILABLE: return "UNAVAILABLE"; - case GRPC_STATUS_DATA_LOSS: + case ::grpc::StatusCode::DATA_LOSS: return "DATA_LOSS"; default: return "UNKNOWN";