Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
EachannChan committed Aug 8, 2024
1 parent 1f6217f commit c7ea8cb
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,6 @@ public class NotifyItem {
*/
private int threshold;

/**
* Arithmetic operator.
*/
private char op='>';

/**
* In a period window, if the actual value exceeds this value, an alarm is triggered.
*/
private int countToTrigger = 1;

/**
* Alarm interval, time unit(s)
*/
Expand Down Expand Up @@ -139,4 +129,4 @@ public static List<NotifyItem> getSimpleNotifyItems() {

return notifyItems;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,7 @@ private static boolean checkLiveness(ExecutorWrapper executorWrapper, NotifyItem
val executor = executorWrapper.getExecutor();
int maximumPoolSize = executor.getMaximumPoolSize();
double div = NumberUtil.div(executor.getActiveCount(), maximumPoolSize, 2) * 100;
int countForNow=executorWrapper.getCountForNow();
if(div>=notifyItem.getThreshold()){
countForNow++;
executorWrapper.setCountForNow(countForNow);
}
return countForNow>=notifyItem.getCountToTrigger();
return div >= notifyItem.getThreshold();
}

private static boolean checkCapacity(ExecutorWrapper executorWrapper, NotifyItem notifyItem) {
Expand All @@ -139,22 +134,12 @@ private static boolean checkCapacity(ExecutorWrapper executorWrapper, NotifyItem
return false;
}
double div = NumberUtil.div(executor.getQueueSize(), executor.getQueueCapacity(), 2) * 100;
int countForNow=executorWrapper.getCountForNow();
if(div>=notifyItem.getThreshold()){
countForNow++;
executorWrapper.setCountForNow(countForNow);
}
return countForNow>=notifyItem.getCountToTrigger();
return div >= notifyItem.getThreshold();
}

private static boolean checkWithAlarmInfo(ExecutorWrapper executorWrapper, NotifyItem notifyItem) {
AlarmInfo alarmInfo = AlarmCounter.getAlarmInfo(executorWrapper.getThreadPoolName(), notifyItem.getType());
int countForNow=executorWrapper.getCountForNow();
if(alarmInfo.getCount() >= notifyItem.getThreshold()){
countForNow++;
executorWrapper.setCountForNow(countForNow);
}
return countForNow>=notifyItem.getCountToTrigger();
return alarmInfo.getCount() >= notifyItem.getThreshold();
}

private static void preAlarm(Runnable runnable) {
Expand All @@ -168,4 +153,4 @@ private static void postAlarm(Runnable runnable) {
MDC.remove(TRACE_ID);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ public class ExecutorWrapper {
*/
private List<NotifyItem> notifyItems;

/**
* The actual value to count that decide whether to trigger an alarm.
*/
private int countForNow = 0;

/**
* Notify platform ids.
*/
Expand Down Expand Up @@ -101,7 +96,6 @@ public ExecutorWrapper(DtpExecutor executor) {
this.threadPoolAliasName = executor.getThreadPoolAliasName();
this.executor = executor;
this.notifyItems = executor.getNotifyItems();
this.countForNow=executor.getCountForNow();
this.notifyEnabled = executor.isNotifyEnabled();
this.platformIds = executor.getPlatformIds();
this.awareNames = executor.getAwareNames();
Expand Down Expand Up @@ -191,4 +185,4 @@ public void setTaskWrappers(List<TaskWrapper> taskWrappers) {
((TaskEnhanceAware) executor.getOriginal()).setTaskWrappers(taskWrappers);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ protected String buildAlarmContent(NotifyPlatform platform, NotifyItemEnum notif
context.setVariable("alarmTime", DateUtil.now());
context.setVariable("trace", getTraceInfo());
context.setVariable("alarmInterval", notifyItem.getInterval());
context.setVariable("op",">");
context.setVariable("countToTrigger", notifyItem.getCountToTrigger());
context.setVariable("highlightVariables", getAlarmKeys(notifyItemEnum));
context.setVariable("ext", getExtInfo());
return ((EmailNotifier) notifier).processTemplateContent("alarm", context);
Expand All @@ -136,8 +134,6 @@ protected String buildNoticeContent(NotifyPlatform platform, TpMainFields oldFie
context.setVariable("queueType", executor.getQueueType());
context.setVariable("oldQueueCapacity", oldFields.getQueueCapacity());
context.setVariable("newQueueCapacity", executor.getQueueCapacity());
context.setVariable("op",">");
context.setVariable("countForNow",executorWrapper.getCountForNow());
context.setVariable("oldRejectType", oldFields.getRejectType());
context.setVariable("newRejectType", executor.getRejectHandlerType());
context.setVariable("notifyTime", DateUtil.now());
Expand All @@ -153,4 +149,4 @@ private Context newContext(ExecutorWrapper executorWrapper) {
context.setVariable("poolName", populatePoolName(executorWrapper));
return context;
}
}
}

0 comments on commit c7ea8cb

Please sign in to comment.