Skip to content

Commit 0ad092f

Browse files
committed
fix(price-pusher): rename metric label namespace -> chain
Devin re-review on this PR pointed out that `namespace` is the label Kubernetes Prometheus service discovery auto-applies to scraped pods (it carries the pod's k8s namespace). With the default `honor_labels: false` on the scrape config, my label would be renamed to `exported_namespace` and the dashboard's `namespace=\$chain` filter would silently break in any in-cluster deployment. With `honor_labels: true` the operator wins but loses k8s namespace context. Renamed everywhere to `chain`, which is what the dashboard's template variable was already called and avoids the collision entirely. Renames applied: - CLI option `--metrics-namespace` -> `--metrics-chain` (option name + variable identifier + help text in `apps/price_pusher/src/options.ts`) - Constructor arg `PricePusherMetrics(logger, namespace)` -> `PricePusherMetrics(logger, chain)` (+ comment noting why the obvious name was avoided) - Default-label key in `registry.setDefaultLabels` from `namespace` to `chain` - Per-chain callsites in `apps/price_pusher/src/{evm,sui,aptos,solana}/command.ts` swap `options.metricsNamespace` / `metricsNamespace` to the new name - `apps/price_pusher/grafana-dashboard.sample.json` panel queries (`namespace=\"$chain\"` -> `chain=\"$chain\"`, Loki `{namespace=~...}` -> `{chain=~...}`, `legendFormat: {{namespace}}` -> `{{chain}}`) and the template variable's source label (`label: 'namespace'` -> `label: 'chain'` on the Loki query that populates `$chain`) Same semantics, less ambiguous label. Refs #3692.
1 parent db7328b commit 0ad092f

7 files changed

Lines changed: 45 additions & 39 deletions

File tree

apps/price_pusher/grafana-dashboard.sample.json

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@
9090
"uid": "edryyydtht14wa"
9191
},
9292
"editorMode": "code",
93-
"expr": "pyth_price_feeds_total{namespace=\"$chain\"}",
93+
"expr": "pyth_price_feeds_total{chain=\"$chain\"}",
9494
"instant": true,
95-
"legendFormat": "{{namespace}}",
95+
"legendFormat": "{{chain}}",
9696
"range": false,
9797
"refId": "A"
9898
}
@@ -169,9 +169,9 @@
169169
"uid": "edryyydtht14wa"
170170
},
171171
"editorMode": "code",
172-
"expr": "count(pyth_price_last_published_time{namespace=\"$chain\"})",
172+
"expr": "count(pyth_price_last_published_time{chain=\"$chain\"})",
173173
"instant": true,
174-
"legendFormat": "{{namespace}}",
174+
"legendFormat": "{{chain}}",
175175
"range": false,
176176
"refId": "A"
177177
}
@@ -252,7 +252,7 @@
252252
"uid": "edryyydtht14wa"
253253
},
254254
"editorMode": "code",
255-
"expr": "time() - pyth_price_last_published_time{namespace=\"$chain\"}",
255+
"expr": "time() - pyth_price_last_published_time{chain=\"$chain\"}",
256256
"instant": true,
257257
"legendFormat": "{{alias}}",
258258
"range": false,
@@ -383,7 +383,7 @@
383383
"uid": "edryyydtht14wa"
384384
},
385385
"editorMode": "code",
386-
"expr": "pyth_price_last_published_time{namespace=\"$chain\"}",
386+
"expr": "pyth_price_last_published_time{chain=\"$chain\"}",
387387
"format": "table",
388388
"instant": true,
389389
"legendFormat": "__auto",
@@ -396,7 +396,7 @@
396396
"uid": "edryyydtht14wa"
397397
},
398398
"editorMode": "code",
399-
"expr": "time() - pyth_price_last_published_time{namespace=\"$chain\"}",
399+
"expr": "time() - pyth_price_last_published_time{chain=\"$chain\"}",
400400
"format": "table",
401401
"instant": true,
402402
"legendFormat": "__auto",
@@ -409,7 +409,7 @@
409409
"uid": "edryyydtht14wa"
410410
},
411411
"editorMode": "code",
412-
"expr": "pyth_price_update_attempts_total{status=\"success\", namespace=\"$chain\"}",
412+
"expr": "pyth_price_update_attempts_total{status=\"success\", chain=\"$chain\"}",
413413
"format": "table",
414414
"instant": true,
415415
"legendFormat": "__auto",
@@ -606,7 +606,7 @@
606606
"uid": "edryyydtht14wa"
607607
},
608608
"editorMode": "code",
609-
"expr": "increase(pyth_price_update_attempts_total{status=\"success\", namespace=\"$chain\"}[$__range])",
609+
"expr": "increase(pyth_price_update_attempts_total{status=\"success\", chain=\"$chain\"}[$__range])",
610610
"legendFormat": "{{alias}} - Updates",
611611
"range": true,
612612
"refId": "A"
@@ -732,7 +732,7 @@
732732
"uid": "edryyydtht14wa"
733733
},
734734
"editorMode": "code",
735-
"expr": "sum by (trigger) (increase(pyth_price_update_attempts_total{namespace=\"$chain\"}[$__range]))",
735+
"expr": "sum by (trigger) (increase(pyth_price_update_attempts_total{chain=\"$chain\"}[$__range]))",
736736
"instant": false,
737737
"legendFormat": "{{trigger}}",
738738
"range": true,
@@ -819,7 +819,7 @@
819819
"uid": "edryyydtht14wa"
820820
},
821821
"editorMode": "code",
822-
"expr": "pyth_wallet_balance{namespace=\"$chain\"}",
822+
"expr": "pyth_wallet_balance{chain=\"$chain\"}",
823823
"instant": true,
824824
"legendFormat": "{{wallet_address}}",
825825
"range": false,
@@ -915,7 +915,7 @@
915915
"uid": "edryyydtht14wa"
916916
},
917917
"editorMode": "code",
918-
"expr": "pyth_wallet_balance{namespace=\"$chain\"}",
918+
"expr": "pyth_wallet_balance{chain=\"$chain\"}",
919919
"legendFormat": "{{wallet_address}} ({{network}})",
920920
"range": true,
921921
"refId": "A"
@@ -1024,7 +1024,7 @@
10241024
"uid": "edryyydtht14wa"
10251025
},
10261026
"editorMode": "code",
1027-
"expr": "increase(pyth_price_update_attempts_total{status=\"error\", namespace=\"$chain\"}[$__range])",
1027+
"expr": "increase(pyth_price_update_attempts_total{status=\"error\", chain=\"$chain\"}[$__range])",
10281028
"legendFormat": "{{alias}} - Errors",
10291029
"range": true,
10301030
"refId": "A"
@@ -1077,7 +1077,7 @@
10771077
"uid": "ads9ouz3jh4hsa"
10781078
},
10791079
"editorMode": "code",
1080-
"expr": "{namespace=~\"$chain\"} | logfmt | json | msg =~ `.*(Price update successful|Transaction confirmed|Successfully updated price).*` | line_format `Tx Hash: {{.hash}}`",
1080+
"expr": "{chain=~\"$chain\"} | logfmt | json | msg =~ `.*(Price update successful|Transaction confirmed|Successfully updated price).*` | line_format `Tx Hash: {{.hash}}`",
10811081
"queryType": "range",
10821082
"refId": "A"
10831083
}
@@ -1127,7 +1127,7 @@
11271127
"uid": "ads9ouz3jh4hsa"
11281128
},
11291129
"editorMode": "code",
1130-
"expr": "{namespace=~\"$chain\"} | logfmt",
1130+
"expr": "{chain=~\"$chain\"} | logfmt",
11311131
"queryType": "range",
11321132
"refId": "A"
11331133
}
@@ -1164,7 +1164,7 @@
11641164
"uid": "ads9ouz3jh4hsa"
11651165
},
11661166
"editorMode": "builder",
1167-
"expr": "{namespace=~\"$chain\"} | logfmt | detected_level = `error`",
1167+
"expr": "{chain=~\"$chain\"} | logfmt | detected_level = `error`",
11681168
"queryType": "range",
11691169
"refId": "A"
11701170
}
@@ -1202,7 +1202,7 @@
12021202
"name": "chain",
12031203
"options": [],
12041204
"query": {
1205-
"label": "namespace",
1205+
"label": "chain",
12061206
"refId": "LokiVariableQueryEditor-VariableQuery",
12071207
"stream": "",
12081208
"type": 1

apps/price_pusher/src/aptos/command.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export default {
5151
...options.controllerLogLevel,
5252
...options.enableMetrics,
5353
...options.metricsPort,
54-
...options.metricsNamespace,
54+
...options.metricsChain,
5555
},
5656
command: "aptos",
5757
describe: "run price pusher for aptos",
@@ -71,7 +71,7 @@ export default {
7171
controllerLogLevel,
7272
enableMetrics,
7373
metricsPort,
74-
metricsNamespace,
74+
metricsChain,
7575
} = argv;
7676

7777
const logger = pino({ level: logLevel });
@@ -86,7 +86,7 @@ export default {
8686
if (enableMetrics) {
8787
metrics = new PricePusherMetrics(
8888
logger.child({ module: "Metrics" }),
89-
metricsNamespace ?? "aptos",
89+
metricsChain ?? "aptos",
9090
);
9191
metrics.start(metricsPort);
9292
logger.info(`Metrics server started on port ${metricsPort}`);

apps/price_pusher/src/evm/command.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ export default {
9393
...options.controllerLogLevel,
9494
...options.enableMetrics,
9595
...options.metricsPort,
96-
...options.metricsNamespace,
96+
...options.metricsChain,
9797
},
9898
command: "evm",
9999
describe: "run price pusher for evm",
@@ -119,7 +119,7 @@ export default {
119119
controllerLogLevel,
120120
enableMetrics,
121121
metricsPort,
122-
metricsNamespace,
122+
metricsChain,
123123
} = argv;
124124

125125
const logger = pino({
@@ -154,7 +154,7 @@ export default {
154154
if (enableMetrics) {
155155
metrics = new PricePusherMetrics(
156156
logger.child({ module: "Metrics" }),
157-
metricsNamespace ?? "evm",
157+
metricsChain ?? "evm",
158158
);
159159
metrics.start(metricsPort);
160160
logger.info(`Metrics server started on port ${metricsPort}`);

apps/price_pusher/src/metrics.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,19 @@ export class PricePusherMetrics {
2323
// Wallet metrics
2424
public walletBalance: Gauge;
2525

26-
constructor(logger: Logger, namespace: string) {
26+
constructor(logger: Logger, chain: string) {
2727
this.logger = logger;
2828
this.registry = new Registry();
2929
this.server = express();
3030

31-
// Register the default metrics (memory, CPU, etc.). `namespace` is set as
32-
// a default label so the sample Grafana dashboard's `namespace=$chain`
33-
// filter actually matches emitted series.
34-
this.registry.setDefaultLabels({ app: "price_pusher", namespace });
31+
// Register the default metrics (memory, CPU, etc.). `chain` is set as a
32+
// default label so the sample Grafana dashboard's `chain=$chain` filter
33+
// actually matches emitted series. Deliberately not named `namespace` —
34+
// Kubernetes Prometheus service discovery auto-applies a `namespace`
35+
// label representing the pod's k8s namespace, and with the default
36+
// `honor_labels: false` our label would be renamed to
37+
// `exported_namespace` and the dashboard filter would silently break.
38+
this.registry.setDefaultLabels({ app: "price_pusher", chain });
3539

3640
// Create metrics
3741
this.lastPublishedTime = new Gauge({

apps/price_pusher/src/options.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,15 @@ export const metricsPort = {
104104
} as Options,
105105
};
106106

107-
export const metricsNamespace = {
108-
"metrics-namespace": {
107+
export const metricsChain = {
108+
"metrics-chain": {
109109
description:
110-
"Value emitted as the `namespace` label on every Prometheus metric. " +
111-
"The sample Grafana dashboard filters by `namespace=$chain`, so set this " +
110+
"Value emitted as the `chain` label on every Prometheus metric. " +
111+
"The sample Grafana dashboard filters by `chain=$chain`, so set this " +
112112
"to your deployment's chain/network name (e.g. `bsc-mainnet`, `sui-testnet`). " +
113-
"Defaults to the chain command name (e.g. `evm`, `sui`, `aptos`, `solana`).",
113+
"Defaults to the chain command name (e.g. `evm`, `sui`, `aptos`, `solana`). " +
114+
"Named `chain` rather than `namespace` to avoid colliding with the " +
115+
"Kubernetes Prometheus service-discovery `namespace` label.",
114116
type: "string",
115117
required: false,
116118
} as Options,

apps/price_pusher/src/solana/command.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ export default {
124124
...options.controllerLogLevel,
125125
...options.enableMetrics,
126126
...options.metricsPort,
127-
...options.metricsNamespace,
127+
...options.metricsChain,
128128
},
129129
command: "solana",
130130
describe: "run price pusher for solana",
@@ -154,7 +154,7 @@ export default {
154154
metricsPort,
155155
pythReceiverProgramId,
156156
wormholeProgramId,
157-
metricsNamespace,
157+
metricsChain,
158158
} = argv;
159159

160160
const logger = pino({ level: logLevel });
@@ -170,7 +170,7 @@ export default {
170170
if (enableMetrics) {
171171
metrics = new PricePusherMetrics(
172172
logger.child({ module: "Metrics" }),
173-
metricsNamespace ?? "solana",
173+
metricsChain ?? "solana",
174174
);
175175
metrics.start(metricsPort);
176176
logger.info(`Metrics server started on port ${metricsPort}`);

apps/price_pusher/src/sui/command.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ export default {
7979
...options.controllerLogLevel,
8080
...options.enableMetrics,
8181
...options.metricsPort,
82-
...options.metricsNamespace,
82+
...options.metricsChain,
8383
},
8484
command: "sui",
8585
describe:
@@ -106,7 +106,7 @@ export default {
106106
controllerLogLevel,
107107
enableMetrics,
108108
metricsPort,
109-
metricsNamespace,
109+
metricsChain,
110110
} = argv;
111111

112112
const logger = pino({ level: logLevel });
@@ -145,7 +145,7 @@ export default {
145145
if (enableMetrics) {
146146
metrics = new PricePusherMetrics(
147147
logger.child({ module: "Metrics" }),
148-
metricsNamespace ?? "sui",
148+
metricsChain ?? "sui",
149149
);
150150
metrics.start(metricsPort);
151151
logger.info(`Metrics server started on port ${metricsPort}`);

0 commit comments

Comments
 (0)