Skip to content

Commit

Permalink
[FLINK-34957][autoscaler] Event handler records the exception stack t…
Browse files Browse the repository at this point in the history
…race when exception message is null
  • Loading branch information
1996fanrui committed Mar 28, 2024
1 parent 96f8b20 commit 1949f30
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,7 @@ protected void scalingSingleJob(Context jobContext) {
autoScaler.scale(jobContext);
} catch (Throwable e) {
LOG.error("Error while scaling job", e);
eventHandler.handleEvent(
jobContext,
AutoScalerEventHandler.Type.Warning,
AUTOSCALER_ERROR,
e.getMessage(),
null,
null);
eventHandler.handleException(jobContext, AUTOSCALER_ERROR, e);
} finally {
MDC.clear();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -228,13 +228,7 @@ private void runScalingLogic(Context ctx, AutoscalerFlinkMetrics autoscalerMetri
private void onError(Context ctx, AutoscalerFlinkMetrics autoscalerMetrics, Throwable e) {
LOG.error("Error while scaling job", e);
autoscalerMetrics.incrementError();
eventHandler.handleEvent(
ctx,
AutoScalerEventHandler.Type.Warning,
AUTOSCALER_ERROR,
e.getMessage(),
null,
null);
eventHandler.handleException(ctx, AUTOSCALER_ERROR, e);
}

private AutoscalerFlinkMetrics getOrInitAutoscalerFlinkMetrics(Context ctx) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import javax.annotation.Nullable;

import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.time.Duration;
import java.util.Map;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -63,6 +65,19 @@ void handleEvent(
@Nullable String messageKey,
@Nullable Duration interval);

/**
* Handle exception, and the exception event is warning type and don't deduplicate by default.
*/
default void handleException(Context context, String reason, Throwable e) {
var message = e.getMessage();
if (message == null) {
var stream = new ByteArrayOutputStream();
e.printStackTrace(new PrintStream(stream));
message = stream.toString();
}
handleEvent(context, Type.Warning, reason, message, null, null);
}

/**
* Handle scaling reports.
*
Expand Down

0 comments on commit 1949f30

Please sign in to comment.