Skip to content

Aggregation of t-digest types broken by default #225

Open

Description

@vincentwoo

In practice, summary data in prometheus can be hard to aggregate, because they lose a bit of data. I've been using a custom IPC setup to push summary data generated on workers to a master's summary metric to avoid integration. However, this is cumbersome and I'd like to use the default metrics aggregator provided by prom-client. Can you speak to how this works in practice? It's a bit difficult for me to figure out.

Activity

  1. SimenB commented on Oct 14, 2018

    @SimenB
    Contributor

    I'm not sure what concretely you're asking? Are you asking how the aggregation works in this library before the scrape by prometheus?

    I'm also not sure what "worker" and "master" is here. Child process? Cluster? The new Worker in node 10?

  2. vincentwoo commented on Oct 14, 2018

    @vincentwoo
    Author

    Yes, sorry for not writing that as well as I could have. I am asking about node's cluster module and specifically about how the summary instrument is aggregated in response to a Prometheus scrape. It seems like the cluster master sends an IPC request to each of the workers, but I'm not sure how the math works out. Other instrument types have straightforward ways to be aggregated, so I'm just curious if anything special needs to be done for summary.

    I was motivated because after I switched to using the default aggregator registry for my summary metric, I noticed my metrics looked very different (several times higher in most quantiles.

  3. SimenB commented on Oct 15, 2018

    @SimenB
    Contributor
  4. zbjornson commented on Oct 15, 2018

    @zbjornson
    Contributor

    I think histograms and summaries behave the same as counters (which sum by default) within each individual sum/bucket. Tomorrow I can test to be sure.

  5. vincentwoo commented on Oct 15, 2018

    @vincentwoo
    Author

    Ah, I think you are correct. Here's a test script:

    const cluster = require('cluster')
    const Prometheus = require('prom-client')
    
    if (cluster.isMaster) {
      for (let i = 0; i < 3; i++) {
        cluster.fork()
      }
      const metricsServer = require('express')()
      const aggregatorRegistry = new Prometheus.AggregatorRegistry()
      metricsServer.get('/metrics', function(req, res) {
        aggregatorRegistry.clusterMetrics((err, metrics) => {
          res.set('Content-Type', aggregatorRegistry.contentType)
          res.end(metrics)
        })
      })
      metricsServer.listen(8000)
    } else {
      const summary = new Prometheus.Summary({
        name: 'test',
        help: 'test'
      })
      summary.observe(1)
    }
    

    And the output:

    $ curl http://localhost:8000/metrics
    # HELP test test
    # TYPE test summary
    test{quantile="0.01"} 3
    test{quantile="0.05"} 3
    test{quantile="0.5"} 3
    test{quantile="0.9"} 3
    test{quantile="0.95"} 3
    test{quantile="0.99"} 3
    test{quantile="0.999"} 3
    test_sum 3
    test_count 3
    

    I think this is probably not the behavior people would expect with default aggregation. I believe that summaries and histograms used the t-digest primitive, which appears to be built to be combined. If so, it seems like we could send the t-digest data over when summaries need to be aggregated.

    Alternatively, might it be better for the library to do something under-the-covers where the master worker holds the "real" in-memory instrument, and the worker nodes, when observing measurements, merely pass those measurements over IPC to the master?

  6. zbjornson commented on Oct 17, 2018

    @zbjornson
    Contributor

    Unfortunately I know very little about how histogram and summary metrics work. Both of the options you suggested in your last two paragraphs sound reasonable though. @brian-brazil, @SimenB or @siimon might know what the best approach. Definitely sounds like something to fix.

  7. brian-brazil commented on Oct 17, 2018

    @brian-brazil

    Those quantiles aren't right, they should all be 1 given that input.

  8. zbjornson commented on Oct 17, 2018

    @zbjornson
    Contributor

    We're wondering what the best way to correct that is: send T-digest data for combining on the master, or sending the individual, pre-sum data for summing/combining on the master?

    I think summing is the correct thing to do for histograms (since it's reporting absolute counts in each bin), so just summaries need to be corrected.

  9. vincentwoo commented on Oct 18, 2018

    @vincentwoo
    Author

    I think one problem is that the t-digest may be kinda large, so serializing/deserializing on every prometheus request is a bit rough. I think having prom-client perform under-the-cover IPC for observations for all metrics is probably better.

  10. vincentwoo commented on Oct 30, 2018

    @vincentwoo
    Author

    Any consensus on approach?

  11. atd-schubert commented on Dec 28, 2018

    @atd-schubert
    Contributor

    There is also a leaking behavior in the solution with t-digest like I described in #142 .

  12. changed the title [-]Clarifying question regarding summary aggregation[/-] [+]Aggregation of t-digest types broken by default[/+] on Sep 27, 2020
  13. vincentwoo commented on Sep 27, 2020

    @vincentwoo
    Author

    I renamed the title to be a bit more on the mark and am bumping the thread! Any news?

  14. jdmarshall commented on Sep 3, 2026

    @jdmarshall
    Contributor

    Based on my slightly limited knowledge of summaries and larger knowledge of histograms, I believe the given example is misleading and thus misinforming @brian-brazil's characterization of the problem. Although I'm really finding that the https://github.com/prometheus/OpenMetrics/blob/main/specification/OpenMetrics.md#summary specification is inadequate to the tasks of implementers.

    Histograms and summaries are both lossy collection mechanisms. Full stop. They are orders of magnitude less lossy than gauges, but still lossy. I found out much as you did, when someone sold me on histograms as being more accurate than statsd,s averages of averages and found at the end that I'd been duped. It's still an average of averages, because each bucket is an average of the samples contained within it. If you need better resolution, the only solution I can recommend is using higher cardinality and sampling rate on the particular values you're collecting. But that is generally frowned upon.

  15. vincentwoo commented on Sep 3, 2026

    @vincentwoo
    Author
  16. jdmarshall commented on Sep 4, 2026

    @jdmarshall
    Contributor

    @vincentwoo It looks as though the client_js implementation is profoundly different than the ruby and python implementations, both of which are just count and sum, which is on a par with the OpenMetrics link I cited above.

    Those can be aggregated via the sum operator.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions