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

suppress metric heartbeat fix #12

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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 @@ -54,7 +54,7 @@ public Boolean checkCondition(SortedMap<String, String> tagsMap) {
subMap.keySet().retainAll(tagKeys);
final long hashCode = AlertUtils.getHashForNAMT(namespace, alertId, subMap);
if (!this.heartbeatMap.containsKey(hashCode)) {
LOG.info("id: {} not in heartbeat subMap: {}", alertId, convertWithStream(subMap));
LOG.info("id: {} not in heartbeat subMap: {} hash: {}", alertId, convertWithStream(subMap), hashCode);
return false;
}
if (this.heartbeatMap.containsKey(hashCode) && this.heartbeatMap.get(hashCode)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,19 +304,22 @@ public AlertEventBag execute(final long endTime,
final AlertEventBag alertEventBag;
final SuppressMetricConfig suppressMetricConfig = this.metricAlertConfig.getSuppressMetricConfig();
if (suppressMetricConfig != null) {
LOG.info("Processing heartbeat for suppress metric config: {}", suppressMetricConfig.toString());

final Set<String> keySet = !suppressMetricConfig.getKeySet().isEmpty()
? suppressMetricConfig.getKeySet() : TsdbV3ResultProcessor.getEmptyHeartbeatTagset() ;
LOG.info("id: {} Processing heartbeat with suppress metric config: {} and key set: {}", this.alertId, suppressMetricConfig, keySet);
if (suppressMetricConfig.getSampler().equals(SUMMARY)) {
Long2BooleanMap long2BooleanMap = TsdbV3ResultProcessor.processHeartBeatForSummaries(response,
suppressMetricConfig,
this.heartBeatMetricNodeId,
metricAlertConfig);
heartbeatSuppressConditional = new HeartbeatSuppressConditional(long2BooleanMap, suppressMetricConfig.getKeySet(), namespace, alertId);
heartbeatSuppressConditional = new HeartbeatSuppressConditional(long2BooleanMap, keySet, namespace, alertId);
} else {
Long2BooleanMap long2BooleanMap = TsdbV3ResultProcessor.processHeartbeatForNonSummaries(response,
suppressMetricConfig,
this.heartBeatMetricNodeId,
metricAlertConfig);
heartbeatSuppressConditional = new HeartbeatSuppressConditional(long2BooleanMap, suppressMetricConfig.getKeySet(), namespace, alertId);
heartbeatSuppressConditional = new HeartbeatSuppressConditional(long2BooleanMap, keySet, namespace, alertId);
}
} else {
heartbeatSuppressConditional = new NoOpConditional();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,7 @@
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;
import java.util.Map;
import java.util.SortedMap;
import java.util.TreeMap;
import java.util.Iterator;
import java.util.*;
import java.util.function.Function;
import java.util.stream.Collectors;

Expand All @@ -72,6 +65,13 @@ public class TsdbV3ResultProcessor {

private static final Logger LOG = LoggerFactory.getLogger(TsdbV3ResultProcessor.class);

private static final Set<String> EMPTY_HEARTBEAT_TAGSET = Collections.unmodifiableSet(new HashSet<>());

static {
EMPTY_HEARTBEAT_TAGSET.add(QueryConstants.GROUP_BY_ALL);
}


public static String runQueryAndGetResponse(TSDBClient tsdbClient, long alertId,
String namespace,
List<QueryNodeConfig> executionGraph,
Expand Down Expand Up @@ -1745,4 +1745,9 @@ private static void fillValuesAndTagsForSummaryType(final JsonNode next,
tagMap.put(QueryConstants.GROUP_BY_ALL, QueryConstants.GROUP_BY_ALL);
}
}

public static Set<String> getEmptyHeartbeatTagset() {
return EMPTY_HEARTBEAT_TAGSET;
}

}