You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@inlong.apache.org by GitBox <gi...@apache.org> on 2022/01/19 11:33:13 UTC

[GitHub] [incubator-inlong] doleyzi commented on a change in pull request #2194: [INLONG-2192] Audit data supports auditId query batch

doleyzi commented on a change in pull request #2194:
URL: https://github.com/apache/incubator-inlong/pull/2194#discussion_r787656338



##########
File path: inlong-manager/manager-service/src/main/java/org/apache/inlong/manager/service/core/impl/AuditServiceImpl.java
##########
@@ -75,49 +76,54 @@
     public List<AuditVO> listByCondition(AuditRequest request) throws IOException {
         LOGGER.info("begin query audit list request={}", request);
         Preconditions.checkNotNull(request, "request is null");
-        List<AuditVO> result = Collections.emptyList();
+        List<AuditVO> result = new ArrayList<>();
         AuditQuerySource querySource = AuditQuerySource.valueOf(auditQuerySource);
-        if (AuditQuerySource.MYSQL == querySource) {
-            String format = "%Y-%m-%d %H:%i:00";
-            // Support min agg at now
-            DateTimeFormatter forPattern = DateTimeFormat.forPattern("yyyy-MM-dd");
-            DateTime dtDate = forPattern.parseDateTime(request.getDt());
-            String eDate = dtDate.plusDays(1).toString(forPattern);
-            List<Map<String, Object>> sumList = auditEntityMapper
-                    .sumByLogTs(request.getInlongGroupId(), request.getInlongStreamId(),
-                            request.getAuditId(), request.getDt(), eDate, format);
-            result = sumList.stream().map(s -> {
-                AuditVO vo = new AuditVO();
-                vo.setLogTs((String) s.get("logTs"));
-                vo.setCount(((BigDecimal) s.get("total")).longValue());
-                return vo;
-            }).collect(Collectors.toList());
-        } else if (AuditQuerySource.ELASTICSEARCH == querySource) {
-            String index = String.format("%s_%s",
-                    request.getDt().replaceAll("-", ""), request.getAuditId());
-            if (elasticsearchApi.indexExists(index)) {
-                SearchResponse response = elasticsearchApi
-                        .search(toAuditSearchRequest(index, request.getInlongGroupId(), request.getInlongStreamId()));
-                final List<Aggregation> aggregations = response.getAggregations().asList();
-                if (CollectionUtils.isNotEmpty(aggregations)) {
-                    ParsedTerms terms = (ParsedTerms) aggregations.get(0);
-                    if (CollectionUtils.isNotEmpty(terms.getBuckets())) {
-                        result = terms.getBuckets().stream().map(bucket -> {
-                            AuditVO vo = new AuditVO();
-                            vo.setLogTs(bucket.getKeyAsString());
-                            vo.setCount((long) ((ParsedSum) bucket.getAggregations().asList().get(0)).getValue());
-                            return vo;
-                        }).collect(Collectors.toList());
+        for (String auditId : request.getAuditIds()) {
+            if (AuditQuerySource.MYSQL == querySource) {
+                String format = "%Y-%m-%d %H:%i:00";
+                // Support min agg at now
+                DateTimeFormatter forPattern = DateTimeFormat.forPattern("yyyy-MM-dd");
+                DateTime dtDate = forPattern.parseDateTime(request.getDt());
+                String eDate = dtDate.plusDays(1).toString(forPattern);
+                List<Map<String, Object>> sumList = auditEntityMapper
+                        .sumByLogTs(request.getInlongGroupId(), request.getInlongStreamId(),
+                                auditId, request.getDt(), eDate, format);
+                List<AuditInfo> auditSet = sumList.stream().map(s -> {
+                    AuditInfo vo = new AuditInfo();
+                    vo.setLogTs((String) s.get("logTs"));
+                    vo.setCount(((BigDecimal) s.get("total")).longValue());
+                    return vo;
+                }).collect(Collectors.toList());
+                result.add(new AuditVO(auditId, auditSet));
+            } else if (AuditQuerySource.ELASTICSEARCH == querySource) {
+                String index = String.format("%s_%s",
+                        request.getDt().replaceAll("-", ""), auditId);
+                if (elasticsearchApi.indexExists(index)) {
+                    SearchResponse response = elasticsearchApi
+                            .search(toAuditSearchRequest(index, request.getInlongGroupId(),
+                                    request.getInlongStreamId()));
+                    final List<Aggregation> aggregations = response.getAggregations().asList();
+                    if (CollectionUtils.isNotEmpty(aggregations)) {
+                        ParsedTerms terms = (ParsedTerms) aggregations.get(0);
+                        if (CollectionUtils.isNotEmpty(terms.getBuckets())) {

Review comment:
       It is recommended to reduce the circle responsibility




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

To unsubscribe, e-mail: commits-unsubscribe@inlong.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org