diff --git a/discovery/nomad/nomad_test.go b/discovery/nomad/nomad_test.go index 32b087524c..c08f017496 100644 --- a/discovery/nomad/nomad_test.go +++ b/discovery/nomad/nomad_test.go @@ -127,19 +127,37 @@ func (m *SDMock) HandleServiceHashiCupsGet() { } func TestConfiguredService(t *testing.T) { - conf := &SDConfig{ - Server: "http://localhost:4646", + testCases := []struct { + name string + server string + acceptedURL bool + }{ + {"invalid hostname URL", "http://foo.bar:4646", true}, + {"invalid even though accepted by parsing", "foo.bar:4646", true}, + {"valid address URL", "http://172.30.29.23:4646", true}, + {"invalid URL", "172.30.29.23:4646", false}, } - reg := prometheus.NewRegistry() - refreshMetrics := discovery.NewRefreshMetrics(reg) - metrics := conf.NewDiscovererMetrics(reg, refreshMetrics) - require.NoError(t, metrics.Register()) + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + conf := &SDConfig{ + Server: tc.server, + } - _, err := NewDiscovery(conf, nil, metrics) - require.NoError(t, err) + reg := prometheus.NewRegistry() + refreshMetrics := discovery.NewRefreshMetrics(reg) + metrics := conf.NewDiscovererMetrics(reg, refreshMetrics) + require.NoError(t, metrics.Register()) + defer metrics.Unregister() - metrics.Unregister() + _, err := NewDiscovery(conf, nil, metrics) + if tc.acceptedURL { + require.NoError(t, err) + } else { + require.Error(t, err) + } + }) + } } func TestNomadSDRefresh(t *testing.T) { diff --git a/docs/configuration/configuration.md b/docs/configuration/configuration.md index 32da2c61c6..746360633e 100644 --- a/docs/configuration/configuration.md +++ b/docs/configuration/configuration.md @@ -2130,7 +2130,8 @@ The following meta labels are available on targets during [relabeling](#relabel_ [ namespace: | default = default ] [ refresh_interval: | default = 60s ] [ region: | default = global ] -[ server: ] +# The URL to connect to the API. +[ server: ] [ tag_separator: | default = ,] # HTTP client settings, including authentication methods (such as basic auth and