From b897f452c43b8d91a955da09f977b60b588660ed Mon Sep 17 00:00:00 2001 From: emeroad Date: Thu, 7 Jul 2022 14:32:40 +0900 Subject: [PATCH] [#9017] Add max limit to getApplicationHostInfo for OOM prevent --- .../web/controller/ApplicationController.java | 18 ++++++++---------- .../pinpoint/web/service/AgentInfoService.java | 4 ++-- .../web/service/AgentInfoServiceImpl.java | 16 +++++----------- 3 files changed, 15 insertions(+), 23 deletions(-) diff --git a/web/src/main/java/com/navercorp/pinpoint/web/controller/ApplicationController.java b/web/src/main/java/com/navercorp/pinpoint/web/controller/ApplicationController.java index c98ba32bb3da..38d1f62d0248 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/controller/ApplicationController.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/controller/ApplicationController.java @@ -21,6 +21,7 @@ import com.navercorp.pinpoint.web.service.ApplicationService; import com.navercorp.pinpoint.web.vo.ApplicationAgentHostList; import com.navercorp.pinpoint.web.response.CodeResult; +import org.apache.commons.lang3.ObjectUtils; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -36,6 +37,7 @@ @RestController public class ApplicationController { + public static final int MAX_PAGING_LIMIT = 100; private final AgentInfoService agentInfoService; @@ -46,19 +48,15 @@ public ApplicationController(AgentInfoService agentInfoService, ApplicationServi this.applicationService = Objects.requireNonNull(applicationService, "applicationService"); } - @GetMapping(value = "/getApplicationHostInfo", params = {"!durationDays"}) - public ApplicationAgentHostList getApplicationHostInfo ( - @RequestParam(value = "offset", required = false, defaultValue = "1") int offset, - @RequestParam(value = "limit", required = false, defaultValue = "100") int limit) { - return agentInfoService.getApplicationAgentHostList(offset, limit); - } - - @GetMapping(value = "/getApplicationHostInfo", params = {"durationDays"}) + @GetMapping(value = "/getApplicationHostInfo") public ApplicationAgentHostList getApplicationHostInfo ( @RequestParam(value = "offset", required = false, defaultValue = "1") int offset, @RequestParam(value = "limit", required = false, defaultValue = "100") int limit, - @RequestParam(value = "durationDays") int durationDays) { - return agentInfoService.getApplicationAgentHostList(offset, limit, durationDays); + @RequestParam(value = "durationDays", required = false) Integer durationDays) { + int maxLimit = Math.min(MAX_PAGING_LIMIT, limit); + durationDays = ObjectUtils.defaultIfNull(durationDays, AgentInfoService.NO_DURATION); + + return agentInfoService.getApplicationAgentHostList(offset, maxLimit, durationDays); } @RequestMapping(value = "/isAvailableApplicationName") diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoService.java b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoService.java index 01a769288500..d7ff793e0031 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoService.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoService.java @@ -36,12 +36,12 @@ */ public interface AgentInfoService { + int NO_DURATION = -1; + ApplicationAgentsList getAllApplicationAgentsList(AgentInfoFilter filter, long timestamp); ApplicationAgentsList getApplicationAgentsList(ApplicationAgentsList.GroupBy key, AgentInfoFilter filter, String applicationName, long timestamp); - ApplicationAgentHostList getApplicationAgentHostList(int offset, int limit); - ApplicationAgentHostList getApplicationAgentHostList(int offset, int limit, int durationDays); Set getAgentsByApplicationName(String applicationName, long timestamp); diff --git a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoServiceImpl.java b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoServiceImpl.java index 9ba65cadb084..40505e67b67c 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoServiceImpl.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/service/AgentInfoServiceImpl.java @@ -123,19 +123,13 @@ public ApplicationAgentsList getApplicationAgentsList(ApplicationAgentsList.Grou return applicationAgentsList; } - @Override - public ApplicationAgentHostList getApplicationAgentHostList(int offset, int limit) { - if (offset <= 0 || limit <= 0) { - throw new IllegalArgumentException("Value must be greater than 0."); - } - - return getApplicationAgentHostList0(offset, limit, -1); - } - @Override public ApplicationAgentHostList getApplicationAgentHostList(int offset, int limit, int durationDays) { - if (offset <= 0 || limit <= 0) { - throw new IllegalArgumentException("Value must be greater than 0."); + if (offset <= 0) { + throw new IllegalArgumentException("offset must be greater than 0"); + } + if (limit <= 0) { + throw new IllegalArgumentException("limit must be greater than 0"); } return getApplicationAgentHostList0(offset, limit, durationDays);