Skip to content

Commit

Permalink
feat: #153 create healthcheck component and use it in main app, strea…
Browse files Browse the repository at this point in the history
…mer app and aggregation app
  • Loading branch information
Sotatek-HuyLe3a committed Mar 25, 2024
1 parent fbd3eb3 commit d25e8bd
Show file tree
Hide file tree
Showing 31 changed files with 338 additions and 551 deletions.
1 change: 1 addition & 0 deletions aggregation-app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ dependencies {
implementation(libs.yaci.store.utxo.starter)
implementation(libs.yaci.store.account.starter)

implementation project(':components:healthcheck')
implementation project(':aggregates:account')
runtimeOnly 'org.postgresql:postgresql'

Expand Down
21 changes: 21 additions & 0 deletions aggregation-app/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,24 @@ store:
blocks-partition-size: 10
use-virtual-thread-for-batch-processing: false
use-virtual-thread-for-event-processing: true

ledger-sync:
healthcheck:
enabled: ${HEALTH_CHECK_ENABLED:true}
event-time-threshold: ${EVENT_TIME_THRESHOLD_IN_SECOND:600}
block-time-check-enabled: ${BLOCK_TIME_CHECK_ENABLED:true}
block-time-threshold: ${BLOCK_TIME_THRESHOLD_IN_SECOND:180}

management:
endpoints:
enabled-by-default: false
web:
exposure:
include: "health,prometheus,health-status"
endpoint:
health:
enabled: true
prometheus:
enabled: true
health-status:
enabled: ${HEALTH_CHECK_ENABLED:true}
1 change: 1 addition & 0 deletions application/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ dependencies {
implementation project(':components:common')
implementation project(':components:consumer-common')
implementation project(':components:scheduler')
implementation project(':components:healthcheck')

implementation(libs.yaci.store.starter)

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.cardanofoundation.ledgersync.aggregate.AggregatedBlock;
import org.cardanofoundation.ledgersync.healthcheck.service.HealthCheckCachingService;
import org.cardanofoundation.ledgersync.repository.BlockRepository;
import org.cardanofoundation.ledgersync.service.*;
import org.cardanofoundation.ledgersync.service.impl.block.BlockAggregatorServiceImpl;
Expand Down Expand Up @@ -38,7 +39,6 @@ public class BlockEventListener {

private final BlockRepository blockRepository;
private final MetricCollectorService metricCollectorService;
private final HealthCheckCachingService healthCheckCachingService;
private final AtomicInteger blockCount = new AtomicInteger(0);

@Value("${blocks.batch-size}")
Expand Down Expand Up @@ -95,10 +95,6 @@ public void handleGenesisBlock(GenesisBlockEvent genesisBlockEvent) {
}

genesisDataService.setupData(genesisHash);
healthCheckCachingService.saveLatestBlockSlot(genesisBlockEvent.getSlot());
healthCheckCachingService.saveLatestBlockInsertTime(LocalDateTime.now(ZoneOffset.UTC));
healthCheckCachingService.saveLatestBlockTime(
LocalDateTime.ofInstant(Instant.ofEpochSecond(genesisBlockEvent.getBlockTime()), ZoneId.of("UTC")));
}

@EventListener
Expand All @@ -121,10 +117,6 @@ public void handleRollback(RollbackEvent rollbackEvent) {
rollbackService.rollBackFrom(rollbackBlockNo);
metricCollectorService.collectRollbackMetric();
blockCount.set(0);

healthCheckCachingService.saveLatestBlockSlot(rollbackEvent.getRollbackTo().getSlot());
healthCheckCachingService.saveLatestBlockInsertTime(LocalDateTime.now(ZoneOffset.UTC));
healthCheckCachingService.saveLatestBlockTime(rollBackBlock.get().getTime().toLocalDateTime());
}

private boolean checkIfBlockExists(EventMetadata metadata) {
Expand Down Expand Up @@ -182,13 +174,6 @@ private void handleAggregateBlock(EventMetadata eventMetadata, AggregatedBlock a
int currentBlockCount = blockCount.incrementAndGet();
if (currentBlockCount % batchSize == 0 || lastReceivedTimeElapsed >= commitThreshold || eventMetadata.isSyncMode()) {
blockSyncService.startBlockSyncing();

healthCheckCachingService.saveLatestBlockInsertTime(LocalDateTime.now(ZoneOffset.UTC));
healthCheckCachingService.saveLatestBlockTime(LocalDateTime.ofEpochSecond(
eventMetadata.getBlockTime(), 0, ZoneOffset.ofHours(0)));
healthCheckCachingService.saveIsSyncMode(eventMetadata.isSyncMode());
healthCheckCachingService.saveLatestBlockSlot(eventMetadata.getSlot());

blockCount.set(0);
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit d25e8bd

Please sign in to comment.