Skip to content

Commit b8778c0

Browse files
authored
[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
1 parent 11a0ba1 commit b8778c0

File tree

4 files changed

+26
-29
lines changed

4 files changed

+26
-29
lines changed

package-lock.json

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

price_service/server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/price-service-server",
3-
"version": "3.0.7",
3+
"version": "3.0.8",
44
"description": "Webservice for retrieving prices from the Pyth oracle.",
55
"private": "true",
66
"main": "index.js",

price_service/server/src/listen.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,26 @@ export class Listener implements PriceStore {
440440
return false;
441441
}
442442

443+
// if too many price feeds are stale it probably means that the price service
444+
// is not receiving messages from Wormhole at all and is essentially dead.
445+
const stalenessThreshold = 60;
446+
const maxToleratedStaleFeeds = 10;
447+
448+
const priceIds = [...this.getPriceIds()];
449+
let stalePriceCnt = 0;
450+
451+
for (const priceId of priceIds) {
452+
const latency =
453+
currentTime - this.getLatestPriceInfo(priceId)!.attestationTime;
454+
if (latency > stalenessThreshold) {
455+
stalePriceCnt++;
456+
}
457+
}
458+
459+
if (stalePriceCnt > maxToleratedStaleFeeds) {
460+
return false;
461+
}
462+
443463
return true;
444464
}
445465

price_service/server/src/rest.ts

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ export class RestAPI {
514514
endpoints.push("/api/stale_feeds?threshold=<staleness_threshold_seconds>");
515515

516516
app.get("/ready", (_, res: Response) => {
517-
if (this.isReady!()) {
517+
if (this.isReady === undefined || this.isReady!()) {
518518
res.sendStatus(StatusCodes.OK);
519519
} else {
520520
res.sendStatus(StatusCodes.SERVICE_UNAVAILABLE);
@@ -523,32 +523,7 @@ export class RestAPI {
523523
endpoints.push("ready");
524524

525525
app.get("/live", (_, res: Response) => {
526-
const threshold = 60;
527-
const stalePriceTreshold = 10;
528-
const minimumNumPrices = 100;
529-
530-
const currentTime: TimestampInSec = Math.floor(Date.now() / 1000);
531-
532-
const priceIds = [...this.priceFeedVaaInfo.getPriceIds()];
533-
let stalePriceCnt = 0;
534-
535-
for (const priceId of priceIds) {
536-
const latency =
537-
currentTime -
538-
this.priceFeedVaaInfo.getLatestPriceInfo(priceId)!.attestationTime;
539-
if (latency > threshold) {
540-
stalePriceCnt++;
541-
}
542-
}
543-
544-
if (
545-
priceIds.length < minimumNumPrices ||
546-
stalePriceCnt > stalePriceTreshold
547-
) {
548-
res.sendStatus(StatusCodes.SERVICE_UNAVAILABLE);
549-
} else {
550-
res.sendStatus(StatusCodes.OK);
551-
}
526+
res.sendStatus(StatusCodes.OK);
552527
});
553528
endpoints.push("live");
554529

0 commit comments

Comments
 (0)