Skip to content

Conversation

@salvatore-campagna
Copy link
Contributor

@salvatore-campagna salvatore-campagna commented Jun 6, 2023

Here we include support for the unit parameter to the time series rate aggregation. Parsing the field
was already there, we just make use of it so that calculation of the rate is done using the right temporal
unit, instead of just using seconds. Before this change the rate was calculated using the number of milliseconds
at the denominator later scaled to seconds. Now we scale that interval to whatever unit the user provides as unit. Supported values include: second, minute, hour, day, week, month, quarter and year.

We fix a bug too. Results were returned as value / time interval (milliseconds) while all tests were written as if
result was returned as value / time interval (seconds). We need to multiply everything by 1000 (milliseconds in 1 second).

Resolves #94630

@elasticsearchmachine elasticsearchmachine added needs:triage Requires assignment of a team area label v8.9.0 labels Jun 6, 2023
@salvatore-campagna salvatore-campagna added >enhancement :StorageEngine/TSDB You know, for Metrics and removed needs:triage Requires assignment of a team area label labels Jun 6, 2023
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytics-geo (Team:Analytics)

@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Jun 6, 2023
@elasticsearchmachine
Copy link
Collaborator

Hi @salvatore-campagna, I've created a changelog YAML for you.

@salvatore-campagna salvatore-campagna changed the title feature: include unit support for time series rate aggregation Include unit support for time series rate aggregation Jun 6, 2023
@elasticsearchmachine
Copy link
Collaborator

Hi @salvatore-campagna, I've updated the changelog YAML for you.

@salvatore-campagna
Copy link
Contributor Author

Will fix the issue with TransportVersion right before merging the PR.

@Override
public double value() {
return (endValue - startValue + resetCompensation) / (endTime - startTime);
long rateUnitSeconds = rateUnit == null
Copy link
Member

Choose a reason for hiding this comment

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

Can rateUnit be null? Looks like this change falls back to use Rounding.DateTimeUnit.SECOND_OF_MINUTE when no rate is specified.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it can be...after deserialization for instance...especially if deserializing from the previous version...right?

Copy link
Member

Choose a reason for hiding this comment

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

On line 67 the rateUnit field is initialised with Rounding.DateTimeUnit.SECOND_OF_MINUTE if from older versions, right?

assertThat(reduced, instanceOf(Rate.class));
assertThat(((Rate) reduced).getValue(), equalTo(0.01));
public void testReductionSecond() {
testReduction(Rounding.DateTimeUnit.SECOND_OF_MINUTE, 0.01);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the existing test returning 0.01 when unit = second (the default).

All other tests just check the result multiplying by 60, 60, 24 and so on...

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.

LGTM

this.startTimes = bigArrays().newLongArray(1, true);
this.endTimes = bigArrays().newLongArray(1, true);
this.resetCompensations = bigArrays().newDoubleArray(1, true);
this.rateUnit = rateUnit;
Copy link
Member

Choose a reason for hiding this comment

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

Maybe just do rateUnit == null ? Rounding.DateTimeUnit.SECOND_OF_MINUTE : rateUnit here?

@martijnvg
Copy link
Member

I do think the main branch need to be merged in and a new transport version needs to be added.

@salvatore-campagna
Copy link
Contributor Author

I do think the main branch need to be merged in and a new transport version needs to be added.

Yes...but I prefer waiting right before merging otherwise it might end up that I need to do it multiple times just because someone else is changing it.

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.

LGTM

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

Labels

>enhancement :StorageEngine/TSDB You know, for Metrics Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.9.0

3 participants