kezhenxu94 commented on a change in pull request #6888:
URL: https://github.com/apache/skywalking/pull/6888#discussion_r624609090



##########
File path: 
oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/AlarmQuery.java
##########
@@ -62,11 +85,166 @@ public Alarms getAlarm(final Duration duration, final 
Scope scope, final String
         }
         long startSecondTB = 0;
         long endSecondTB = 0;
+        EventQueryCondition condition = new EventQueryCondition();
         if (nonNull(duration)) {
             startSecondTB = duration.getStartTimeBucketInSec();
             endSecondTB = duration.getEndTimeBucketInSec();
+            condition.setTime(duration);
+        }
+        condition.setType(EventType.Error);
+        condition.setName("Alarm");
+        Alarms alarms = getQueryService().getAlarm(
+                scopeId, keyword, paging, startSecondTB, endSecondTB, tags);
+        Events events = null;
+        try {
+            events = getEventQueryService().queryEvents(condition);
+        } catch (Throwable e) {
+            LOGGER.error(e.getMessage(), e);
+            return alarms;
         }
-        return getQueryService().getAlarm(
-            scopeId, keyword, paging, startSecondTB, endSecondTB, tags);
+        return includeEvents2Alarms(alarms, events);
+    }
+
+    private Alarms includeEvents2Alarms(Alarms alarms, Events events) {
+        if (alarms.getTotal() < 1 || CollectionUtils.isEmpty(alarms.getMsgs()) 
|| events.getTotal() < 1 || CollectionUtils.isEmpty(events.getEvents())) {
+            return alarms;
+        }
+        Map<String, List<Event>> mappingMap = 
events.getEvents().stream().collect(Collectors.groupingBy(Event::getServiceInSource));
+        alarms.getMsgs().forEach(a -> {
+            switch (a.getScopeId()) {
+                case DefaultScopeDefine.SERVICE :
+                    List<Event> serviceEvent = 
mappingMap.get(IDManager.ServiceID.analysisId(a.getId()).getName());
+                    if (CollectionUtils.isNotEmpty(serviceEvent)) {
+                        if (serviceEvent.size() == 1) {
+                            a.setEvents(serviceEvent);
+                        } else {
+                            Event event = serviceEvent.stream().filter(e -> 
StringUtils.equals(a.getMessage(), e.getMessage())).findFirst().orElse(null);

Review comment:
       Ditto, filtering according to the message makes no sense as per our goal




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to