Skip to content

[improve][fn] Port the function instance metrics to the Prometheus Java client 1.x - #27484

Open
namest504 wants to merge 1 commit into
apache:masterfrom
namest504:improve/functions-instance-prometheus-1x
Open

namest504 wants to merge 1 commit into
apache:masterfrom
namest504:improve/functions-instance-prometheus-1x

Conversation

@namest504

Copy link
Copy Markdown
Contributor

Main Issue: #27045

Motivation

Part of the Functions item in #27045: the metrics of a Java function instance, the HTTP endpoint that serves them, the JMX collector and the instance JVM metrics. These four share one registry, so they move together. This PR does not depend on #27350.

Modifications

  • FunctionCollectorRegistryImpl now extends the 1.x PrometheusRegistry. It keeps the register once per name behaviour that the stats managers rely on when several instances share one registry in thread mode.
  • FunctionStatsManager, SinkStatsManager, SourceStatsManager: all counters, gauges and latency summaries are 1.x metrics with the same names and labels. Summaries keep their quantiles and the 10 minute window. As before, nothing is unregistered when an instance closes, because the metric objects are shared by every instance on the registry, and reset() still clears the shared metric and recreates this instance's label set.
  • ContextImpl: the user metrics summary is a 1.x Summary. The admin API keys user_metric_<name>_{sum,count,0.5,0.9,0.99,0.999} and their values are unchanged; a test now pins that.
  • JavaInstanceStarter and LocalRunner serve the registry with the 1.x HTTPServer. The root path / keeps returning metrics text, because the worker fetches instance metrics from there and splices the text into its own /metrics. The 1.x server would otherwise return an HTML page on /. RuntimeUtils.getPrometheusMetrics now asks for /metrics, which every instance version serves.
  • RuntimeUtils.registerDefaultCollectors: the JMX collector is io.prometheus.jmx:collector 1.5.0 (built on client 1.4.1, no new dependencies, same MBean naming). The JVM metrics are the 1.x collectors, registered one by one instead of through JvmMetrics, because JvmMetrics keeps every registry it saw in a static set and LocalRunner creates a registry per start.
  • Removed: the class level Lombok getters and setters on FunctionStatsManager and the unused getProcessLatency* getters, which exposed simpleclient types. Nothing in the repository used them.
  • PrometheusTextFormat stays until the worker PR stops using it.
  • Dependencies: prometheus-jmx 0.16.1 to 1.5.0; pulsar-functions-instance, -runtime and -local-runner-original move from simpleclient to the 1.x artifacts. The HTTP server dependency excludes the full exposition-formats jar and uses the no-protobuf one, the same way the OpenTelemetry Prometheus exporter already in the distribution does, so only one copy of those classes is shipped.

Metric and exposition format changes (for the 5.1 release notes)

Function, sink and source metrics keep their names, labels and values. The text format differs as in #27350: counter # TYPE lines carry _total, _created series are gone, counts are integers, labels are sorted, no trailing comma, and the thread mode text now has # HELP lines.

Two changes are visible to anyone scraping a function instance directly, for example a Kubernetes pod:

  • JVM metrics: 9 names change, jvm_memory_bytes_{used,committed,max,init} to jvm_memory_{used,committed,max,init}_bytes, jvm_memory_pool_bytes_{used,committed,max,init} to jvm_memory_pool_{used,committed,max,init}_bytes, and jvm_info to jvm_runtime_info. Two new families appear, jvm_compilation_time_seconds_total and jvm_memory_pool_allocated_bytes_total. This is the same change the bookie made in [improve][monitor] Restore the BookKeeper Prometheus stats provider on the Prometheus Java client 1.x #26360; the broker, proxy and worker will follow in one PR.
  • JMX: the 216 MBean families are unchanged; jmx_config_reload_success_total and jmx_config_reload_failure_total are new.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:

  • ContextImplTest.testGetMetricsKeys: the user metric keys and values after two recordMetric calls.
  • ComponentStatsManagerTest: names, labels and NaN quantiles of empty summaries on a fresh registry.
  • RuntimeUtilsTest.testRegisterDefaultCollectorsOnFreshRegistries: two fresh registries both get the JVM and JMX families, and the static set in JvmMetrics does not grow.
  • pulsar-functions-instance (189 tests) and pulsar-functions-runtime (95 tests) pass. On the broker side PulsarFunctionE2ETest, PulsarSinkE2ETest, PulsarSourceE2ETest, PulsarBatchSourceE2ETest and PulsarFunctionLocalRunTest (52 tests) pass; they parse the spliced metrics text.
  • A real instance answers / and /metrics with text/plain; version=0.0.4 and the same family set as before, apart from the JVM and JMX changes above.
  • Personal CI: https://github.com/namest504/pulsar/actions/runs/42582324593 (the two failed jobs could not download the Gradle distribution and GraalVM)

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The threading model
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • The metrics
  • Anything that affects deployment

Dependencies: io.prometheus.jmx:collector 0.16.1 to 1.5.0; the Functions instance, runtime and local runner modules replace simpleclient with prometheus-metrics-core, -model, -exposition-textformats, -exporter-httpserver, -instrumentation-jvm 1.8.0 (all already shipped). Metrics: format changes and the JVM and JMX changes listed above.

Documentation

  • doc
  • doc-required
  • doc-not-needed
  • doc-complete

…va client 1.x

FunctionCollectorRegistry now extends PrometheusRegistry; the instance HTTP server, JMX collector 1.5.0 and JvmMetrics register on it. Metric names and labels are unchanged (apache#27045).
The instance endpoint keeps serving metrics on the root path, which the worker scrapes from older instances; the worker now requests /metrics.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants