Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: alert add level match checking #59

Merged
merged 4 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -160,12 +160,17 @@ public static void main(String[] args) throws Exception {
.setParallelism(parameterTool.getInt(STREAM_PARALLELISM_OPERATOR))
.name("broadcast alert notify");

DataStream<AlertEvent> levelMatchedAlertEventsWithNotify = alertEventsWithNotify
.filter(new AlertEventLevelFilterFunction())
.setParallelism(parameterTool.getInt(STREAM_PARALLELISM_OPERATOR))
.name("filter event notify level");

DataStream<NotifyEvent> notifyEventWithTemplate = notifyEventDataStream.connect(allUniversalTemplates.broadcast(StateDescriptors.notifyTemplate))
.process(new NotifyTemplateProcessFunction(parameterTool.getLong(METRIC_METADATA_TTL, 7500), StateDescriptors.notifyTemplate))
.setParallelism(parameterTool.getInt(STREAM_PARALLELISM_OPERATOR))
.name("notify event with template");

DataStream<AlertEvent> alertEventsWithTemplate = alertEventsWithNotify
DataStream<AlertEvent> alertEventsWithTemplate = levelMatchedAlertEventsWithNotify
.connect(alertNotifyTemplateQuery.union(alertNotifyCustomTemplateQuery).broadcast(StateDescriptors.alertNotifyTemplateStateDescriptor))
.process(new AlertNotifyTemplateBroadcastProcessFunction(parameterTool.getLong(METRIC_METADATA_TTL,
75000), StateDescriptors.alertNotifyTemplateStateDescriptor))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cloud.erda.analyzer.alert.functions;

import cloud.erda.analyzer.alert.models.AlertEvent;
import cloud.erda.analyzer.common.constant.AlertConstants;
import org.apache.flink.api.common.functions.FilterFunction;

import java.util.Arrays;

public class AlertEventLevelFilterFunction implements FilterFunction<AlertEvent> {

@Override
public boolean filter(AlertEvent alertEvent) throws Exception {
String eventLevel = alertEvent.getMetricEvent().getTags().get(AlertConstants.ALERT_EXPRESSION_LEVEL);
String[] notifyLevels = alertEvent.getAlertNotify().getNotifyTarget().getLevel();

if (eventLevel == null || notifyLevels == null || notifyLevels.length == 0)
return true;

int len = notifyLevels.length;
for (int i = 0; i < len; i++) {
if (eventLevel.equals(notifyLevels[i]))
return true;
}

return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,7 @@ public class AlertNotifyTarget {
@SerializedName(value = "dingding_url")
private String dingdingUrl;

private String[] level;

private String[] groupTypes;
}
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class AlertConstants {

public static final String ALERT_EXPRESSION_ID = "expression_id";

public static final String ALERT_EXPRESSION_LEVEL = "level";

public static final String ALERT_RULE_ID = "rule_id";

public static final String ALERT_NOTIFY_TEMPLATE_ID = "notify_template_id";
Expand Down