Skip to content

Commit

Permalink
reduce load for metrics bean
Browse files Browse the repository at this point in the history
  • Loading branch information
krusche committed Nov 27, 2024
1 parent 545e376 commit 5782918
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -290,16 +290,15 @@ private void registerLocalCIMetrics() {
}

private static int extractRunningBuilds(Optional<SharedQueueManagementService> sharedQueueManagementService) {
return sharedQueueManagementService.map(queueManagementService -> queueManagementService.getBuildAgentInformation().stream()
.map(buildAgentInformation -> buildAgentInformation.runningBuildJobs().size()).reduce(0, Integer::sum)).orElse(0);
return sharedQueueManagementService.map(SharedQueueManagementService::getProcessingJobsSize).orElse(0);
}

private static int extractQueuedBuilds(Optional<SharedQueueManagementService> sharedQueueManagementService) {
return sharedQueueManagementService.map(queueManagementService -> queueManagementService.getQueuedJobs().size()).orElse(0);
return sharedQueueManagementService.map(SharedQueueManagementService::getQueuedJobsSize).orElse(0);
}

private static int extractBuildAgents(Optional<SharedQueueManagementService> sharedQueueManagementService) {
return sharedQueueManagementService.map(queueManagementService -> queueManagementService.getBuildAgentInformation().size()).orElse(0);
return sharedQueueManagementService.map(SharedQueueManagementService::getBuildAgentInformationSize).orElse(0);
}

private static int extractMaxConcurrentBuilds(Optional<SharedQueueManagementService> sharedQueueManagementService) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,10 @@ public List<BuildJobQueueItem> getQueuedJobs() {
return new ArrayList<>(queue);
}

public int getQueuedJobsSize() {
return queue.size();
}

/**
* @return a copy of the processing jobs as ArrayList
*/
Expand All @@ -124,6 +128,10 @@ public List<BuildJobQueueItem> getProcessingJobs() {
return new ArrayList<>(processingJobs.values());
}

public int getProcessingJobsSize() {
return processingJobs.size();
}

public List<BuildJobQueueItem> getQueuedJobsForCourse(long courseId) {
return getQueuedJobs().stream().filter(job -> job.courseId() == courseId).toList();
}
Expand All @@ -145,6 +153,10 @@ public List<BuildAgentInformation> getBuildAgentInformation() {
return new ArrayList<>(buildAgentInformation.values());
}

public int getBuildAgentInformationSize() {
return buildAgentInformation.size();
}

public List<BuildAgentInformation> getBuildAgentInformationWithoutRecentBuildJobs() {
return getBuildAgentInformation().stream().map(agent -> new BuildAgentInformation(agent.buildAgent(), agent.maxNumberOfConcurrentBuildJobs(),
agent.numberOfCurrentBuildJobs(), agent.runningBuildJobs(), agent.status(), null, null)).toList();
Expand Down Expand Up @@ -303,5 +315,4 @@ public Page<BuildJob> getFilteredFinishedBuildJobs(FinishedBuildJobPageableSearc

return new PageImpl<>(orderedBuildJobs, buildJobIdsPage.getPageable(), buildJobIdsPage.getTotalElements());
}

}

0 comments on commit 5782918

Please sign in to comment.