فهرست منبع

feat(metrics): add price update delay metric and update method

Daniel Chew 7 ماه پیش
والد
کامیت
f446942c27
2فایلهای تغییر یافته به همراه32 افزوده شده و 0 حذف شده
  1. 10 0
      apps/price_pusher/src/controller.ts
  2. 22 0
      apps/price_pusher/src/metrics.ts

+ 10 - 0
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,

+ 22 - 0
apps/price_pusher/src/metrics.ts

@@ -14,6 +14,7 @@ export class PricePusherMetrics {
   public lastPublishedTime: Gauge<string>;
   public priceUpdateAttempts: Counter<string>;
   public priceFeedsTotal: Gauge<string>;
+  public priceUpdateDelay: Gauge<string>;
   // Wallet metrics
   public walletBalance: Gauge<string>;
 
@@ -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,