-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[improve] update alarm inhibit rule and alarm ui #2957
Merged
Merged
Changes from 11 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
32c8095
[improve] update alarm inhibit
tomsun28 952ae1f
[improve] update alarm inhibit
tomsun28 c6ee842
[improve] update alarm inhibit
tomsun28 9883fb0
[improve] update alarm inhibit
tomsun28 b296667
[improve] update alarm inhibit
tomsun28 bb86428
[improve] update alarm inhibit
tomsun28 9c5ebe0
[webapp] update UI
tomsun28 810b2c3
[improve] update alarm inhibit
tomsun28 908a9e5
[improve] update alarm inhibit
tomsun28 a15f2ac
[webapp] update UI
tomsun28 bc603bc
[webapp] update UI
tomsun28 b426c1e
[improve] update alarm inhibit
tomsun28 59d721d
Add @lctking as a contributor
tomsun28 9a1a6f6
Add @simonsigre as a contributor
tomsun28 34335cd
Add @ponfee as a contributor
tomsun28 7bb7e23
Add @Vedant7789 as a contributor
tomsun28 3dff4c3
Add @Craaaaazy77 as a contributor
tomsun28 e5edd75
[improve] update alarm inhibit
tomsun28 2a6c05f
[improve] fix export import bug
tomsun28 4595982
[improve] fix export import bug
tomsun28 a486831
[improve] fix export import bug
tomsun28 9dd5328
[improve] fix export import bug
tomsun28 6255ba2
Merge branch 'master' into alarm-inhibit
tomsun28 14641e1
[improve] fix status bug
tomsun28 ff2cabf
Merge branch 'master' into alarm-inhibit
tomsun28 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
hertzbeat-alerter/src/test/java/org/apache/hertzbeat/alert/reduce/AlarmGroupReduceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package org.apache.hertzbeat.alert.reduce; | ||
|
||
|
||
|
||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.argThat; | ||
import static org.mockito.Mockito.never; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import org.apache.hertzbeat.alert.dao.AlertGroupConvergeDao; | ||
import org.apache.hertzbeat.common.entity.alerter.AlertGroupConverge; | ||
import org.apache.hertzbeat.common.entity.alerter.SingleAlert; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
|
||
/** | ||
* Test for AlarmGroupReduce | ||
*/ | ||
class AlarmGroupReduceTest { | ||
|
||
@Mock | ||
private AlarmInhibitReduce alarmInhibitReduce; | ||
|
||
@Mock | ||
private AlertGroupConvergeDao alertGroupConvergeDao; | ||
|
||
private AlarmGroupReduce alarmGroupReduce; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
MockitoAnnotations.openMocks(this); | ||
when(alertGroupConvergeDao.findAlertGroupConvergesByEnableIsTrue()) | ||
.thenReturn(Collections.emptyList()); | ||
alarmGroupReduce = new AlarmGroupReduce(alarmInhibitReduce, alertGroupConvergeDao); | ||
} | ||
|
||
@Test | ||
void whenNoGroupRules_shouldSendSingleAlert() { | ||
SingleAlert alert = SingleAlert.builder() | ||
.fingerprint("fp1") | ||
.status("firing") | ||
.labels(createLabels("severity", "critical")) | ||
.build(); | ||
|
||
alarmGroupReduce.processGroupAlert(alert); | ||
|
||
verify(alarmInhibitReduce).inhibitAlarm(argThat(group -> | ||
group.getAlerts().size() == 1 && group.getAlerts().get(0).getFingerprint().equals("fp1"))); | ||
} | ||
|
||
@Test | ||
void whenMatchingGroupRule_shouldGroup() { | ||
// Setup group rule | ||
AlertGroupConverge rule = new AlertGroupConverge(); | ||
rule.setName("test-rule"); | ||
rule.setGroupLabels(Arrays.asList("severity", "instance")); | ||
when(alertGroupConvergeDao.findAlertGroupConvergesByEnableIsTrue()) | ||
.thenReturn(Collections.singletonList(rule)); | ||
alarmGroupReduce.refreshGroupDefines(Collections.singletonList(rule)); | ||
|
||
SingleAlert alert = SingleAlert.builder() | ||
.fingerprint("fp1") | ||
.status("firing") | ||
.labels(createLabels("severity", "critical", "instance", "host1")) | ||
.build(); | ||
|
||
alarmGroupReduce.processGroupAlert(alert); | ||
|
||
// Verify group is created and cached (implicitly tested through internal state) | ||
verify(alarmInhibitReduce, never()).inhibitAlarm(any()); // Should not send immediately due to group wait | ||
} | ||
|
||
private Map<String, String> createLabels(String... keyValues) { | ||
Map<String, String> labels = new HashMap<>(); | ||
for (int i = 0; i < keyValues.length; i += 2) { | ||
labels.put(keyValues[i], keyValues[i + 1]); | ||
} | ||
return labels; | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.