[price-service] Update readiness probe (#893)
* [price-service] Update readiness probe This also refactors and explains the last changes on the liveness probe. * Update comments * Address review comments
This commit is contained in:
parent
11a0ba17d0
commit
b8778c02d5
|
@ -1336,6 +1336,7 @@
|
|||
"@coral-xyz/anchor": "^0.26.0",
|
||||
"@pythnetwork/client": "^2.17.0",
|
||||
"@pythnetwork/pyth-sdk-solidity": "*",
|
||||
"@pythnetwork/xc-governance-sdk": "*",
|
||||
"@solana/buffer-layout": "^4.0.1",
|
||||
"@solana/web3.js": "^1.73.0",
|
||||
"@sqds/mesh": "^1.0.6",
|
||||
|
@ -57295,7 +57296,7 @@
|
|||
},
|
||||
"price_service/server": {
|
||||
"name": "@pythnetwork/price-service-server",
|
||||
"version": "3.0.7",
|
||||
"version": "3.0.8",
|
||||
"license": "Apache-2.0",
|
||||
"dependencies": {
|
||||
"@certusone/wormhole-sdk": "^0.9.9",
|
||||
|
@ -106550,6 +106551,7 @@
|
|||
"@coral-xyz/anchor": "^0.26.0",
|
||||
"@pythnetwork/client": "^2.17.0",
|
||||
"@pythnetwork/pyth-sdk-solidity": "*",
|
||||
"@pythnetwork/xc-governance-sdk": "*",
|
||||
"@solana/buffer-layout": "^4.0.1",
|
||||
"@solana/web3.js": "^1.73.0",
|
||||
"@sqds/mesh": "^1.0.6",
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "@pythnetwork/price-service-server",
|
||||
"version": "3.0.7",
|
||||
"version": "3.0.8",
|
||||
"description": "Webservice for retrieving prices from the Pyth oracle.",
|
||||
"private": "true",
|
||||
"main": "index.js",
|
||||
|
|
|
@ -440,6 +440,26 @@ export class Listener implements PriceStore {
|
|||
return false;
|
||||
}
|
||||
|
||||
// if too many price feeds are stale it probably means that the price service
|
||||
// is not receiving messages from Wormhole at all and is essentially dead.
|
||||
const stalenessThreshold = 60;
|
||||
const maxToleratedStaleFeeds = 10;
|
||||
|
||||
const priceIds = [...this.getPriceIds()];
|
||||
let stalePriceCnt = 0;
|
||||
|
||||
for (const priceId of priceIds) {
|
||||
const latency =
|
||||
currentTime - this.getLatestPriceInfo(priceId)!.attestationTime;
|
||||
if (latency > stalenessThreshold) {
|
||||
stalePriceCnt++;
|
||||
}
|
||||
}
|
||||
|
||||
if (stalePriceCnt > maxToleratedStaleFeeds) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -514,7 +514,7 @@ export class RestAPI {
|
|||
endpoints.push("/api/stale_feeds?threshold=<staleness_threshold_seconds>");
|
||||
|
||||
app.get("/ready", (_, res: Response) => {
|
||||
if (this.isReady!()) {
|
||||
if (this.isReady === undefined || this.isReady!()) {
|
||||
res.sendStatus(StatusCodes.OK);
|
||||
} else {
|
||||
res.sendStatus(StatusCodes.SERVICE_UNAVAILABLE);
|
||||
|
@ -523,32 +523,7 @@ export class RestAPI {
|
|||
endpoints.push("ready");
|
||||
|
||||
app.get("/live", (_, res: Response) => {
|
||||
const threshold = 60;
|
||||
const stalePriceTreshold = 10;
|
||||
const minimumNumPrices = 100;
|
||||
|
||||
const currentTime: TimestampInSec = Math.floor(Date.now() / 1000);
|
||||
|
||||
const priceIds = [...this.priceFeedVaaInfo.getPriceIds()];
|
||||
let stalePriceCnt = 0;
|
||||
|
||||
for (const priceId of priceIds) {
|
||||
const latency =
|
||||
currentTime -
|
||||
this.priceFeedVaaInfo.getLatestPriceInfo(priceId)!.attestationTime;
|
||||
if (latency > threshold) {
|
||||
stalePriceCnt++;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
priceIds.length < minimumNumPrices ||
|
||||
stalePriceCnt > stalePriceTreshold
|
||||
) {
|
||||
res.sendStatus(StatusCodes.SERVICE_UNAVAILABLE);
|
||||
} else {
|
||||
res.sendStatus(StatusCodes.OK);
|
||||
}
|
||||
res.sendStatus(StatusCodes.OK);
|
||||
});
|
||||
endpoints.push("live");
|
||||
|
||||
|
|
Loading…
Reference in New Issue