Skip to content

Commit dde35f1

Browse files
committed
feat: document metrics endpoint
Document metrics endpoint in `config.yml.example` and update the YAML based configuration to its own top-level key in the configuration file to match the `debug` implementation. Fixes #15 Signed-off-by: Chris Gianelloni <[email protected]>
1 parent f40eba4 commit dde35f1

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

config.yaml.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@ api:
1919
# This can also be set via the API_LISTEN_PORT environment variable
2020
port: 8090
2121

22+
metrics:
23+
# Listen address for the metrics endpoint
24+
#
25+
# This can also be set via the METRICS_LISTEN_ADDRESS environment variable
26+
address:
27+
28+
# Listen port for the metrics endpoint
29+
#
30+
# This can also be set via the METRICS_LISTEN_PORT environment variable
31+
port: 8081
32+
2233
# The debug endpoint provides access to pprof for debugging purposes. This is
2334
# disabled by default, but it can be enabled by setting the port to a non-zero
2435
# value

internal/api/api.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ func Start(cfg *config.Config) error {
6666
go func() {
6767
// TODO: return error if we cannot initialize metrics
6868
_ = metricsRouter.Run(fmt.Sprintf("%s:%d",
69-
cfg.Api.MetricsAddress,
70-
cfg.Api.MetricsPort))
69+
cfg.Metrics.MetricsAddress,
70+
cfg.Metrics.MetricsPort))
7171
}()
7272

7373
// Configure API routes

internal/config/config.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const (
1616
type Config struct {
1717
Logging LoggingConfig `yaml:"logging"`
1818
Api ApiConfig `yaml:"api"`
19+
Metrics MetricsConfig `yaml:"metrics"`
1920
Debug DebugConfig `yaml:"debug"`
2021
Node NodeConfig `yaml:"node"`
2122
}
@@ -27,15 +28,18 @@ type LoggingConfig struct {
2728
type ApiConfig struct {
2829
ListenAddress string `yaml:"address" envconfig:"API_LISTEN_ADDRESS"`
2930
ListenPort uint `yaml:"port" envconfig:"API_LISTEN_PORT"`
30-
MetricsAddress string `yaml:"metricsAddress" envconfig:"METRICS_LISTEN_ADDRESS"`
31-
MetricsPort uint `yaml:"metricsPort" envconfig:"METRICS_LISTEN_PORT"`
3231
}
3332

3433
type DebugConfig struct {
3534
ListenAddress string `yaml:"address" envconfig:"DEBUG_ADDRESS"`
3635
ListenPort uint `yaml:"port" envconfig:"DEBUG_PORT"`
3736
}
3837

38+
type MetricsConfig struct {
39+
MetricsAddress string `yaml:"metricsAddress" envconfig:"METRICS_LISTEN_ADDRESS"`
40+
MetricsPort uint `yaml:"metricsPort" envconfig:"METRICS_LISTEN_PORT"`
41+
}
42+
3943
type NodeConfig struct {
4044
Network string `yaml:"network" envconfig:"NETWORK"`
4145
NetworkMagic uint32 `yaml:"networkMagic" envconfig:"CARDANO_NODE_NETWORK_MAGIC"`
@@ -52,13 +56,15 @@ var globalConfig = &Config{
5256
Api: ApiConfig{
5357
ListenAddress: "",
5458
ListenPort: 8090,
55-
MetricsAddress: "",
56-
MetricsPort: 8081,
5759
},
5860
Debug: DebugConfig{
5961
ListenAddress: "localhost",
6062
ListenPort: 0,
6163
},
64+
Metrics: MetricsConfig{
65+
MetricsAddress: "",
66+
MetricsPort: 8081,
67+
},
6268
Node: NodeConfig{
6369
Network: "mainnet",
6470
SocketPath: "/node-ipc/node.socket",

0 commit comments

Comments
 (0)