diff --git a/wasin/src/main/java/com/wasin/wasin/_core/util/web_api/MonitoringApiUtil.java b/wasin/src/main/java/com/wasin/wasin/_core/util/web_api/MonitoringApiUtil.java index 8055c84..a09373d 100644 --- a/wasin/src/main/java/com/wasin/wasin/_core/util/web_api/MonitoringApiUtil.java +++ b/wasin/src/main/java/com/wasin/wasin/_core/util/web_api/MonitoringApiUtil.java @@ -33,9 +33,9 @@ public RouterResponse.MonitorResult getMetric(Metric metric, Router router, Long return getResult(monitoringQuery); } - public RouterResponse.MonitorResult getMetricInRangeTime(Metric metric, Router router, Long nowTime, Long targetTime) { + public RouterResponse.MonitorResult getMetricInRangeTime(Metric metric, Router router, Long time) { String expr = getExpression(metric, router); - RouterResponse.MonitoringQueries monitoringQuery = getMonitoringQueryInRange(expr, nowTime, targetTime); + RouterResponse.MonitoringQueries monitoringQuery = getMonitoringQuery(expr, time); return getResult(monitoringQuery); } @@ -102,6 +102,7 @@ private RouterResponse.MonitorResult getResult(RouterResponse.MonitoringQueries return new ServerException(BaseException.GRAFANA_REQUEST_FAIL); })) .bodyToMono(RouterResponse.MonitorResult.class) + .doOnSuccess(result -> log.debug(result.toString())) .block()); } catch(Exception e) { log.debug(e.getMessage()); @@ -120,17 +121,6 @@ private RouterResponse.MonitoringQueries getMonitoringQuery(String expr, Long ti ); } - private RouterResponse.MonitoringQueries getMonitoringQueryInRange(String expr, Long nowTime, Long targetTime) { - RouterResponse.Datasource datasource = new RouterResponse.Datasource("prometheus", grafanaDatasourceUID); - RouterResponse.MonitoringQuery query = getQuery(expr, datasource); - - return new RouterResponse.MonitoringQueries( - List.of(query), - nowTime.toString(), - targetTime.toString() - ); - } - private static RouterResponse.MonitoringQuery getQuery(String expr, RouterResponse.Datasource datasource) { return new RouterResponse.MonitoringQuery( datasource, diff --git a/wasin/src/main/java/com/wasin/wasin/domain/validation/RouterValidation.java b/wasin/src/main/java/com/wasin/wasin/domain/validation/RouterValidation.java index ef20223..63487fc 100644 --- a/wasin/src/main/java/com/wasin/wasin/domain/validation/RouterValidation.java +++ b/wasin/src/main/java/com/wasin/wasin/domain/validation/RouterValidation.java @@ -23,7 +23,7 @@ public void checkRouterNonExistInDB(RouterRequest.CreateDTO requestDTO) { } public void checkRouterPermission(Router router, User user) { - if (!user.getCompany().equals(router.getCompany())) { + if (!user.getCompany().getId().equals(router.getCompany().getId())) { throw new ForbiddenException(BaseException.ROUTER_PERMISSION_DENIED); } } diff --git a/wasin/src/main/java/com/wasin/wasin/service/impl/MonitoringServiceImpl.java b/wasin/src/main/java/com/wasin/wasin/service/impl/MonitoringServiceImpl.java index 4340ee8..223da67 100644 --- a/wasin/src/main/java/com/wasin/wasin/service/impl/MonitoringServiceImpl.java +++ b/wasin/src/main/java/com/wasin/wasin/service/impl/MonitoringServiceImpl.java @@ -15,13 +15,13 @@ import com.wasin.wasin.repository.UserJPARepository; import com.wasin.wasin.service.MonitoringService; import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.time.LocalDateTime; -import java.time.ZoneOffset; import java.util.List; +@Slf4j @RequiredArgsConstructor @Transactional(readOnly = true) @Service @@ -43,6 +43,7 @@ public MonitorResponse.FindById monitorById(Long routerId, Long metricId, Long t monitoringValidation.checkRouterExistInGroup(router, user); RouterResponse.MonitorResult results = monitoringApiUtil.getMetric(metric, router, time); + log.debug(results.toString()); return monitoringMapper.resultToDTO(results, metricId, time); } @@ -56,11 +57,9 @@ public MonitorResponse.FindMultiple monitorMultiple(Long metricId, Long time, Us Company company = user.getCompany(); List routerList = routerJPARepository.findAllRouterByCompanyId(company.getId()); - long toTime = LocalDateTime.now().atZone(ZoneOffset.UTC).toInstant().toEpochMilli() - 60 * 60 * 1000 * 9; - long fromTime = toTime - time * 60 * 1000; - + Long finalTime = time; List results = routerList.stream().map(router -> - monitoringApiUtil.getMetricInRangeTime(metric, router, fromTime, toTime) + monitoringApiUtil.getMetricInRangeTime(metric, router, finalTime) ).toList(); return monitoringMapper.resultToMultipleDTO(results, metricId, time);