forked from grafana/metrictank
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathconfig.go
81 lines (69 loc) · 3.28 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
73
74
75
76
77
78
79
80
81
package api
import (
"flag"
"net"
"net/http/httputil"
"net/url"
"time"
"github.com/raintank/dur"
"github.com/raintank/worldping-api/pkg/log"
"github.com/rakyll/globalconf"
)
var (
maxPointsPerReqSoft int
maxPointsPerReqHard int
logMinDurStr string
logMinDur uint32
Addr string
UseSSL bool
useGzip bool
certFile string
keyFile string
multiTenant bool
fallbackGraphite string
timeZoneStr string
getTargetsConcurrency int
tagdbDefaultLimit uint
speculationThreshold float64
graphiteProxy *httputil.ReverseProxy
timeZone *time.Location
)
func ConfigSetup() {
apiCfg := flag.NewFlagSet("http", flag.ExitOnError)
apiCfg.IntVar(&maxPointsPerReqSoft, "max-points-per-req-soft", 1000000, "lower resolution rollups will be used to try and keep requests below this number of datapoints. (0 disables limit)")
apiCfg.IntVar(&maxPointsPerReqHard, "max-points-per-req-hard", 20000000, "limit of number of datapoints a request can return. Requests that exceed this limit will be rejected. (0 disables limit)")
apiCfg.StringVar(&logMinDurStr, "log-min-dur", "5min", "only log incoming requests if their timerange is at least this duration. Use 0 to disable")
apiCfg.StringVar(&Addr, "listen", ":6060", "http listener address.")
apiCfg.BoolVar(&UseSSL, "ssl", false, "use HTTPS")
apiCfg.BoolVar(&useGzip, "gzip", true, "use GZIP compression of all responses")
apiCfg.StringVar(&certFile, "cert-file", "", "SSL certificate file")
apiCfg.StringVar(&keyFile, "key-file", "", "SSL key file")
apiCfg.BoolVar(&multiTenant, "multi-tenant", true, "require x-org-id authentication to auth as a specific org. otherwise orgId 1 is assumed")
apiCfg.StringVar(&fallbackGraphite, "fallback-graphite-addr", "http://localhost:8080", "in case our /render endpoint does not support the requested processing, proxy the request to this graphite")
apiCfg.StringVar(&timeZoneStr, "time-zone", "local", "timezone for interpreting from/until values when needed, specified using [zoneinfo name](https://en.wikipedia.org/wiki/Tz_database#Names_of_time_zones) e.g. 'America/New_York', 'UTC' or 'local' to use local server timezone")
apiCfg.IntVar(&getTargetsConcurrency, "get-targets-concurrency", 20, "maximum number of concurrent threads for fetching data on the local node. Each thread handles a single series.")
apiCfg.UintVar(&tagdbDefaultLimit, "tagdb-default-limit", 100, "default limit for tagdb query results, can be overridden with query parameter \"limit\"")
apiCfg.Float64Var(&speculationThreshold, "speculation-threshold", 1, "ratio of peer responses after which speculation is used. Set to 1 to disable.")
globalconf.Register("http", apiCfg)
}
func ConfigProcess() {
logMinDur = dur.MustParseDuration("log-min-dur", logMinDurStr)
//validate the addr
_, err := net.ResolveTCPAddr("tcp", Addr)
if err != nil {
log.Fatal(4, "API listen address is not a valid TCP address.")
}
u, err := url.Parse(fallbackGraphite)
if err != nil {
log.Fatal(4, "API Cannot parse fallback-graphite-addr: %s", err)
}
graphiteProxy = NewGraphiteProxy(u)
if timeZoneStr == "local" {
timeZone = time.Local
} else {
timeZone, err = time.LoadLocation(timeZoneStr)
if err != nil {
log.Fatal(4, "API Cannot load timezone %q: %s", timeZoneStr, err)
}
}
}