Skip to content
This repository has been archived by the owner on Mar 9, 2022. It is now read-only.

Commit

Permalink
config: Set a default port for the monitor.
Browse files Browse the repository at this point in the history
Port 9331 has been allocated for use by influx-spout.

See https://github.com/prometheus/prometheus/wiki/Default-port-allocations
  • Loading branch information
mjs committed Apr 10, 2018
1 parent f5e652b commit 380fbfd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
15 changes: 11 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,18 @@ func NewConfigFromFile(fileName string) (*Config, error) {
if conf.Name == "" {
conf.Name = pathToConfigName(fileName)
}
if conf.Mode == "listener" && conf.Port == 0 {
conf.Port = 10001
} else if conf.Mode == "listener_http" && conf.Port == 0 {
conf.Port = 13337

if conf.Port == 0 {
switch conf.Mode {
case "listener":
conf.Port = 10001
case "listener_http":
conf.Port = 13337
case "monitor":
conf.Port = 9331
}
}

return conf, nil
}

Expand Down
6 changes: 6 additions & 0 deletions config/config_small_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ func TestDefaultPortHTTPListener(t *testing.T) {
assert.Equal(t, 13337, conf.Port)
}

func TestDefaultPortMonitor(t *testing.T) {
conf, err := parseConfig(`mode = "monitor"`)
require.NoError(t, err)
assert.Equal(t, 9331, conf.Port)
}

func TestNoMode(t *testing.T) {
_, err := parseConfig("")
assert.EqualError(t, err, "mode not specified in config")
Expand Down

0 comments on commit 380fbfd

Please sign in to comment.