Skip to content

Commit d2ec68d

Browse files
authored
feat(metrics): replace metrics port with address (breaking change) (#2382)
1 parent e826702 commit d2ec68d

File tree

23 files changed

+101
-100
lines changed

23 files changed

+101
-100
lines changed

Dockerfile.staging

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ RUN go get ./...
2323
RUN go build github.com/ChainSafe/gossamer/cmd/gossamer
2424

2525
RUN ["sh", "-c", "gossamer init --chain=${chain}"]
26-
ENTRYPOINT ["sh", "-c", "service datadog-agent restart && gossamer --chain=${chain} --basepath=${basepath}/${chain} --publish-metrics --pprofserver --pprofaddress=\":6060\""]
26+
ENTRYPOINT ["sh", "-c", "service datadog-agent restart && gossamer --chain=${chain} --basepath=${basepath}/${chain} --publish-metrics --metrics-address=\":9876\" --pprofserver --pprofaddress=\":6060\""]
2727
EXPOSE 7001 8546 8540 9876 6060

chain/dev/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[global]
22
basepath = "~/.gossamer/dev"
33
log = "info"
4-
metrics-port = 9876
4+
metrics-address = ":9876"
55

66
[log]
77
core = ""

chain/dev/defaults.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ var (
2121
// DefaultBasePath is the node base directory path
2222
DefaultBasePath = string("~/.gossamer/dev")
2323

24-
// DefaultMetricsPort is the metrics server port
25-
DefaultMetricsPort = uint32(9876)
24+
// DefaultMetricsAddress is the default metrics server listening address.
25+
DefaultMetricsAddress = ":9876"
2626

2727
// DefaultLvl is the default log level
2828
DefaultLvl = log.Info

chain/gssmr/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[global]
22
basepath = "~/.gossamer/gssmr"
33
log = "info"
4-
metrics-port = 9876
4+
metrics-address = "localhost:9876"
55

66
[log]
77
core = ""

chain/gssmr/defaults.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ var (
2323
// DefaultBasePath Default node base directory path
2424
DefaultBasePath = string("~/.gossamer/gssmr")
2525

26-
// DefaultMetricsPort is the metrics server port
27-
DefaultMetricsPort = uint32(9876)
26+
// DefaultMetricsAddress is the default metrics server listening address.
27+
DefaultMetricsAddress = "localhost:9876"
2828

2929
// DefaultLvl is the default log level
3030
DefaultLvl = log.Info

chain/kusama/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[global]
22
basepath = "~/.gossamer/kusama"
33
log = "info"
4-
metrics-port = 9876
4+
metrics-address = "localhost:9876"
55

66
[log]
77
core = ""

chain/kusama/defaults.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ var (
2121
// DefaultBasePath Default node base directory path
2222
DefaultBasePath = string("~/.gossamer/kusama")
2323

24-
// DefaultMetricsPort is the metrics server port
25-
DefaultMetricsPort = uint32(9876)
24+
// DefaultMetricsAddress is the default metrics server listening address.
25+
DefaultMetricsAddress = "localhost:9876"
2626

2727
// DefaultLvl is the default log level
2828
DefaultLvl = log.Info

chain/polkadot/config.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[global]
22
basepath = "~/.gossamer/polkadot"
33
log = "info"
4-
metrics-port = 9876
4+
metrics-address = "localhost:9876"
55

66
[log]
77
core = ""

cmd/gossamer/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ defined in [lib/runtime/wasmer/exports.go](../../lib/runtime/wasmer/exports.go).
188188
Gossamer publishes telemetry data and also includes an embedded Prometheus server that reports metrics. The metrics
189189
capabilities are defined in the [dot/metrics](../../dot/metrics) package and build on
190190
[the metrics library that is included with Go Ethereum](https://github.com/ethereum/go-ethereum/blob/master/metrics/README.md).
191-
The default port for Prometheus metrics is 9090, and Gossamer allows the user to configure this parameter with the
192-
`--metrics-port` command-line parameter. The Gossamer telemetry server publishes telemetry data that is compatible with
191+
The default listening address for Prometheus metrics is `localhost:9090`, and Gossamer allows the user to configure this parameter with the
192+
`--metrics-address` command-line parameter. The Gossamer telemetry server publishes telemetry data that is compatible with
193193
[Polkadot Telemetry](https://github.com/paritytech/substrate-telemetry) and
194194
[its helpful UI](https://telemetry.polkadot.io/).

cmd/gossamer/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ func setDotGlobalConfigFromToml(tomlCfg *ctoml.Config, cfg *dot.GlobalConfig) {
458458
}
459459
}
460460

461-
cfg.MetricsPort = tomlCfg.Global.MetricsPort
461+
cfg.MetricsAddress = tomlCfg.Global.MetricsAddress
462462

463463
cfg.RetainBlocks = tomlCfg.Global.RetainBlocks
464464
cfg.Pruning = pruner.Mode(tomlCfg.Global.Pruning)
@@ -485,9 +485,9 @@ func setDotGlobalConfigFromFlags(ctx *cli.Context, cfg *dot.GlobalConfig) error
485485

486486
cfg.PublishMetrics = ctx.Bool("publish-metrics")
487487

488-
// check --metrics-port flag and update node configuration
489-
if metricsPort := ctx.GlobalUint(MetricsPortFlag.Name); metricsPort != 0 {
490-
cfg.MetricsPort = uint32(metricsPort)
488+
// check --metrics-address flag and update node configuration
489+
if metricsAddress := ctx.GlobalString(MetricsAddressFlag.Name); metricsAddress != "" {
490+
cfg.MetricsAddress = metricsAddress
491491
}
492492

493493
cfg.RetainBlocks = ctx.Int64(RetainBlockNumberFlag.Name)

cmd/gossamer/config_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func TestGlobalConfigFromFlags(t *testing.T) {
136136
BasePath: testCfg.Global.BasePath,
137137
LogLvl: log.Info,
138138
PublishMetrics: testCfg.Global.PublishMetrics,
139-
MetricsPort: testCfg.Global.MetricsPort,
139+
MetricsAddress: testCfg.Global.MetricsAddress,
140140
},
141141
},
142142
{
@@ -149,7 +149,7 @@ func TestGlobalConfigFromFlags(t *testing.T) {
149149
BasePath: dot.KusamaConfig().Global.BasePath,
150150
LogLvl: log.Info,
151151
PublishMetrics: testCfg.Global.PublishMetrics,
152-
MetricsPort: testCfg.Global.MetricsPort,
152+
MetricsAddress: testCfg.Global.MetricsAddress,
153153
},
154154
},
155155
{
@@ -162,7 +162,7 @@ func TestGlobalConfigFromFlags(t *testing.T) {
162162
BasePath: testCfg.Global.BasePath,
163163
LogLvl: log.Info,
164164
PublishMetrics: testCfg.Global.PublishMetrics,
165-
MetricsPort: testCfg.Global.MetricsPort,
165+
MetricsAddress: testCfg.Global.MetricsAddress,
166166
},
167167
},
168168
{
@@ -175,7 +175,7 @@ func TestGlobalConfigFromFlags(t *testing.T) {
175175
BasePath: "test_basepath",
176176
LogLvl: log.Info,
177177
PublishMetrics: testCfg.Global.PublishMetrics,
178-
MetricsPort: testCfg.Global.MetricsPort,
178+
MetricsAddress: testCfg.Global.MetricsAddress,
179179
},
180180
},
181181
{
@@ -188,7 +188,7 @@ func TestGlobalConfigFromFlags(t *testing.T) {
188188
BasePath: testCfg.Global.BasePath,
189189
LogLvl: log.Info,
190190
PublishMetrics: testCfg.Global.PublishMetrics,
191-
MetricsPort: testCfg.Global.MetricsPort,
191+
MetricsAddress: testCfg.Global.MetricsAddress,
192192
},
193193
},
194194
{
@@ -201,20 +201,20 @@ func TestGlobalConfigFromFlags(t *testing.T) {
201201
BasePath: testCfg.Global.BasePath,
202202
LogLvl: log.Info,
203203
PublishMetrics: true,
204-
MetricsPort: testCfg.Global.MetricsPort,
204+
MetricsAddress: testCfg.Global.MetricsAddress,
205205
},
206206
},
207207
{
208-
"Test gossamer --metrics-port",
209-
[]string{"config", "metrics-port", "name"},
210-
[]interface{}{testCfgFile.Name(), "9871", testCfg.Global.Name},
208+
"Test gossamer --metrics-address",
209+
[]string{"config", "metrics-address", "name"},
210+
[]interface{}{testCfgFile.Name(), ":9871", testCfg.Global.Name},
211211
dot.GlobalConfig{
212212
Name: testCfg.Global.Name,
213213
ID: testCfg.Global.ID,
214214
BasePath: testCfg.Global.BasePath,
215215
LogLvl: log.Info,
216216
PublishMetrics: testCfg.Global.PublishMetrics,
217-
MetricsPort: uint32(9871),
217+
MetricsAddress: ":9871",
218218
},
219219
},
220220
{
@@ -227,7 +227,7 @@ func TestGlobalConfigFromFlags(t *testing.T) {
227227
BasePath: testCfg.Global.BasePath,
228228
LogLvl: log.Info,
229229
PublishMetrics: testCfg.Global.PublishMetrics,
230-
MetricsPort: testCfg.Global.MetricsPort,
230+
MetricsAddress: testCfg.Global.MetricsAddress,
231231
NoTelemetry: true,
232232
},
233233
},
@@ -245,7 +245,7 @@ func TestGlobalConfigFromFlags(t *testing.T) {
245245
BasePath: testCfg.Global.BasePath,
246246
LogLvl: log.Info,
247247
PublishMetrics: testCfg.Global.PublishMetrics,
248-
MetricsPort: testCfg.Global.MetricsPort,
248+
MetricsAddress: testCfg.Global.MetricsAddress,
249249
NoTelemetry: false,
250250
TelemetryURLs: []genesis.TelemetryEndpoint{
251251
{Endpoint: "ws://localhost:8001/submit", Verbosity: 0},
@@ -783,7 +783,7 @@ func TestUpdateConfigFromGenesisJSON(t *testing.T) {
783783
BasePath: testCfg.Global.BasePath,
784784
LogLvl: testCfg.Global.LogLvl,
785785
PublishMetrics: testCfg.Global.PublishMetrics,
786-
MetricsPort: testCfg.Global.MetricsPort,
786+
MetricsAddress: testCfg.Global.MetricsAddress,
787787
TelemetryURLs: testCfg.Global.TelemetryURLs,
788788
},
789789
Log: dot.LogConfig{
@@ -837,7 +837,7 @@ func TestUpdateConfigFromGenesisJSON_Default(t *testing.T) {
837837
BasePath: testCfg.Global.BasePath,
838838
LogLvl: testCfg.Global.LogLvl,
839839
PublishMetrics: testCfg.Global.PublishMetrics,
840-
MetricsPort: testCfg.Global.MetricsPort,
840+
MetricsAddress: testCfg.Global.MetricsAddress,
841841
TelemetryURLs: testCfg.Global.TelemetryURLs,
842842
},
843843
Log: dot.LogConfig{
@@ -887,7 +887,7 @@ func TestUpdateConfigFromGenesisData(t *testing.T) {
887887
BasePath: testCfg.Global.BasePath,
888888
LogLvl: testCfg.Global.LogLvl,
889889
PublishMetrics: testCfg.Global.PublishMetrics,
890-
MetricsPort: testCfg.Global.MetricsPort,
890+
MetricsAddress: testCfg.Global.MetricsAddress,
891891
TelemetryURLs: testCfg.Global.TelemetryURLs,
892892
},
893893
Log: dot.LogConfig{

cmd/gossamer/export.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ func dotConfigToToml(dcfg *dot.Config) *ctoml.Config {
6767
}
6868

6969
cfg.Global = ctoml.GlobalConfig{
70-
Name: dcfg.Global.Name,
71-
ID: dcfg.Global.ID,
72-
BasePath: dcfg.Global.BasePath,
73-
LogLvl: dcfg.Global.LogLvl.String(),
74-
MetricsPort: dcfg.Global.MetricsPort,
75-
RetainBlocks: dcfg.Global.RetainBlocks,
76-
Pruning: string(dcfg.Global.Pruning),
70+
Name: dcfg.Global.Name,
71+
ID: dcfg.Global.ID,
72+
BasePath: dcfg.Global.BasePath,
73+
LogLvl: dcfg.Global.LogLvl.String(),
74+
MetricsAddress: dcfg.Global.MetricsAddress,
75+
RetainBlocks: dcfg.Global.RetainBlocks,
76+
Pruning: string(dcfg.Global.Pruning),
7777
}
7878

7979
cfg.Log = ctoml.LogConfig{

cmd/gossamer/export_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func TestExportCommand(t *testing.T) {
4747
BasePath: testCfg.Global.BasePath,
4848
LogLvl: log.Info,
4949
PublishMetrics: testCfg.Global.PublishMetrics,
50-
MetricsPort: testCfg.Global.MetricsPort,
50+
MetricsAddress: testCfg.Global.MetricsAddress,
5151
},
5252
Log: dot.LogConfig{
5353
CoreLvl: log.Info,

cmd/gossamer/flags.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ var (
128128
Usage: "Publish node metrics",
129129
}
130130

131-
// MetricsPortFlag set metric listen port
132-
MetricsPortFlag = cli.StringFlag{
133-
Name: "metrics-port",
134-
Usage: "Set metric listening port ",
131+
// MetricsAddressFlag sets the metric server listening address
132+
MetricsAddressFlag = cli.StringFlag{
133+
Name: "metrics-address",
134+
Usage: "Set the metric server listening address",
135135
}
136136

137137
// NoTelemetryFlag stops publishing telemetry to default defined in genesis.json
@@ -442,7 +442,7 @@ var (
442442

443443
// metrics flag
444444
PublishMetricsFlag,
445-
MetricsPortFlag,
445+
MetricsAddressFlag,
446446

447447
// telemetry flags
448448
NoTelemetryFlag,

cmd/gossamer/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func newTestConfig(t *testing.T) *dot.Config {
7676
BasePath: dir,
7777
LogLvl: log.Info,
7878
PublishMetrics: dot.GssmrConfig().Global.PublishMetrics,
79-
MetricsPort: dot.GssmrConfig().Global.MetricsPort,
79+
MetricsAddress: dot.GssmrConfig().Global.MetricsAddress,
8080
RetainBlocks: dot.GssmrConfig().Global.RetainBlocks,
8181
Pruning: dot.GssmrConfig().Global.Pruning,
8282
TelemetryURLs: dot.GssmrConfig().Global.TelemetryURLs,

devnet/alice.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ RUN go run cmd/update-dd-agent-confd/main.go -n=${METRICS_NAMESPACE} -t=key:alic
3838

3939
WORKDIR /gossamer
4040

41-
ENTRYPOINT service datadog-agent start && gossamer --key=alice --babe-lead --publish-metrics --rpc --rpc-external=true --pubdns=alice --port 7001
41+
ENTRYPOINT service datadog-agent start && gossamer --key=alice --babe-lead --publish-metrics --metrics-address=":9876" --rpc --rpc-external=true --pubdns=alice --port 7001
4242

4343
EXPOSE 7001/tcp 8545/tcp 8546/tcp 8540/tcp 9876/tcp 6060/tcp

devnet/bob.Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ WORKDIR /gossamer
4242
ENTRYPOINT service datadog-agent start && gossamer --key=${key} \
4343
--bootnodes=/dns/alice/tcp/7001/p2p/12D3KooWMER5iow67nScpWeVqEiRRx59PJ3xMMAYPTACYPRQbbWU \
4444
--publish-metrics \
45+
--metrics-address=":9876" \
4546
--rpc \
4647
--port 7001 \
4748
--pubdns=${key}

docs/docs/integrate/using-prometheus.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ the above command will starts the Prometheus service on `0.0.0.0:9090`.
2222

2323
### Prometheus
2424

25-
Actually the Prometheus service reads a file `prometheus.yml` placed in the root level project folder, this file contains the definitions that Prometheus needs to collect the metrics.
25+
Actually the Prometheus service reads a file `prometheus.yml` placed in the root level project folder, this file contains the definitions that Prometheus needs to collect the metrics.
2626

2727
Linux: In the **job_name == gossamer** the **targets** property should be `[localhost:9876]`
2828

29-
To publish metrics from the node use the flag **--publish-metrics**; i.e, `./bin/gossamer --chain {chain} --key {key} --publish-metrics`
29+
To publish metrics from the node use the flag `--publish-metrics`; i.e, `./bin/gossamer --chain {chain} --key {key} --publish-metrics`.
30+
31+
By default, the Prometheus server listens on `localhost:9876`, which you can change with `--metrics-address`. To listen on all interfaces, you can use `--metrics-address=":9876"`.

0 commit comments

Comments
 (0)