Skip to content

Commit

Permalink
[Transform] Do not log error on node restart when the transform is al…
Browse files Browse the repository at this point in the history
…ready failed.
  • Loading branch information
przemekwitek committed Mar 12, 2024
1 parent e474910 commit 875807c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,15 @@ public void audit(Level level, String resourceId, String message) {
}

public void info(String resourceId, String message) {
indexDoc(messageFactory.newMessage(resourceId, message, Level.INFO, new Date(), nodeName));
audit(Level.INFO, resourceId, message);
}

public void warning(String resourceId, String message) {
indexDoc(messageFactory.newMessage(resourceId, message, Level.WARNING, new Date(), nodeName));
audit(Level.WARNING, resourceId, message);
}

public void error(String resourceId, String message) {
indexDoc(messageFactory.newMessage(resourceId, message, Level.ERROR, new Date(), nodeName));
audit(Level.ERROR, resourceId, message);
}

private static void onIndexResponse(DocWriteResponse response) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.transform.transforms;

import org.elasticsearch.ElasticsearchException;

class CannotStartFailedTransformException extends ElasticsearchException {
CannotStartFailedTransformException(String msg) {
super(msg);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

package org.elasticsearch.xpack.transform.transforms;

import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.lucene.util.SetOnce;
Expand Down Expand Up @@ -62,6 +63,8 @@
import java.util.stream.Collectors;

import static org.elasticsearch.core.Strings.format;
import static org.elasticsearch.xpack.core.common.notifications.Level.ERROR;
import static org.elasticsearch.xpack.core.common.notifications.Level.INFO;
import static org.elasticsearch.xpack.transform.transforms.TransformNodes.nodeCanRunThisTransform;

public class TransformPersistentTasksExecutor extends PersistentTasksExecutor<TransformTaskParams> {
Expand Down Expand Up @@ -203,11 +206,17 @@ protected void nodeOperation(AllocatedPersistentTask task, @Nullable TransformTa
ActionListener<StartTransformAction.Response> startTaskListener = ActionListener.wrap(
response -> logger.info("[{}] successfully completed and scheduled task in node operation", transformId),
failure -> {
auditor.error(
// If the transform is failed then there is no need to log an error on every node restart as the error had already been
// logged when the transform first failed.
boolean logErrorAsInfo = failure instanceof CannotStartFailedTransformException;
auditor.audit(
logErrorAsInfo ? INFO : ERROR,
transformId,
"Failed to start transform. " + "Please stop and attempt to start again. Failure: " + failure.getMessage()
"Failed to start transform. Please stop and attempt to start again. Failure: " + failure.getMessage()
);
logger.error("Failed to start task [" + transformId + "] in node operation", failure);
logger.atLevel(logErrorAsInfo ? Level.INFO : Level.ERROR)
.withThrowable(failure)
.log("[{}] Failed to start task in node operation", transformId);
}
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,8 @@ void start(Long startingCheckpoint, ActionListener<StartTransformAction.Response
logger.debug("[{}] start called with state [{}].", getTransformId(), getState());
if (context.getTaskState() == TransformTaskState.FAILED) {
listener.onFailure(
new ElasticsearchStatusException(
TransformMessages.getMessage(CANNOT_START_FAILED_TRANSFORM, getTransformId(), context.getStateReason()),
RestStatus.CONFLICT
new CannotStartFailedTransformException(
TransformMessages.getMessage(CANNOT_START_FAILED_TRANSFORM, getTransformId(), context.getStateReason())
)
);
return;
Expand Down

0 comments on commit 875807c

Please sign in to comment.