Skip to content

Commit e3ad85f

Browse files
authored
Merge pull request #2619 from pyth-network/price-update-delay
feat(metrics): add price update delay metric and update method
2 parents 6474c70 + afa4a0f commit e3ad85f

File tree

3 files changed

+44
-18
lines changed

3 files changed

+44
-18
lines changed

apps/price_pusher/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-pusher",
3-
"version": "9.3.0",
3+
"version": "9.3.1",
44
"description": "Pyth Price Pusher",
55
"homepage": "https://pyth.network",
66
"main": "lib/index.js",

apps/price_pusher/src/controller.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,13 @@ export class Controller {
5353
const sourceLatestPrice =
5454
this.sourcePriceListener.getLatestPriceInfo(priceId);
5555

56-
// Update metrics for the last published time if available
57-
if (this.metrics && targetLatestPrice) {
58-
this.metrics.updateLastPublishedTime(
56+
if (this.metrics && targetLatestPrice && sourceLatestPrice) {
57+
this.metrics.updateTimestamps(
5958
priceId,
6059
alias,
61-
targetLatestPrice,
60+
targetLatestPrice.publishTime,
61+
sourceLatestPrice.publishTime,
62+
priceConfig.timeDifference,
6263
);
6364
}
6465

apps/price_pusher/src/metrics.ts

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Registry, Counter, Gauge } from "prom-client";
22
import express from "express";
3-
import { PriceInfo } from "./interface";
43
import { Logger } from "pino";
54
import { UpdateCondition } from "./price-config";
65

@@ -14,6 +13,8 @@ export class PricePusherMetrics {
1413
public lastPublishedTime: Gauge<string>;
1514
public priceUpdateAttempts: Counter<string>;
1615
public priceFeedsTotal: Gauge<string>;
16+
public sourceTimestamp: Gauge<string>;
17+
public configuredTimeDifference: Gauge<string>;
1718
// Wallet metrics
1819
public walletBalance: Gauge<string>;
1920

@@ -46,6 +47,20 @@ export class PricePusherMetrics {
4647
registers: [this.registry],
4748
});
4849

50+
this.sourceTimestamp = new Gauge({
51+
name: "pyth_source_timestamp",
52+
help: "Latest source chain price publish timestamp",
53+
labelNames: ["price_id", "alias"],
54+
registers: [this.registry],
55+
});
56+
57+
this.configuredTimeDifference = new Gauge({
58+
name: "pyth_configured_time_difference",
59+
help: "Configured time difference threshold between source and target chains",
60+
labelNames: ["price_id", "alias"],
61+
registers: [this.registry],
62+
});
63+
4964
// Wallet balance metric
5065
this.walletBalance = new Gauge({
5166
name: "pyth_wallet_balance",
@@ -68,18 +83,6 @@ export class PricePusherMetrics {
6883
});
6984
}
7085

71-
// Update the last published time for a price feed
72-
public updateLastPublishedTime(
73-
priceId: string,
74-
alias: string,
75-
priceInfo: PriceInfo,
76-
): void {
77-
this.lastPublishedTime.set(
78-
{ price_id: priceId, alias },
79-
priceInfo.publishTime,
80-
);
81-
}
82-
8386
// Record a successful price update
8487
public recordPriceUpdate(
8588
priceId: string,
@@ -133,6 +136,28 @@ export class PricePusherMetrics {
133136
this.priceFeedsTotal.set(count);
134137
}
135138

139+
// Update source, target and configured time difference timestamps
140+
public updateTimestamps(
141+
priceId: string,
142+
alias: string,
143+
targetLatestPricePublishTime: number,
144+
sourceLatestPricePublishTime: number,
145+
priceConfigTimeDifference: number,
146+
): void {
147+
this.sourceTimestamp.set(
148+
{ price_id: priceId, alias },
149+
sourceLatestPricePublishTime,
150+
);
151+
this.lastPublishedTime.set(
152+
{ price_id: priceId, alias },
153+
targetLatestPricePublishTime,
154+
);
155+
this.configuredTimeDifference.set(
156+
{ price_id: priceId, alias },
157+
priceConfigTimeDifference,
158+
);
159+
}
160+
136161
// Update wallet balance
137162
public updateWalletBalance(
138163
walletAddress: string,

0 commit comments

Comments
 (0)