-
Notifications
You must be signed in to change notification settings - Fork 25.3k
[Rollup] Validate timezones based on rules not string comparision #36237
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
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
9037c4a
[Rollup] Compare timezones based on rules not string comparision
polyfractal cc6563e
Fix timestamps in test
polyfractal 4867d99
Use ZoneId
polyfractal 1ef04f0
Merge remote-tracking branch 'origin/master' into rollup_obsolete_tz
polyfractal da7ebe3
Fix test
polyfractal 21a38f5
Merge remote-tracking branch 'origin/master' into rollup_obsolete_tz
polyfractal aadf68b
Deprecation warnings when using obsolete timezones
polyfractal 38ca541
Merge remote-tracking branch 'origin/master' into rollup_obsolete_tz
polyfractal ef0f695
Switch DateHistoConfig over to ZoneId
polyfractal d41dda4
Merge remote-tracking branch 'origin/master' into rollup_obsolete_tz
polyfractal d049fea
Test fix: searching the wrong index
polyfractal e9f42ef
checkstyle
polyfractal 1f7802f
ML needs to use zones instead of strings too
polyfractal 5a2cac4
Revert "Switch DateHistoConfig over to ZoneId"
polyfractal 72a1bed
Fix rule matching
polyfractal 94abbeb
Add test for TZ validation in action
polyfractal d573aef
Merge remote-tracking branch 'origin/master' into rollup_obsolete_tz
polyfractal feba7e5
Yml test version updates
polyfractal 9f4aada
Merge remote-tracking branch 'origin/master' into rollup_obsolete_tz
polyfractal de22b2f
Remove last traces of Joda
polyfractal b88091b
Do not set timezone on rollup request histo
polyfractal d80e035
Merge remote-tracking branch 'origin/master' into rollup_obsolete_tz
polyfractal 83bf9bf
Merge remote-tracking branch 'origin/master' into rollup_obsolete_tz
polyfractal fbda167
checkstyle
polyfractal 8822afd
Fix tests, make more realistic
polyfractal a9f2911
Remove unnecessary changes
polyfractal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,8 +11,6 @@ | |
import org.elasticsearch.common.io.stream.NamedWriteableAwareStreamInput; | ||
import org.elasticsearch.common.io.stream.NamedWriteableRegistry; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.index.query.QueryBuilder; | ||
import org.elasticsearch.index.query.TermQueryBuilder; | ||
import org.elasticsearch.search.aggregations.AggregationBuilder; | ||
import org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder; | ||
import org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder; | ||
|
@@ -22,8 +20,8 @@ | |
import org.elasticsearch.search.aggregations.support.ValuesSourceAggregationBuilder; | ||
import org.elasticsearch.xpack.core.rollup.RollupField; | ||
import org.elasticsearch.xpack.core.rollup.job.DateHistogramGroupConfig; | ||
import org.joda.time.DateTimeZone; | ||
|
||
import java.time.ZoneId; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
@@ -47,7 +45,7 @@ | |
* }</pre> | ||
* | ||
* | ||
* The only publicly "consumable" API is {@link #translateAggregation(AggregationBuilder, List, NamedWriteableRegistry)}. | ||
* The only publicly "consumable" API is {@link #translateAggregation(AggregationBuilder, NamedWriteableRegistry)}. | ||
*/ | ||
public class RollupRequestTranslator { | ||
|
||
|
@@ -116,26 +114,22 @@ public class RollupRequestTranslator { | |
* relevant method below. | ||
* | ||
* @param source The source aggregation to translate into rollup-enabled version | ||
* @param filterConditions A list used to track any filter conditions that sub-aggs may | ||
* require. | ||
* @param registry Registry containing the various aggregations so that we can easily | ||
* deserialize into a stream for cloning | ||
* @return Returns the fully translated aggregation tree. Note that it returns a list instead | ||
* of a single AggBuilder, since some aggregations (e.g. avg) may result in two | ||
* translated aggs (sum + count) | ||
*/ | ||
public static List<AggregationBuilder> translateAggregation(AggregationBuilder source, | ||
List<QueryBuilder> filterConditions, | ||
NamedWriteableRegistry registry) { | ||
public static List<AggregationBuilder> translateAggregation(AggregationBuilder source, NamedWriteableRegistry registry) { | ||
|
||
if (source.getWriteableName().equals(DateHistogramAggregationBuilder.NAME)) { | ||
return translateDateHistogram((DateHistogramAggregationBuilder) source, filterConditions, registry); | ||
return translateDateHistogram((DateHistogramAggregationBuilder) source, registry); | ||
} else if (source.getWriteableName().equals(HistogramAggregationBuilder.NAME)) { | ||
return translateHistogram((HistogramAggregationBuilder) source, filterConditions, registry); | ||
return translateHistogram((HistogramAggregationBuilder) source, registry); | ||
} else if (RollupField.SUPPORTED_METRICS.contains(source.getWriteableName())) { | ||
return translateVSLeaf((ValuesSourceAggregationBuilder.LeafOnly)source, registry); | ||
} else if (source.getWriteableName().equals(TermsAggregationBuilder.NAME)) { | ||
return translateTerms((TermsAggregationBuilder)source, filterConditions, registry); | ||
return translateTerms((TermsAggregationBuilder)source, registry); | ||
} else { | ||
throw new IllegalArgumentException("Unable to translate aggregation tree into Rollup. Aggregation [" | ||
+ source.getName() + "] is of type [" + source.getClass().getSimpleName() + "] which is " + | ||
|
@@ -195,22 +189,13 @@ public static List<AggregationBuilder> translateAggregation(AggregationBuilder s | |
* <li>Field: `{timestamp field}.date_histogram._count`</li> | ||
* </ul> | ||
* </li> | ||
* <li>Add a filter condition:</li> | ||
* <li> | ||
* <ul> | ||
* <li>Query type: TermQuery</li> | ||
* <li>Field: `{timestamp_field}.date_histogram.interval`</li> | ||
* <li>Value: `{source interval}`</li> | ||
* </ul> | ||
* </li> | ||
* </ul> | ||
* | ||
*/ | ||
private static List<AggregationBuilder> translateDateHistogram(DateHistogramAggregationBuilder source, | ||
List<QueryBuilder> filterConditions, | ||
NamedWriteableRegistry registry) { | ||
|
||
return translateVSAggBuilder(source, filterConditions, registry, () -> { | ||
return translateVSAggBuilder(source, registry, () -> { | ||
DateHistogramAggregationBuilder rolledDateHisto | ||
= new DateHistogramAggregationBuilder(source.getName()); | ||
|
||
|
@@ -220,13 +205,9 @@ private static List<AggregationBuilder> translateDateHistogram(DateHistogramAggr | |
rolledDateHisto.interval(source.interval()); | ||
} | ||
|
||
String timezone = source.timeZone() == null ? DateTimeZone.UTC.toString() : source.timeZone().toString(); | ||
filterConditions.add(new TermQueryBuilder(RollupField.formatFieldName(source, | ||
DateHistogramGroupConfig.TIME_ZONE), timezone)); | ||
ZoneId timeZone = source.timeZone() == null ? DateHistogramGroupConfig.DEFAULT_ZONEID_TIMEZONE : source.timeZone(); | ||
rolledDateHisto.timeZone(timeZone); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: this has the change of always setting a timezone. The only practical change is that UTC will be explicitly set now instead of implicit. Every other timezone will be the same. I figured this would make debugging a bit easier since there will always be a timezone. |
||
|
||
if (source.timeZone() != null) { | ||
rolledDateHisto.timeZone(source.timeZone()); | ||
} | ||
rolledDateHisto.offset(source.offset()); | ||
if (source.extendedBounds() != null) { | ||
rolledDateHisto.extendedBounds(source.extendedBounds()); | ||
|
@@ -248,14 +229,13 @@ private static List<AggregationBuilder> translateDateHistogram(DateHistogramAggr | |
* Notably, it adds a Sum metric to calculate the doc_count in each bucket. | ||
* | ||
* Conventions are identical to a date_histogram (excepting date-specific details), so see | ||
* {@link #translateDateHistogram(DateHistogramAggregationBuilder, List, NamedWriteableRegistry)} for | ||
* {@link #translateDateHistogram(DateHistogramAggregationBuilder, NamedWriteableRegistry)} for | ||
* a complete list of conventions, examples, etc | ||
*/ | ||
private static List<AggregationBuilder> translateHistogram(HistogramAggregationBuilder source, | ||
List<QueryBuilder> filterConditions, | ||
NamedWriteableRegistry registry) { | ||
|
||
return translateVSAggBuilder(source, filterConditions, registry, () -> { | ||
return translateVSAggBuilder(source, registry, () -> { | ||
HistogramAggregationBuilder rolledHisto | ||
= new HistogramAggregationBuilder(source.getName()); | ||
|
||
|
@@ -328,10 +308,9 @@ private static List<AggregationBuilder> translateHistogram(HistogramAggregationB | |
* | ||
*/ | ||
private static List<AggregationBuilder> translateTerms(TermsAggregationBuilder source, | ||
List<QueryBuilder> filterConditions, | ||
NamedWriteableRegistry registry) { | ||
|
||
return translateVSAggBuilder(source, filterConditions, registry, () -> { | ||
return translateVSAggBuilder(source, registry, () -> { | ||
TermsAggregationBuilder rolledTerms | ||
= new TermsAggregationBuilder(source.getName(), source.valueType()); | ||
rolledTerms.field(RollupField.formatFieldName(source, RollupField.VALUE)); | ||
|
@@ -359,8 +338,6 @@ private static List<AggregationBuilder> translateTerms(TermsAggregationBuilder s | |
* ValueSourceBuilder. This method is called by all the agg-specific methods (e.g. translateDateHistogram()) | ||
* | ||
* @param source The source aggregation that we wish to translate | ||
* @param filterConditions A list of existing filter conditions, in case we need to add some | ||
* for this particular agg | ||
* @param registry Named registry for serializing leaf metrics. Not actually used by this method, | ||
* but is passed downwards for leaf usage | ||
* @param factory A factory closure that generates a new shallow clone of the `source`. E.g. if `source` is | ||
|
@@ -371,15 +348,14 @@ private static List<AggregationBuilder> translateTerms(TermsAggregationBuilder s | |
* @return the translated multi-bucket ValueSourceAggBuilder | ||
*/ | ||
private static <T extends ValuesSourceAggregationBuilder> List<AggregationBuilder> | ||
translateVSAggBuilder(ValuesSourceAggregationBuilder source, List<QueryBuilder> filterConditions, | ||
NamedWriteableRegistry registry, Supplier<T> factory) { | ||
translateVSAggBuilder(ValuesSourceAggregationBuilder source, NamedWriteableRegistry registry, Supplier<T> factory) { | ||
|
||
T rolled = factory.get(); | ||
|
||
// Translate all subaggs and add to the newly translated agg | ||
// NOTE: using for loop instead of stream because compiler explodes with a bug :/ | ||
for (AggregationBuilder subAgg : source.getSubAggregations()) { | ||
List<AggregationBuilder> translated = translateAggregation(subAgg, filterConditions, registry); | ||
List<AggregationBuilder> translated = translateAggregation(subAgg, registry); | ||
for (AggregationBuilder t : translated) { | ||
rolled.subAggregation(t); | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.