-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Expose REST API to fetch runtime metrics in prometheus format
Co-authored-by:jaystarshot <jay.narale@uber.com>
- Loading branch information
1 parent
e484062
commit 1d56b00
Showing
17 changed files
with
620 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
presto-native-execution/presto_cpp/main/common/runtime-metrics/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
add_library(presto_runtime_metrics PrestoRuntimeMetricsReporter.cpp) | ||
|
||
target_link_libraries(presto_runtime_metrics prometheus_reporter) | ||
|
||
set_property(TARGET presto_runtime_metrics PROPERTY JOB_POOL_LINK | ||
presto_link_job_pool) | ||
|
||
add_subdirectory(prometheus-reporter) |
50 changes: 50 additions & 0 deletions
50
...-native-execution/presto_cpp/main/common/runtime-metrics/PrestoRuntimeMetricsReporter.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// Created by Karteek Murthy Samba Murthy on 5/14/24. | ||
// | ||
|
||
#include "presto_cpp/main/common/runtime-metrics/PrestoRuntimeMetricsReporter.h" | ||
|
||
namespace facebook::presto { | ||
namespace { | ||
|
||
std::unordered_map< | ||
std::string, | ||
std::unique_ptr<facebook::velox::BaseStatsReporter>>& | ||
metricsReporters() { | ||
static std::unordered_map< | ||
std::string, | ||
std::unique_ptr<facebook::velox::BaseStatsReporter>> | ||
metricsReporters; | ||
return metricsReporters; | ||
} | ||
|
||
void initLabelsForPrometheusReporter(prometheus::Labels& labels) { | ||
facebook::velox::BaseStatsReporter::registered = true; | ||
auto nodeConfig = facebook::presto::NodeConfig::instance(); | ||
const std::string cluster = nodeConfig->nodeEnvironment(); | ||
const char* hostName = std::getenv("HOSTNAME"); | ||
const std::string worker = !hostName ? "" : hostName; | ||
labels.emplace("cluster", cluster); | ||
labels.emplace("worker", worker); | ||
} | ||
} // namespace | ||
|
||
void registerRuntimeMetricsReporters() { | ||
prometheus::Labels labels; | ||
initLabelsForPrometheusReporter(labels); | ||
auto prometheusReporter = | ||
std::make_unique<prometheus::PrometheusReporter>(labels); | ||
metricsReporters().insert( | ||
{kPrometheusReporterName.data(), std::move(prometheusReporter)}); | ||
metricsReporters().insert( | ||
{kDummyReporterName.data(), | ||
std::make_unique<facebook::velox::DummyStatsReporter>()}); | ||
} | ||
|
||
// Initialize singleton for the reporter | ||
folly::Singleton<facebook::velox::BaseStatsReporter> reporter([]() { | ||
auto systemConfig = facebook::presto::SystemConfig::instance(); | ||
auto reporterName = systemConfig->getRuntimeMetricReporter(); | ||
return metricsReporters()[reporterName].get(); | ||
}); | ||
}; // namespace facebook::presto. |
24 changes: 24 additions & 0 deletions
24
...to-native-execution/presto_cpp/main/common/runtime-metrics/PrestoRuntimeMetricsReporter.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
#include "presto_cpp/main/common/Configs.h" | ||
#include "presto_cpp/main/common/runtime-metrics/prometheus-reporter/PrometheusReporter.h" | ||
|
||
namespace facebook::presto { | ||
|
||
constexpr std::string_view kPrometheusReporterName = "prometheus"; | ||
constexpr std::string_view kDummyReporterName = "dummy"; | ||
|
||
void registerRuntimeMetricsReporters(); | ||
}; // namespace facebook::presto |
9 changes: 9 additions & 0 deletions
9
...ative-execution/presto_cpp/main/common/runtime-metrics/prometheus-reporter/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
find_package(prometheus-cpp CONFIG REQUIRED) | ||
|
||
add_library(prometheus_reporter PrometheusReporter.cpp) | ||
|
||
target_link_libraries(prometheus_reporter presto_common prometheus-cpp::core) | ||
|
||
set_property(TARGET prometheus_reporter PROPERTY JOB_POOL_LINK | ||
presto_link_job_pool) | ||
add_subdirectory(tests) |
Oops, something went wrong.