-
Notifications
You must be signed in to change notification settings - Fork 316
/
config.go
72 lines (63 loc) · 1.89 KB
/
config.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package stats
import (
"sync"
"github.com/rudderlabs/rudder-server/config"
"github.com/rudderlabs/rudder-server/services/metric"
"gopkg.in/alexcesaro/statsd.v2"
)
type statsdConfig struct {
enabled bool
tagsFormat string
excludedTags []string
statsdServerURL string
instanceID string
samplingRate float32
periodic periodicStatsConfig
}
type periodicStatsConfig struct {
enabled bool
statsCollectionInterval int64
enableCPUStats bool
enableMemStats bool
enableGCStats bool
metricManager metric.Manager
}
// statsdDefaultTags returns the default tags to use for statsd
func (c *statsdConfig) statsdDefaultTags() statsd.Option {
tags := []string{"instanceName", c.instanceID}
if len(config.GetKubeNamespace()) > 0 {
tags = append(tags, "namespace", config.GetKubeNamespace())
}
return statsd.Tags(tags...)
}
// statsdTagsFormat returns the tags format to use for statsd
func (c *statsdConfig) statsdTagsFormat() statsd.Option {
switch c.tagsFormat {
case "datadog":
return statsd.TagsFormat(statsd.Datadog)
default:
return statsd.TagsFormat(statsd.InfluxDB)
}
}
type statsdState struct {
conn statsd.Option
client *statsdClient
connEstablished bool
rc runtimeStatsCollector
mc metricStatsCollector
clientsLock sync.RWMutex
clients map[string]*statsdClient
pendingClients map[string]*statsdClient
}
// statsdClient is a wrapper around statsd.Client.
// We use this wrapper to allow for filling the actual statsd client at a later stage,
// in case a connection cannot be established immediately at startup.
type statsdClient struct {
samplingRate float32
tags []string
statsd *statsd.Client
}
// ready returns true if the statsd client is ready to be used (not nil).
func (sc *statsdClient) ready() bool {
return sc.statsd != nil
}