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. |
|
|
||
| http_archive( | ||
| name = "com_github_jupp0r_prometheus_cpp", | ||
| strip_prefix = "prometheus-cpp-master", |
There was a problem hiding this comment.
Please pin to a version (and add sha256), for consistency with other deps.
There was a problem hiding this comment.
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.
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.
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.
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.
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; |
| std::chrono::nanoseconds time, | ||
| const std::string &labels) | ||
| { | ||
| metric.timestamp_ms = time.count() / 1000; |
There was a problem hiding this comment.
milliseconds = nanoseconds / 1000?
| if (origin_name != sanitized) | ||
| { | ||
| std::cout << "Sanitized label name \"" << origin_name << "\" to \"" << sanitized << "\"" | ||
| << std::endl; |
| # 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.
Consider extract this logic to a separate file under the Prometheus exporter folder.
There was a problem hiding this comment.
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_partytosudo make install) to a separate script inexporters/prometheus. For example,exporters/prometheus/install_prometheus_client.sh - run
install_prometheus_client.shhere
| 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.
Why would we want to take exception here?
There was a problem hiding this comment.
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.
| 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.
Is this intended or just for development/debugging purpose?
There was a problem hiding this comment.
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.
| 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.
Same here, need to understand if we intend to keep the cout lines.
…s-create-or-update-comment-digest chore(deps): update peter-evans/create-or-update-comment digest to b8f7611
This PR implements exporter utils helper functions for the Prometheus Exporter project. The C++ file
prometheus_exporter_utils.ccimplements all the helper functions that will be called when we translate a OpenTelemetry (OTLP) metric to a Prometheus metric.Changes
WORKSPACEfile and added C++ Prometheus Client as a dependency to the project.CMakeLists.txtfile in exporters folder to add Prometheus Exporter as a sub-project.exporters/prometheusto support building project and the tests with Bazel.CMakeLists.txtfile inexporters/prometheusto support building project with CMake.exporters/prometheus/includeexporters/prometheus/src/prometheus_exporter_utils.ccexporters/prometheus/test/prometheus_exporter_utils_test.ccCMakeLists.txtfile inexporters/prometheus/testto support building tests with CMake.ci/setup_cmake.shto configure Prometheus C++ client as a dependency.github/workflows/ci.ymlto execute Prometheus Exporter test sub-jobci/do_ci.shto add Prometheus Exporter test setup scripts, and ignore Prometheus tests inbazel.noexcept