Skip to content

Commit

Permalink
[#9017] Add max limit to getApplicationHostInfo for OOM prevent
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Jul 7, 2022
1 parent 00d181c commit b897f45
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -36,6 +37,7 @@

@RestController
public class ApplicationController {
public static final int MAX_PAGING_LIMIT = 100;

private final AgentInfoService agentInfoService;

Expand All @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<AgentInfo> getAgentsByApplicationName(String applicationName, long timestamp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit b897f45

Please sign in to comment.