wu-sheng commented on a change in pull request #6888:
URL: https://github.com/apache/skywalking/pull/6888#discussion_r628840628



##########
File path: 
oap-server/server-query-plugin/query-graphql-plugin/src/main/java/org/apache/skywalking/oap/query/graphql/resolver/AlarmQuery.java
##########
@@ -50,23 +65,199 @@ private AlarmQueryService getQueryService() {
         return queryService;
     }
 
+    private EventQueryService getEventQueryService() {
+        if (eventQueryService == null) {
+            this.eventQueryService = 
moduleManager.find(CoreModule.NAME).provider().getService(EventQueryService.class);
+        }
+        return eventQueryService;
+    }
+
+    private ForkJoinPool getForkJoinPool() {
+        if (forkJoinPool == null) {
+            this.forkJoinPool = new 
ForkJoinPool(Runtime.getRuntime().availableProcessors());
+        }
+        return forkJoinPool;
+    }
+
     public AlarmTrend getAlarmTrend(final Duration duration) {
         return new AlarmTrend();
     }
 
     public Alarms getAlarm(final Duration duration, final Scope scope, final 
String keyword,
-                           final Pagination paging, final List<Tag> tags) 
throws IOException {
+                           final Pagination paging, final List<Tag> tags) 
throws Throwable {
         Integer scopeId = null;
         if (scope != null) {
             scopeId = scope.getScopeId();
         }
         long startSecondTB = 0;
         long endSecondTB = 0;
+        EventQueryCondition condition = new EventQueryCondition();
         if (nonNull(duration)) {
             startSecondTB = duration.getStartTimeBucketInSec();
             endSecondTB = duration.getEndTimeBucketInSec();
+            condition.setTime(duration);
+        }
+        Alarms alarms = getQueryService().getAlarm(
+                scopeId, keyword, paging, startSecondTB, endSecondTB, tags);
+        return includeEvents2AlarmsByCondition(alarms, condition);
+    }
+
+    private Alarms includeEvents2AlarmsByCondition(Alarms alarms, 
EventQueryCondition condition) throws Throwable {
+        if (alarms.getTotal() < 1) {
+            return alarms;
+        }
+        SearchEventTask searchEventTask = new 
SearchEventTask(alarms.getMsgs(), condition);
+        ForkJoinTask<List<AlarmMessage>> queryEventTask = 
getForkJoinPool().submit(searchEventTask);

Review comment:
       A question, do we really need this? At least, do we really need this at 
OAP service level?
   Multiple conditions match(like a `OR` in SQL) could be handled by ES 
`should` or `SQL's OR statement`or `SQL's Union statement`. I think most 
database has good optimization to do this kind of query in the DB engine.




-- 
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