mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-24 21:24:05 -08:00
feat(config): allow no remote write configs
Signed-off-by: Julien Levesy <jlevesy@gmail.com>
This commit is contained in:
parent
77dd468cc6
commit
8c5da5e078
|
@ -112,10 +112,6 @@ func LoadFile(filename string, agentMode, expandExternalLabels bool, logger log.
|
||||||
}
|
}
|
||||||
|
|
||||||
if agentMode {
|
if agentMode {
|
||||||
if len(cfg.RemoteWriteConfigs) == 0 {
|
|
||||||
return nil, errors.New("at least one remote_write target must be specified in agent mode")
|
|
||||||
}
|
|
||||||
|
|
||||||
if len(cfg.AlertingConfig.AlertmanagerConfigs) > 0 || len(cfg.AlertingConfig.AlertRelabelConfigs) > 0 {
|
if len(cfg.AlertingConfig.AlertmanagerConfigs) > 0 || len(cfg.AlertingConfig.AlertRelabelConfigs) > 0 {
|
||||||
return nil, errors.New("field alerting is not allowed in agent mode")
|
return nil, errors.New("field alerting is not allowed in agent mode")
|
||||||
}
|
}
|
||||||
|
|
|
@ -1745,6 +1745,33 @@ func TestExpandExternalLabels(t *testing.T) {
|
||||||
require.Equal(t, labels.FromStrings("bar", "foo", "baz", "fooTestValuebar", "foo", "TestValue", "qux", "foo${TEST}", "xyz", "foo$bar"), c.GlobalConfig.ExternalLabels)
|
require.Equal(t, labels.FromStrings("bar", "foo", "baz", "fooTestValuebar", "foo", "TestValue", "qux", "foo${TEST}", "xyz", "foo$bar"), c.GlobalConfig.ExternalLabels)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAgentMode(t *testing.T) {
|
||||||
|
_, err := LoadFile("testdata/agent_mode.with_alert_manager.yml", true, false, log.NewNopLogger())
|
||||||
|
require.ErrorContains(t, err, "field alerting is not allowed in agent mode")
|
||||||
|
|
||||||
|
_, err = LoadFile("testdata/agent_mode.with_alert_relabels.yml", true, false, log.NewNopLogger())
|
||||||
|
require.ErrorContains(t, err, "field alerting is not allowed in agent mode")
|
||||||
|
|
||||||
|
_, err = LoadFile("testdata/agent_mode.with_rule_files.yml", true, false, log.NewNopLogger())
|
||||||
|
require.ErrorContains(t, err, "field rule_files is not allowed in agent mode")
|
||||||
|
|
||||||
|
_, err = LoadFile("testdata/agent_mode.with_remote_reads.yml", true, false, log.NewNopLogger())
|
||||||
|
require.ErrorContains(t, err, "field remote_read is not allowed in agent mode")
|
||||||
|
|
||||||
|
c, err := LoadFile("testdata/agent_mode.without_remote_writes.yml", true, false, log.NewNopLogger())
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, c.RemoteWriteConfigs, 0)
|
||||||
|
|
||||||
|
c, err = LoadFile("testdata/agent_mode.good.yml", true, false, log.NewNopLogger())
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Len(t, c.RemoteWriteConfigs, 1)
|
||||||
|
require.Equal(
|
||||||
|
t,
|
||||||
|
"http://remote1/push",
|
||||||
|
c.RemoteWriteConfigs[0].URL.String(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
func TestEmptyGlobalBlock(t *testing.T) {
|
func TestEmptyGlobalBlock(t *testing.T) {
|
||||||
c, err := Load("global:\n", false, log.NewNopLogger())
|
c, err := Load("global:\n", false, log.NewNopLogger())
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
2
config/testdata/agent_mode.good.yml
vendored
Normal file
2
config/testdata/agent_mode.good.yml
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
remote_write:
|
||||||
|
- url: http://remote1/push
|
6
config/testdata/agent_mode.with_alert_manager.yml
vendored
Normal file
6
config/testdata/agent_mode.with_alert_manager.yml
vendored
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
alerting:
|
||||||
|
alertmanagers:
|
||||||
|
- scheme: https
|
||||||
|
static_configs:
|
||||||
|
- targets:
|
||||||
|
- "1.2.3.4:9093"
|
5
config/testdata/agent_mode.with_alert_relabels.yml
vendored
Normal file
5
config/testdata/agent_mode.with_alert_relabels.yml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
alerting:
|
||||||
|
alert_relabel_configs:
|
||||||
|
- action: uppercase
|
||||||
|
source_labels: [instance]
|
||||||
|
target_label: instance
|
5
config/testdata/agent_mode.with_remote_reads.yml
vendored
Normal file
5
config/testdata/agent_mode.with_remote_reads.yml
vendored
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
remote_read:
|
||||||
|
- url: http://remote1/read
|
||||||
|
read_recent: true
|
||||||
|
name: default
|
||||||
|
enable_http2: false
|
3
config/testdata/agent_mode.with_rule_files.yml
vendored
Normal file
3
config/testdata/agent_mode.with_rule_files.yml
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
rule_files:
|
||||||
|
- "first.rules"
|
||||||
|
- "my/*.rules"
|
2
config/testdata/agent_mode.without_remote_writes.yml
vendored
Normal file
2
config/testdata/agent_mode.without_remote_writes.yml
vendored
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
global:
|
||||||
|
scrape_interval: 15s
|
Loading…
Reference in a new issue