mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-21 03:16:00 -08:00
Add basic test for TargetManager.targetSet
Verify that if the configs change, target groups are cleaned on TargetManager.reload (rather than having old ones linger around, even if they are no longer present in the configs). This covers the bug fixed in #1907 -- I verified that by checking out source from before that commit. This is a start on #1906
This commit is contained in:
parent
0ac2dbe6aa
commit
79216011cb
|
@ -12,3 +12,63 @@
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
package retrieval
|
package retrieval
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"golang.org/x/net/context"
|
||||||
|
"gopkg.in/yaml.v2"
|
||||||
|
|
||||||
|
"github.com/prometheus/prometheus/config"
|
||||||
|
"github.com/prometheus/prometheus/storage/local"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestTargetSetRecreatesTargetGroupsEveryRun(t *testing.T) {
|
||||||
|
scrapeConfig := &config.ScrapeConfig{}
|
||||||
|
|
||||||
|
sOne := `
|
||||||
|
job_name: "foo"
|
||||||
|
dns_sd_configs:
|
||||||
|
- names:
|
||||||
|
- "srv.name.one.example.org"
|
||||||
|
`
|
||||||
|
if err := yaml.Unmarshal([]byte(sOne), scrapeConfig); err != nil {
|
||||||
|
t.Fatalf("Unable to load YAML config sOne: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not properly setting it up, but that seems okay
|
||||||
|
mss := &local.MemorySeriesStorage{}
|
||||||
|
|
||||||
|
ts := newTargetSet(scrapeConfig, mss)
|
||||||
|
|
||||||
|
ts.runProviders(context.Background(), providersFromConfig(scrapeConfig))
|
||||||
|
|
||||||
|
verifyPresence(t, ts.tgroups, "dns/0/srv.name.one.example.org", true)
|
||||||
|
|
||||||
|
sTwo := `
|
||||||
|
job_name: "foo"
|
||||||
|
dns_sd_configs:
|
||||||
|
- names:
|
||||||
|
- "srv.name.two.example.org"
|
||||||
|
`
|
||||||
|
if err := yaml.Unmarshal([]byte(sTwo), scrapeConfig); err != nil {
|
||||||
|
t.Fatalf("Unable to load YAML config sTwo: %s", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
ts.runProviders(context.Background(), providersFromConfig(scrapeConfig))
|
||||||
|
|
||||||
|
verifyPresence(t, ts.tgroups, "dns/0/srv.name.one.example.org", false)
|
||||||
|
verifyPresence(t, ts.tgroups, "dns/0/srv.name.two.example.org", true)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func verifyPresence(t *testing.T, tgroups map[string][]*Target, name string, present bool) {
|
||||||
|
if _, ok := tgroups[name]; ok != present {
|
||||||
|
msg := ""
|
||||||
|
if !present {
|
||||||
|
msg = "not "
|
||||||
|
}
|
||||||
|
t.Fatalf("'%s' should %sbe present in TargetSet.tgroups: %s", name, msg, tgroups)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue