From f446942c271fa8cee4cfbdcd38e3179cf6924438 Mon Sep 17 00:00:00 2001 From: Daniel Chew Date: Fri, 25 Apr 2025 15:18:06 +0900 Subject: [PATCH 1/5] feat(metrics): add price update delay metric and update method --- apps/price_pusher/src/controller.ts | 10 ++++++++++ apps/price_pusher/src/metrics.ts | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/apps/price_pusher/src/controller.ts b/apps/price_pusher/src/controller.ts index 787c19b036..94ba80bf32 100644 --- a/apps/price_pusher/src/controller.ts +++ b/apps/price_pusher/src/controller.ts @@ -62,6 +62,16 @@ export class Controller { ); } + if (this.metrics && targetLatestPrice && sourceLatestPrice) { + this.metrics.updatePriceDelay( + priceId, + alias, + targetLatestPrice.publishTime, + sourceLatestPrice.publishTime, + priceConfig.timeDifference, + ); + } + const priceShouldUpdate = shouldUpdate( priceConfig, sourceLatestPrice, diff --git a/apps/price_pusher/src/metrics.ts b/apps/price_pusher/src/metrics.ts index 0090f717dd..592cafd508 100644 --- a/apps/price_pusher/src/metrics.ts +++ b/apps/price_pusher/src/metrics.ts @@ -14,6 +14,7 @@ export class PricePusherMetrics { public lastPublishedTime: Gauge; public priceUpdateAttempts: Counter; public priceFeedsTotal: Gauge; + public priceUpdateDelay: Gauge; // Wallet metrics public walletBalance: Gauge; @@ -46,6 +47,13 @@ export class PricePusherMetrics { registers: [this.registry], }); + this.priceUpdateDelay = new Gauge({ + name: "pyth_price_update_delay", + help: "Delay between source and target timestamps relative to configured threshold (positive means over threshold)", + labelNames: ["price_id", "alias"], + registers: [this.registry], + }); + // Wallet balance metric this.walletBalance = new Gauge({ name: "pyth_wallet_balance", @@ -133,6 +141,20 @@ export class PricePusherMetrics { this.priceFeedsTotal.set(count); } + // Update price delay relative to threshold + public updatePriceDelay( + priceId: string, + alias: string, + targetLatestPricePublishTime: number, + sourceLatestPricePublishTime: number, + priceConfigTimeDifference: number, + ): void { + this.priceUpdateDelay.set( + { price_id: priceId, alias }, + sourceLatestPricePublishTime - targetLatestPricePublishTime - priceConfigTimeDifference + ); + } + // Update wallet balance public updateWalletBalance( walletAddress: string, From 63d7dd000fd9494c84f0942696a298440a995c78 Mon Sep 17 00:00:00 2001 From: Daniel Chew Date: Fri, 25 Apr 2025 15:24:23 +0900 Subject: [PATCH 2/5] feat(metrics): add price update delay metric and update method --- apps/price_pusher/src/controller.ts | 2 +- apps/price_pusher/src/metrics.ts | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/price_pusher/src/controller.ts b/apps/price_pusher/src/controller.ts index 94ba80bf32..6131560487 100644 --- a/apps/price_pusher/src/controller.ts +++ b/apps/price_pusher/src/controller.ts @@ -71,7 +71,7 @@ export class Controller { priceConfig.timeDifference, ); } - + const priceShouldUpdate = shouldUpdate( priceConfig, sourceLatestPrice, diff --git a/apps/price_pusher/src/metrics.ts b/apps/price_pusher/src/metrics.ts index 592cafd508..cf03bbc7a9 100644 --- a/apps/price_pusher/src/metrics.ts +++ b/apps/price_pusher/src/metrics.ts @@ -151,7 +151,9 @@ export class PricePusherMetrics { ): void { this.priceUpdateDelay.set( { price_id: priceId, alias }, - sourceLatestPricePublishTime - targetLatestPricePublishTime - priceConfigTimeDifference + sourceLatestPricePublishTime - + targetLatestPricePublishTime - + priceConfigTimeDifference, ); } From 15ddbd03c80968307e665d3f9e004b7e1d53b8f3 Mon Sep 17 00:00:00 2001 From: Daniel Chew Date: Mon, 28 Apr 2025 18:17:06 +0900 Subject: [PATCH 3/5] feat(metrics): refactor price update delay metrics to use source and target timestamps --- apps/price_pusher/src/controller.ts | 2 +- apps/price_pusher/src/metrics.ts | 42 ++++++++++++++++++++++------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/apps/price_pusher/src/controller.ts b/apps/price_pusher/src/controller.ts index 6131560487..49d81ce6cf 100644 --- a/apps/price_pusher/src/controller.ts +++ b/apps/price_pusher/src/controller.ts @@ -63,7 +63,7 @@ export class Controller { } if (this.metrics && targetLatestPrice && sourceLatestPrice) { - this.metrics.updatePriceDelay( + this.metrics.updateTimestamps( priceId, alias, targetLatestPrice.publishTime, diff --git a/apps/price_pusher/src/metrics.ts b/apps/price_pusher/src/metrics.ts index cf03bbc7a9..9fc87b5966 100644 --- a/apps/price_pusher/src/metrics.ts +++ b/apps/price_pusher/src/metrics.ts @@ -14,7 +14,9 @@ export class PricePusherMetrics { public lastPublishedTime: Gauge; public priceUpdateAttempts: Counter; public priceFeedsTotal: Gauge; - public priceUpdateDelay: Gauge; + public sourceTimestamp: Gauge; + public targetTimestamp: Gauge; + public configuredTimeDifference: Gauge; // Wallet metrics public walletBalance: Gauge; @@ -47,9 +49,23 @@ export class PricePusherMetrics { registers: [this.registry], }); - this.priceUpdateDelay = new Gauge({ - name: "pyth_price_update_delay", - help: "Delay between source and target timestamps relative to configured threshold (positive means over threshold)", + this.sourceTimestamp = new Gauge({ + name: "pyth_source_timestamp", + help: "Latest source chain price publish timestamp", + labelNames: ["price_id", "alias"], + registers: [this.registry], + }); + + this.targetTimestamp = new Gauge({ + name: "pyth_target_timestamp", + help: "Latest target chain price publish timestamp", + labelNames: ["price_id", "alias"], + registers: [this.registry], + }); + + this.configuredTimeDifference = new Gauge({ + name: "pyth_configured_time_difference", + help: "Configured time difference threshold between source and target chains", labelNames: ["price_id", "alias"], registers: [this.registry], }); @@ -141,19 +157,25 @@ export class PricePusherMetrics { this.priceFeedsTotal.set(count); } - // Update price delay relative to threshold - public updatePriceDelay( + // Update source, target and configured time difference timestamps + public updateTimestamps( priceId: string, alias: string, targetLatestPricePublishTime: number, sourceLatestPricePublishTime: number, priceConfigTimeDifference: number, ): void { - this.priceUpdateDelay.set( + this.sourceTimestamp.set( + { price_id: priceId, alias }, + sourceLatestPricePublishTime, + ); + this.targetTimestamp.set( + { price_id: priceId, alias }, + targetLatestPricePublishTime, + ); + this.configuredTimeDifference.set( { price_id: priceId, alias }, - sourceLatestPricePublishTime - - targetLatestPricePublishTime - - priceConfigTimeDifference, + priceConfigTimeDifference, ); } From ff853d07e0c090a5680f262ae0d7e5607f83bd57 Mon Sep 17 00:00:00 2001 From: Daniel Chew Date: Mon, 28 Apr 2025 18:38:39 +0900 Subject: [PATCH 4/5] chore(package): bump version to 9.3.1 --- apps/price_pusher/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/price_pusher/package.json b/apps/price_pusher/package.json index 19b3740a3f..de10c99b1d 100644 --- a/apps/price_pusher/package.json +++ b/apps/price_pusher/package.json @@ -1,6 +1,6 @@ { "name": "@pythnetwork/price-pusher", - "version": "9.3.0", + "version": "9.3.1", "description": "Pyth Price Pusher", "homepage": "https://pyth.network", "main": "lib/index.js", From afa4a0fa1d2e319ec2722a39e1d62db55fe512ae Mon Sep 17 00:00:00 2001 From: Daniel Chew Date: Mon, 28 Apr 2025 18:52:53 +0900 Subject: [PATCH 5/5] refactor(metrics): remove target timestamp metric and update last published time logic --- apps/price_pusher/src/controller.ts | 9 --------- apps/price_pusher/src/metrics.ts | 23 +---------------------- 2 files changed, 1 insertion(+), 31 deletions(-) diff --git a/apps/price_pusher/src/controller.ts b/apps/price_pusher/src/controller.ts index 49d81ce6cf..ffedd414f0 100644 --- a/apps/price_pusher/src/controller.ts +++ b/apps/price_pusher/src/controller.ts @@ -53,15 +53,6 @@ export class Controller { const sourceLatestPrice = this.sourcePriceListener.getLatestPriceInfo(priceId); - // Update metrics for the last published time if available - if (this.metrics && targetLatestPrice) { - this.metrics.updateLastPublishedTime( - priceId, - alias, - targetLatestPrice, - ); - } - if (this.metrics && targetLatestPrice && sourceLatestPrice) { this.metrics.updateTimestamps( priceId, diff --git a/apps/price_pusher/src/metrics.ts b/apps/price_pusher/src/metrics.ts index 9fc87b5966..700c6e979b 100644 --- a/apps/price_pusher/src/metrics.ts +++ b/apps/price_pusher/src/metrics.ts @@ -1,6 +1,5 @@ import { Registry, Counter, Gauge } from "prom-client"; import express from "express"; -import { PriceInfo } from "./interface"; import { Logger } from "pino"; import { UpdateCondition } from "./price-config"; @@ -15,7 +14,6 @@ export class PricePusherMetrics { public priceUpdateAttempts: Counter; public priceFeedsTotal: Gauge; public sourceTimestamp: Gauge; - public targetTimestamp: Gauge; public configuredTimeDifference: Gauge; // Wallet metrics public walletBalance: Gauge; @@ -56,13 +54,6 @@ export class PricePusherMetrics { registers: [this.registry], }); - this.targetTimestamp = new Gauge({ - name: "pyth_target_timestamp", - help: "Latest target chain price publish timestamp", - labelNames: ["price_id", "alias"], - registers: [this.registry], - }); - this.configuredTimeDifference = new Gauge({ name: "pyth_configured_time_difference", help: "Configured time difference threshold between source and target chains", @@ -92,18 +83,6 @@ export class PricePusherMetrics { }); } - // Update the last published time for a price feed - public updateLastPublishedTime( - priceId: string, - alias: string, - priceInfo: PriceInfo, - ): void { - this.lastPublishedTime.set( - { price_id: priceId, alias }, - priceInfo.publishTime, - ); - } - // Record a successful price update public recordPriceUpdate( priceId: string, @@ -169,7 +148,7 @@ export class PricePusherMetrics { { price_id: priceId, alias }, sourceLatestPricePublishTime, ); - this.targetTimestamp.set( + this.lastPublishedTime.set( { price_id: priceId, alias }, targetLatestPricePublishTime, );