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 ce53567
Show file tree
Hide file tree
Showing 3 changed files with 16 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 @@ -22,6 +22,9 @@
import org.apache.flink.autoscaler.ScalingSummary;
import org.apache.flink.runtime.jobgraph.JobVertexID;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils;

import javax.annotation.Nullable;

import java.time.Duration;
Expand Down Expand Up @@ -63,6 +66,17 @@ 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) {
message = StringUtils.abbreviate(ExceptionUtils.getStackTrace(e), 2048);
}
handleEvent(context, Type.Warning, reason, message, null, null);
}

/**
* Handle scaling reports.
*
Expand Down

0 comments on commit ce53567

Please sign in to comment.