Skip to content

Commit

Permalink
Merge branch 'main' into fix_iwyu_cleanup_4
Browse files Browse the repository at this point in the history
  • Loading branch information
marcalff authored Sep 3, 2024
2 parents f7fb698 + 7f785b5 commit 2d54730
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 333 deletions.
4 changes: 2 additions & 2 deletions ci/do_ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -484,8 +484,8 @@ elif [[ "$1" == "bazel.noexcept" ]]; then
# there are some exceptions and error handling code from the Prometheus Client
# as well as Opentracing shim (due to some third party code in its Opentracing dependency)
# that make this test always fail. Ignore these packages in the noexcept test here.
bazel $BAZEL_STARTUP_OPTIONS build --copt=-fno-exceptions $BAZEL_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//examples/prometheus/... -//sdk/test/metrics:attributes_hashmap_test -//opentracing-shim/...
bazel $BAZEL_STARTUP_OPTIONS test --copt=-fno-exceptions $BAZEL_TEST_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//examples/prometheus/... -//sdk/test/metrics:attributes_hashmap_test -//opentracing-shim/...
bazel $BAZEL_STARTUP_OPTIONS build --copt=-fno-exceptions $BAZEL_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//examples/prometheus/... -//opentracing-shim/...
bazel $BAZEL_STARTUP_OPTIONS test --copt=-fno-exceptions $BAZEL_TEST_OPTIONS_ASYNC -- //... -//exporters/prometheus/... -//examples/prometheus/... -//opentracing-shim/...
exit 0
elif [[ "$1" == "bazel.nortti" ]]; then
# there are some exceptions and error handling code from the Prometheus Client
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/metrics/export/periodic_exporting_metric_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ bool PeriodicExportingMetricReader::OnForceFlush(std::chrono::microseconds timeo
// - If original `timeout` is `zero`, use that in exporter::forceflush
// - Else if remaining `timeout_steady` more than zero, use that in exporter::forceflush
// - Else don't invoke exporter::forceflush ( as remaining time is zero or less)
if (timeout <= std::chrono::steady_clock::duration::zero())
if (timeout <= std::chrono::milliseconds::duration::zero())
{
result =
exporter_->ForceFlush(std::chrono::duration_cast<std::chrono::microseconds>(timeout));
Expand Down
34 changes: 12 additions & 22 deletions sdk/src/metrics/meter_context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,46 +168,36 @@ bool MeterContext::ForceFlush(std::chrono::microseconds timeout) noexcept
bool result = true;
// Simultaneous flush not allowed.
const std::lock_guard<opentelemetry::common::SpinLockMutex> locked(forceflush_lock_);
// Convert to nanos to prevent overflow
auto timeout_ns = (std::chrono::nanoseconds::max)();
if (std::chrono::duration_cast<std::chrono::microseconds>(timeout_ns) > timeout)
{
timeout_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(timeout);
}

auto current_time = std::chrono::system_clock::now();
std::chrono::system_clock::time_point expire_time;
auto overflow_checker = (std::chrono::system_clock::time_point::max)();

// check if the expected expire time doesn't overflow.
if (overflow_checker - current_time > timeout_ns)
auto time_remaining = (std::chrono::steady_clock::duration::max)();
if (std::chrono::duration_cast<std::chrono::microseconds>(time_remaining) > timeout)
{
expire_time =
current_time + std::chrono::duration_cast<std::chrono::system_clock::duration>(timeout_ns);
time_remaining = timeout;
}
else

auto current_time = std::chrono::steady_clock::now();
auto expire_time = (std::chrono::steady_clock::time_point::max)();
if (expire_time - current_time > time_remaining)
{
// overflow happens, reset expire time to max.
expire_time = overflow_checker;
expire_time = current_time + time_remaining;
}

for (auto &collector : collectors_)
{
if (!std::static_pointer_cast<MetricCollector>(collector)->ForceFlush(
std::chrono::duration_cast<std::chrono::microseconds>(timeout_ns)))
std::chrono::duration_cast<std::chrono::microseconds>(time_remaining)))
{
result = false;
}

current_time = std::chrono::system_clock::now();

current_time = std::chrono::steady_clock::now();
if (expire_time >= current_time)
{
timeout_ns = std::chrono::duration_cast<std::chrono::nanoseconds>(expire_time - current_time);
time_remaining = expire_time - current_time;
}
else
{
timeout_ns = std::chrono::nanoseconds::zero();
time_remaining = std::chrono::steady_clock::duration::zero();
}
}
if (!result)
Expand Down
303 changes: 2 additions & 301 deletions sdk/test/metrics/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -19,307 +19,8 @@ cc_library(
)

