Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

metric: add prometheus-based histogram #85990

Merged
merged 2 commits into from
Aug 26, 2022

Commits on Aug 26, 2022

  1. metric: add prometheus-based histogram

    Our current histogram is based on `hdrhistogram`. This tends to create
    lots of buckets and is inflexible w.r.t the bucket layout. In hindsight,
    it was a poor choice of default implementation (I can say that since I
    introduced it) and its cost is disincentivizing the introduction of
    histograms that would be useful.
    
    This commit introduces a histogram that is based on a completely vanilla
    `prometheus.Histogram`. The only reason we need to wrap it is because we
    want to export quantiles to CockraochDB's internal timeseries (it does
    not support histograms) and this requires maintaining an internal windowed
    histogram (on top of the cumulative histogram).
    
    With this done, we can now introduce metrics with any kind of buckets we
    want. Helpfully, we introduce two common kinds of buckets, suitable for
    IO-type and RPC-type latencies. These are defined in a human-readable
    format by explicitly listing out the buckets.
    
    We can move existing metrics to HistogramV2 easily, assuming we are not
    concerned with existing prometheus scrapers getting tripped up by the
    changes in bucket boundaries. I assume this is not a big deal in
    practice as long as it doesn't happen "all the time". In fact, I would
    strongly suggest we move all metrics wholesale and remove the
    hdrhistogram-based implementation. If this is not acceptable for some
    reason, we ought to at least deprecated it.
    
    We also slightly improve the existing `Histogram` code by unifying how
    the windowed histograms are ticked and by making explicit where their
    quantiles are recorded (this dependency was previously hidden via a
    local interface assertion).
    
    Resolves cockroachdb#10015.
    Resolves cockroachdb#64962.
    Alternative to dhartunian@eac3d06
    
    TODO
    - export quantiles (how to do this? Not clear, don't see the code
      laying around in prometheus, might have to hand-roll it but should
      be easy enough)
    
    Release note: None
    tbg authored and aadityasondhi committed Aug 26, 2022
    Configuration menu
    Copy the full SHA
    eb82a43 View commit details
    Browse the repository at this point in the history
  2. metric: export quantiles from prometheus-based histogram

    This change builds on the previous one and adds a function to export
    quantiles from the Prometheus-based histogram. This functionality is
    used to store histogram data in the internal timeseries database. The
    hdr library came with a function to do this, while Prometheus does not
    have a public API for exporting quantiles.
    
    The function implemented here is very similar to the one found
    internally in Prometheus, using linear interpolation to calculate values
    at a given quantile.
    
    This commit also includes some additional testing and general
    refactoring of the metrics code.
    
    Release note: None
    
    Release justification: low risk, high benefit changes
    aadityasondhi committed Aug 26, 2022
    Configuration menu
    Copy the full SHA
    d7d5838 View commit details
    Browse the repository at this point in the history