Skip to content

Commit

Permalink
fix: panic on null metrics port (#8680)
Browse files Browse the repository at this point in the history
  • Loading branch information
jycor authored Dec 14, 2024
1 parent e409d61 commit 5483f71
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions go/libraries/doltcore/servercfg/yaml_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ func (cfg YAMLConfig) MetricsPort() int {
if cfg.MetricsConfig.Host == nil {
return DefaultMetricsPort
}
if cfg.MetricsConfig.Port == nil {
return DefaultMetricsPort
}

return *cfg.MetricsConfig.Port
}
Expand Down
13 changes: 13 additions & 0 deletions go/libraries/doltcore/servercfg/yaml_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,3 +414,16 @@ listener:
err = ValidateConfig(cfg)
assert.Error(t, err)
}

func TestYAMLConfigMetrics(t *testing.T) {
var cfg YAMLConfig
err := yaml.Unmarshal([]byte(`
metrics:
host: localhost
port: null
`), &cfg)
require.NoError(t, err)

assert.Equal(t, "localhost", cfg.MetricsHost())
assert.Equal(t, -1, cfg.MetricsPort())
}

0 comments on commit 5483f71

Please sign in to comment.