-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Move time_series aggregation to aggregations module. #91356
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
elasticsearchmachine
merged 4 commits into
elastic:main
from
martijnvg:move_time_series_agg_to_aggregations_module
Nov 8, 2022
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
2821ace
Move time_series aggregation to aggregations module.
martijnvg cd7cb1d
fix some precommit errors
martijnvg 9bfbb87
Merge remote-tracking branch 'es/main' into move_time_series_agg_to_a…
martijnvg 5d5f740
Merge remote-tracking branch 'es/main' into move_time_series_agg_to_a…
martijnvg 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
136 changes: 136 additions & 0 deletions
136
.../internalClusterTest/java/org/elasticsearch/aggregations/bucket/SearchCancellationIT.java
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 |
|---|---|---|
| @@ -0,0 +1,136 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License | ||
| * 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
| * in compliance with, at your election, the Elastic License 2.0 or the Server | ||
| * Side Public License, v 1. | ||
| */ | ||
|
|
||
| package org.elasticsearch.aggregations.bucket; | ||
|
|
||
| import org.elasticsearch.ExceptionsHelper; | ||
| import org.elasticsearch.action.ActionFuture; | ||
| import org.elasticsearch.action.DocWriteRequest; | ||
| import org.elasticsearch.action.bulk.BulkRequestBuilder; | ||
| import org.elasticsearch.action.search.SearchAction; | ||
| import org.elasticsearch.action.search.SearchPhaseExecutionException; | ||
| import org.elasticsearch.action.search.SearchResponse; | ||
| import org.elasticsearch.action.support.WriteRequest; | ||
| import org.elasticsearch.aggregations.AggregationsPlugin; | ||
| import org.elasticsearch.aggregations.bucket.timeseries.TimeSeriesAggregationBuilder; | ||
| import org.elasticsearch.cluster.metadata.IndexMetadata; | ||
| import org.elasticsearch.common.settings.Settings; | ||
| import org.elasticsearch.index.IndexMode; | ||
| import org.elasticsearch.index.IndexSettings; | ||
| import org.elasticsearch.plugins.Plugin; | ||
| import org.elasticsearch.rest.RestStatus; | ||
| import org.elasticsearch.script.Script; | ||
| import org.elasticsearch.script.ScriptType; | ||
| import org.elasticsearch.search.aggregations.metrics.ScriptedMetricAggregationBuilder; | ||
| import org.elasticsearch.test.AbstractSearchCancellationTestCase; | ||
|
|
||
| import java.time.Instant; | ||
| import java.util.ArrayList; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.List; | ||
|
|
||
| import static org.elasticsearch.index.IndexSettings.TIME_SERIES_END_TIME; | ||
| import static org.elasticsearch.index.IndexSettings.TIME_SERIES_START_TIME; | ||
| import static org.elasticsearch.index.query.QueryBuilders.matchAllQuery; | ||
| import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; | ||
| import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertNoFailures; | ||
| import static org.hamcrest.Matchers.containsString; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
|
|
||
| public class SearchCancellationIT extends AbstractSearchCancellationTestCase { | ||
|
|
||
| @Override | ||
| protected Collection<Class<? extends Plugin>> nodePlugins() { | ||
| List<Class<? extends Plugin>> plugins = new ArrayList<>(super.nodePlugins()); | ||
| plugins.add(AggregationsPlugin.class); | ||
| return List.copyOf(plugins); | ||
| } | ||
|
|
||
| public void testCancellationDuringTimeSeriesAggregation() throws Exception { | ||
| List<ScriptedBlockPlugin> plugins = initBlockFactory(); | ||
| int numberOfShards = between(2, 5); | ||
| long now = Instant.now().toEpochMilli(); | ||
| int numberOfRefreshes = between(1, 5); | ||
| // After a few initial checks we check every 2048 - number of shards records so we need to ensure all | ||
| // shards have enough records to trigger a check | ||
| int numberOfDocsPerRefresh = numberOfShards * between(3000, 3500) / numberOfRefreshes; | ||
| assertAcked( | ||
| prepareCreate("test").setSettings( | ||
| Settings.builder() | ||
| .put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, numberOfShards) | ||
| .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) | ||
| .put(IndexSettings.MODE.getKey(), IndexMode.TIME_SERIES.name()) | ||
| .put(IndexMetadata.INDEX_ROUTING_PATH.getKey(), "dim") | ||
| .put(TIME_SERIES_START_TIME.getKey(), now) | ||
| .put(TIME_SERIES_END_TIME.getKey(), now + (long) numberOfRefreshes * numberOfDocsPerRefresh + 1) | ||
| .build() | ||
| ).setMapping(""" | ||
| { | ||
| "properties": { | ||
| "@timestamp": {"type": "date", "format": "epoch_millis"}, | ||
| "dim": {"type": "keyword", "time_series_dimension": true} | ||
| } | ||
| } | ||
| """) | ||
| ); | ||
|
|
||
| for (int i = 0; i < numberOfRefreshes; i++) { | ||
| // Make sure we sometimes have a few segments | ||
| BulkRequestBuilder bulkRequestBuilder = client().prepareBulk().setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE); | ||
| for (int j = 0; j < numberOfDocsPerRefresh; j++) { | ||
| bulkRequestBuilder.add( | ||
| client().prepareIndex("test") | ||
| .setOpType(DocWriteRequest.OpType.CREATE) | ||
| .setSource( | ||
| "@timestamp", | ||
| now + (long) i * numberOfDocsPerRefresh + j, | ||
| "val", | ||
| (double) j, | ||
| "dim", | ||
| String.valueOf(j % 100) | ||
| ) | ||
| ); | ||
| } | ||
| assertNoFailures(bulkRequestBuilder.get()); | ||
| } | ||
|
|
||
| logger.info("Executing search"); | ||
| TimeSeriesAggregationBuilder timeSeriesAggregationBuilder = new TimeSeriesAggregationBuilder("test_agg"); | ||
| ActionFuture<SearchResponse> searchResponse = client().prepareSearch("test") | ||
| .setQuery(matchAllQuery()) | ||
| .addAggregation( | ||
| timeSeriesAggregationBuilder.subAggregation( | ||
| new ScriptedMetricAggregationBuilder("sub_agg").initScript( | ||
| new Script(ScriptType.INLINE, "mockscript", ScriptedBlockPlugin.INIT_SCRIPT_NAME, Collections.emptyMap()) | ||
| ) | ||
| .mapScript( | ||
| new Script(ScriptType.INLINE, "mockscript", ScriptedBlockPlugin.MAP_BLOCK_SCRIPT_NAME, Collections.emptyMap()) | ||
| ) | ||
| .combineScript( | ||
| new Script(ScriptType.INLINE, "mockscript", ScriptedBlockPlugin.COMBINE_SCRIPT_NAME, Collections.emptyMap()) | ||
| ) | ||
| .reduceScript( | ||
| new Script(ScriptType.INLINE, "mockscript", ScriptedBlockPlugin.REDUCE_FAIL_SCRIPT_NAME, Collections.emptyMap()) | ||
| ) | ||
| ) | ||
| ) | ||
| .execute(); | ||
| awaitForBlock(plugins); | ||
| cancelSearch(SearchAction.NAME); | ||
| disableBlocks(plugins); | ||
|
|
||
| SearchPhaseExecutionException ex = expectThrows(SearchPhaseExecutionException.class, searchResponse::actionGet); | ||
| assertThat(ExceptionsHelper.status(ex), equalTo(RestStatus.BAD_REQUEST)); | ||
| logger.info("All shards failed with", ex); | ||
| if (lowLevelCancellation) { | ||
| // Ensure that we cancelled in TimeSeriesIndexSearcher and not in reduce phase | ||
| assertThat(ExceptionsHelper.stackTrace(ex), containsString("TimeSeriesIndexSearcher")); | ||
| } | ||
| } | ||
| } | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably fine to just return
plugins?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test also needs a plugin from the super class. This is the test plugin that allows for testing the cancellation.