[ML] Don't write timing stats on no-op (#43680)
Similar to elastic/ml-cpp#512, if a job opens and closes and does nothing in between we shouldn't write timing stats to the results index.
This commit is contained in:
parent
df4b30fd8b
commit
f39619d182
|
@ -42,6 +42,14 @@ public class TimingStatsReporter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void finishReporting() {
|
||||||
|
// Don't flush if current timing stats are identical to the persisted ones
|
||||||
|
if (currentTimingStats.equals(persistedTimingStats)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
flush();
|
||||||
|
}
|
||||||
|
|
||||||
public void flush() {
|
public void flush() {
|
||||||
persistedTimingStats = new TimingStats(currentTimingStats);
|
persistedTimingStats = new TimingStats(currentTimingStats);
|
||||||
bulkResultsPersister.persistTimingStats(persistedTimingStats);
|
bulkResultsPersister.persistTimingStats(persistedTimingStats);
|
||||||
|
|
|
@ -134,7 +134,7 @@ public class AutodetectResultProcessor {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (processKilled == false) {
|
if (processKilled == false) {
|
||||||
timingStatsReporter.flush();
|
timingStatsReporter.finishReporting();
|
||||||
bulkResultsPersister.executeRequest();
|
bulkResultsPersister.executeRequest();
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
|
@ -14,6 +14,7 @@ import static org.hamcrest.Matchers.equalTo;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.mockito.Mockito.inOrder;
|
import static org.mockito.Mockito.inOrder;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.verifyZeroInteractions;
|
import static org.mockito.Mockito.verifyZeroInteractions;
|
||||||
|
|
||||||
public class TimingStatsReporterTests extends ESTestCase {
|
public class TimingStatsReporterTests extends ESTestCase {
|
||||||
|
@ -76,6 +77,24 @@ public class TimingStatsReporterTests extends ESTestCase {
|
||||||
inOrder.verifyNoMoreInteractions();
|
inOrder.verifyNoMoreInteractions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testFinishReportingNoChange() {
|
||||||
|
TimingStatsReporter reporter = new TimingStatsReporter(new TimingStats(JOB_ID), bulkResultsPersister);
|
||||||
|
|
||||||
|
reporter.finishReporting();
|
||||||
|
|
||||||
|
verifyZeroInteractions(bulkResultsPersister);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testFinishReportingWithChange() {
|
||||||
|
TimingStatsReporter reporter = new TimingStatsReporter(new TimingStats(JOB_ID), bulkResultsPersister);
|
||||||
|
|
||||||
|
reporter.reportBucketProcessingTime(10);
|
||||||
|
|
||||||
|
reporter.finishReporting();
|
||||||
|
|
||||||
|
verify(bulkResultsPersister).persistTimingStats(new TimingStats(JOB_ID, 1, 10.0, 10.0, 10.0, 10.0));
|
||||||
|
}
|
||||||
|
|
||||||
public void testTimingStatsDifferSignificantly() {
|
public void testTimingStatsDifferSignificantly() {
|
||||||
assertThat(
|
assertThat(
|
||||||
TimingStatsReporter.differSignificantly(
|
TimingStatsReporter.differSignificantly(
|
||||||
|
|
|
@ -124,7 +124,7 @@ setup:
|
||||||
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
|
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
|
||||||
count:
|
count:
|
||||||
index: .ml-anomalies-shared
|
index: .ml-anomalies-shared
|
||||||
- match: {count: 8}
|
- match: {count: 6}
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
headers:
|
headers:
|
||||||
|
@ -138,7 +138,7 @@ setup:
|
||||||
term:
|
term:
|
||||||
job_id: index-layout-job
|
job_id: index-layout-job
|
||||||
|
|
||||||
- match: {count: 4}
|
- match: {count: 3}
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
headers:
|
headers:
|
||||||
|
@ -152,7 +152,7 @@ setup:
|
||||||
term:
|
term:
|
||||||
job_id: index-layout-job
|
job_id: index-layout-job
|
||||||
|
|
||||||
- match: {count: 4}
|
- match: {count: 3}
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
headers:
|
headers:
|
||||||
|
@ -166,7 +166,7 @@ setup:
|
||||||
term:
|
term:
|
||||||
job_id: index-layout-job2
|
job_id: index-layout-job2
|
||||||
|
|
||||||
- match: {count: 4}
|
- match: {count: 3}
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
headers:
|
headers:
|
||||||
|
@ -179,7 +179,7 @@ setup:
|
||||||
filter:
|
filter:
|
||||||
term:
|
term:
|
||||||
job_id: index-layout-job2
|
job_id: index-layout-job2
|
||||||
- match: {count: 4}
|
- match: {count: 3}
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
headers:
|
headers:
|
||||||
|
@ -236,7 +236,7 @@ setup:
|
||||||
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
|
Authorization: "Basic eF9wYWNrX3Jlc3RfdXNlcjp4LXBhY2stdGVzdC1wYXNzd29yZA==" # run as x_pack_rest_user, i.e. the test setup superuser
|
||||||
count:
|
count:
|
||||||
index: .ml-anomalies-shared
|
index: .ml-anomalies-shared
|
||||||
- match: {count: 4}
|
- match: {count: 3}
|
||||||
|
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
|
@ -251,7 +251,7 @@ setup:
|
||||||
term:
|
term:
|
||||||
job_id: index-layout-job2
|
job_id: index-layout-job2
|
||||||
|
|
||||||
- match: {count: 4}
|
- match: {count: 3}
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
headers:
|
headers:
|
||||||
|
@ -265,7 +265,7 @@ setup:
|
||||||
term:
|
term:
|
||||||
job_id: index-layout-job2
|
job_id: index-layout-job2
|
||||||
|
|
||||||
- match: {count: 4}
|
- match: {count: 3}
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
ml.delete_job:
|
ml.delete_job:
|
||||||
|
|
Loading…
Reference in New Issue