[PROMETHEUS] Upgrade otelcpp to 1.28, add prometheus file exporter - #646
[PROMETHEUS] Upgrade otelcpp to 1.28, add prometheus file exporter#646owent wants to merge 10 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the Prometheus exporter module to OpenTelemetry C++ 1.28 and adds a new Prometheus file exporter implementation alongside the existing push exporter.
Changes:
- Bump Prometheus module versions/references from 1.19.0 to 1.28.0 (CMake/Bazel/GitHub Actions/vcpkg).
- Add a new Prometheus file exporter (implementation, options, factory) and wire it into CMake + Bazel builds.
- Extend Prometheus push exporter options/translation path with
populate_target_infoandwithout_otel_scopeflags.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| exporters/prometheus/vcpkg.json | Adds vcpkg manifest for the Prometheus contrib module (now needs metadata aligned with push + file exporters). |
| exporters/prometheus/tools.cmake | Introduces CMake helpers for import/export visibility; contains Windows attribute and SunPro detection issues. |
| exporters/prometheus/src/push_exporter.cc | Plumbs new translation options through push exporter collection/translation. |
| exporters/prometheus/src/push_exporter_factory.cc | Exports the factory Create symbol via the new API macro. |
| exporters/prometheus/src/file_exporter.cc | Adds the new rotating-file exporter implementation (includes time/path formatting, background flush thread). |
| exporters/prometheus/src/file_exporter_factory.cc | Adds factory entry point for constructing the new file exporter. |
| exporters/prometheus/MODULE.bazel | Updates Bazel module + dependency versions to 1.28.0. |
| exporters/prometheus/include/opentelemetry/exporters/prometheus/push_exporter.h | Minor formatting-only change. |
| exporters/prometheus/include/opentelemetry/exporters/prometheus/push_exporter_options.h | Adds new options + API visibility macro definition. |
| exporters/prometheus/include/opentelemetry/exporters/prometheus/push_exporter_factory.h | Exposes factory Create with API macro and includes options header. |
| exporters/prometheus/include/opentelemetry/exporters/prometheus/file_exporter.h | Adds public header for the new file exporter (needs API export annotation). |
| exporters/prometheus/include/opentelemetry/exporters/prometheus/file_exporter_options.h | Adds options + API visibility macro definition for file exporter. |
| exporters/prometheus/include/opentelemetry/exporters/prometheus/file_exporter_factory.h | Adds public factory header for the file exporter. |
| exporters/prometheus/CMakeLists.txt | Updates project version, adds new library target, and adds import/export macro wiring. |
| exporters/prometheus/BUILD | Adds Bazel cc_library target for the file exporter. |
| .github/workflows/prometheus.yml | Updates CI to test against opentelemetry-cpp v1.28.0. |
Suppressed comments (3)
exporters/prometheus/tools.cmake:44
- Same issue as the export path:
__attribute__((__dllimport__))is not the standard GCC/Clang attribute spelling. This likely results in no import decoration on Windows with MinGW/Clang.
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang|AppleClang|Intel|XL|XLClang")
if(CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(${OUTPUT_VARNAME}
"__attribute__((__dllimport__))"
PARENT_SCOPE)
exporters/prometheus/src/file_exporter.cc:693
~PrometheusFileBackend()joins the background flush thread but never setsis_shutdownto stop it. The thread can run for up to 1 minute before exiting (idle timeout), so destroying the exporter can block for a long time ifShutdown()wasn’t called.
~PrometheusFileBackend()
{
if (file_)
{
file_->background_thread_waker_cv.notify_all();
std::unique_ptr<std::thread> background_flush_thread;
exporters/prometheus/src/file_exporter.cc:1089
CheckUpdate()updatesrotate_indexand callsResetLogFile()without holdingfile_lock, even thoughResetLogFile()explicitly assumes it is called under lock. This is a data race ifAddMetricData()can be invoked concurrently, and can also conflict withOpenLogFile()/RotateLog()which use the same state underfile_lock.
// Reset rotate index when directory changes
if (new_dir != old_dir)
{
file_->rotate_index = 0;
}
ResetLogFile();
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| class PrometheusFileExporter : public ::opentelemetry::sdk::metrics::PushMetricExporter | ||
| { |
7b153bb to
da9b374
Compare
|
Sorry for it's be a long time to update this package. Could you please review it again when you have time? @ThomsonTan @esigo @lalitb |
proost
left a comment
There was a problem hiding this comment.
Maintainers looks very busy, so i'd like to help out.
Can you add test cases for file exporter?
| return 0; | ||
| } | ||
|
|
||
| file.seekg(std::ios::end); |
There was a problem hiding this comment.
file.seekg(0, std::ios::end)
There was a problem hiding this comment.
Thanks, unit tests are added.
| std::string new_dir = FileSystemUtil::DirName(new_file_path); | ||
| std::string old_dir = FileSystemUtil::DirName(old_file_path); | ||
|
|
||
| // Reset rotate index when directory changes |
There was a problem hiding this comment.
Looks like we should hold lock in here to call ResetLogFile. Am i correct?
There was a problem hiding this comment.
It's not required to be very precise in file size calculation. So I changed all the variables in ResetLogFile tobe atomic.And no lock is reauired neither.
| file_->flushed_metric_family_count.store(0); | ||
| } | ||
|
|
||
| ~PrometheusFileBackend() |
There was a problem hiding this comment.
Are there no need to set "is_shutdown" to true?
There was a problem hiding this comment.
Thanks, is_shutdown is set now.
436105b to
ac28893
Compare
| std::lock_guard<std::mutex> lock_guard{file_->background_thread_lock}; | ||
| if (!file_->background_flush_thread) | ||
| { | ||
| break; |
There was a problem hiding this comment.
non-blocking; no background flush thread and "is_shutdown" is true, can we return earlier right?
There was a problem hiding this comment.
Sorry, I'm not sure I follow. When there's been no IO for a while, the background thread exits on its own, so it shouldn't matter whether it's explicitly shut down or not.
ba10b0e to
4156383
Compare
Uh oh!
There was an error while loading. Please reload this page.