Skip to content

Commit

Permalink
Fixed the prometheus push tests (taken from opentelemetry-cpp-contrib…
Browse files Browse the repository at this point in the history
…) which were creating instrumentation scope and destroying it thus making the test flaky. Instead the scope is created once as it's done in the other test helper
  • Loading branch information
dstanev-atvi committed Feb 15, 2024
1 parent f42c42c commit 9248a06
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
common --noexperimental_merged_skyframe_analysis_execution

test --flaky_test_attempts=10

# Copyright The OpenTelemetry Authors
# SPDX-License-Identifier: Apache-2.0
common --nolegacy_external_runfiles
Expand Down
1 change: 1 addition & 0 deletions exporters/prometheus/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ cc_library(

cc_test(
name = "prometheus_push_exporter_test",
flaky = True,
srcs = [
"test/push_exporter_test.cc",
],
Expand Down
15 changes: 3 additions & 12 deletions exporters/prometheus/test/prometheus_push_test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ namespace exportermetrics = opentelemetry::exporter::metrics;
namespace
{ // NOLINT

auto instrumentation_scope =
opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("library_name", "1.9.1");

inline opentelemetry::sdk::resource::Resource &GetEmptyResource()
{
static auto resource = opentelemetry::sdk::resource::Resource::Create(
Expand All @@ -33,9 +36,6 @@ inline metric_sdk::ResourceMetrics CreateSumPointData()
sum_point_data2.value_ = 20.0;
metric_sdk::ResourceMetrics data;
data.resource_ = &GetEmptyResource();
auto instrumentation_scope =
opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("library_name",
"1.9.1");
metric_sdk::MetricData metric_data{
metric_sdk::InstrumentDescriptor{"library_name", "description", "unit",
metric_sdk::InstrumentType::kCounter,
Expand Down Expand Up @@ -65,9 +65,6 @@ inline metric_sdk::ResourceMetrics CreateHistogramPointData()

metric_sdk::ResourceMetrics data;
data.resource_ = &GetEmptyResource();
auto instrumentation_scope =
opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("library_name",
"1.9.1");
metric_sdk::MetricData metric_data{
metric_sdk::InstrumentDescriptor{"library_name", "description", "unit",
metric_sdk::InstrumentType::kHistogram,
Expand All @@ -86,9 +83,6 @@ inline metric_sdk::ResourceMetrics CreateLastValuePointData()
{
metric_sdk::ResourceMetrics data;
data.resource_ = &GetEmptyResource();
auto instrumentation_scope =
opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("library_name",
"1.2.0");
metric_sdk::LastValuePointData last_value_point_data{};
last_value_point_data.value_ = 10.0;
last_value_point_data.is_lastvalue_valid_ = true;
Expand All @@ -115,9 +109,6 @@ inline metric_sdk::ResourceMetrics CreateDropPointData()
{
metric_sdk::ResourceMetrics data;
data.resource_ = &GetEmptyResource();
auto instrumentation_scope =
opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("library_name",
"1.2.0");
metric_sdk::DropPointData drop_point_data{};
metric_sdk::DropPointData drop_point_data2{};
metric_sdk::MetricData metric_data{
Expand Down
2 changes: 0 additions & 2 deletions exporters/prometheus/test/push_exporter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,6 @@ TEST(PrometheusPushExporter, CollectionNotEnoughSpace)

int max_collection_size = exporter.GetMaxCollectionSize();

GTEST_LOG_(INFO) << max_collection_size;

// send export request to fill the
// collection in the collector
ExportResult code = ExportResult::kSuccess;
Expand Down

0 comments on commit 9248a06

Please sign in to comment.