fix the TestManagerReloadNoChange test (#4267)
Signed-off-by: Krasi Georgiev <kgeorgie@redhat.com>
This commit is contained in:
parent
709ad10d97
commit
9f2f6accba
|
@ -16,13 +16,13 @@ package scrape
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/prometheus/common/model"
|
"github.com/prometheus/common/model"
|
||||||
"github.com/prometheus/prometheus/config"
|
"github.com/prometheus/prometheus/config"
|
||||||
"github.com/prometheus/prometheus/discovery/targetgroup"
|
|
||||||
"github.com/prometheus/prometheus/pkg/labels"
|
"github.com/prometheus/prometheus/pkg/labels"
|
||||||
"github.com/prometheus/prometheus/util/testutil"
|
"github.com/prometheus/prometheus/util/testutil"
|
||||||
|
|
||||||
|
yaml "gopkg.in/yaml.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
func mustNewRegexp(s string) config.Regexp {
|
func mustNewRegexp(s string) config.Regexp {
|
||||||
|
@ -229,39 +229,41 @@ func TestPopulateLabels(t *testing.T) {
|
||||||
func TestManagerReloadNoChange(t *testing.T) {
|
func TestManagerReloadNoChange(t *testing.T) {
|
||||||
tsetName := "test"
|
tsetName := "test"
|
||||||
|
|
||||||
reloadCfg := &config.Config{
|
cfgText := `
|
||||||
ScrapeConfigs: []*config.ScrapeConfig{
|
scrape_configs:
|
||||||
&config.ScrapeConfig{
|
- job_name: '` + tsetName + `'
|
||||||
ScrapeInterval: model.Duration(3 * time.Second),
|
static_configs:
|
||||||
ScrapeTimeout: model.Duration(2 * time.Second),
|
- targets: ["foo:9090"]
|
||||||
},
|
- targets: ["bar:9090"]
|
||||||
},
|
`
|
||||||
|
cfg := &config.Config{}
|
||||||
|
if err := yaml.UnmarshalStrict([]byte(cfgText), cfg); err != nil {
|
||||||
|
t.Fatalf("Unable to load YAML config cfgYaml: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
scrapeManager := NewManager(nil, nil)
|
scrapeManager := NewManager(nil, nil)
|
||||||
scrapeManager.scrapeConfigs[tsetName] = reloadCfg.ScrapeConfigs[0]
|
// Load the current config.
|
||||||
|
scrapeManager.ApplyConfig(cfg)
|
||||||
|
|
||||||
// As reload never happens, new loop should never be called.
|
// As reload never happens, new loop should never be called.
|
||||||
newLoop := func(_ *Target, s scraper, _ int, _ bool, _ []*config.RelabelConfig) loop {
|
newLoop := func(_ *Target, s scraper, _ int, _ bool, _ []*config.RelabelConfig) loop {
|
||||||
t.Fatal("reload happened")
|
t.Fatal("reload happened")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
sp := &scrapePool{
|
sp := &scrapePool{
|
||||||
appendable: &nopAppendable{},
|
appendable: &nopAppendable{},
|
||||||
targets: map[uint64]*Target{},
|
targets: map[uint64]*Target{},
|
||||||
loops: map[uint64]loop{
|
loops: map[uint64]loop{
|
||||||
1: &scrapeLoop{},
|
1: &testLoop{},
|
||||||
},
|
},
|
||||||
newLoop: newLoop,
|
newLoop: newLoop,
|
||||||
logger: nil,
|
logger: nil,
|
||||||
config: reloadCfg.ScrapeConfigs[0],
|
config: cfg.ScrapeConfigs[0],
|
||||||
}
|
}
|
||||||
scrapeManager.scrapePools = map[string]*scrapePool{
|
scrapeManager.scrapePools = map[string]*scrapePool{
|
||||||
tsetName: sp,
|
tsetName: sp,
|
||||||
}
|
}
|
||||||
|
|
||||||
targets := map[string][]*targetgroup.Group{
|
scrapeManager.ApplyConfig(cfg)
|
||||||
tsetName: []*targetgroup.Group{},
|
|
||||||
}
|
|
||||||
|
|
||||||
scrapeManager.reload(targets)
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue