-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
[native] Update prometheus metrics asynchronously #24716
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,8 @@ namespace facebook::presto::prometheus { | |
class PrometheusReporterTest : public testing::Test { | ||
public: | ||
void SetUp() override { | ||
reporter = std::make_shared<PrometheusStatsReporter>(testLabels); | ||
reporter = std::make_shared<PrometheusStatsReporter>(testLabels, 1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not test with multiple threads? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The problem is that for gauge metric its the last value which stays so the testing has to be in a single thread for it to be deterministic There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @jaystarshot : Could we have a single test without gauge metrics but with the multi-threading. Without that there is no signal that this code is working. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
multiThreadedReporter = std::make_shared<PrometheusStatsReporter>(testLabels, 2); | ||
} | ||
|
||
void verifySerializedResult( | ||
|
@@ -40,6 +41,43 @@ class PrometheusReporterTest : public testing::Test { | |
const std::string labelsSerialized = | ||
R"(cluster="test_cluster",worker="test_worker_pod")"; | ||
std::shared_ptr<PrometheusStatsReporter> reporter; | ||
std::shared_ptr<PrometheusStatsReporter> multiThreadedReporter; | ||
}; | ||
|
||
TEST_F(PrometheusReporterTest, testConcurrentReporting) { | ||
multiThreadedReporter->registerMetricExportType( | ||
"test.key1", facebook::velox::StatType::COUNT); | ||
multiThreadedReporter->registerMetricExportType( | ||
"test.key3", facebook::velox::StatType::SUM); | ||
EXPECT_EQ( | ||
facebook::velox::StatType::COUNT, | ||
multiThreadedReporter->registeredMetricsMap_.find("test.key1")->second.statType); | ||
EXPECT_EQ( | ||
facebook::velox::StatType::SUM, | ||
multiThreadedReporter->registeredMetricsMap_.find("test.key3")->second.statType); | ||
|
||
std::vector<size_t> testData = {10, 12, 14}; | ||
for (auto i : testData) { | ||
multiThreadedReporter->addMetricValue("test.key1", i); | ||
multiThreadedReporter->addMetricValue("test.key3", i + 2000); | ||
} | ||
|
||
// Uses default value of 1 for second parameter. | ||
multiThreadedReporter->addMetricValue("test.key1"); | ||
multiThreadedReporter->addMetricValue("test.key3"); | ||
|
||
// Wait for all async updates to finish before validation | ||
multiThreadedReporter->waitForCompletion(); | ||
|
||
auto fullSerializedResult = multiThreadedReporter->fetchMetrics(); | ||
|
||
std::vector<std::string> expected = { | ||
"# TYPE test_key1 counter", | ||
"test_key1{" + labelsSerialized + "} 37", | ||
"# TYPE test_key3 gauge", | ||
"test_key3{" + labelsSerialized + "} 6037"}; | ||
|
||
verifySerializedResult(fullSerializedResult, expected); | ||
}; | ||
|
||
TEST_F(PrometheusReporterTest, testCountAndGauge) { | ||
|
@@ -75,6 +113,7 @@ TEST_F(PrometheusReporterTest, testCountAndGauge) { | |
// Uses default value of 1 for second parameter. | ||
reporter->addMetricValue("test.key1"); | ||
reporter->addMetricValue("test.key3"); | ||
reporter->waitForCompletion(); | ||
|
||
auto fullSerializedResult = reporter->fetchMetrics(); | ||
|
||
|
@@ -114,6 +153,7 @@ TEST_F(PrometheusReporterTest, testHistogramSummary) { | |
} | ||
} | ||
reporter->addHistogramMetricValue(histogramKey, 10); | ||
reporter->waitForCompletion(); | ||
auto fullSerializedResult = reporter->fetchMetrics(); | ||
std::replace(histSummaryKey.begin(), histSummaryKey.end(), '.', '_'); | ||
std::replace(histogramKey.begin(), histogramKey.end(), '.', '_'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to be called in the destructor as well ? Would ensure we didn't lose metrics at shutdown.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope we don't need in destructor. Prometheus is pull based and unless the metrics are pulled by the backend before closing that would be useless.