Skip to content

Add Support for Prometheus Metrics #8130

Closed
@checketts

Description

@checketts

Improve DefaultCacheStatistics and MetricFilter to track metrics that can be useful to Prometheus integrations.

Prometheus takes a different approach with metrics. There are 3 changes that are fundamentally different from other libraries like DropWizard.

Labels (multi-dimensional metrics)

Instead of hierarchical metrics like counter.status.200.metrics and gauge.response.metrics for tracking endpoint requests and latency, Prometheus would expose a metric named like http_requests{status="200", path="metrics"} and http_requests_latency_seconds{path="metrics"}. While both metrics' names contain the same data, aggregation uses methods like sum(counter.status.200.*) to find how many requests are occurring. The Prometheus equivalent (sum(http_requests) by (status)) allows breaking them out by status code very easily and avoiding hierarchical limitations.

Track counters, not rates or ratios

Prometheus also surfaces metrics as raw total and calculates the ratios and rates on the Prometheus server side, via its query language.

This makes metrics collection simpler on the client side (just incrementing a double) and more powerful. Take the current DefaultCacheStatistics as an example. It exposes a caches.<cacheName>.hit.ratio and a .miss.ratio. The Prometheus approach of having metrics like cache_request_total{cache="<cacheName>", result="hit"} keeps the tracking simpler, but allows for queries like rate(cache_request_total[1m]) to see how often the cache is being hit.

Pull Model for metrics collection

DropWizard/statsd approaches push metrics out from a service. Prometheus calls the service and collects the metrics from a service endpoint (similar to the /metrics endpoint supplied by actuator).

Proposal

I'm working on a pull request to add in Prometheus support to Spring boot Actuator. I want to keep the result simple so it can fit in with the existing Spring Boot metrics (and so it will be simple for the Spring Boot team to review and accept).

Right now there is a Prometheus simpleclient_spring_boot that add in an actuator endpoint. Unfortunately any raw copying of Spring Boot PublicMetrics and exposing them as Prometheus metrics causes more noise than useful metrics. I'll iterate with the Prometheus client to see if we can pull out metrics in a useful way, in the meantime I wanted to try to improve the existing interfaces to better expose data so the Prometheus extensions can connect in completely.

On Gitter @dsyer mentioned interest in multi-dimensional metrics with Spring Boot 2. Is that something I could actively contribute to? Should I treat all interfaces declared as unchangeable or would adding methods be allowed (Like the CounterService for example)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions