use of org.apache.skywalking.oap.server.core.alarm.AlarmMessage in project incubator-skywalking by apache.
the class EventHookCallbackTest method testEventCallbackHasRightFlow.
@Test
public void testEventCallbackHasRightFlow() throws Exception {
List<AlarmMessage> msgs = mockAlarmMessagesHasSingleElement();
EventHookCallback callback = new EventHookCallback(this.moduleManager);
when(moduleManager.find("event-analyzer")).thenReturn(moduleProviderHolder);
when(moduleProviderHolder.provider()).thenReturn(moduleServiceHolder);
when(moduleServiceHolder.getService(EventAnalyzerService.class)).thenReturn(mockEventAnalyzerService);
// make sure current service be called.
callback.doAlarm(msgs);
verify(mockEventAnalyzerService).analyze(any(Event.class));
when(moduleServiceHolder.getService(EventAnalyzerService.class)).thenReturn(eventAnalyzerService);
callback.doAlarm(msgs);
// Ensure that the current Event is properly constructed
ArgumentCaptor<Event> argument = ArgumentCaptor.forClass(Event.class);
verify(eventAnalyzerService).analyze(argument.capture());
Event value = argument.getValue();
AlarmMessage msg = msgs.get(0);
assertEquals(msg.getName(), value.getSource().getService());
assertEquals("Alarm", value.getName());
assertEquals(msg.getAlarmMessage(), value.getMessage());
assertEquals(msg.getPeriod(), (value.getEndTime() - value.getStartTime()) / 1000 / 60);
}
use of org.apache.skywalking.oap.server.core.alarm.AlarmMessage in project incubator-skywalking by apache.
the class EventHookCallbackTest method mockAlarmMessagesHasSourceAndDest.
private List<AlarmMessage> mockAlarmMessagesHasSourceAndDest() {
AlarmMessage msg = new AlarmMessage();
msg.setScopeId(DefaultScopeDefine.SERVICE_RELATION);
msg.setScope("");
msg.setName("test-skywalking");
msg.setId0(IDManager.ServiceID.buildId("sourceIdStr", true));
msg.setId1(IDManager.ServiceID.buildId("destIdStr", true));
msg.setAlarmMessage("Alarm caused by Rule service_resp_time_rule");
msg.setPeriod(5);
return Arrays.asList(msg);
}
use of org.apache.skywalking.oap.server.core.alarm.AlarmMessage in project incubator-skywalking by apache.
the class EventHookCallbackTest method testRelationEventBeProperlyConstructed.
@Test
public void testRelationEventBeProperlyConstructed() {
List<AlarmMessage> msgs = mockAlarmMessagesHasSourceAndDest();
EventHookCallback callback = new EventHookCallback(this.moduleManager);
when(moduleManager.find("event-analyzer")).thenReturn(moduleProviderHolder);
when(moduleProviderHolder.provider()).thenReturn(moduleServiceHolder);
when(moduleServiceHolder.getService(EventAnalyzerService.class)).thenReturn(eventAnalyzerService);
callback.doAlarm(msgs);
ArgumentCaptor<Event> argument = ArgumentCaptor.forClass(Event.class);
verify(eventAnalyzerService, times(2)).analyze(argument.capture());
List<Event> events = argument.getAllValues();
assertEquals(events.size(), 2);
Event sourceEvent = events.get(0);
Event destEvent = events.get(1);
AlarmMessage msg = msgs.get(0);
assertEquals(sourceEvent.getSource().getService(), IDManager.ServiceID.analysisId(msg.getId0()).getName());
assertEquals((sourceEvent.getEndTime() - sourceEvent.getStartTime()) / 1000 / 60, msg.getPeriod());
assertEquals(destEvent.getSource().getService(), IDManager.ServiceID.analysisId(msg.getId1()).getName());
assertEquals((destEvent.getEndTime() - destEvent.getStartTime()) / 1000 / 60, msg.getPeriod());
}
use of org.apache.skywalking.oap.server.core.alarm.AlarmMessage in project incubator-skywalking by apache.
the class RunningRuleTest method testMultipleValuesAlarm.
@Test
public void testMultipleValuesAlarm() {
AlarmRule alarmRule = new AlarmRule();
alarmRule.setAlarmRuleName("endpoint_multiple_values_rule");
alarmRule.setMetricsName("endpoint_percent");
alarmRule.setOp(">");
alarmRule.setThreshold("50,60,70,-, 100");
alarmRule.setCount(3);
alarmRule.setPeriod(15);
alarmRule.setMessage("response percentile of endpoint {name} is lower than expected values");
alarmRule.setTags(new HashMap<String, String>() {
{
put("key", "value");
}
});
RunningRule runningRule = new RunningRule(alarmRule);
LocalDateTime startTime = TIME_BUCKET_FORMATTER.parseLocalDateTime("201808301440");
long timeInPeriod1 = 201808301434L;
long timeInPeriod2 = 201808301436L;
long timeInPeriod3 = 201808301438L;
runningRule.in(getMetaInAlarm(123), getMultipleValueMetrics(timeInPeriod1, 70, 60, 40, 40, 40));
runningRule.in(getMetaInAlarm(123), getMultipleValueMetrics(timeInPeriod2, 60, 60, 40, 40, 40));
// check at 201808301440
List<AlarmMessage> alarmMessages = runningRule.check();
Assert.assertEquals(0, alarmMessages.size());
runningRule.moveTo(TIME_BUCKET_FORMATTER.parseLocalDateTime("201808301441"));
runningRule.in(getMetaInAlarm(123), getMultipleValueMetrics(timeInPeriod3, 74, 60, 40, 40, 40));
// check at 201808301440
alarmMessages = runningRule.check();
Assert.assertEquals(1, alarmMessages.size());
runningRule.moveTo(TIME_BUCKET_FORMATTER.parseLocalDateTime("201808301441"));
}
use of org.apache.skywalking.oap.server.core.alarm.AlarmMessage in project incubator-skywalking by apache.
the class RunningRuleTest method testAlarm.
@Test
public void testAlarm() {
AlarmRule alarmRule = new AlarmRule();
alarmRule.setAlarmRuleName("endpoint_percent_rule");
alarmRule.setMetricsName("endpoint_percent");
alarmRule.setOp("<");
alarmRule.setThreshold("75");
alarmRule.setCount(3);
alarmRule.setPeriod(15);
alarmRule.setMessage("Successful rate of endpoint {name} is lower than 75%");
alarmRule.setTags(new HashMap<String, String>() {
{
put("key", "value");
}
});
RunningRule runningRule = new RunningRule(alarmRule);
LocalDateTime startTime = TIME_BUCKET_FORMATTER.parseLocalDateTime("201808301440");
long timeInPeriod1 = 201808301434L;
long timeInPeriod2 = 201808301436L;
long timeInPeriod3 = 201808301438L;
runningRule.in(getMetaInAlarm(123), getMetrics(timeInPeriod1, 70));
runningRule.in(getMetaInAlarm(123), getMetrics(timeInPeriod2, 71));
// check at 201808301440
List<AlarmMessage> alarmMessages = runningRule.check();
Assert.assertEquals(0, alarmMessages.size());
runningRule.in(getMetaInAlarm(123), getMetrics(timeInPeriod3, 74));
// check at 201808301440
alarmMessages = runningRule.check();
Assert.assertEquals(1, alarmMessages.size());
}
Aggregations