Skip to content

Commit

Permalink
Add benchmark tests for Sum Aggregation #1949 (#1948)
Browse files Browse the repository at this point in the history
  • Loading branch information
lalitb authored Feb 22, 2023
1 parent 5c121cf commit 7c0826e
Show file tree
Hide file tree
Showing 16 changed files with 336 additions and 355 deletions.
73 changes: 53 additions & 20 deletions sdk/test/metrics/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,21 @@

load("//bazel:otel_cc_benchmark.bzl", "otel_cc_benchmark")

cc_library(
name = "metrics_common_test_utils",
srcs = [
"common.cc",
],
hdrs = ["common.h"],
tags = [
"metrics",
"test",
],
deps = [
"//sdk/src/metrics",
],
)

cc_test(
name = "meter_test",
srcs = [
Expand All @@ -13,7 +28,7 @@ cc_test(
"test",
],
deps = [
"//sdk/src/metrics",
"metrics_common_test_utils",
"@com_google_googletest//:gtest_main",
],
)
Expand All @@ -28,7 +43,7 @@ cc_test(
"test",
],
deps = [
"//sdk/src/metrics",
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
Expand All @@ -44,7 +59,7 @@ cc_test(
"test",
],
deps = [
"//sdk/src/metrics",
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
Expand All @@ -60,7 +75,7 @@ cc_test(
"test",
],
deps = [
"//sdk/src/metrics",
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
Expand All @@ -76,7 +91,7 @@ cc_test(
"test",
],
deps = [
"//sdk/src/metrics",
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
Expand All @@ -92,7 +107,7 @@ cc_test(
"test",
],
deps = [
"//sdk/src/metrics",
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
Expand All @@ -108,7 +123,7 @@ cc_test(
"test",
],
deps = [
"//sdk/src/metrics",
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
Expand All @@ -124,7 +139,7 @@ cc_test(
"test",
],
deps = [
"//sdk/src/metrics",
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
Expand All @@ -140,7 +155,7 @@ cc_test(
"test",
],
deps = [
"//sdk/src/metrics",
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
Expand All @@ -156,7 +171,7 @@ cc_test(
"test",
],
deps = [
"//sdk/src/metrics",
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
Expand All @@ -172,7 +187,7 @@ cc_test(
"test",
],
deps = [
"//sdk/src/metrics",
"metrics_common_test_utils",
"@com_google_googletest//:gtest_main",
],
)
Expand All @@ -187,7 +202,7 @@ cc_test(
"test",
],
deps = [
"//sdk/src/metrics",
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
Expand All @@ -203,7 +218,7 @@ cc_test(
"test",
],
deps = [
"//sdk/src/metrics",
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
Expand All @@ -219,7 +234,7 @@ cc_test(
"test",
],
deps = [
"//sdk/src/metrics",
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
Expand All @@ -235,7 +250,7 @@ cc_test(
"test",
],
deps = [
"//sdk/src/metrics",
"metrics_common_test_utils",
"@com_google_googletest//:gtest_main",
],
)
Expand All @@ -250,7 +265,7 @@ cc_test(
"test",
],
deps = [
"//sdk/src/metrics",
"metrics_common_test_utils",
"@com_google_googletest//:gtest_main",
],
)
Expand All @@ -265,7 +280,7 @@ cc_test(
"test",
],
deps = [
"//sdk/src/metrics",
"metrics_common_test_utils",
"@com_google_googletest//:gtest_main",
],
)
Expand All @@ -280,7 +295,7 @@ cc_test(
"test",
],
deps = [
"//sdk/src/metrics",
"metrics_common_test_utils",
"@com_google_googletest//:gtest_main",
],
)
Expand All @@ -296,7 +311,7 @@ otel_cc_benchmark(
"test",
],
deps = [
"//sdk/src/metrics",
"metrics_common_test_utils",
],
)

Expand All @@ -311,7 +326,7 @@ otel_cc_benchmark(
"test",
],
deps = [
"//sdk/src/metrics",
"metrics_common_test_utils",
],
)

Expand All @@ -326,6 +341,24 @@ otel_cc_benchmark(
"test",
],
deps = [
"metrics_common_test_utils",
"//sdk/src/metrics",
"//sdk/src/resource",
],
)

otel_cc_benchmark(
name = "sum_aggregation_benchmark",
srcs = [
"sum_aggregation_benchmark.cc",
],
tags = [
"benchmark",
"metrics",
"test",
],
deps = [
"metrics_common_test_utils",
"//sdk/src/metrics",
"//sdk/src/resource",
],
Expand Down
12 changes: 10 additions & 2 deletions sdk/test/metrics/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0

add_library(metrics_common_test_utils common.cc)
target_link_libraries(metrics_common_test_utils opentelemetry_metrics)

foreach(
testname
meter_provider_sdk_test
Expand All @@ -27,7 +30,7 @@ foreach(
add_executable(${testname} "${testname}.cc")
target_link_libraries(
${testname} ${GTEST_BOTH_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT}
opentelemetry_resources opentelemetry_metrics)
metrics_common_test_utils opentelemetry_resources)
gtest_add_tests(
TARGET ${testname}
TEST_PREFIX metrics.
Expand All @@ -48,8 +51,13 @@ if(WITH_BENCHMARK)
histogram_aggregation_benchmark.cc)
target_link_libraries(
histogram_aggregation_benchmark benchmark::benchmark
${CMAKE_THREAD_LIBS_INIT} opentelemetry_common opentelemetry_metrics
${CMAKE_THREAD_LIBS_INIT} metrics_common_test_utils opentelemetry_common
opentelemetry_resources)

add_executable(sum_aggregation_benchmark sum_aggregation_benchmark.cc)
target_link_libraries(
sum_aggregation_benchmark benchmark::benchmark ${CMAKE_THREAD_LIBS_INIT}
metrics_common_test_utils opentelemetry_common opentelemetry_resources)
endif()

add_subdirectory(exemplar)
26 changes: 5 additions & 21 deletions sdk/test/metrics/async_metric_storage_test.cc
Original file line number Diff line number Diff line change
@@ -1,47 +1,31 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include "opentelemetry/sdk/metrics/state/async_metric_storage.h"
#include <cstdint>
#include "common.h"

#include "opentelemetry/common/key_value_iterable_view.h"
#include "opentelemetry/sdk/metrics/async_instruments.h"
#include "opentelemetry/sdk/metrics/instruments.h"
#include "opentelemetry/sdk/metrics/meter_context.h"
#include "opentelemetry/sdk/metrics/metric_reader.h"
#include "opentelemetry/sdk/metrics/observer_result.h"
#include "opentelemetry/sdk/metrics/push_metric_exporter.h"
#include "opentelemetry/sdk/metrics/state/async_metric_storage.h"
#include "opentelemetry/sdk/metrics/state/metric_collector.h"
#include "opentelemetry/sdk/metrics/state/observable_registry.h"

#include <gtest/gtest.h>
#include <cstdint>
#include <memory>
#include <vector>

using namespace opentelemetry::sdk::metrics;
using namespace opentelemetry::sdk::instrumentationscope;
using namespace opentelemetry::sdk::resource;

using namespace opentelemetry::sdk::metrics;
using namespace opentelemetry::common;
using M = std::map<std::string, std::string>;
namespace nostd = opentelemetry::nostd;

class MockCollectorHandle : public CollectorHandle
{
public:
MockCollectorHandle(AggregationTemporality temp) : temporality(temp) {}

~MockCollectorHandle() override = default;

AggregationTemporality GetAggregationTemporality(
InstrumentType /* instrument_type */) noexcept override
{
return temporality;
}

private:
AggregationTemporality temporality;
};
using M = std::map<std::string, std::string>;

class WritableMetricStorageTestFixture : public ::testing::TestWithParam<AggregationTemporality>
{};
Expand Down
68 changes: 68 additions & 0 deletions sdk/test/metrics/common.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

#include "common.h"

using namespace opentelemetry;
using namespace opentelemetry::sdk::instrumentationscope;
using namespace opentelemetry::sdk::metrics;
using namespace opentelemetry::sdk::common;

// MockMetricExporter

ExportResult MockMetricExporter::Export(const ResourceMetrics & /*resource_metrics*/) noexcept
{
return ExportResult::kSuccess;
}

AggregationTemporality MockMetricExporter::GetAggregationTemporality(
InstrumentType /*instrument_type*/) const noexcept
{
return AggregationTemporality::kCumulative;
}

bool MockMetricExporter::ForceFlush(std::chrono::microseconds /* timeout */) noexcept
{
return true;
}

bool MockMetricExporter::Shutdown(std::chrono::microseconds /* timeout */) noexcept
{
return true;
}

// MockMetricReader
MockMetricReader::MockMetricReader(std::unique_ptr<PushMetricExporter> exporter)
: exporter_(std::move(exporter))
{}

MockMetricReader::MockMetricReader() : exporter_{new MockMetricExporter()} {}

AggregationTemporality MockMetricReader::GetAggregationTemporality(
InstrumentType instrument_type) const noexcept

{
return exporter_->GetAggregationTemporality(instrument_type);
}

bool MockMetricReader::OnForceFlush(std::chrono::microseconds /* timeout */) noexcept
{
return true;
}

bool MockMetricReader::OnShutDown(std::chrono::microseconds /* timeout */) noexcept
{
return true;
}

void MockMetricReader::OnInitialized() noexcept {}

// MockCollectorHandle

MockCollectorHandle::MockCollectorHandle(AggregationTemporality temp) : temporality_(temp) {}

AggregationTemporality MockCollectorHandle::GetAggregationTemporality(
InstrumentType /* instrument_type */) noexcept
{
return temporality_;
}
Loading

0 comments on commit 7c0826e

Please sign in to comment.