Ver código fonte

Merge pull request #2619 from pyth-network/price-update-delay

feat(metrics): add price update delay metric and update method
Daniel Chew 6 meses atrás
pai
commit
e3ad85f450

+ 1 - 1
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",

+ 5 - 4
apps/price_pusher/src/controller.ts

@@ -53,12 +53,13 @@ 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(
+        if (this.metrics && targetLatestPrice && sourceLatestPrice) {
+          this.metrics.updateTimestamps(
             priceId,
             alias,
-            targetLatestPrice,
+            targetLatestPrice.publishTime,
+            sourceLatestPrice.publishTime,
+            priceConfig.timeDifference,
           );
         }
 

+ 38 - 13
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";
 
@@ -14,6 +13,8 @@ export class PricePusherMetrics {
   public lastPublishedTime: Gauge<string>;
   public priceUpdateAttempts: Counter<string>;
   public priceFeedsTotal: Gauge<string>;
+  public sourceTimestamp: Gauge<string>;
+  public configuredTimeDifference: Gauge<string>;
   // Wallet metrics
   public walletBalance: Gauge<string>;
 
@@ -46,6 +47,20 @@ export class PricePusherMetrics {
       registers: [this.registry],
     });
 
+    this.sourceTimestamp = new Gauge({
+      name: "pyth_source_timestamp",
+      help: "Latest source 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],
+    });
+
     // Wallet balance metric
     this.walletBalance = new Gauge({
       name: "pyth_wallet_balance",
@@ -68,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,
@@ -133,6 +136,28 @@ export class PricePusherMetrics {
     this.priceFeedsTotal.set(count);
   }
 
+  // Update source, target and configured time difference timestamps
+  public updateTimestamps(
+    priceId: string,
+    alias: string,
+    targetLatestPricePublishTime: number,
+    sourceLatestPricePublishTime: number,
+    priceConfigTimeDifference: number,
+  ): void {
+    this.sourceTimestamp.set(
+      { price_id: priceId, alias },
+      sourceLatestPricePublishTime,
+    );
+    this.lastPublishedTime.set(
+      { price_id: priceId, alias },
+      targetLatestPricePublishTime,
+    );
+    this.configuredTimeDifference.set(
+      { price_id: priceId, alias },
+      priceConfigTimeDifference,
+    );
+  }
+
   // Update wallet balance
   public updateWalletBalance(
     walletAddress: string,