Skip to content

Fix bug when formatting epoch dates#73955

Merged
not-napoleon merged 11 commits intoelastic:masterfrom
not-napoleon:docvalueformat-epoch-seconds-tz
Jun 15, 2021
Merged

Fix bug when formatting epoch dates#73955
not-napoleon merged 11 commits intoelastic:masterfrom
not-napoleon:docvalueformat-epoch-seconds-tz

Conversation

@not-napoleon
Copy link
Copy Markdown
Member

@not-napoleon not-napoleon commented Jun 9, 2021

Resolves #68963

Date based aggregations accept a timezone, which gets applied to both the bucketing logic and the formatter. This is usually what you want, but in the case of date formats where a timezone doesn't make any sense, it can create problems. In particular, our formatting logic and our parsing logic were doing different things for epoch_second and epoch_millis formats with time zones. This led to a problem on composite where we'd return an after key for the last bucket that would parse to a time before the last bucket, so instead of correctly returning an empty response to indicate the end of the aggregation, we'd keep returning the same last page of data.

The proposed fix here is to always coerce the timezone to UTC for formatters only when using an epoch-based format. This aligns with the general expectation that epoch time is always UTC based.

Turns out we just need to make the formatter timezone aware.

@not-napoleon not-napoleon added >bug v8.0.0 Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v7.14.0 :Analytics/CompositeAggs labels Jun 9, 2021
@elasticmachine
Copy link
Copy Markdown
Collaborator

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

@not-napoleon not-napoleon changed the title Force epoch date formats to use UTC for aggregations Fix bug when formatting epoch dates Jun 14, 2021
Copy link
Copy Markdown
Contributor

@imotov imotov 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.timeZone = Objects.requireNonNull(timeZone);
this.parser = formatter.toDateMathParser();
this.formatter = formatter.withZone(timeZone);
this.parser = this.formatter.toDateMathParser();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

That's a good one 😄

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Credit to Przemyslaw who spotted it. I was just going to force it to UTC.

Copy link
Copy Markdown
Contributor

@pgomulka pgomulka left a comment

Choose a reason for hiding this comment

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

LGTM

@pgomulka
Copy link
Copy Markdown
Contributor

@elasticmachine update branch

@not-napoleon
Copy link
Copy Markdown
Member Author

@elasticmachine update branch

@not-napoleon not-napoleon merged commit e6c5688 into elastic:master Jun 15, 2021
@not-napoleon not-napoleon deleted the docvalueformat-epoch-seconds-tz branch June 15, 2021 16:20
not-napoleon added a commit to not-napoleon/elasticsearch that referenced this pull request Jun 15, 2021
Date based aggregations accept a timezone, which gets applied to both the bucketing logic and the formatter. This is usually what you want, but in the case of date formats where a timezone doesn't make any sense, it can create problems. In particular, our formatting logic and our parsing logic were doing different things for epoch_second and epoch_millis formats with time zones. This led to a problem on composite where we'd return an after key for the last bucket that would parse to a time before the last bucket, so instead of correctly returning an empty response to indicate the end of the aggregation, we'd keep returning the same last page of data.
not-napoleon added a commit that referenced this pull request Jun 15, 2021
Date based aggregations accept a timezone, which gets applied to both the bucketing logic and the formatter. This is usually what you want, but in the case of date formats where a timezone doesn't make any sense, it can create problems. In particular, our formatting logic and our parsing logic were doing different things for epoch_second and epoch_millis formats with time zones. This led to a problem on composite where we'd return an after key for the last bucket that would parse to a time before the last bucket, so instead of correctly returning an empty response to indicate the end of the aggregation, we'd keep returning the same last page of data.
not-napoleon added a commit that referenced this pull request Jun 15, 2021
* Fix bug when formatting epoch dates (#73955)

Date based aggregations accept a timezone, which gets applied to both the bucketing logic and the formatter. This is usually what you want, but in the case of date formats where a timezone doesn't make any sense, it can create problems. In particular, our formatting logic and our parsing logic were doing different things for epoch_second and epoch_millis formats with time zones. This led to a problem on composite where we'd return an after key for the last bucket that would parse to a time before the last bucket, so instead of correctly returning an empty response to indicate the end of the aggregation, we'd keep returning the same last page of data.

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

Labels

>bug Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v7.13.3 v7.14.0 v8.0.0-alpha1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

incorrect pagination with date_histogram and format in composite aggregation

5 participants