cc_test(
name = "meter_test",
srcs = [
"meter_test.cc",
],
tags = [
"metrics",
"test",
],
deps = [
"metrics_common_test_utils",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "meter_provider_sdk_test",
srcs = [
"meter_provider_sdk_test.cc",
],
tags = [
"metrics",
"test",
],
deps = [
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "metric_reader_test",
srcs = [
"metric_reader_test.cc",
],
tags = [
"metrics",
"test",
],
deps = [
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "histogram_test",
srcs = [
"histogram_test.cc",
],
tags = [
"metrics",
"test",
],
deps = [
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "view_registry_test",
srcs = [
"view_registry_test.cc",
],
tags = [
"metrics",
"test",
],
deps = [
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "aggregation_test",
srcs = [
"aggregation_test.cc",
],
tags = [
"metrics",
"test",
],
deps = [
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "sync_metric_storage_counter_test",
srcs = [
"sync_metric_storage_counter_test.cc",
],
tags = [
"metrics",
"test",
],
deps = [
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "sync_metric_storage_up_down_counter_test",
srcs = [
"sync_metric_storage_up_down_counter_test.cc",
],
tags = [
"metrics",
"test",
],
deps = [
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "sync_metric_storage_histogram_test",
srcs = [
"sync_metric_storage_histogram_test.cc",
],
tags = [
"metrics",
"test",
],
deps = [
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "sync_instruments_test",
srcs = [
"sync_instruments_test.cc",
],
tags = [
"metrics",
"test",
],
deps = [
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "async_instruments_test",
srcs = [
"async_instruments_test.cc",
],
tags = [
"metrics",
"test",
],
deps = [
"metrics_common_test_utils",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "async_metric_storage_test",
srcs = [
"async_metric_storage_test.cc",
],
tags = [
"metrics",
"test",
],
deps = [
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "observer_result_test",
srcs = [
"observer_result_test.cc",
],
tags = [
"metrics",
"test",
],
deps = [
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "multi_metric_storage_test",
srcs = [
"multi_metric_storage_test.cc",
],
tags = [
"metrics",
"test",
],
deps = [
"metrics_common_test_utils",
"//sdk/src/resource",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "attributes_processor_test",
srcs = [
"attributes_processor_test.cc",
],
tags = [
"metrics",
"test",
],
deps = [
"metrics_common_test_utils",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "attributes_hashmap_test",
srcs = [
"attributes_hashmap_test.cc",
],
tags = [
"metrics",
"test",
],
deps = [
"metrics_common_test_utils",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "circular_buffer_counter_test",
srcs = [
"circular_buffer_counter_test.cc",
],
tags = [
"metrics",
"test",
],
deps = [
"//sdk/src/metrics",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "base2_exponential_histogram_indexer_test",
srcs = [
"base2_exponential_histogram_indexer_test.cc",
],
tags = [
"metrics",
"test",
],
deps = [
"metrics_common_test_utils",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "histogram_aggregation_test",
srcs = [
"histogram_aggregation_test.cc",
],
tags = [
"metrics",
"test",
],
deps = [
"metrics_common_test_utils",
"@com_google_googletest//:gtest_main",
],
)

cc_test(
name = "sum_aggregation_test",
srcs = [
"sum_aggregation_test.cc",
],
name = "all_tests",
srcs = glob(["*_test.cc"]),
tags = [
"metrics",
"test",
Expand Down
Loading

0 comments on commit 2d54730

Please sign in to comment.