Skip to content

Comments

feat(engine): rate() aggregate function#19589

Merged
spiridonov merged 10 commits intomainfrom
spiridonov-rate-2
Oct 29, 2025
Merged

feat(engine): rate() aggregate function#19589
spiridonov merged 10 commits intomainfrom
spiridonov-rate-2

Conversation

@spiridonov
Copy link
Contributor

@spiridonov spiridonov commented Oct 24, 2025

What this PR does / why we need it:

This adds rate range aggregation as count_over_time/$interval.

Which issue(s) this PR fixes:
https://github.com/grafana/loki-private/issues/2015

Special notes for your reviewer:

Checklist

  • Reviewed the CONTRIBUTING.md guide (required)
  • Documentation added
  • Tests updated
  • Title matches the required conventional commits format, see here
    • Note that Promtail is considered to be feature complete, and future development for logs collection will be in Grafana Alloy. As such, feat PRs are unlikely to be accepted unless a case can be made for the feature actually being a bug fix to existing behavior.
  • Changes that require user attention or interaction to upgrade are documented in docs/sources/setup/upgrade/_index.md
  • If the change is deprecating or removing a configuration option, update the deprecated-config.yaml and deleted-config.yaml files respectively in the tools/deprecated-config-checker directory. Example PR

@spiridonov spiridonov changed the title feat: rate() aggregate function feat(engine): rate() aggregate function Oct 24, 2025
@spiridonov spiridonov marked this pull request as ready for review October 24, 2025 22:05
@spiridonov spiridonov requested a review from a team as a code owner October 24, 2025 22:05
@spiridonov spiridonov enabled auto-merge (squash) October 24, 2025 22:14
case syntax.OpRangeTypeRate:
// rate is implemented as count_over_time/$interval
builder = builder.BinOpRight(types.BinaryOpDiv, &Literal{
Literal: NewLiteral(params.Interval().Seconds()),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right hand side here should be rangeInterval. For reference:

return rateLogs(r.Left.Interval, r.Left.Unwrap != nil), nil

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the query has unwrap along with rate, left side should be sum_over_time or we can mark this as unimplemented for now

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Did not know about that unwrap with rate. Fixed.

Copy link
Contributor

@ashwanthgoli ashwanthgoli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@spiridonov spiridonov merged commit 2229243 into main Oct 29, 2025
66 checks passed
@spiridonov spiridonov deleted the spiridonov-rate-2 branch October 29, 2025 05:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants