Skip to content

Commit 7d24f33

Browse files
authored
Fx/notification interval and description (#19)
* Fix notification interval and clarify description * Increase waiting interval * Remove alert by label * Fix duplicates
1 parent fb7a365 commit 7d24f33

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

src/main/java/dev/vality/alerting/mayday/prometheus/client/k8s/PrometheusClient.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616
import org.springframework.http.HttpStatus;
1717
import org.springframework.stereotype.Component;
1818

19-
import java.util.Optional;
20-
import java.util.Set;
19+
import java.util.*;
2120
import java.util.function.UnaryOperator;
2221
import java.util.stream.Collectors;
2322

@@ -64,11 +63,15 @@ public Set<PrometheusRuleSpec.Rule> getPrometheusRuleGroupAlerts(String ruleName
6463
if (rule == null) {
6564
return Set.of();
6665
}
67-
return rule.getSpec().getGroups().stream()
66+
List<PrometheusRuleSpec.Rule> rules = rule.getSpec().getGroups().stream()
6867
.flatMap(group -> group.getRules().stream()
6968
.filter(rule1 -> rule1.getLabels().containsKey(PrometheusRuleLabel.USERNAME)
7069
&& rule1.getLabels().get(PrometheusRuleLabel.USERNAME).equals(groupName)))
71-
.collect(Collectors.toSet());
70+
.toList();
71+
72+
Map<String, PrometheusRuleSpec.Rule> distinctRules = new HashMap<>();
73+
rules.forEach(rule1 -> distinctRules.put(rule1.getAlert(), rule1));
74+
return new HashSet<>(distinctRules.values());
7275
}
7376
}
7477

src/main/java/dev/vality/alerting/mayday/prometheus/client/k8s/util/PrometheusFunctionsUtil.java

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import dev.vality.alerting.mayday.prometheus.client.k8s.model.PrometheusRuleSpec;
66
import lombok.experimental.UtilityClass;
77
import lombok.extern.slf4j.Slf4j;
8+
import org.springframework.util.ObjectUtils;
89

910
import java.util.HashSet;
1011
import java.util.Set;
@@ -69,8 +70,22 @@ public static UnaryOperator<PrometheusRule> getAddAlertToGroupFunc(String groupN
6970
groups = new HashSet<>();
7071
prometheusRule.getSpec().setGroups(groups);
7172
}
72-
PrometheusRuleSpec.Group group = groups.stream().filter(g -> g.getName().equals(groupName)).findFirst()
73-
.orElse(createPrometheusRuleGroup(groupName));
73+
74+
var groupIterator = groups.iterator();
75+
PrometheusRuleSpec.Group group = null;
76+
while (groupIterator.hasNext()) {
77+
var cursor = groupIterator.next();
78+
log.info("Found group with name '{}'...", cursor.getName());
79+
if (cursor.getName().equals(groupName)) {
80+
log.info("Found matching group with name '{}'! Group: {}", cursor.getName(), cursor);
81+
group = cursor;
82+
break;
83+
}
84+
}
85+
86+
if (ObjectUtils.isEmpty(group)) {
87+
group = createPrometheusRuleGroup(groupName);
88+
}
7489
groups.add(group);
7590
var rules = group.getRules();
7691
if (rules == null) {

0 commit comments

Comments
 (0)