-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add health endpoints for LS app and streamer app * feat: update logic or health checking in LS app and streamer app * fix: Add block insert time threshold for batch processing * chore: add message_desc and message_code in healthcheck response * chore: use atomic variables in HealthStatusCachingServiceImpl * fix: change properties in @value in HealthStatusServiceImpl.java * fix: ensure that the values used for health checks are saved after the data is successfully written to the database * chore: (streamer) add message code and message description in healthcheck response * fix: fix unit tests in BlockSyncServiceImplTest * chore: (streamer) use atomic variable in HealthCheckCachingServiceImpl
- Loading branch information
1 parent
be0d925
commit d5c9c95
Showing
23 changed files
with
688 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
application/src/main/java/org/cardanofoundation/ledgersync/dto/healthcheck/HealthStatus.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.cardanofoundation.ledgersync.dto.healthcheck; | ||
|
||
import lombok.*; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class HealthStatus { | ||
Boolean isHealthy; | ||
String messageCode; | ||
String messageDesc; | ||
LocalDateTime latestBlockInsertTime; | ||
Boolean hasStopSlot; | ||
} |
22 changes: 22 additions & 0 deletions
22
application/src/main/java/org/cardanofoundation/ledgersync/dto/healthcheck/Message.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.cardanofoundation.ledgersync.dto.healthcheck; | ||
|
||
import lombok.Getter; | ||
|
||
@Getter | ||
public enum Message { | ||
READY_TO_SERVE("READY_TO_SERVE", "Data is ready to serve"), | ||
IS_NOT_SYNCING("IS_NOT_SYNCING", "Connection to node is not healthy, data is not being synchronized"), | ||
SYNCING_BUT_NOT_READY("SYNCING_BUT_NOT_READY", "Data is being synchronized, but it isn't ready to serve yet"), | ||
CONNECTION_HEALTHY_BUT_BLOCK_CONSUMING_NOT_HEALTHY("CONNECTION_HEALTHY_BUT_BLOCK_CONSUMING_NOT_HEALTHY", | ||
"Connection to node is healthy, but the latest block insertion time has exceeded the threshold"), | ||
SYNCING_HAS_FINISHED("SYNCING_HAS_FINISHED", | ||
"Connection to node is healthy, but the latest block insertion time has exceeded the threshold"); | ||
|
||
private final String code; | ||
private final String desc; | ||
|
||
Message(String code, String desc) { | ||
this.code = code; | ||
this.desc = desc; | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
.../src/main/java/org/cardanofoundation/ledgersync/healthcheck/LedgerSyncHealthEndpoint.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package org.cardanofoundation.ledgersync.healthcheck; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.cardanofoundation.ledgersync.dto.healthcheck.HealthStatus; | ||
import org.cardanofoundation.ledgersync.service.HealthStatusService; | ||
import org.springframework.boot.actuate.endpoint.annotation.Endpoint; | ||
import org.springframework.boot.actuate.endpoint.annotation.ReadOperation; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Endpoint(id = "health-status") | ||
@RequiredArgsConstructor | ||
@Component | ||
public class LedgerSyncHealthEndpoint { | ||
|
||
private final HealthStatusService healthStatusService; | ||
|
||
@ReadOperation | ||
@Bean | ||
public ResponseEntity<HealthStatus> checkHealthStatus() { | ||
var healthStatus = healthStatusService.getHealthStatus(); | ||
|
||
if (Boolean.FALSE.equals(healthStatus.getIsHealthy())) { | ||
return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR) | ||
.body(healthStatus); | ||
} | ||
|
||
return ResponseEntity.ok().body(healthStatus); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...ion/src/main/java/org/cardanofoundation/ledgersync/service/HealthCheckCachingService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package org.cardanofoundation.ledgersync.service; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public interface HealthCheckCachingService { | ||
|
||
/** | ||
* Cache latest block time | ||
*/ | ||
void saveLatestBlockTime(LocalDateTime blockTime); | ||
|
||
/** | ||
* Get the latest block | ||
*/ | ||
LocalDateTime getLatestBlockTime(); | ||
|
||
/** | ||
* Cache the time when the most recent block was inserted | ||
*/ | ||
void saveLatestBlockInsertTime(LocalDateTime insertTime); | ||
|
||
LocalDateTime getLatestBlockInsertTime(); | ||
|
||
/** | ||
* Cache latest slot no | ||
*/ | ||
void saveLatestBlockSlot(Long slot); | ||
|
||
/** | ||
* Get latest slot no | ||
*/ | ||
Long getLatestBlockSlot(); | ||
|
||
/** | ||
* Cache the value indicates whether the yaci is crawling with sync mode or not (use Chain-Sync protocol) | ||
*/ | ||
void saveIsSyncMode(Boolean isSyncMode); | ||
|
||
/** | ||
* Get the value indicates whether the yaci is crawling with sync mode or not (use Chain-Sync protocol) | ||
*/ | ||
Boolean getIsSyncMode(); | ||
} | ||
|
9 changes: 9 additions & 0 deletions
9
application/src/main/java/org/cardanofoundation/ledgersync/service/HealthStatusService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.cardanofoundation.ledgersync.service; | ||
|
||
|
||
import org.cardanofoundation.ledgersync.dto.healthcheck.HealthStatus; | ||
|
||
public interface HealthStatusService { | ||
|
||
HealthStatus getHealthStatus(); | ||
} |
65 changes: 65 additions & 0 deletions
65
...in/java/org/cardanofoundation/ledgersync/service/impl/HealthStatusCachingServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package org.cardanofoundation.ledgersync.service.impl; | ||
|
||
import jakarta.annotation.PostConstruct; | ||
import org.cardanofoundation.ledgersync.service.HealthCheckCachingService; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.ZoneOffset; | ||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
@Service | ||
public class HealthStatusCachingServiceImpl implements HealthCheckCachingService { | ||
private LocalDateTime latestBlockTime; | ||
private LocalDateTime latestBlockInsertTime; | ||
private final AtomicLong latestBlockSlot = new AtomicLong(); | ||
private final AtomicBoolean isSyncMode = new AtomicBoolean(); | ||
|
||
@PostConstruct | ||
void init() { | ||
latestBlockInsertTime = LocalDateTime.now(ZoneOffset.UTC); | ||
latestBlockSlot.set(-10L); // dummy value | ||
isSyncMode.set(Boolean.FALSE); | ||
} | ||
|
||
@Override | ||
public void saveLatestBlockTime(LocalDateTime blockTime) { | ||
latestBlockTime = blockTime; | ||
} | ||
|
||
@Override | ||
public LocalDateTime getLatestBlockTime() { | ||
return latestBlockTime; | ||
} | ||
|
||
@Override | ||
public void saveLatestBlockInsertTime(LocalDateTime insertTime) { | ||
latestBlockInsertTime = insertTime; | ||
} | ||
|
||
@Override | ||
public LocalDateTime getLatestBlockInsertTime() { | ||
return latestBlockInsertTime; | ||
} | ||
|
||
@Override | ||
public void saveLatestBlockSlot(Long slot) { | ||
latestBlockSlot.set(slot); | ||
} | ||
|
||
@Override | ||
public Long getLatestBlockSlot() { | ||
return latestBlockSlot.get(); | ||
} | ||
|
||
@Override | ||
public void saveIsSyncMode(Boolean value) { | ||
isSyncMode.set(value); | ||
} | ||
|
||
@Override | ||
public Boolean getIsSyncMode() { | ||
return isSyncMode.get(); | ||
} | ||
} |
Oops, something went wrong.