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

Bump yaci store version and custom health check for aggr app #160

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package org.cardanofoundation.ledgersync.aggregation.app.healthcheck;

import com.bloxbean.cardano.yaci.store.core.service.BlockFetchService;
import lombok.RequiredArgsConstructor;
import org.cardanofoundation.ledgersync.healthcheck.HealthCheckProperties;
import org.cardanofoundation.ledgersync.healthcheck.model.HealthStatus;
import org.cardanofoundation.ledgersync.healthcheck.model.Message;
import org.cardanofoundation.ledgersync.healthcheck.service.HealthCheckCachingService;
import org.cardanofoundation.ledgersync.healthcheck.service.HealthStatusService;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.time.temporal.ChronoUnit;

@Component
@RequiredArgsConstructor
public class CustomHealthStatusServiceImpl implements HealthStatusService {
private final HealthCheckCachingService healthCheckCachingService;
private final HealthCheckProperties healthCheckProperties;
private final BlockFetchService blockFetchService;

@Override
public HealthStatus getHealthStatus() {
final var latestEventTime = healthCheckCachingService.getLatestEventTime();
final var latestSlotNo = healthCheckCachingService.getLatestSlotNo();
final var latestBlockTime = healthCheckCachingService.getLatestBlockTime();
final var stopSlot = healthCheckProperties.getStopSlot();
if (blockFetchService.isScheduledToStop()) {
return new HealthStatus(Boolean.TRUE, CustomMessage.IS_SCHEDULED_TO_STOP.getCode(),
CustomMessage.IS_SCHEDULED_TO_STOP.getDesc());
}

if (!isInThreshold(healthCheckProperties.getEventTimeThreshold(), latestEventTime)) {
if (stopSlot > 0 && latestSlotNo >= stopSlot) {
return new HealthStatus(Boolean.TRUE, Message.STOP_SLOT_HAS_REACHED);
}
return new HealthStatus(Boolean.FALSE, Message.IS_BAD);
}

if (healthCheckProperties.isBlockTimeCheckEnabled() && latestBlockTime != null &&
isInThreshold(healthCheckProperties.getBlockTimeThreshold(), latestBlockTime)) {
return new HealthStatus(Boolean.TRUE, Message.BLOCK_HAS_REACHED_TIP);
}

return new HealthStatus(Boolean.TRUE, Message.IS_GOOD);
}

private boolean isInThreshold(Long threshold, LocalDateTime time) {
long value = ChronoUnit.SECONDS.between(time, LocalDateTime.now(ZoneOffset.UTC));
return value <= threshold;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.cardanofoundation.ledgersync.aggregation.app.healthcheck;

import lombok.Getter;

@Getter
public enum CustomMessage {
IS_SCHEDULED_TO_STOP("IS_SCHEDULED_TO_STOP", "Service is scheduled to stop");

private final String code;
private final String desc;

CustomMessage(String code, String desc) {
this.code = code;
this.desc = desc;
}
}
12 changes: 6 additions & 6 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
[libraries]
yaci-store-starter="com.bloxbean.cardano:yaci-store-spring-boot-starter:0.1.0-rc2-a863cfe-SNAPSHOT"
yaci-store-utxo-starter="com.bloxbean.cardano:yaci-store-utxo-spring-boot-starter:0.1.0-rc2-a863cfe-SNAPSHOT"
yaci-store-account-starter="com.bloxbean.cardano:yaci-store-account-spring-boot-starter:0.1.0-rc2-a863cfe-SNAPSHOT"
yaci-store-remote-starter="com.bloxbean.cardano:yaci-store-remote-spring-boot-starter:0.1.0-rc2-a863cfe-SNAPSHOT"
yaci-store-governance-starter="com.bloxbean.cardano:yaci-store-governance-spring-boot-starter:0.1.0-rc2-a863cfe-SNAPSHOT"
yaci-store-events="com.bloxbean.cardano:yaci-store-events:0.1.0-rc2-a863cfe-SNAPSHOT"
yaci-store-starter="com.bloxbean.cardano:yaci-store-spring-boot-starter:0.1.0-rc2-87c7beb-SNAPSHOT"
yaci-store-utxo-starter="com.bloxbean.cardano:yaci-store-utxo-spring-boot-starter:0.1.0-rc2-87c7beb-SNAPSHOT"
yaci-store-account-starter="com.bloxbean.cardano:yaci-store-account-spring-boot-starter:0.1.0-rc2-87c7beb-SNAPSHOT"
yaci-store-remote-starter="com.bloxbean.cardano:yaci-store-remote-spring-boot-starter:0.1.0-rc2-87c7beb-SNAPSHOT"
yaci-store-governance-starter="com.bloxbean.cardano:yaci-store-governance-spring-boot-starter:0.1.0-rc2-87c7beb-SNAPSHOT"
yaci-store-events="com.bloxbean.cardano:yaci-store-events:0.1.0-rc2-87c7beb-SNAPSHOT"

cardano-client-lib="com.bloxbean.cardano:cardano-client-lib:0.5.1"
snakeyaml="org.yaml:snakeyaml:2.0"
Expand Down
Loading