-
Notifications
You must be signed in to change notification settings - Fork 410
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
Add Prometheus Exporter: Step 1 #280
Add Prometheus Exporter: Step 1 #280
Conversation
…and unit test file
For the CI, we actually need to have prometheus-cpp library installed in the CI environment because it's a project dependency |
Codecov Report
@@ Coverage Diff @@
## master #280 +/- ##
=======================================
Coverage 94.55% 94.55%
=======================================
Files 146 146
Lines 6610 6610
=======================================
Hits 6250 6250
Misses 360 360 |
… windows with vcpkg
Could you add a GitHub Actions to cover that? You can potentially leverage a linux container and install the dependency you need for testing. Here goes and example of how to do that https://github.com/open-telemetry/opentelemetry-dotnet/tree/master/test/OpenTelemetry.Instrumentation.StackExchangeRedis.Tests. |
WORKSPACE
Outdated
|
||
http_archive( | ||
name = "com_github_jupp0r_prometheus_cpp", | ||
strip_prefix = "prometheus-cpp-master", |
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.
Please pin to a version (and add sha256), for consistency with other deps.
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.
pin to v0.9.0, and sha256 added
#include "opentelemetry/sdk/metrics/record.h" | ||
#include "prometheus/metric_family.h" | ||
|
||
namespace prometheus_client = ::prometheus; |
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.
Is there a way to limit the scope of these? I'm worried about having them in a header file.
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.
removed it from header, and put it in implementation files
* @return a collection of translated metrics that is acceptable by Prometheus | ||
*/ | ||
std::vector<prometheus_client::MetricFamily> PrometheusExporterUtils::TranslateToPrometheus( | ||
std::vector<metric_sdk::Record> &records) |
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.
Can records be a constref?
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.
changed to a constref
/** | ||
* Set value to metric family according to record | ||
*/ | ||
void PrometheusExporterUtils::SetMetricFamily(metric_sdk::Record &record, |
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.
Can record be a constref?
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.
If I make record a constref here, I need to change all getter functions in Record class const functions. Record class was implemented by previous interns, and also used in other classes.
if (origin_name != sanitized) | ||
{ | ||
std::cout << "Sanitized metric name \"" << origin_name << "\" to \"" << sanitized << "\"" | ||
<< std::endl; |
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.
Please use \n over endl.
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.
fixed
std::chrono::nanoseconds time, | ||
const std::string &labels) | ||
{ | ||
metric.timestamp_ms = time.count() / 1000; |
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.
milliseconds = nanoseconds / 1000?
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.
fixed. thanks
if (origin_name != sanitized) | ||
{ | ||
std::cout << "Sanitized label name \"" << origin_name << "\" to \"" << sanitized << "\"" | ||
<< std::endl; |
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.
\n
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.
fixed
# apt-get install zlib1g-dev | ||
# apt-get -y install libcurl4-openssl-dev | ||
cd third_party | ||
git clone https://github.com/jupp0r/prometheus-cpp |
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.
Consider extract this logic to a separate file under the Prometheus exporter folder.
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.
Sure, correct me if I misunderstand something:
- keep the
elif [[ "$1" == "cmake.exporter.prometheus.test" ]];
block here - move the scripts of installing the Prometheus client (from
cd third_party
tosudo make install
) to a separate script inexporters/prometheus
. For example,exporters/prometheus/install_prometheus_client.sh
- run
install_prometheus_client.sh
here
@@ -83,8 +110,8 @@ elif [[ "$1" == "bazel.legacy.test" ]]; then | |||
bazel test $BAZEL_TEST_OPTIONS -- //... -//exporters/otlp/... | |||
exit 0 | |||
elif [[ "$1" == "bazel.noexcept" ]]; then | |||
bazel build --copt=-fno-exceptions $BAZEL_OPTIONS //... | |||
bazel test --copt=-fno-exceptions $BAZEL_TEST_OPTIONS //... | |||
bazel build --copt=-fno-exceptions $BAZEL_OPTIONS -- //... -//exporters/prometheus/... |
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.
Why would we want to take exception here?
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.
When we run the test, we found some error handling and exceptions from the Prometheus client, which made this test always fail. We discussed this problem with Johannes last week, and he suggested us to consider excluding the Prometheus component in the noexcept test.
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.
Please add a comment here.
auto sanitized = SanitizeNames(origin_name); | ||
if (origin_name != sanitized) | ||
{ | ||
std::cout << "Sanitized metric name \"" << origin_name << "\" to \"" << sanitized << "\"\n"; |
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.
Is this intended or just for development/debugging purpose?
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.
We added this printing in order to tell the user we have changed their metrics name or label names. We know this is not in the specification, and we can remove this.
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.
removed.
auto sanitized = SanitizeNames(origin_name); | ||
if (origin_name != sanitized) | ||
{ | ||
std::cout << "Sanitized label name \"" << origin_name << "\" to \"" << sanitized << "\"\n"; |
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.
Same here, need to understand if we intend to keep the cout lines.
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.
removed.
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.
LGTM.
This PR implements exporter utils helper functions for the Prometheus Exporter project. The C++ file
prometheus_exporter_utils.cc
implements all the helper functions that will be called when we translate a OpenTelemetry (OTLP) metric to a Prometheus metric.Changes
WORKSPACE
file and added C++ Prometheus Client as a dependency to the project.CMakeLists.txt
file in exporters folder to add Prometheus Exporter as a sub-project.exporters/prometheus
to support building project and the tests with Bazel.CMakeLists.txt
file inexporters/prometheus
to support building project with CMake.exporters/prometheus/include
exporters/prometheus/src/prometheus_exporter_utils.cc
exporters/prometheus/test/prometheus_exporter_utils_test.cc
CMakeLists.txt
file inexporters/prometheus/test
to support building tests with CMake.ci/setup_cmake.sh
to configure Prometheus C++ client as a dependency.github/workflows/ci.yml
to execute Prometheus Exporter test sub-jobci/do_ci.sh
to add Prometheus Exporter test setup scripts, and ignore Prometheus tests inbazel.noexcept