Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPCC-33167 Add unique ID to each metric #19394

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions system/jlib/jmetrics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ MODULE_EXIT()
metricsManager.destroy();
}

// MetricBase static member
std::atomic<int> MetricBase::metricId = 0;

HistogramMetric::HistogramMetric(const char *_name, const char *_desc, StatisticMeasure _units, const std::vector<__uint64> &_bucketLimits, const MetricMetaData &_metaData) :
MetricBase(_name, _desc, MetricType::METRICS_HISTOGRAM, _units, _metaData)
Expand Down
7 changes: 6 additions & 1 deletion system/jlib/jmetrics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ class jlib_decl MetricBase : public IMetric
StatisticMeasure queryUnits() const override { return units; }
virtual std::vector<__uint64> queryHistogramValues() const override { return {}; }
virtual std::vector<__uint64> queryHistogramBucketLimits() const override { return {}; }
int queryId() const { return myId; }


protected:
Expand All @@ -135,14 +136,18 @@ class jlib_decl MetricBase : public IMetric
description{_desc},
metricType{_metricType},
units{_units},
metaData{_metaData} { }
metaData{_metaData} { myId = ++metricId; }

protected:
std::string name;
std::string description;
MetricType metricType;
StatisticMeasure units;
MetricMetaData metaData;

private:
static std::atomic<int> metricId;
int myId;
};


Expand Down
26 changes: 26 additions & 0 deletions testing/unittests/metrics/MetricFrameworkTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class MetricFrameworkTests : public CppUnit::TestFixture
CPPUNIT_TEST(Test_metric_meta_data);
CPPUNIT_TEST(Test_gauge_by_counters_metric);
CPPUNIT_TEST(Test_histogram_metric);
CPPUNIT_TEST(Test_validate_unique_metric_ids);
CPPUNIT_TEST_SUITE_END();

protected:
Expand Down Expand Up @@ -469,6 +470,31 @@ class MetricFrameworkTests : public CppUnit::TestFixture
CPPUNIT_ASSERT(result);
}

void Test_validate_unique_metric_ids()
{
std::shared_ptr<CounterMetric> pCounter1 = std::make_shared<CounterMetric>("testcounter1", "description", SMeasureCount);
auto initialMetricId1 = pCounter1->queryId();
std::shared_ptr<CounterMetric> pCounter2 = std::make_shared<CounterMetric>("testcounter2", "description", SMeasureCount);
auto initialMetricId2 = pCounter2->queryId();
std::shared_ptr<CounterMetric> pCounter3 = std::make_shared<CounterMetric>("testcounter3", "description", SMeasureCount);
auto initialMetricId3 = pCounter3->queryId();

// make sure initial id query values all different
bool different = initialMetricId1 != initialMetricId2 && initialMetricId1 != initialMetricId3 && initialMetricId2 != initialMetricId3;
CPPUNIT_ASSERT(different);

// requery values since some were queried before additional metrics allocated
auto afterMetricId1 = pCounter1->queryId();
auto afterMetricId2 = pCounter2->queryId();
auto afterMetricId3 = pCounter3->queryId();

bool different2 = afterMetricId1 != afterMetricId2 && afterMetricId1 != afterMetricId3 && afterMetricId2 != afterMetricId3;
CPPUNIT_ASSERT(different2);

bool unchanged = initialMetricId1 == afterMetricId1 && initialMetricId2 == afterMetricId2 && initialMetricId3 == afterMetricId3;
CPPUNIT_ASSERT(unchanged);
}

protected:
MetricsManager frameworkTestManager;
MetricFrameworkTestSink *pTestSink;
Expand Down
Loading