Skip to content

Commit

Permalink
[ML] Get ML filters size should default to 100
Browse files Browse the repository at this point in the history
When get filters is called without setting the `size`
paramter only up to 10 filters are returned. However,
100 filters should be returned. This commit fixes this
and adds an integ test to guard it.

It seems this was accidentally broken in elastic#39976.

Closes elastic#54206
  • Loading branch information
dimitris-athanasiou committed Mar 25, 2020
1 parent 7e22ae4 commit d89ce57
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static class Request extends AbstractGetResourcesRequest {

public Request() {
// Put our own defaults for backwards compatibility
super(null, null, true);
super(null, PageParams.defaultParams(), true);
}

public Request(StreamInput in) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

package org.elasticsearch.xpack.ml.integration;

import org.elasticsearch.xpack.core.ml.action.GetFiltersAction;
import org.elasticsearch.xpack.core.ml.job.config.MlFilter;

import static org.hamcrest.Matchers.equalTo;

public class MlFiltersIT extends MlNativeIntegTestCase {

@Override
protected void cleanUpResources() {
// nothing to clean
}

public void testGetFilters_ShouldReturnUpTo100ByDefault() {
int filtersCount = randomIntBetween(11, 100);
for (int i = 0; i < filtersCount; i++) {
putMlFilter(MlFilter.builder("filter-" + i).setItems("item-" + i).build());
}

GetFiltersAction.Response filters = getMlFilters();
assertThat((int) filters.getFilters().count(), equalTo(filtersCount));
assertThat(filters.getFilters().results().size(), equalTo(filtersCount));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -353,10 +353,6 @@ protected List<Forecast> getForecasts(String jobId, ForecastRequestStats forecas
return forecasts;
}

protected PutFilterAction.Response putMlFilter(MlFilter filter) {
return client().execute(PutFilterAction.INSTANCE, new PutFilterAction.Request(filter)).actionGet();
}

protected PutCalendarAction.Response putCalendar(String calendarId, List<String> jobIds, String description) {
PutCalendarAction.Request request = new PutCalendarAction.Request(new Calendar(calendarId, jobIds, description));
return client().execute(PutCalendarAction.INSTANCE, request).actionGet();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@
import org.elasticsearch.xpack.core.ml.MlMetadata;
import org.elasticsearch.xpack.core.ml.MlTasks;
import org.elasticsearch.xpack.core.ml.action.DeleteExpiredDataAction;
import org.elasticsearch.xpack.core.ml.action.GetFiltersAction;
import org.elasticsearch.xpack.core.ml.action.OpenJobAction;
import org.elasticsearch.xpack.core.ml.action.PutFilterAction;
import org.elasticsearch.xpack.core.ml.action.StartDataFrameAnalyticsAction;
import org.elasticsearch.xpack.core.ml.action.StartDatafeedAction;
import org.elasticsearch.xpack.core.ml.datafeed.DatafeedState;
import org.elasticsearch.xpack.core.ml.dataframe.DataFrameAnalyticsTaskState;
import org.elasticsearch.xpack.core.ml.job.config.JobTaskState;
import org.elasticsearch.xpack.core.ml.job.config.MlFilter;
import org.elasticsearch.xpack.core.security.SecurityField;
import org.elasticsearch.xpack.core.security.authc.TokenMetaData;
import org.elasticsearch.xpack.ilm.IndexLifecycle;
Expand Down Expand Up @@ -161,6 +164,14 @@ protected DeleteExpiredDataAction.Response deleteExpiredData() throws Exception
return response;
}

protected PutFilterAction.Response putMlFilter(MlFilter filter) {
return client().execute(PutFilterAction.INSTANCE, new PutFilterAction.Request(filter)).actionGet();
}

protected GetFiltersAction.Response getMlFilters() {
return client().execute(GetFiltersAction.INSTANCE, new GetFiltersAction.Request()).actionGet();
}

@Override
protected void ensureClusterStateConsistency() throws IOException {
if (cluster() != null && cluster().size() > 0) {
Expand Down

0 comments on commit d89ce57

Please sign in to comment.