mirror of
https://github.com/weaveworks/scope.git
synced 2026-07-21 22:36:39 +00:00
multitenant: resolve collectors less frequently
DNS records don't change that fast
This commit is contained in:
@@ -156,6 +156,9 @@ type awsCollector struct {
|
||||
nats *nats.Conn
|
||||
waitersLock sync.Mutex
|
||||
waiters map[watchKey]*nats.Subscription
|
||||
|
||||
collectors []string
|
||||
lastResolved time.Time
|
||||
}
|
||||
|
||||
// Shortcut reports:
|
||||
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"context"
|
||||
|
||||
@@ -114,12 +115,14 @@ func (c *awsCollector) reportsFromLive(ctx context.Context, userid string) ([]re
|
||||
}
|
||||
|
||||
// We are a querier: fetch the most up-to-date reports from collectors
|
||||
// TODO: resolve c.collectorAddress periodically instead of every time we make a call
|
||||
addrs := resolve(c.cfg.CollectorAddr)
|
||||
reports := make([]*report.Report, len(addrs))
|
||||
if time.Since(c.lastResolved) > time.Second*5 {
|
||||
c.collectors = resolve(c.cfg.CollectorAddr)
|
||||
c.lastResolved = time.Now()
|
||||
}
|
||||
reports := make([]*report.Report, len(c.collectors))
|
||||
// make a call to each collector and fetch its data for this userid
|
||||
g, ctx := errgroup.WithContext(ctx)
|
||||
for i, addr := range addrs {
|
||||
for i, addr := range c.collectors {
|
||||
i, addr := i, addr // https://golang.org/doc/faq#closures_and_goroutines
|
||||
g.Go(func() error {
|
||||
body, err := oneCall(ctx, addr, "/api/report", userid)
|
||||
@@ -141,7 +144,7 @@ func (c *awsCollector) reportsFromLive(ctx context.Context, userid string) ([]re
|
||||
}
|
||||
|
||||
// dereference pointers into the expected return format
|
||||
ret := make([]report.Report, 0, len(addrs))
|
||||
ret := make([]report.Report, 0, len(reports))
|
||||
for _, rpt := range reports {
|
||||
if rpt != nil {
|
||||
ret = append(ret, *rpt)
|
||||
|
||||
Reference in New Issue
Block a user