mirror of
https://github.com/weaveworks/scope.git
synced 2026-02-14 18:09:59 +00:00
Refactor: extract multitenant collection of 'live' reports
To help clarify subsequent changes
This commit is contained in:
@@ -145,13 +145,6 @@ type AWSCollectorConfig struct {
|
||||
CollectorAddr string
|
||||
}
|
||||
|
||||
// if StoreInterval is set, reports are merged into here and held until flushed to store
|
||||
type pendingEntry struct {
|
||||
sync.Mutex
|
||||
report report.Report
|
||||
count int
|
||||
}
|
||||
|
||||
type awsCollector struct {
|
||||
cfg AWSCollectorConfig
|
||||
db *dynamodb.DynamoDB
|
||||
@@ -707,16 +700,8 @@ func (c *awsCollector) Add(ctx context.Context, rep report.Report, buf []byte) e
|
||||
return nil
|
||||
}
|
||||
|
||||
// We are building up a report in memory; merge into that and it will be saved shortly
|
||||
rep = c.massageReport(userid, rep)
|
||||
entry := &pendingEntry{report: report.MakeReport()}
|
||||
if e, found := c.pending.LoadOrStore(userid, entry); found {
|
||||
entry = e.(*pendingEntry)
|
||||
}
|
||||
entry.Lock()
|
||||
entry.report.UnsafeMerge(rep)
|
||||
entry.count++
|
||||
entry.Unlock()
|
||||
c.addToLive(ctx, userid, rep)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
34
app/multitenant/collector.go
Normal file
34
app/multitenant/collector.go
Normal file
@@ -0,0 +1,34 @@
|
||||
package multitenant
|
||||
|
||||
// Collect reports from probes per-tenant, and supply them to queriers on demand
|
||||
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"context"
|
||||
|
||||
"github.com/weaveworks/scope/report"
|
||||
)
|
||||
|
||||
// if StoreInterval is set, reports are merged into here and held until flushed to store
|
||||
type pendingEntry struct {
|
||||
sync.Mutex
|
||||
report *report.Report
|
||||
}
|
||||
|
||||
// We are building up a report in memory; merge into that and it will be saved shortly
|
||||
// NOTE: may retain a reference to rep; must not be used by caller after this.
|
||||
func (c *awsCollector) addToLive(ctx context.Context, userid string, rep report.Report) {
|
||||
entry := &pendingEntry{}
|
||||
if e, found := c.pending.LoadOrStore(userid, entry); found {
|
||||
entry = e.(*pendingEntry)
|
||||
}
|
||||
entry.Lock()
|
||||
if entry.report == nil {
|
||||
entry.report = &rep
|
||||
} else {
|
||||
entry.report.UnsafeMerge(rep)
|
||||
}
|
||||
entry.Unlock()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user