Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stop fetching completed tasks count from DB #638

Merged
merged 3 commits into from
Dec 4, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -11,6 +11,7 @@ All notable changes to this project will be documented in this file.
- Move `PlatformMetric` to `iexec-core-library` subproject, modify it to become immutable. (#628 #629)
- Add prometheus endpoint with custom metrics. (#632)
- Expose version through prometheus endpoint. (#637)
- Stop fetching completed tasks count from DB. (#638)

### Quality

Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ public class PlatformMetric {
int aliveAvailableCpu;
int aliveTotalGpu;
int aliveAvailableGpu;
int completedTasks;
long completedTasks;
long dealEventsCount;
long dealsCount;
long replayDealsCount;
3 changes: 1 addition & 2 deletions src/main/java/com/iexec/core/metric/MetricService.java
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@

import com.iexec.core.chain.DealWatcherService;
import com.iexec.core.task.TaskService;
import com.iexec.core.task.TaskStatus;
import com.iexec.core.worker.WorkerService;
import org.springframework.stereotype.Service;

@@ -43,7 +42,7 @@ public PlatformMetric getPlatformMetrics() {
.aliveAvailableCpu(workerService.getAliveAvailableCpu())
.aliveTotalGpu(workerService.getAliveTotalGpu())
.aliveAvailableGpu(workerService.getAliveAvailableGpu())
.completedTasks(taskService.findByCurrentStatus(TaskStatus.COMPLETED).size())
.completedTasks(taskService.getCompletedTasksCount())
.dealEventsCount(dealWatcherService.getDealEventsCount())
.dealsCount(dealWatcherService.getDealsCount())
.replayDealsCount(dealWatcherService.getReplayDealsCount())
4 changes: 4 additions & 0 deletions src/main/java/com/iexec/core/task/TaskService.java
Original file line number Diff line number Diff line change
@@ -260,4 +260,8 @@ public boolean isConsensusReached(ReplicatesList replicatesList) {
int offChainWinners = replicatesList.getNbValidContributedWinners(chainTask.getConsensusValue());
return offChainWinners >= onChainWinners;
}

public long getCompletedTasksCount() {
return (long) completedTasksCounter.count();
}
}
9 changes: 4 additions & 5 deletions src/test/java/com/iexec/core/metric/MetricServiceTests.java
Original file line number Diff line number Diff line change
@@ -18,7 +18,6 @@

import com.iexec.core.chain.DealWatcherService;
import com.iexec.core.task.TaskService;
import com.iexec.core.task.TaskStatus;
import com.iexec.core.worker.Worker;
import com.iexec.core.worker.WorkerService;
import org.junit.jupiter.api.BeforeEach;
@@ -58,8 +57,8 @@ void shouldGetPlatformMetrics() {
when(workerService.getAliveAvailableCpu()).thenReturn(1);
when(workerService.getAliveTotalGpu()).thenReturn(1);
when(workerService.getAliveAvailableGpu()).thenReturn(1);
when(taskService.findByCurrentStatus(TaskStatus.COMPLETED))
.thenReturn(List.of());
when(taskService.getCompletedTasksCount())
.thenReturn(10L);
when(dealWatcherService.getDealEventsCount()).thenReturn(10L);
when(dealWatcherService.getDealsCount()).thenReturn(8L);
when(dealWatcherService.getReplayDealsCount()).thenReturn(2L);
@@ -71,11 +70,11 @@ void shouldGetPlatformMetrics() {
assertThat(metric.getAliveAvailableCpu()).isEqualTo(1);
assertThat(metric.getAliveTotalGpu()).isEqualTo(1);
assertThat(metric.getAliveAvailableGpu()).isEqualTo(1);
assertThat(metric.getCompletedTasks()).isZero();
assertThat(metric.getCompletedTasks()).isEqualTo(10L);
assertThat(metric.getDealEventsCount()).isEqualTo(10);
assertThat(metric.getDealsCount()).isEqualTo(8);
assertThat(metric.getReplayDealsCount()).isEqualTo(2);
assertThat(metric.getLatestBlockNumberWithDeal()).isEqualTo(255);
}

}
}
23 changes: 21 additions & 2 deletions src/test/java/com/iexec/core/task/TaskServiceTests.java
Original file line number Diff line number Diff line change
@@ -40,8 +40,7 @@
import java.time.temporal.ChronoUnit;
import java.util.*;

import static com.iexec.core.task.TaskStatus.INITIALIZED;
import static com.iexec.core.task.TaskStatus.RUNNING;
import static com.iexec.core.task.TaskStatus.*;
import static com.iexec.core.task.TaskTestsUtils.*;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
@@ -358,4 +357,24 @@ void shouldConsensusBeReached() {
Mockito.verify(iexecHubService).getChainTask(any());
}
// endregion

// region getCompletedTasksCount
@Test
void shouldGet0CompletedTasksCountWhenNoTaskCompleted() {
final long completedTasksCount = taskService.getCompletedTasksCount();
assertThat(completedTasksCount).isZero();
}

@Test
void shouldGet3CompletedTasksCount() {
final TaskService taskService = new TaskService(taskRepository, iexecHubService);
final Task task = Task.builder().currentStatus(COMPLETED).build();
when(taskRepository.findByCurrentStatus(COMPLETED))
.thenReturn(List.of(task, task, task));
taskService.init();

final long completedTasksCount = taskService.getCompletedTasksCount();
assertThat(completedTasksCount).isEqualTo(3);
}
// endregion
}