Turn target group members into plain lists.

As the scrape pool deduplicates targets now, it is no longer necessary
to store a hash map for members of each group.
This commit is contained in:
Fabian Reinartz 2016-02-28 20:03:44 +01:00
parent 0d7105abee
commit 2060a0a15b
1 changed files with 9 additions and 12 deletions

View File

@ -176,7 +176,7 @@ type targetSet struct {
mtx sync.RWMutex mtx sync.RWMutex
// Sets of targets by a source string that is unique across target providers. // Sets of targets by a source string that is unique across target providers.
tgroups map[string]map[uint64]*Target tgroups map[string][]*Target
providers map[string]TargetProvider providers map[string]TargetProvider
scrapePool *scrapePool scrapePool *scrapePool
@ -189,7 +189,7 @@ type targetSet struct {
func newTargetSet(cfg *config.ScrapeConfig, app storage.SampleAppender) *targetSet { func newTargetSet(cfg *config.ScrapeConfig, app storage.SampleAppender) *targetSet {
ts := &targetSet{ ts := &targetSet{
tgroups: map[string]map[uint64]*Target{}, tgroups: map[string][]*Target{},
scrapePool: newScrapePool(cfg, app), scrapePool: newScrapePool(cfg, app),
syncCh: make(chan struct{}, 1), syncCh: make(chan struct{}, 1),
config: cfg, config: cfg,
@ -247,13 +247,11 @@ Loop:
} }
func (ts *targetSet) sync() { func (ts *targetSet) sync() {
targets := []*Target{} var all []*Target
for _, tgroup := range ts.tgroups { for _, targets := range ts.tgroups {
for _, t := range tgroup { all = append(all, targets...)
targets = append(targets, t)
}
} }
ts.scrapePool.sync(targets) ts.scrapePool.sync(all)
} }
func (ts *targetSet) runProviders(ctx context.Context, providers map[string]TargetProvider) { func (ts *targetSet) runProviders(ctx context.Context, providers map[string]TargetProvider) {
@ -394,8 +392,8 @@ func providersFromConfig(cfg *config.ScrapeConfig) map[string]TargetProvider {
} }
// targetsFromGroup builds targets based on the given TargetGroup and config. // targetsFromGroup builds targets based on the given TargetGroup and config.
func targetsFromGroup(tg *config.TargetGroup, cfg *config.ScrapeConfig) (map[uint64]*Target, error) { func targetsFromGroup(tg *config.TargetGroup, cfg *config.ScrapeConfig) ([]*Target, error) {
targets := make(map[uint64]*Target, len(tg.Targets)) targets := make([]*Target, 0, len(tg.Targets))
for i, labels := range tg.Targets { for i, labels := range tg.Targets {
for k, v := range cfg.Params { for k, v := range cfg.Params {
@ -464,8 +462,7 @@ func targetsFromGroup(tg *config.TargetGroup, cfg *config.ScrapeConfig) (map[uin
labels[model.InstanceLabel] = labels[model.AddressLabel] labels[model.InstanceLabel] = labels[model.AddressLabel]
} }
tr := NewTarget(labels, preRelabelLabels, cfg.Params) targets = append(targets, NewTarget(labels, preRelabelLabels, cfg.Params))
targets[tr.hash()] = tr
} }
return targets, nil return targets, nil