diff --git a/apps/price_pusher/grafana-dashboard.sample.json b/apps/price_pusher/grafana-dashboard.sample.json index b4780fa196..0a6a0b0bf7 100644 --- a/apps/price_pusher/grafana-dashboard.sample.json +++ b/apps/price_pusher/grafana-dashboard.sample.json @@ -90,9 +90,9 @@ "uid": "edryyydtht14wa" }, "editorMode": "code", - "expr": "pyth_price_feeds_total{namespace=\"$chain\"}", + "expr": "pyth_price_feeds_total{chain=\"$chain\"}", "instant": true, - "legendFormat": "{{namespace}}", + "legendFormat": "{{chain}}", "range": false, "refId": "A" } @@ -169,9 +169,9 @@ "uid": "edryyydtht14wa" }, "editorMode": "code", - "expr": "count(pyth_price_last_published_time{namespace=\"$chain\"})", + "expr": "count(pyth_price_last_published_time{chain=\"$chain\"})", "instant": true, - "legendFormat": "{{namespace}}", + "legendFormat": "{{chain}}", "range": false, "refId": "A" } @@ -252,7 +252,7 @@ "uid": "edryyydtht14wa" }, "editorMode": "code", - "expr": "time() - pyth_price_last_published_time{namespace=\"$chain\"}", + "expr": "time() - pyth_price_last_published_time{chain=\"$chain\"}", "instant": true, "legendFormat": "{{alias}}", "range": false, @@ -383,7 +383,7 @@ "uid": "edryyydtht14wa" }, "editorMode": "code", - "expr": "pyth_price_last_published_time{namespace=\"$chain\"}", + "expr": "pyth_price_last_published_time{chain=\"$chain\"}", "format": "table", "instant": true, "legendFormat": "__auto", @@ -396,7 +396,7 @@ "uid": "edryyydtht14wa" }, "editorMode": "code", - "expr": "time() - pyth_price_last_published_time{namespace=\"$chain\"}", + "expr": "time() - pyth_price_last_published_time{chain=\"$chain\"}", "format": "table", "instant": true, "legendFormat": "__auto", @@ -409,7 +409,7 @@ "uid": "edryyydtht14wa" }, "editorMode": "code", - "expr": "pyth_price_update_attempts_total{status=\"success\", namespace=\"$chain\"}", + "expr": "pyth_price_update_attempts_total{status=\"success\", chain=\"$chain\"}", "format": "table", "instant": true, "legendFormat": "__auto", @@ -606,7 +606,7 @@ "uid": "edryyydtht14wa" }, "editorMode": "code", - "expr": "increase(pyth_price_update_attempts_total{status=\"success\", namespace=\"$chain\"}[$__range])", + "expr": "increase(pyth_price_update_attempts_total{status=\"success\", chain=\"$chain\"}[$__range])", "legendFormat": "{{alias}} - Updates", "range": true, "refId": "A" @@ -732,7 +732,7 @@ "uid": "edryyydtht14wa" }, "editorMode": "code", - "expr": "sum by (trigger) (increase(pyth_price_update_attempts_total{namespace=\"$chain\"}[$__range]))", + "expr": "sum by (trigger) (increase(pyth_price_update_attempts_total{chain=\"$chain\"}[$__range]))", "instant": false, "legendFormat": "{{trigger}}", "range": true, @@ -819,7 +819,7 @@ "uid": "edryyydtht14wa" }, "editorMode": "code", - "expr": "pyth_wallet_balance{namespace=\"$chain\"}", + "expr": "pyth_wallet_balance{chain=\"$chain\"}", "instant": true, "legendFormat": "{{wallet_address}}", "range": false, @@ -915,7 +915,7 @@ "uid": "edryyydtht14wa" }, "editorMode": "code", - "expr": "pyth_wallet_balance{namespace=\"$chain\"}", + "expr": "pyth_wallet_balance{chain=\"$chain\"}", "legendFormat": "{{wallet_address}} ({{network}})", "range": true, "refId": "A" @@ -1024,7 +1024,7 @@ "uid": "edryyydtht14wa" }, "editorMode": "code", - "expr": "increase(pyth_price_update_attempts_total{status=\"error\", namespace=\"$chain\"}[$__range])", + "expr": "increase(pyth_price_update_attempts_total{status=\"error\", chain=\"$chain\"}[$__range])", "legendFormat": "{{alias}} - Errors", "range": true, "refId": "A" @@ -1077,7 +1077,7 @@ "uid": "ads9ouz3jh4hsa" }, "editorMode": "code", - "expr": "{namespace=~\"$chain\"} | logfmt | json | msg =~ `.*(Price update successful|Transaction confirmed|Successfully updated price).*` | line_format `Tx Hash: {{.hash}}`", + "expr": "{chain=~\"$chain\"} | logfmt | json | msg =~ `.*(Price update successful|Transaction confirmed|Successfully updated price).*` | line_format `Tx Hash: {{.hash}}`", "queryType": "range", "refId": "A" } @@ -1127,7 +1127,7 @@ "uid": "ads9ouz3jh4hsa" }, "editorMode": "code", - "expr": "{namespace=~\"$chain\"} | logfmt", + "expr": "{chain=~\"$chain\"} | logfmt", "queryType": "range", "refId": "A" } @@ -1164,7 +1164,7 @@ "uid": "ads9ouz3jh4hsa" }, "editorMode": "builder", - "expr": "{namespace=~\"$chain\"} | logfmt | detected_level = `error`", + "expr": "{chain=~\"$chain\"} | logfmt | detected_level = `error`", "queryType": "range", "refId": "A" } @@ -1202,7 +1202,7 @@ "name": "chain", "options": [], "query": { - "label": "namespace", + "label": "chain", "refId": "LokiVariableQueryEditor-VariableQuery", "stream": "", "type": 1 diff --git a/apps/price_pusher/package.json b/apps/price_pusher/package.json index 79abf56c0e..20e69aff37 100644 --- a/apps/price_pusher/package.json +++ b/apps/price_pusher/package.json @@ -219,5 +219,5 @@ }, "type": "module", "types": "./dist/index.d.ts", - "version": "10.4.0" + "version": "10.5.0" } diff --git a/apps/price_pusher/src/aptos/command.ts b/apps/price_pusher/src/aptos/command.ts index ab6928b873..dfbde2e271 100644 --- a/apps/price_pusher/src/aptos/command.ts +++ b/apps/price_pusher/src/aptos/command.ts @@ -51,6 +51,7 @@ export default { ...options.controllerLogLevel, ...options.enableMetrics, ...options.metricsPort, + ...options.metricsChain, }, command: "aptos", describe: "run price pusher for aptos", @@ -70,6 +71,7 @@ export default { controllerLogLevel, enableMetrics, metricsPort, + metricsChain, } = argv; const logger = pino({ level: logLevel }); @@ -82,7 +84,10 @@ export default { // Initialize metrics if enabled let metrics: PricePusherMetrics | undefined; if (enableMetrics) { - metrics = new PricePusherMetrics(logger.child({ module: "Metrics" })); + metrics = new PricePusherMetrics( + logger.child({ module: "Metrics" }), + metricsChain ?? "aptos", + ); metrics.start(metricsPort); logger.info(`Metrics server started on port ${metricsPort}`); } diff --git a/apps/price_pusher/src/evm/command.ts b/apps/price_pusher/src/evm/command.ts index 281c9d9ab0..f7fb521f9e 100644 --- a/apps/price_pusher/src/evm/command.ts +++ b/apps/price_pusher/src/evm/command.ts @@ -93,6 +93,7 @@ export default { ...options.controllerLogLevel, ...options.enableMetrics, ...options.metricsPort, + ...options.metricsChain, }, command: "evm", describe: "run price pusher for evm", @@ -118,6 +119,7 @@ export default { controllerLogLevel, enableMetrics, metricsPort, + metricsChain, } = argv; const logger = pino({ @@ -150,7 +152,10 @@ export default { // Initialize metrics if enabled let metrics: PricePusherMetrics | undefined; if (enableMetrics) { - metrics = new PricePusherMetrics(logger.child({ module: "Metrics" })); + metrics = new PricePusherMetrics( + logger.child({ module: "Metrics" }), + metricsChain ?? "evm", + ); metrics.start(metricsPort); logger.info(`Metrics server started on port ${metricsPort}`); } diff --git a/apps/price_pusher/src/metrics.ts b/apps/price_pusher/src/metrics.ts index fb129f79e6..edebb723ae 100644 --- a/apps/price_pusher/src/metrics.ts +++ b/apps/price_pusher/src/metrics.ts @@ -23,13 +23,19 @@ export class PricePusherMetrics { // Wallet metrics public walletBalance: Gauge; - constructor(logger: Logger) { + constructor(logger: Logger, chain: string) { this.logger = logger; this.registry = new Registry(); this.server = express(); - // Register the default metrics (memory, CPU, etc.) - this.registry.setDefaultLabels({ app: "price_pusher" }); + // Register the default metrics (memory, CPU, etc.). `chain` is set as a + // default label so the sample Grafana dashboard's `chain=$chain` filter + // actually matches emitted series. Deliberately not named `namespace` — + // Kubernetes Prometheus service discovery auto-applies a `namespace` + // label representing the pod's k8s namespace, and with the default + // `honor_labels: false` our label would be renamed to + // `exported_namespace` and the dashboard filter would silently break. + this.registry.setDefaultLabels({ app: "price_pusher", chain }); // Create metrics this.lastPublishedTime = new Gauge({ diff --git a/apps/price_pusher/src/options.ts b/apps/price_pusher/src/options.ts index 294dbd8eca..8f6239b8c2 100644 --- a/apps/price_pusher/src/options.ts +++ b/apps/price_pusher/src/options.ts @@ -103,3 +103,17 @@ export const metricsPort = { type: "number", } as Options, }; + +export const metricsChain = { + "metrics-chain": { + description: + "Value emitted as the `chain` label on every Prometheus metric. " + + "The sample Grafana dashboard filters by `chain=$chain`, so set this " + + "to your deployment's chain/network name (e.g. `bsc-mainnet`, `sui-testnet`). " + + "Defaults to the chain command name (e.g. `evm`, `sui`, `aptos`, `solana`). " + + "Named `chain` rather than `namespace` to avoid colliding with the " + + "Kubernetes Prometheus service-discovery `namespace` label.", + type: "string", + required: false, + } as Options, +}; diff --git a/apps/price_pusher/src/solana/command.ts b/apps/price_pusher/src/solana/command.ts index 8f3b13163c..bc3ce4e0b7 100644 --- a/apps/price_pusher/src/solana/command.ts +++ b/apps/price_pusher/src/solana/command.ts @@ -124,6 +124,7 @@ export default { ...options.controllerLogLevel, ...options.enableMetrics, ...options.metricsPort, + ...options.metricsChain, }, command: "solana", describe: "run price pusher for solana", @@ -153,6 +154,7 @@ export default { metricsPort, pythReceiverProgramId, wormholeProgramId, + metricsChain, } = argv; const logger = pino({ level: logLevel }); @@ -166,7 +168,10 @@ export default { // Initialize metrics if enabled let metrics: PricePusherMetrics | undefined; if (enableMetrics) { - metrics = new PricePusherMetrics(logger.child({ module: "Metrics" })); + metrics = new PricePusherMetrics( + logger.child({ module: "Metrics" }), + metricsChain ?? "solana", + ); metrics.start(metricsPort); logger.info(`Metrics server started on port ${metricsPort}`); } diff --git a/apps/price_pusher/src/sui/command.ts b/apps/price_pusher/src/sui/command.ts index 270a1b936e..3482a9714b 100644 --- a/apps/price_pusher/src/sui/command.ts +++ b/apps/price_pusher/src/sui/command.ts @@ -79,6 +79,7 @@ export default { ...options.controllerLogLevel, ...options.enableMetrics, ...options.metricsPort, + ...options.metricsChain, }, command: "sui", describe: @@ -105,6 +106,7 @@ export default { controllerLogLevel, enableMetrics, metricsPort, + metricsChain, } = argv; const logger = pino({ level: logLevel }); @@ -141,7 +143,10 @@ export default { // Initialize metrics if enabled let metrics: PricePusherMetrics | undefined; if (enableMetrics) { - metrics = new PricePusherMetrics(logger.child({ module: "Metrics" })); + metrics = new PricePusherMetrics( + logger.child({ module: "Metrics" }), + metricsChain ?? "sui", + ); metrics.start(metricsPort); logger.info(`Metrics server started on port ${metricsPort}`); }