Skip to content

Commit

Permalink
Emit deprecation warning when executing one of the rollup APIs (#112807)
Browse files Browse the repository at this point in the history
Currently none of the rollup APIs deprecation warning. Only the reference docs indicate that rollup has been deprecated.

Relates to #112690
  • Loading branch information
martijnvg committed Sep 17, 2024
1 parent d7b90e1 commit fb9261d
Show file tree
Hide file tree
Showing 32 changed files with 336 additions and 24 deletions.
27 changes: 18 additions & 9 deletions docs/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,9 @@ buildRestTests.setups['library'] = '''
'''
buildRestTests.setups['sensor_rollup_job'] = '''
- requires:
test_runner_features: [ "allowed_warnings" ]
- do:
indices.create:
index: dummy-rollup-index
Expand Down Expand Up @@ -883,9 +886,10 @@ buildRestTests.setups['sensor_rollup_job'] = '''
node:
type: keyword
- do:
raw:
method: PUT
path: _rollup/job/sensor
allowed_warnings:
- "The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information."
rollup.put_job:
id: sensor
body: >
{
"index_pattern": "sensor-*",
Expand Down Expand Up @@ -915,6 +919,9 @@ buildRestTests.setups['sensor_rollup_job'] = '''
}
'''
buildRestTests.setups['sensor_started_rollup_job'] = '''
- requires:
test_runner_features: [ "allowed_warnings" ]
- do:
indices.create:
index: dummy-rollup-index
Expand Down Expand Up @@ -964,9 +971,10 @@ buildRestTests.setups['sensor_started_rollup_job'] = '''
{"timestamp": 1516297294000, "temperature": 202, "voltage": 4.0, "node": "c"}
- do:
raw:
method: PUT
path: _rollup/job/sensor
allowed_warnings:
- "The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information."
rollup.put_job:
id: sensor
body: >
{
"index_pattern": "sensor-*",
Expand Down Expand Up @@ -995,9 +1003,10 @@ buildRestTests.setups['sensor_started_rollup_job'] = '''
]
}
- do:
raw:
method: POST
path: _rollup/job/sensor/_start
allowed_warnings:
- "The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information."
rollup.start_job:
id: sensor
'''

buildRestTests.setups['sensor_index'] = '''
Expand Down
1 change: 1 addition & 0 deletions docs/reference/rollup/apis/delete-job.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ If we have a rollup job named `sensor`, it can be deleted with:
DELETE _rollup/job/sensor
--------------------------------------------------
// TEST[setup:sensor_rollup_job]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]

Which will return the response:

Expand Down
2 changes: 2 additions & 0 deletions docs/reference/rollup/apis/get-job.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ job can be retrieved with:
GET _rollup/job/sensor
--------------------------------------------------
// TEST[setup:sensor_rollup_job]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]

The API yields the following response:

Expand Down Expand Up @@ -192,6 +193,7 @@ PUT _rollup/job/sensor2 <1>
GET _rollup/job/_all <2>
--------------------------------------------------
// TEST[setup:sensor_rollup_job]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]
<1> We create a second job with name `sensor2`
<2> Then request all jobs by using `_all` in the GetJobs API

Expand Down
1 change: 1 addition & 0 deletions docs/reference/rollup/apis/put-job.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ PUT _rollup/job/sensor
}
--------------------------------------------------
// TEST[setup:sensor_index]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]
<1> This configuration enables date histograms to be used on the `timestamp`
field and `terms` aggregations to be used on the `node` field.
<2> This configuration defines metrics over two fields: `temperature` and
Expand Down
4 changes: 4 additions & 0 deletions docs/reference/rollup/apis/rollup-caps.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ PUT _rollup/job/sensor
}
--------------------------------------------------
// TEST[setup:sensor_index]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]

We can then retrieve the rollup capabilities of that index pattern (`sensor-*`)
via the following command:
Expand All @@ -92,6 +93,7 @@ via the following command:
GET _rollup/data/sensor-*
--------------------------------------------------
// TEST[continued]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]

Which will yield the following response:

Expand Down Expand Up @@ -164,6 +166,7 @@ We could also retrieve the same information with a request to `_all`:
GET _rollup/data/_all
--------------------------------------------------
// TEST[continued]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]

But note that if we use the concrete index name (`sensor-1`), we'll retrieve no
rollup capabilities:
Expand All @@ -173,6 +176,7 @@ rollup capabilities:
GET _rollup/data/sensor-1
--------------------------------------------------
// TEST[continued]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]

[source,console-result]
----
Expand Down
3 changes: 3 additions & 0 deletions docs/reference/rollup/apis/rollup-index-caps.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ PUT _rollup/job/sensor
}
--------------------------------------------------
// TEST[setup:sensor_index]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]

If at a later date, we'd like to determine what jobs and capabilities were
stored in the `sensor_rollup` index, we can use the get rollup index API:
Expand All @@ -89,6 +90,7 @@ stored in the `sensor_rollup` index, we can use the get rollup index API:
GET /sensor_rollup/_rollup/data
--------------------------------------------------
// TEST[continued]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]

Note how we are requesting the concrete rollup index name (`sensor_rollup`) as
the first part of the URL. This will yield the following response:
Expand Down Expand Up @@ -164,3 +166,4 @@ instead of explicit indices:
GET /*_rollup/_rollup/data
--------------------------------------------------
// TEST[continued]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]
4 changes: 4 additions & 0 deletions docs/reference/rollup/apis/rollup-search.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ PUT _rollup/job/sensor
}
--------------------------------------------------
// TEST[setup:sensor_index]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]

This rolls up the `sensor-*` pattern and stores the results in `sensor_rollup`.
To search this rolled up data, we need to use the `_rollup_search` endpoint.
Expand All @@ -127,6 +128,7 @@ GET /sensor_rollup/_rollup_search
--------------------------------------------------
// TEST[setup:sensor_prefab_data]
// TEST[s/_rollup_search/_rollup_search?filter_path=took,timed_out,terminated_early,_shards,hits,aggregations/]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]

The query is targeting the `sensor_rollup` data, since this contains the rollup
data as configured in the job. A `max` aggregation has been used on the
Expand Down Expand Up @@ -182,6 +184,7 @@ GET sensor_rollup/_rollup_search
--------------------------------------------------
// TEST[continued]
// TEST[catch:/illegal_argument_exception/]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]

[source,console-result]
----
Expand Down Expand Up @@ -225,6 +228,7 @@ GET sensor-1,sensor_rollup/_rollup_search <1>
--------------------------------------------------
// TEST[continued]
// TEST[s/_rollup_search/_rollup_search?filter_path=took,timed_out,terminated_early,_shards,hits,aggregations/]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]
<1> Note the URI now searches `sensor-1` and `sensor_rollup` at the same time

When the search is executed, the rollup search endpoint does two things:
Expand Down
3 changes: 2 additions & 1 deletion docs/reference/rollup/apis/start-job.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ If we have already created a {rollup-job} named `sensor`, it can be started with
POST _rollup/job/sensor/_start
--------------------------------------------------
// TEST[setup:sensor_rollup_job]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]

Which will return the response:

Expand All @@ -59,4 +60,4 @@ Which will return the response:
{
"started": true
}
----
----
1 change: 1 addition & 0 deletions docs/reference/rollup/apis/stop-job.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ the indexer has fully stopped. This is accomplished with the
POST _rollup/job/sensor/_stop?wait_for_completion=true&timeout=10s
--------------------------------------------------
// TEST[setup:sensor_started_rollup_job]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]

The parameter blocks the API call from returning until either the job has moved
to `STOPPED` or the specified time has elapsed. If the specified time elapses
Expand Down
1 change: 1 addition & 0 deletions docs/reference/rollup/migrating-to-downsampling.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ PUT _rollup/job/sensor
}
--------------------------------------------------
// TEST[setup:sensor_index]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]

The equivalent <<tsds,time series data stream (TSDS)>> setup that uses downsampling via DSL:

Expand Down
5 changes: 5 additions & 0 deletions docs/reference/rollup/rollup-getting-started.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ PUT _rollup/job/sensor
}
--------------------------------------------------
// TEST[setup:sensor_index]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]

We give the job the ID of "sensor" (in the url: `PUT _rollup/job/sensor`), and tell it to rollup the index pattern `"sensor-*"`.
This job will find and rollup any index that matches that pattern. Rollup summaries are then stored in the `"sensor_rollup"` index.
Expand Down Expand Up @@ -143,6 +144,7 @@ To start the job, execute this command:
POST _rollup/job/sensor/_start
--------------------------------------------------
// TEST[setup:sensor_rollup_job]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]

[discrete]
==== Searching the rolled results
Expand All @@ -167,6 +169,7 @@ GET /sensor_rollup/_rollup_search
}
--------------------------------------------------
// TEST[setup:sensor_prefab_data]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]

It's a simple aggregation that calculates the maximum of the `temperature` field. But you'll notice that it is being sent to the `sensor_rollup`
index instead of the raw `sensor-*` indices. And you'll also notice that it is using the `_rollup_search` endpoint. Otherwise the syntax
Expand Down Expand Up @@ -198,6 +201,7 @@ If you were to execute that query, you'd receive a result that looks like a norm
----
// TESTRESPONSE[s/"took" : 102/"took" : $body.$_path/]
// TESTRESPONSE[s/"_shards" : \.\.\. /"_shards" : $body.$_path/]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]

The only notable difference is that Rollup search results have zero `hits`, because we aren't really searching the original, live data any
more. Otherwise it's identical syntax.
Expand Down Expand Up @@ -244,6 +248,7 @@ GET /sensor_rollup/_rollup_search
}
--------------------------------------------------
// TEST[setup:sensor_prefab_data]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]

Which returns a corresponding response:

Expand Down
1 change: 1 addition & 0 deletions docs/reference/rollup/rollup-search-limitations.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ GET sensor_rollup/_rollup_search
--------------------------------------------------
// TEST[setup:sensor_prefab_data]
// TEST[catch:/illegal_argument_exception/]
// TEST[warning:The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.]

The response will tell you that the field and aggregation were not possible, because no rollup jobs were found which contained them:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,20 @@ public abstract class ESRestTestCase extends ESTestCase {

private static final Pattern SEMANTIC_VERSION_PATTERN = Pattern.compile("^(\\d+\\.\\d+\\.\\d+)\\D?.*");

private static final String EXPECTED_ROLLUP_WARNING_MESSAGE =
"The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.";
public static final RequestOptions.Builder ROLLUP_REQUESTS_OPTIONS = RequestOptions.DEFAULT.toBuilder().setWarningsHandler(warnings -> {
// Either no warning, because of bwc integration test OR
// the expected warning, because on current version
if (warnings.isEmpty()) {
return false;
} else if (warnings.size() == 1 && EXPECTED_ROLLUP_WARNING_MESSAGE.equals(warnings.get(0))) {
return false;
} else {
return true;
}
});

/**
* Convert the entity from a {@link Response} into a map of maps.
* Consumes the underlying HttpEntity, releasing any resources it may be holding.
Expand Down Expand Up @@ -1274,7 +1288,9 @@ private static void wipeClusterSettings() throws IOException {
private void wipeRollupJobs() throws IOException {
final Response response;
try {
response = adminClient().performRequest(new Request("GET", "/_rollup/job/_all"));
var request = new Request("GET", "/_rollup/job/_all");
request.setOptions(ROLLUP_REQUESTS_OPTIONS);
response = adminClient().performRequest(request);
} catch (ResponseException e) {
// If we don't see the rollup endpoint (possibly because of running against an older ES version) we just bail
if (e.getResponse().getStatusLine().getStatusCode() == RestStatus.NOT_FOUND.getStatus()) {
Expand All @@ -1294,6 +1310,7 @@ private void wipeRollupJobs() throws IOException {
@SuppressWarnings("unchecked")
String jobId = (String) ((Map<String, Object>) jobConfig.get("config")).get("id");
Request request = new Request("POST", "/_rollup/job/" + jobId + "/_stop");
request.setOptions(ROLLUP_REQUESTS_OPTIONS);
setIgnoredErrorResponseCodes(request, RestStatus.NOT_FOUND);
request.addParameter("wait_for_completion", "true");
request.addParameter("timeout", "10s");
Expand All @@ -1305,6 +1322,7 @@ private void wipeRollupJobs() throws IOException {
@SuppressWarnings("unchecked")
String jobId = (String) ((Map<String, Object>) jobConfig.get("config")).get("id");
Request request = new Request("DELETE", "/_rollup/job/" + jobId);
request.setOptions(ROLLUP_REQUESTS_OPTIONS);
setIgnoredErrorResponseCodes(request, RestStatus.NOT_FOUND); // 404s imply someone was racing us to delete this
logger.debug("deleting rollup job [{}]", jobId);
adminClient().performRequest(request);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@

public class Rollup extends Plugin implements ActionPlugin, PersistentTaskPlugin {

public static final String DEPRECATION_MESSAGE =
"The rollup functionality will be removed in in Elasticsearch 9.0. See docs for more information.";
public static final String DEPRECATION_KEY = "rollup_removal";

// Introduced in ES version 6.3
public static final int ROLLUP_VERSION_V1 = 1;
// Introduced in ES Version 6.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.logging.DeprecationCategory;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.discovery.MasterNotDiscoveredException;
import org.elasticsearch.injection.guice.Inject;
Expand All @@ -31,12 +33,17 @@

import java.util.List;

import static org.elasticsearch.xpack.rollup.Rollup.DEPRECATION_KEY;
import static org.elasticsearch.xpack.rollup.Rollup.DEPRECATION_MESSAGE;

public class TransportDeleteRollupJobAction extends TransportTasksAction<
RollupJobTask,
DeleteRollupJobAction.Request,
DeleteRollupJobAction.Response,
DeleteRollupJobAction.Response> {

private static final DeprecationLogger DEPRECATION_LOGGER = DeprecationLogger.getLogger(TransportDeleteRollupJobAction.class);

@Inject
public TransportDeleteRollupJobAction(TransportService transportService, ActionFilters actionFilters, ClusterService clusterService) {
super(
Expand All @@ -52,6 +59,7 @@ public TransportDeleteRollupJobAction(TransportService transportService, ActionF

@Override
protected void doExecute(Task task, DeleteRollupJobAction.Request request, ActionListener<DeleteRollupJobAction.Response> listener) {
DEPRECATION_LOGGER.warn(DeprecationCategory.API, DEPRECATION_KEY, DEPRECATION_MESSAGE);
final ClusterState state = clusterService.state();
final DiscoveryNodes nodes = state.nodes();

Expand Down Expand Up @@ -93,7 +101,6 @@ protected void taskOperation(
RollupJobTask jobTask,
ActionListener<DeleteRollupJobAction.Response> listener
) {

assert jobTask.getConfig().getId().equals(request.getId());
IndexerState state = ((RollupJobStatus) jobTask.getStatus()).getIndexerState();
if (state.equals(IndexerState.STOPPED)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.elasticsearch.cluster.metadata.MappingMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.cluster.service.ClusterService;
import org.elasticsearch.common.logging.DeprecationCategory;
import org.elasticsearch.common.logging.DeprecationLogger;
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.injection.guice.Inject;
import org.elasticsearch.tasks.Task;
Expand All @@ -32,8 +34,13 @@
import java.util.concurrent.Executor;
import java.util.stream.Collectors;

import static org.elasticsearch.xpack.rollup.Rollup.DEPRECATION_KEY;
import static org.elasticsearch.xpack.rollup.Rollup.DEPRECATION_MESSAGE;

public class TransportGetRollupCapsAction extends HandledTransportAction<GetRollupCapsAction.Request, GetRollupCapsAction.Response> {

private static final DeprecationLogger DEPRECATION_LOGGER = DeprecationLogger.getLogger(TransportGetRollupCapsAction.class);

private final ClusterService clusterService;
private final Executor managementExecutor;

Expand All @@ -53,6 +60,7 @@ public TransportGetRollupCapsAction(TransportService transportService, ClusterSe

@Override
protected void doExecute(Task task, GetRollupCapsAction.Request request, ActionListener<GetRollupCapsAction.Response> listener) {
DEPRECATION_LOGGER.warn(DeprecationCategory.API, DEPRECATION_KEY, DEPRECATION_MESSAGE);
// Workaround for https://github.com/elastic/elasticsearch/issues/97916 - TODO remove this when we can
managementExecutor.execute(ActionRunnable.wrap(listener, l -> doExecuteForked(request.getIndexPattern(), l)));
}
Expand Down
Loading

0 comments on commit fb9261d

Please sign in to comment.