Skip to content

Commit

Permalink
Add more metrics to follow deal events and effective deals in all wat…
Browse files Browse the repository at this point in the history
…chers
  • Loading branch information
jbern0rd committed Feb 17, 2023
1 parent aee8902 commit 7219438
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 8 deletions.
21 changes: 15 additions & 6 deletions src/main/java/com/iexec/core/chain/DealWatcherService.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,11 @@ public class DealWatcherService {
@Getter
private BigInteger latestBlockNumberWithDeal = BigInteger.ZERO;
@Getter
private int dealEventsCount = 0;
private long dealEventsCount = 0;
@Getter
private long dealsCount = 0;
@Getter
private long replayDealsCount = 0;

public DealWatcherService(ChainConfig chainConfig,
IexecHubService iexecHubService,
Expand Down Expand Up @@ -97,7 +101,7 @@ Disposable subscribeToDealEventFromOneBlockToLatest(BigInteger from) {
EthFilter filter = createDealEventFilter(from, null);
return iexecHubService.getDealEventObservable(filter)
.map(this::schedulerNoticeToDealEvent)
.subscribe(dealEvent -> dealEvent.ifPresent(this::onDealEvent));
.subscribe(dealEvent -> dealEvent.ifPresent(event -> onDealEvent(event, "start")));
}

/**
Expand All @@ -106,11 +110,16 @@ Disposable subscribeToDealEventFromOneBlockToLatest(BigInteger from) {
*
* @param dealEvent
*/
private void onDealEvent(DealEvent dealEvent) {
private void onDealEvent(DealEvent dealEvent, String watcher) {
if ("replay".equals(watcher)) {
replayDealsCount++;
} else {
dealsCount++;
}
String dealId = dealEvent.getChainDealId();
BigInteger dealBlock = dealEvent.getBlockNumber();
log.info("Received deal [dealId:{}, block:{}]", dealId,
dealBlock);
log.info("Received deal [dealId:{}, block:{}, watcher: {}]",
dealId, dealBlock, watcher);
if (dealBlock.equals(BigInteger.ZERO)) {
log.warn("Deal block number is empty, fetching later blockchain " +
"events will be more expensive [chainDealId:{}, dealBlock:{}, " +
Expand Down Expand Up @@ -193,7 +202,7 @@ private Disposable subscribeToDealEventInRange(BigInteger from, BigInteger to) {
EthFilter filter = createDealEventFilter(from, to);
return iexecHubService.getDealEventObservable(filter)
.map(this::schedulerNoticeToDealEvent)
.subscribe(dealEvent -> dealEvent.ifPresent(this::onDealEvent));
.subscribe(dealEvent -> dealEvent.ifPresent(event -> onDealEvent(event, "replay")));
}

EthFilter createDealEventFilter(BigInteger from, BigInteger to) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/com/iexec/core/metric/MetricService.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public PlatformMetric getPlatformMetrics() {
.aliveAvailableGpu(workerService.getAliveAvailableGpu())
.completedTasks(taskService.findByCurrentStatus(TaskStatus.COMPLETED).size())
.dealEventsCount(dealWatcherService.getDealEventsCount())
.dealsCount(dealWatcherService.getDealsCount())
.replayDealsCount(dealWatcherService.getReplayDealsCount())
.latestBlockNumberWithDeal(dealWatcherService.getLatestBlockNumberWithDeal())
.build();
}
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/com/iexec/core/metric/PlatformMetric.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ public class PlatformMetric {
private int aliveTotalGpu;
private int aliveAvailableGpu;
private int completedTasks;
private int dealEventsCount;
private long dealEventsCount;
private long dealsCount;
private long replayDealsCount;
private BigInteger latestBlockNumberWithDeal;

}
6 changes: 5 additions & 1 deletion src/test/java/com/iexec/core/metric/MetricServiceTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ void shouldGetPlatformMetrics() {
when(workerService.getAliveAvailableGpu()).thenReturn(1);
when(taskService.findByCurrentStatus(TaskStatus.COMPLETED))
.thenReturn(List.of());
when(dealWatcherService.getDealEventsCount()).thenReturn(10);
when(dealWatcherService.getDealEventsCount()).thenReturn(10L);
when(dealWatcherService.getDealsCount()).thenReturn(8L);
when(dealWatcherService.getReplayDealsCount()).thenReturn(2L);
when(dealWatcherService.getLatestBlockNumberWithDeal()).thenReturn(BigInteger.valueOf(255L));

PlatformMetric metric = metricService.getPlatformMetrics();
Expand All @@ -71,6 +73,8 @@ void shouldGetPlatformMetrics() {
assertThat(metric.getAliveAvailableGpu()).isEqualTo(1);
assertThat(metric.getCompletedTasks()).isZero();
assertThat(metric.getDealEventsCount()).isEqualTo(10);
assertThat(metric.getDealsCount()).isEqualTo(8);
assertThat(metric.getReplayDealsCount()).isEqualTo(2);
assertThat(metric.getLatestBlockNumberWithDeal()).isEqualTo(255);
}

Expand Down

0 comments on commit 7219438

Please sign in to comment.