Skip to content

feat(query): histogram_avg PromQL function - #2302

Open
saathvikrv wants to merge 7 commits into
filodb:developfrom
saathvikrv:hist-avg3
Open

feat(query): histogram_avg PromQL function#2302
saathvikrv wants to merge 7 commits into
filodb:developfrom
saathvikrv:hist-avg3

Conversation

@saathvikrv

@saathvikrv saathvikrv commented Jul 5, 2026

Copy link
Copy Markdown

Pull Request checklist

  • The commit(s) message(s) follows the contribution guidelines ?
  • Tests for the changes have been added (for bug fixes / features) ?
  • Docs have been added / updated (for bug fixes / features) ?

Current behavior : (link exiting issues here : https://help.github.com/articles/basic-writing-and-formatting-syntax/#referencing-issues-and-pull-requests)

PromQL Query to calculate average from histogram time series:
sum(rate(http_request_latency::sum{_ns_="App-0",_ws_="demo"}[5m])) / sum(rate(http_request_latency::count{_ns_="App-0",_ws_="demo"}[5m]))

  • MSPE executes twice, unnecessary computation
  • Long query, less user friendly

New behavior :

Implemented new PromQL aggregation function - havg
New Query: histogram_avg(rate(http_request_latency{_ns_="App-0",_ws_="demo"}[5m]))

  • Much more user readable
  • Fetches sum and count together in the same scan to get better performance
  • Adheres to official PromQL function syntax

Testing :

  • Unit tests added for histogram_avg function
  • Unit tests added for Double-Double schema cumulative and delta rate and increase range functions. These tests were added using Claude code
  • Manual integration using 2 FiloServers in asper dev setup; Ensured that the above two queries have the same result

Benchmark Results :

[info] Benchmark                                                   Mode  Cnt    Score   Error  Units
[info] Base2ExponentialHistogramQueryBenchmark.histAvgNewQueries  thrpt    2  730.126          ops/s
[info] Base2ExponentialHistogramQueryBenchmark.histAvgOldQueries  thrpt    2  423.102          ops/s

Acknowledgments to @vishramachandran who mentored me with this project.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant