[improve][monitor] Restore the BookKeeper Prometheus stats provider on the Prometheus Java client 1.x - #26360
[improve][monitor] Restore the BookKeeper Prometheus stats provider on the Prometheus Java client 1.x#26360lhotari wants to merge 2 commits into
Conversation
…n the Prometheus Java client 1.x Restores the Pulsar-owned BookKeeper stats provider that was removed in 982eac3 ('[feat] Upgrade BookKeeper dependency to 4.18.0', apache#25886), rebuilt on the Prometheus Java client 1.x instead of the legacy simpleclient. The module now lives at the repository root as bookkeeper-prometheus-metrics-provider rather than under jetty-upgrade/, since it is no longer tied to the Jetty upgrade work. conf/bookkeeper.conf points statsProviderClass back at org.apache.pulsar.metrics.prometheus.bookkeeper.PrometheusMetricsProvider, and the server distribution ships this module in place of org.apache.bookkeeper.stats:prometheus-metrics-provider, which is still on simpleclient. Migration details: - CollectorRegistry -> io.prometheus.metrics.model.registry.PrometheusRegistry - hotspot *Exports -> io.prometheus.metrics.instrumentation.jvm.JvmMetrics - Gauge.build().setChild() -> io.prometheus.metrics.core.metrics.GaugeWithCallback - Collector.sanitizeMetricName -> PrometheusNaming.sanitizeMetricName - TextFormat.CONTENT_TYPE_004 -> PrometheusTextFormatWriter.CONTENT_TYPE - The registry portion of the output is now rendered by the client library's own PrometheusTextFormatWriter rather than a hand-rolled formatter, so every snapshot type is emitted exactly as the exposition format specifies. BREAKING: bookie JVM metric names change. The Prometheus Java client 1.x renamed several metrics relative to the simpleclient hotspot exports: - jvm_memory_bytes_used -> jvm_memory_used_bytes - jvm_memory_bytes_committed -> jvm_memory_committed_bytes - jvm_memory_bytes_init -> jvm_memory_init_bytes - jvm_memory_bytes_max -> jvm_memory_max_bytes - jvm_memory_pool_bytes_used -> jvm_memory_pool_used_bytes - jvm_memory_pool_bytes_committed -> jvm_memory_pool_committed_bytes - jvm_memory_pool_bytes_init -> jvm_memory_pool_init_bytes - jvm_memory_pool_bytes_max -> jvm_memory_pool_max_bytes jvm_gc_collection_seconds, jvm_threads_*, process_* and the Netty-tracked jvm_memory_direct_bytes_used / jvm_memory_direct_bytes_max keep their names. Dashboards and alerts on the renamed bookie JVM metrics need updating. Two smaller output differences, both from the client library rather than this change: metrics with no labels are now written as 'name value' rather than 'name{} value', and a new jvm_runtime_info metric is exposed. The restored tests are updated accordingly. Note that this does not remove simpleclient from the distribution: Pulsar's broker, proxy, functions and the vendored ZooKeeper provider still use it. This module is the first step. Assisted-by: Claude Code (Opus 5)
…theus-provider # Conflicts: # gradle/libs.versions.toml
|
Thanks for working on this. I noticed a couple of compatibility details and wanted to share them for consideration. First, around Since this provider still writes those BookKeeper metrics manually in the legacy Prometheus text format, preserving the previous underscore escaping behavior would help avoid compatibility surprises. A small regression test with a hyphenated metric name would also make the intended behavior explicit. Second, I noticed |
Motivation
io.prometheus:simpleclient0.16.0 is the final release of the Prometheus Java client 0.x line. Pulsaris still on it everywhere, and one of the things pinning us there is that the server distribution ships
org.apache.bookkeeper.stats:prometheus-metrics-provider, whose POM has hard compile dependencies onsimpleclient,simpleclient_hotspotandsimpleclient_servlet.Pulsar used to own this provider: it lived at
jetty-upgrade/bookkeeper-prometheus-metrics-provideruntil it was removed in 982eac3 ([feat] Upgrade BookKeeper dependency to 4.18.0, #25886), which
also repointed
conf/bookkeeper.confat BookKeeper's own provider. This PR restores it, rebuilt on thePrometheus Java client 1.x, as the first concrete step off simpleclient.
Modifications
The module is restored at the repository root as
bookkeeper-prometheus-metrics-providerrather thanunder
jetty-upgrade/, since it is no longer related to the Jetty upgrade work. The Gradle project name:pulsar-bookkeeper-prometheus-metrics-providerand theorg.apache.pulsar.metrics.prometheus.bookkeeperpackage are unchanged from before the removal.Wiring:
conf/bookkeeper.conf—statsProviderClasspoints back atorg.apache.pulsar.metrics.prometheus.bookkeeper.PrometheusMetricsProvider.distribution/server— ships this module instead oforg.apache.bookkeeper.stats:prometheus-metrics-provider.settings.gradle.kts,gradle/libs.versions.toml— new module plus aprometheus-client-javaversionreference (1.8.0) and the four artifacts it needs.
API migration inside the module:
CollectorRegistryio.prometheus.metrics.model.registry.PrometheusRegistryhotspot.{Standard,MemoryPools,GarbageCollector,Thread}Exportsio.prometheus.metrics.instrumentation.jvm.JvmMetricsGauge.build(...).create().setChild(...)io.prometheus.metrics.core.metrics.GaugeWithCallbackCollector.sanitizeMetricNamePrometheusNaming.sanitizeMetricNameTextFormat.CONTENT_TYPE_004PrometheusTextFormatWriter.CONTENT_TYPEPrometheusTextFormat.writeMetricsCollectedByPrometheusClientnow delegates to the client library's ownPrometheusTextFormatWriterinstead of hand-rolling the rendering, so every snapshot type is emittedexactly as the exposition format specifies. The hand-written gauge/counter/opStat output that this module
has always produced for BookKeeper's own stats is unchanged.
Note that
prometheus-metrics-*1.8.0 was already on the server classpath viaopentelemetry-exporter-prometheus, so this adds no new dependency family — only-coreand-instrumentation-jvmare newly bundled.The Prometheus Java client 1.x renamed several JVM metrics relative to the simpleclient hotspot exports.
Since
conf/bookkeeper.confcurrently selects BookKeeper's simpleclient-based provider, bookies emit theold names today, and this change switches them:
jvm_memory_bytes_usedjvm_memory_used_bytesjvm_memory_bytes_committedjvm_memory_committed_bytesjvm_memory_bytes_initjvm_memory_init_bytesjvm_memory_bytes_maxjvm_memory_max_bytesjvm_memory_pool_bytes_usedjvm_memory_pool_used_bytesjvm_memory_pool_bytes_committedjvm_memory_pool_committed_bytesjvm_memory_pool_bytes_initjvm_memory_pool_init_bytesjvm_memory_pool_bytes_maxjvm_memory_pool_max_bytesjvm_gc_collection_seconds,jvm_threads_*,process_*and the Netty-trackedjvm_memory_direct_bytes_used/jvm_memory_direct_bytes_maxkeep their names. Dashboards and alertson the renamed bookie JVM metrics need updating, so this should be called out in the release notes.
Two smaller output differences also come from the client library:
name valuerather than simpleclient'sname{} value;jvm_runtime_infometric is exposed, whose label values contain spaces and+characters.The restored tests are updated for both, including relaxing the test's own "hacky parsing" regex, whose
trailing-label-value character class could not represent a value like
21.0.11+10-LTS.This does not remove simpleclient
To set expectations: simpleclient stays in the distribution after this change. 64 files across
pulsar-broker,pulsar-broker-common,pulsar-proxy,pulsar-metadata,managed-ledger,pulsar-transaction,pulsar-common,pulsar-functionsand the vendored ZooKeeper provider still useit, and
PrometheusMetricsGeneratorUtilsscrapesCollectorRegistry.defaultRegistry. This module is thefirst of four independent units; the ZooKeeper provider is the natural next one, and the
pulsar-functionsinstance metrics stack is what would unlock upgradingprometheus-jmxto 1.x.Verifying this change
This change is already covered by existing tests — the module's restored
TestPrometheusFormatterandTestPrometheusMetricsProvider, which pin the exposition text format and the direct-memory gauges.Verified locally:
./gradlew :pulsar-bookkeeper-prometheus-metrics-provider:test— 11 tests, all green./gradlew quickCheck sanityCheck./gradlew checkBinaryLicense— confirms the BookKeeper provider jar is gone from the serverdistribution and the client_java jars that replaced it are accounted for
apache-pulsar-*-bin.tar.gzto confirm it shipspulsar-bookkeeper-prometheus-metrics-providerand no longer shipsorg.apache.bookkeeper.stats-prometheus-metrics-providerDoes this pull request potentially affect one of the following parts:
conf/bookkeeper.conf'sstatsProviderClassdefault changes, and the bookie JVM metric names change asdescribed above.