ML: fix delayed data annotations on secured cluster (#37193)
* changing executing context for writing annotation * adjusting user * removing unused import
This commit is contained in:
parent
e34658edba
commit
6b376a1ff4
|
@ -32,7 +32,7 @@ import org.elasticsearch.xpack.core.ml.job.config.DataDescription;
|
||||||
import org.elasticsearch.xpack.core.ml.job.messages.Messages;
|
import org.elasticsearch.xpack.core.ml.job.messages.Messages;
|
||||||
import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.DataCounts;
|
import org.elasticsearch.xpack.core.ml.job.process.autodetect.state.DataCounts;
|
||||||
import org.elasticsearch.xpack.core.ml.job.results.Bucket;
|
import org.elasticsearch.xpack.core.ml.job.results.Bucket;
|
||||||
import org.elasticsearch.xpack.core.security.user.SystemUser;
|
import org.elasticsearch.xpack.core.security.user.XPackUser;
|
||||||
import org.elasticsearch.xpack.ml.datafeed.delayeddatacheck.DelayedDataDetector;
|
import org.elasticsearch.xpack.ml.datafeed.delayeddatacheck.DelayedDataDetector;
|
||||||
import org.elasticsearch.xpack.ml.datafeed.delayeddatacheck.DelayedDataDetectorFactory.BucketWithMissingData;
|
import org.elasticsearch.xpack.ml.datafeed.delayeddatacheck.DelayedDataDetectorFactory.BucketWithMissingData;
|
||||||
import org.elasticsearch.xpack.ml.datafeed.extractor.DataExtractorFactory;
|
import org.elasticsearch.xpack.ml.datafeed.extractor.DataExtractorFactory;
|
||||||
|
@ -225,12 +225,12 @@ class DatafeedJob {
|
||||||
Date currentTime = new Date(currentTimeSupplier.get());
|
Date currentTime = new Date(currentTimeSupplier.get());
|
||||||
return new Annotation(msg,
|
return new Annotation(msg,
|
||||||
currentTime,
|
currentTime,
|
||||||
SystemUser.NAME,
|
XPackUser.NAME,
|
||||||
startTime,
|
startTime,
|
||||||
endTime,
|
endTime,
|
||||||
jobId,
|
jobId,
|
||||||
currentTime,
|
currentTime,
|
||||||
SystemUser.NAME,
|
XPackUser.NAME,
|
||||||
"annotation");
|
"annotation");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,9 +238,11 @@ class DatafeedJob {
|
||||||
try (XContentBuilder xContentBuilder = annotation.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)) {
|
try (XContentBuilder xContentBuilder = annotation.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)) {
|
||||||
IndexRequest request = new IndexRequest(AnnotationIndex.WRITE_ALIAS_NAME);
|
IndexRequest request = new IndexRequest(AnnotationIndex.WRITE_ALIAS_NAME);
|
||||||
request.source(xContentBuilder);
|
request.source(xContentBuilder);
|
||||||
IndexResponse response = client.index(request).actionGet();
|
try (ThreadContext.StoredContext ignore = stashWithOrigin(client.threadPool().getThreadContext(), ML_ORIGIN)) {
|
||||||
lastDataCheckAnnotation = annotation;
|
IndexResponse response = client.index(request).actionGet();
|
||||||
return response.getId();
|
lastDataCheckAnnotation = annotation;
|
||||||
|
return response.getId();
|
||||||
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
String errorMessage = "[" + jobId + "] failed to create annotation for delayed data checker.";
|
String errorMessage = "[" + jobId + "] failed to create annotation for delayed data checker.";
|
||||||
LOGGER.error(errorMessage, ex);
|
LOGGER.error(errorMessage, ex);
|
||||||
|
@ -251,7 +253,7 @@ class DatafeedJob {
|
||||||
|
|
||||||
private void updateAnnotation(Annotation annotation) {
|
private void updateAnnotation(Annotation annotation) {
|
||||||
Annotation updatedAnnotation = new Annotation(lastDataCheckAnnotation);
|
Annotation updatedAnnotation = new Annotation(lastDataCheckAnnotation);
|
||||||
updatedAnnotation.setModifiedUsername(SystemUser.NAME);
|
updatedAnnotation.setModifiedUsername(XPackUser.NAME);
|
||||||
updatedAnnotation.setModifiedTime(new Date(currentTimeSupplier.get()));
|
updatedAnnotation.setModifiedTime(new Date(currentTimeSupplier.get()));
|
||||||
updatedAnnotation.setAnnotation(annotation.getAnnotation());
|
updatedAnnotation.setAnnotation(annotation.getAnnotation());
|
||||||
updatedAnnotation.setTimestamp(annotation.getTimestamp());
|
updatedAnnotation.setTimestamp(annotation.getTimestamp());
|
||||||
|
@ -260,8 +262,10 @@ class DatafeedJob {
|
||||||
IndexRequest indexRequest = new IndexRequest(AnnotationIndex.WRITE_ALIAS_NAME);
|
IndexRequest indexRequest = new IndexRequest(AnnotationIndex.WRITE_ALIAS_NAME);
|
||||||
indexRequest.id(lastDataCheckAnnotationId);
|
indexRequest.id(lastDataCheckAnnotationId);
|
||||||
indexRequest.source(xContentBuilder);
|
indexRequest.source(xContentBuilder);
|
||||||
client.index(indexRequest).actionGet();
|
try (ThreadContext.StoredContext ignore = stashWithOrigin(client.threadPool().getThreadContext(), ML_ORIGIN)) {
|
||||||
lastDataCheckAnnotation = updatedAnnotation;
|
client.index(indexRequest).actionGet();
|
||||||
|
lastDataCheckAnnotation = updatedAnnotation;
|
||||||
|
}
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
String errorMessage = "[" + jobId + "] failed to update annotation for delayed data checker.";
|
String errorMessage = "[" + jobId + "] failed to update annotation for delayed data checker.";
|
||||||
LOGGER.error(errorMessage, ex);
|
LOGGER.error(errorMessage, ex);
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.elasticsearch.xpack.core.ml.annotations.AnnotationIndex;
|
||||||
import org.elasticsearch.xpack.core.ml.datafeed.extractor.DataExtractor;
|
import org.elasticsearch.xpack.core.ml.datafeed.extractor.DataExtractor;
|
||||||
import org.elasticsearch.xpack.core.ml.job.messages.Messages;
|
import org.elasticsearch.xpack.core.ml.job.messages.Messages;
|
||||||
import org.elasticsearch.xpack.core.ml.job.results.Bucket;
|
import org.elasticsearch.xpack.core.ml.job.results.Bucket;
|
||||||
import org.elasticsearch.xpack.core.security.user.SystemUser;
|
import org.elasticsearch.xpack.core.security.user.XPackUser;
|
||||||
import org.elasticsearch.xpack.ml.datafeed.delayeddatacheck.DelayedDataDetector;
|
import org.elasticsearch.xpack.ml.datafeed.delayeddatacheck.DelayedDataDetector;
|
||||||
import org.elasticsearch.xpack.ml.datafeed.delayeddatacheck.DelayedDataDetectorFactory.BucketWithMissingData;
|
import org.elasticsearch.xpack.ml.datafeed.delayeddatacheck.DelayedDataDetectorFactory.BucketWithMissingData;
|
||||||
import org.elasticsearch.xpack.ml.datafeed.extractor.DataExtractorFactory;
|
import org.elasticsearch.xpack.ml.datafeed.extractor.DataExtractorFactory;
|
||||||
|
@ -271,12 +271,12 @@ public class DatafeedJobTests extends ESTestCase {
|
||||||
|
|
||||||
Annotation expectedAnnotation = new Annotation(msg,
|
Annotation expectedAnnotation = new Annotation(msg,
|
||||||
new Date(currentTime),
|
new Date(currentTime),
|
||||||
SystemUser.NAME,
|
XPackUser.NAME,
|
||||||
bucket.getTimestamp(),
|
bucket.getTimestamp(),
|
||||||
new Date((bucket.getEpoch() + bucket.getBucketSpan()) * 1000),
|
new Date((bucket.getEpoch() + bucket.getBucketSpan()) * 1000),
|
||||||
jobId,
|
jobId,
|
||||||
new Date(currentTime),
|
new Date(currentTime),
|
||||||
SystemUser.NAME,
|
XPackUser.NAME,
|
||||||
"annotation");
|
"annotation");
|
||||||
|
|
||||||
IndexRequest request = new IndexRequest(AnnotationIndex.WRITE_ALIAS_NAME);
|
IndexRequest request = new IndexRequest(AnnotationIndex.WRITE_ALIAS_NAME);
|
||||||
|
@ -312,7 +312,7 @@ public class DatafeedJobTests extends ESTestCase {
|
||||||
Annotation updatedAnnotation = new Annotation(expectedAnnotation);
|
Annotation updatedAnnotation = new Annotation(expectedAnnotation);
|
||||||
updatedAnnotation.setAnnotation(msg);
|
updatedAnnotation.setAnnotation(msg);
|
||||||
updatedAnnotation.setModifiedTime(new Date(currentTime));
|
updatedAnnotation.setModifiedTime(new Date(currentTime));
|
||||||
updatedAnnotation.setModifiedUsername(SystemUser.NAME);
|
updatedAnnotation.setModifiedUsername(XPackUser.NAME);
|
||||||
updatedAnnotation.setEndTimestamp(new Date((bucket2.getEpoch() + bucket2.getBucketSpan()) * 1000));
|
updatedAnnotation.setEndTimestamp(new Date((bucket2.getEpoch() + bucket2.getBucketSpan()) * 1000));
|
||||||
try (XContentBuilder xContentBuilder = updatedAnnotation.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)) {
|
try (XContentBuilder xContentBuilder = updatedAnnotation.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)) {
|
||||||
indexRequest.source(xContentBuilder);
|
indexRequest.source(xContentBuilder);
|
||||||
|
|
Loading…
Reference in New Issue