From 42bb2bae216af113c72059095ad3850f6f24aa7b Mon Sep 17 00:00:00 2001 From: David Kyle Date: Wed, 2 Jan 2019 16:52:20 +0000 Subject: [PATCH] [ML] Order GET job stats response by job id (#36841) --- .../xpack/ml/action/TransportGetJobsStatsAction.java | 3 +++ .../resources/rest-api-spec/test/ml/jobs_get_stats.yml | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetJobsStatsAction.java b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetJobsStatsAction.java index c9a6d717f31..da24af0ca74 100644 --- a/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetJobsStatsAction.java +++ b/x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/action/TransportGetJobsStatsAction.java @@ -37,6 +37,7 @@ import org.elasticsearch.xpack.ml.job.process.autodetect.AutodetectProcessManage import java.time.Duration; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.Optional; import java.util.Set; @@ -91,6 +92,7 @@ public class TransportGetJobsStatsAction extends TransportTasksAction task : tasks) { stats.addAll(task.results()); } + Collections.sort(stats, Comparator.comparing(GetJobsStatsAction.Response.JobStats::getJobId)); return new GetJobsStatsAction.Response(taskOperationFailures, failedNodeExceptions, new QueryPage<>(stats, stats.size(), Job.RESULTS_FIELD)); } @@ -148,6 +150,7 @@ public class TransportGetJobsStatsAction extends TransportTasksAction results = response.getResponse().results(); results.addAll(jobStats.asList()); + Collections.sort(results, Comparator.comparing(GetJobsStatsAction.Response.JobStats::getJobId)); listener.onResponse(new GetJobsStatsAction.Response(response.getTaskFailures(), response.getNodeFailures(), new QueryPage<>(results, results.size(), Job.RESULTS_FIELD))); } diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/ml/jobs_get_stats.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/ml/jobs_get_stats.yml index aea80c69f49..9f9f6826325 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/ml/jobs_get_stats.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/ml/jobs_get_stats.yml @@ -151,7 +151,9 @@ setup: ml.get_job_stats: job_id: _all - match: { count: 2 } + - match: { jobs.0.job_id : job-stats-test } - match: { jobs.0.state: opened } + - match: { jobs.1.job_id : jobs-get-stats-datafeed-job } - match: { jobs.1.state: opened } --- @@ -161,7 +163,9 @@ setup: ml.get_job_stats: job_id: "*" - match: { count: 2 } + - match: { jobs.0.job_id : job-stats-test } - match: { jobs.0.state: opened } + - match: { jobs.1.job_id : jobs-get-stats-datafeed-job } - match: { jobs.1.state: opened } --- @@ -311,6 +315,7 @@ setup: - do: ml.get_job_stats: {} - match: { count: 2 } + - match: { jobs.0.job_id : job-stats-test } - match: { jobs.0.data_counts.processed_record_count: 0 } - match: { jobs.0.data_counts.processed_field_count: 0 } - match: { jobs.0.data_counts.input_field_count: 0 } @@ -318,6 +323,7 @@ setup: - match: { jobs.0.state: closed } - is_false: jobs.0.node - is_false: jobs.0.open_time + - match: { jobs.1.job_id : jobs-get-stats-datafeed-job } - match: { jobs.1.data_counts.processed_record_count: 0 } - match: { jobs.1.data_counts.processed_field_count: 0 } - match: { jobs.1.data_counts.input_field_count: 0 } @@ -325,5 +331,3 @@ setup: - match: { jobs.1.state: closed } - is_false: jobs.1.node - is_false: jobs.1.open_time - -