Skip to content

Remove time unit from rate aggregation #126497

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

Merged
merged 2 commits into from
Apr 9, 2025
Merged

Conversation

dnhatn
Copy link
Member

@dnhatn dnhatn commented Apr 9, 2025

Currently, the rate aggregation accepts two parameters: the first specifies the counter field, and the second specifies the time unit of the rate. The time unit parameter was introduced to conveniently compute requests per minute or per hour. However, this can be replaced easily - for example, rate(field, 1minute) with 60 * rate(field).

This change removes the time unit parameter and reserves it for potential future usage, such as introducing a sliding window unit. If we decide on other options later, we can reintroduce it. Removing it now avoids breaking changes while the rate aggregation is not yet available.

@dnhatn dnhatn changed the title Remove time unit from Rate aggregation Remove time unit from rate aggregation Apr 9, 2025
@dnhatn dnhatn force-pushed the remove-rate-unit branch 2 times, most recently from 14e3b97 to 286f847 Compare April 9, 2025 03:44
@dnhatn dnhatn force-pushed the remove-rate-unit branch from 286f847 to 2f4321c Compare April 9, 2025 06:20
@dnhatn dnhatn marked this pull request as ready for review April 9, 2025 06:23
@elasticsearchmachine elasticsearchmachine added Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) Team:StorageEngine labels Apr 9, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-storage-engine (Team:StorageEngine)

@@ -40,26 +49,26 @@ max_cost: double

maxRateAndBytes
required_capability: metrics_command
TS k8s | STATS max(rate(network.total_bytes_in, 1minute)), max(network.bytes_in);
TS k8s | STATS max(60 * rate(network.total_bytes_in)), max(network.bytes_in);
Copy link
Contributor

Choose a reason for hiding this comment

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

I see the point, however I must say rate(network.total_bytes_in, 1minute) reads a little better, especially for longer intervals (such as day).

Should we remove it from the aggregator for simplicity, but have org.elasticsearch.xpack.esql.expression.SurrogateExpression to introduce an optional second argument for time window?

Copy link
Contributor

Choose a reason for hiding this comment

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

In most cases we'd have something like:

TS metrics | STATS max(rate(foo, 1minute)) BY TBUCKET(1minute), hostname

i.e. the rate window matches the bucketing timespan. The second arg should be optional in this case. In the future, we want to support different values between the two; we'll think about the right syntax for that when time comes.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that's why I proposed removing it now and reintroducing it once we have settled on the syntax.

@@ -219,14 +219,14 @@ record RateKey(String cluster, String host) {
assertThat((double) values.get(0).get(0), closeTo(rates.stream().mapToDouble(d -> d).max().orElse(0.0), 0.1));
assertThat((double) values.get(0).get(1), closeTo(rates.stream().mapToDouble(d -> d).min().orElse(0.0), 0.1));
}
try (var resp = run("TS hosts | STATS max(rate(request_count)), avg(rate(request_count)), max(rate(request_count, 1minute))")) {
try (var resp = run("TS hosts | STATS max(rate(request_count)), avg(rate(request_count)), max(60 * rate(request_count))")) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: do we need the 60 * factor? It hurts readability somewhat, can we skip it and update results?

Copy link
Member Author

Choose a reason for hiding this comment

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

++ updated in 7de74a5

Copy link
Contributor

@kkrik-es kkrik-es left a comment

Choose a reason for hiding this comment

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

Just a minor question on testing, thanks Nhat.

Copy link
Member

@martijnvg martijnvg left a comment

Choose a reason for hiding this comment

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

Removing this parameter for now sound good to me.

@dnhatn
Copy link
Member Author

dnhatn commented Apr 9, 2025

Thanks friends!

@dnhatn dnhatn merged commit 7c77ead into elastic:main Apr 9, 2025
17 checks passed
@dnhatn dnhatn deleted the remove-rate-unit branch April 9, 2025 14:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Analytics/ES|QL AKA ESQL >non-issue :StorageEngine/TSDB You know, for Metrics Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) Team:StorageEngine v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants