Search in sources :

Example 1 with AlarmMessage

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);
}
Also used : AlarmMessage(org.apache.skywalking.oap.server.core.alarm.AlarmMessage) Event(org.apache.skywalking.apm.network.event.v3.Event) Test(org.junit.Test)

Example 2 with AlarmMessage

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);
}
Also used : AlarmMessage(org.apache.skywalking.oap.server.core.alarm.AlarmMessage)

Example 3 with AlarmMessage

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());
}
Also used : AlarmMessage(org.apache.skywalking.oap.server.core.alarm.AlarmMessage) Event(org.apache.skywalking.apm.network.event.v3.Event) Test(org.junit.Test)

Example 4 with AlarmMessage

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"));
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) AlarmMessage(org.apache.skywalking.oap.server.core.alarm.AlarmMessage) Test(org.junit.Test)

Example 5 with AlarmMessage

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());
}
Also used : LocalDateTime(org.joda.time.LocalDateTime) AlarmMessage(org.apache.skywalking.oap.server.core.alarm.AlarmMessage) Test(org.junit.Test)

Aggregations

AlarmMessage (org.apache.skywalking.oap.server.core.alarm.AlarmMessage)44 ArrayList (java.util.ArrayList)24 Test (org.junit.Test)24 AlarmRulesWatcher (org.apache.skywalking.oap.server.core.alarm.provider.AlarmRulesWatcher)14 Rules (org.apache.skywalking.oap.server.core.alarm.provider.Rules)14 LocalDateTime (org.joda.time.LocalDateTime)8 Event (org.apache.skywalking.apm.network.event.v3.Event)4 Tag (org.apache.skywalking.oap.server.core.analysis.manual.searchtag.Tag)4 StreamObserver (io.grpc.stub.StreamObserver)2 HashMap (java.util.HashMap)2 List (java.util.List)2 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)2 Executors (java.util.concurrent.Executors)2 TimeUnit (java.util.concurrent.TimeUnit)2 Collectors (java.util.stream.Collectors)2 AlarmCallback (org.apache.skywalking.oap.server.core.alarm.AlarmCallback)2 EndpointMetaInAlarm (org.apache.skywalking.oap.server.core.alarm.EndpointMetaInAlarm)2 EndpointRelationMetaInAlarm (org.apache.skywalking.oap.server.core.alarm.EndpointRelationMetaInAlarm)2 MetaInAlarm (org.apache.skywalking.oap.server.core.alarm.MetaInAlarm)2 ProcessMetaInAlarm (org.apache.skywalking.oap.server.core.alarm.ProcessMetaInAlarm)2