doc(nomad): adjust sections about nomad_sd_config's server

test(nomad): extend TestConfiguredService with more valid/invalid servers configs

fixes https://github.com/prometheus/prometheus/issues/12306

Signed-off-by: machine424 <ayoubmrini424@gmail.com>
pull/15532/head
machine424 2024-12-03 19:41:45 +01:00
parent 7f26371af8
commit c9f3d9b47f
No known key found for this signature in database
GPG Key ID: A4B001A4FDEE017D
2 changed files with 29 additions and 10 deletions

View File

@ -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) {

View File

@ -2130,7 +2130,8 @@ The following meta labels are available on targets during [relabeling](#relabel_
[ namespace: <string> | default = default ]
[ refresh_interval: <duration> | default = 60s ]
[ region: <string> | default = global ]
[ server: <host> ]
# The URL to connect to the API.
[ server: <string> ]
[ tag_separator: <string> | default = ,]
# HTTP client settings, including authentication methods (such as basic auth and