forked from bookingcom/carbonapi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.go
181 lines (159 loc) · 5.13 KB
/
common.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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package cfg
import (
"io"
"time"
"github.com/lomik/zapwriter"
"gopkg.in/yaml.v2"
)
// TODO (grzkv): Remove from global scope. Probably should be replaced with flags
var DEBUG bool = false
// TODO (grzkv): This type of config does not makes sense, since there is no such entity as graphite
// GraphiteConfig does not makes real sense
type GraphiteConfig struct {
Pattern string
Host string
Interval time.Duration
Prefix string
}
// ParseCommon sets the default config, parses input one, and overrides the defaults
func ParseCommon(r io.Reader) (Common, error) {
d := yaml.NewDecoder(r)
d.SetStrict(DEBUG)
// set the default config
c := DefaultCommonConfig()
err := d.Decode(&c)
return c, err
}
// DefaultCommonConfig gives the default config shared by carbonapi and zipper
func DefaultCommonConfig() Common {
return Common{
Listen: ":8080",
ListenInternal: ":7080",
MaxProcs: 1,
Timeouts: Timeouts{
Global: 10000 * time.Millisecond,
AfterStarted: 2 * time.Second,
Connect: 200 * time.Millisecond,
},
ConcurrencyLimitPerServer: 20,
KeepAliveInterval: 30 * time.Second,
MaxIdleConnsPerHost: 100,
ExpireDelaySec: int32(10 * time.Minute / time.Second),
InternalRoutingCache: int32(5 * time.Minute / time.Second),
Buckets: 10,
Graphite: GraphiteConfig{
Interval: 60 * time.Second,
Host: "",
Prefix: "carbon.zipper",
Pattern: "{prefix}.{fqdn}",
},
Logger: []zapwriter.Config{GetDefaultLoggerConfig()},
Monitoring: MonitoringConfig{
TimeInQueueExpHistogram: HistogramConfig{
Start: 0.01,
BucketsNum: 25,
BucketSize: 2,
},
TimeInQueueLinHistogram: HistogramConfig{
Start: 0.05,
BucketsNum: 25,
BucketSize: 0.02,
},
RequestDurationExp: HistogramConfig{
Start: 0.05,
BucketSize: 2,
BucketsNum: 20,
},
RequestDurationLin: HistogramConfig{
Start: 0.05,
BucketSize: 0.05,
BucketsNum: 40,
},
RenderDurationExp: HistogramConfig{
Start: 0.05,
BucketSize: 2,
BucketsNum: 20,
},
RenderDurationLinSimple: HistogramConfig{
Start: 0.1,
BucketSize: 0.1,
BucketsNum: 30,
},
FindDurationExp: HistogramConfig{
Start: 0.05,
BucketSize: 2,
BucketsNum: 20,
},
FindDurationLin: HistogramConfig{
Start: 0.5,
BucketSize: 0.5,
BucketsNum: 20,
},
FindDurationLinSimple: HistogramConfig{
Start: 0.5,
BucketSize: 0.5,
BucketsNum: 20,
},
FindDurationLinComplex: HistogramConfig{
Start: 0.5,
BucketSize: 0.5,
BucketsNum: 20,
},
},
}
}
// GetDefaultLoggerConfig returns sane default for the logger conf
func GetDefaultLoggerConfig() zapwriter.Config {
return zapwriter.Config{
Logger: "",
File: "stdout",
Level: "info",
Encoding: "console",
EncodingTime: "iso8601",
EncodingDuration: "seconds",
}
}
// Common is the configuration shared by carbonapi and carbonzipper
type Common struct {
Listen string `yaml:"listen"`
ListenInternal string `yaml:"listenInternal"`
Backends []string `yaml:"backends"`
MaxProcs int `yaml:"maxProcs"`
Timeouts Timeouts `yaml:"timeouts"`
ConcurrencyLimitPerServer int `yaml:"concurrencyLimit"`
KeepAliveInterval time.Duration `yaml:"keepAliveInterval"`
MaxIdleConnsPerHost int `yaml:"maxIdleConnsPerHost"`
ExpireDelaySec int32 `yaml:"expireDelaySec"`
InternalRoutingCache int32 `yaml:"internalRoutingCache"`
GraphiteWeb09Compatibility bool `yaml:"graphite09compat"`
CorruptionThreshold float64 `yaml:"corruptionThreshold"`
Buckets int `yaml:"buckets"`
Graphite GraphiteConfig `yaml:"graphite"`
Logger []zapwriter.Config `yaml:"logger"`
Monitoring MonitoringConfig `yaml:"monitoring"`
}
// MonitoringConfig allows setting custom monitoring parameters
type MonitoringConfig struct {
RequestDurationExp HistogramConfig `yaml:"requestDurationExpHistogram"`
RequestDurationLin HistogramConfig `yaml:"requestDurationLinHistogram"`
RenderDurationExp HistogramConfig `yaml:"renderDurationExpHistogram"`
RenderDurationLinSimple HistogramConfig `yaml:"renderDurationLinHistogram"`
FindDurationExp HistogramConfig `yaml:"findDurationExpHistogram"`
FindDurationLin HistogramConfig `yaml:"findDurationLinHistogram"`
FindDurationLinSimple HistogramConfig `yaml:"findDurationSimpleLinHistogram"`
FindDurationLinComplex HistogramConfig `yaml:"findDurationComplexLinHistogram"`
TimeInQueueExpHistogram HistogramConfig `yaml:"timeInQueueExpHistogram"`
TimeInQueueLinHistogram HistogramConfig `yaml:"timeInQueueLinHistogram"`
}
// HistogramConfig is histogram config for Prometheus metrics
type HistogramConfig struct {
Start float64 `yaml:"start"`
BucketsNum int `yaml:"bucketsNum"`
BucketSize float64 `yaml:"bucketSize"`
}
// Timeouts needs some figuring out
type Timeouts struct {
Global time.Duration `yaml:"global"`
AfterStarted time.Duration `yaml:"afterStarted"`
Connect time.Duration `yaml:"connect"`
}