-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcountaggregatorconfig.go
52 lines (43 loc) · 1.38 KB
/
countaggregatorconfig.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package stat
import (
"context"
"sync"
"time"
"github.com/rs/xstats"
)
// CountAggregatorConfig is the configuration for a CountAggregator.
type CountAggregatorConfig struct {
FlushInterval time.Duration `description:"Frequency of when to send aggregated metrics."`
StatConfig *DatadogConfig
}
// Name of the configuration as it might appear in config files.
func (*CountAggregatorConfig) Name() string {
return "statcountaggregator"
}
// CountAggregatorComponent implements the settings.Component interface for
// a countaggregator.
type CountAggregatorComponent struct {
StatComponent *DatadogComponent
}
// Settings generates a config with default values applied.
func (c *CountAggregatorComponent) Settings() *CountAggregatorConfig {
return &CountAggregatorConfig{
FlushInterval: 10 * time.Second,
StatConfig: c.StatComponent.Settings(),
}
}
// New creates a configured countaggregator that wraps around a stats client.
func (c *CountAggregatorComponent) New(ctx context.Context, conf *CountAggregatorConfig) (xstats.XStater, error) {
stater, err := c.StatComponent.New(ctx, conf.StatConfig)
if err != nil {
return nil, err
}
countAggregator := CountAggregator{
Stater: stater,
Bucket: make(map[StatTagKey]float64),
lock: &sync.Mutex{},
flushJob: make(chan int, 1),
FlushInterval: conf.FlushInterval,
}
return &countAggregator, nil
}