Skip to content

Commit

Permalink
Fix invalid resource pointer in unit test of prometheus
Browse files Browse the repository at this point in the history
  • Loading branch information
owent committed Sep 9, 2023
1 parent 22b8c94 commit 3b15502
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
24 changes: 12 additions & 12 deletions exporters/prometheus/test/prometheus_test_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ namespace exportermetrics = opentelemetry::exporter::metrics;

namespace
{

inline opentelemetry::sdk::resource::Resource &GetEmptyResource()
{
static auto resource = opentelemetry::sdk::resource::Resource::Create(
opentelemetry::sdk::resource::ResourceAttributes{});
return resource;
}

/**
* Helper function to create ResourceMetrics
*/
Expand All @@ -21,9 +29,7 @@ inline metric_sdk::ResourceMetrics CreateSumPointData()
metric_sdk::SumPointData sum_point_data2{};
sum_point_data2.value_ = 20.0;
metric_sdk::ResourceMetrics data;
auto resource = opentelemetry::sdk::resource::Resource::Create(
opentelemetry::sdk::resource::ResourceAttributes{});
data.resource_ = &resource;
data.resource_ = &GetEmptyResource();
auto instrumentation_scope =
opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("library_name",
"1.2.0");
Expand Down Expand Up @@ -54,9 +60,7 @@ inline metric_sdk::ResourceMetrics CreateHistogramPointData()
histogram_point_data2.counts_ = {200, 300, 400, 500};
histogram_point_data2.sum_ = (int64_t)900;
metric_sdk::ResourceMetrics data;
static auto resource = opentelemetry::sdk::resource::Resource::Create(
opentelemetry::sdk::resource::ResourceAttributes{});
data.resource_ = &resource;
data.resource_ = &GetEmptyResource();
auto instrumentation_scope =
opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("library_name",
"1.2.0");
Expand All @@ -77,9 +81,7 @@ inline metric_sdk::ResourceMetrics CreateHistogramPointData()
inline metric_sdk::ResourceMetrics CreateLastValuePointData()
{
metric_sdk::ResourceMetrics data;
static auto resource = opentelemetry::sdk::resource::Resource::Create(
opentelemetry::sdk::resource::ResourceAttributes{});
data.resource_ = &resource;
data.resource_ = &GetEmptyResource();
auto instrumentation_scope =
opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("library_name",
"1.2.0");
Expand Down Expand Up @@ -108,9 +110,7 @@ inline metric_sdk::ResourceMetrics CreateLastValuePointData()
inline metric_sdk::ResourceMetrics CreateDropPointData()
{
metric_sdk::ResourceMetrics data;
static auto resource = opentelemetry::sdk::resource::Resource::Create(
opentelemetry::sdk::resource::ResourceAttributes{});
data.resource_ = &resource;
data.resource_ = &GetEmptyResource();
auto instrumentation_scope =
opentelemetry::sdk::instrumentationscope::InstrumentationScope::Create("library_name",
"1.2.0");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ struct ScopeMetrics
inline ScopeMetrics(ScopeMetrics &&) = default;

inline ScopeMetrics &operator=(const ScopeMetrics &) = default;
inline ScopeMetrics &operator=(ScopeMetrics &&) = default;

inline ScopeMetrics &operator=(ScopeMetrics &&) = default;
};

struct ResourceMetrics
Expand All @@ -63,7 +64,8 @@ struct ResourceMetrics
inline ResourceMetrics(ResourceMetrics &&) = default;

inline ResourceMetrics &operator=(const ResourceMetrics &) = default;
inline ResourceMetrics &operator=(ResourceMetrics &&) = default;

inline ResourceMetrics &operator=(ResourceMetrics &&) = default;
};

/**
Expand Down

0 comments on commit 3b15502

Please sign in to comment.