github.com/go-graphite/carbonapi@v0.17.0/cmd/carbonapi/config/config.go (about) 1 package config 2 3 import ( 4 "encoding/json" 5 "time" 6 7 "github.com/go-graphite/carbonapi/cache" 8 "github.com/go-graphite/carbonapi/expr" 9 "github.com/go-graphite/carbonapi/expr/interfaces" 10 "github.com/go-graphite/carbonapi/limiter" 11 "github.com/go-graphite/carbonapi/pkg/tlsconfig" 12 zipperCfg "github.com/go-graphite/carbonapi/zipper/config" 13 zipper "github.com/go-graphite/carbonapi/zipper/interfaces" 14 zipperTypes "github.com/go-graphite/carbonapi/zipper/types" 15 16 "github.com/lomik/zapwriter" 17 ) 18 19 var DefaultLoggerConfig = zapwriter.Config{ 20 Logger: "", 21 File: "stdout", 22 Level: "info", 23 Encoding: "console", 24 EncodingTime: "iso8601", 25 EncodingDuration: "seconds", 26 } 27 28 type CacheConfig struct { 29 Type string `mapstructure:"type"` 30 Size int `mapstructure:"size_mb"` 31 MemcachedServers []string `mapstructure:"memcachedServers"` 32 DefaultTimeoutSec int32 `mapstructure:"defaultTimeoutSec"` 33 ShortTimeoutSec int32 `mapstructure:"shortTimeoutSec"` 34 ShortDuration time.Duration `mapstructure:"shortDuration"` 35 ShortUntilOffsetSec int64 `mapstructure:"shortUntilOffsetSec"` 36 } 37 38 type GraphiteConfig struct { 39 Pattern string 40 Host string 41 Statsd string 42 Interval time.Duration 43 Prefix string 44 } 45 46 type Define struct { 47 Name string `mapstructure:"name"` 48 Template string `mapstructure:"template"` 49 } 50 51 type ExpvarConfig struct { 52 Listen string `mapstructure:"listen"` 53 Enabled bool `mapstructure:"enabled"` 54 PProfEnabled bool `mapstructure:"pprofEnabled"` 55 } 56 57 type Listener struct { 58 Address string `mapstructure:"address"` 59 60 // Server TLS 61 ServerTLSConfig tlsconfig.TLSConfig `mapstructure:"serverTLSConfig"` 62 63 // Client TLS 64 ClientTLSConfig tlsconfig.TLSConfig `mapstructure:"clientTLSConfig"` 65 } 66 67 type DurationTruncate struct { 68 Duration time.Duration 69 Truncate time.Duration 70 } 71 72 type ConfigType struct { 73 ExtrapolateExperiment bool `mapstructure:"extrapolateExperiment"` 74 Logger []zapwriter.Config `mapstructure:"logger"` 75 Listen string `mapstructure:"listen"` 76 Listeners []Listener `mapstructure:"listeners"` 77 Buckets int `mapstructure:"buckets"` 78 Concurency int `mapstructure:"concurency"` 79 ResponseCacheConfig CacheConfig `mapstructure:"cache"` 80 BackendCacheConfig CacheConfig `mapstructure:"backendCache"` 81 Cpus int `mapstructure:"cpus"` 82 TimezoneString string `mapstructure:"tz"` 83 UnicodeRangeTables []string `mapstructure:"unicodeRangeTables"` 84 Graphite GraphiteConfig `mapstructure:"graphite"` 85 IdleConnections int `mapstructure:"idleConnections"` 86 PidFile string `mapstructure:"pidFile"` 87 SendGlobsAsIs *bool `mapstructure:"sendGlobsAsIs"` 88 AlwaysSendGlobsAsIs *bool `mapstructure:"alwaysSendGlobsAsIs"` 89 ExtractTagsFromArgs bool `mapstructure:"extractTagsFromArgs"` 90 PassFunctionsToBackend bool `mapstructure:"passFunctionsToBackend"` 91 MaxBatchSize int `mapstructure:"maxBatchSize"` 92 Zipper string `mapstructure:"zipper"` 93 Upstreams zipperCfg.Config `mapstructure:"upstreams"` 94 ExpireDelaySec int32 `mapstructure:"expireDelaySec"` 95 GraphiteWeb09Compatibility bool `mapstructure:"graphite09compat"` 96 IgnoreClientTimeout bool `mapstructure:"ignoreClientTimeout"` 97 DefaultColors map[string]string `mapstructure:"defaultColors"` 98 GraphTemplates string `mapstructure:"graphTemplates"` 99 FunctionsConfigs map[string]string `mapstructure:"functionsConfig"` 100 HeadersToPass []string `mapstructure:"headersToPass"` 101 HeadersToLog []string `mapstructure:"headersToLog"` 102 Define []Define `mapstructure:"define"` 103 Prefix string `mapstructure:"prefix"` 104 Expvar ExpvarConfig `mapstructure:"expvar"` 105 NotFoundStatusCode int `mapstructure:"notFoundStatusCode"` 106 HTTPResponseStackTrace bool `mapstructure:"httpResponseStackTrace"` 107 UseCachingDNSResolver bool `mapstructure:"useCachingDNSResolver"` 108 CachingDNSRefreshTime time.Duration `mapstructure:"cachingDNSRefreshTime"` 109 110 TruncateTimeMap map[time.Duration]time.Duration `mapstructure:"truncateTime"` 111 TruncateTime []DurationTruncate `mapstructure:"-" json:"-"` // produce from TruncateTimeMap and sort in reverse order 112 113 MaxQueryLength uint64 `mapstructure:"maxQueryLength"` 114 CombineMultipleTargetsInOne bool `mapstructure:"combineMultipleTargetsInOne"` 115 116 NudgeStartTimeOnAggregation bool `mapstructure:"nudgeStartTimeOnAggregation"` 117 UseBucketsHighestTimestampOnAggregation bool `mapstructure:"useBucketsHighestTimestampOnAggregation"` 118 119 ResponseCache cache.BytesCache `mapstructure:"-" json:"-"` 120 BackendCache cache.BytesCache `mapstructure:"-" json:"-"` 121 122 DefaultTimeZone *time.Location `mapstructure:"-" json:"-"` 123 124 // ZipperInstance is API entry to carbonzipper 125 ZipperInstance zipper.CarbonZipper `mapstructure:"-" json:"-"` 126 127 // Limiter limits concurrent zipper requests 128 Limiter limiter.SimpleLimiter `mapstructure:"-" json:"-"` 129 130 Evaluator interfaces.Evaluator `mapstructure:"-" json:"-"` 131 } 132 133 // skipcq: CRT-P0003 134 func (c ConfigType) String() string { 135 data, err := json.Marshal(c) 136 if err != nil { 137 return "Failed to marshal config: " + err.Error() 138 } else { 139 return string(data) 140 } 141 } 142 143 func (c *ConfigType) SetZipper(zipper zipper.CarbonZipper) (err error) { 144 c.ZipperInstance = zipper 145 c.Evaluator, err = expr.NewEvaluator(c.Limiter, c.ZipperInstance, c.PassFunctionsToBackend) 146 return 147 } 148 149 var Config = ConfigType{ 150 ExtrapolateExperiment: false, 151 Buckets: 10, 152 Concurency: 1000, 153 MaxBatchSize: 100, 154 ResponseCacheConfig: CacheConfig{ 155 Type: "mem", 156 DefaultTimeoutSec: 60, 157 ShortTimeoutSec: 0, 158 ShortDuration: 0, 159 }, 160 BackendCacheConfig: CacheConfig{ 161 Type: "null", 162 DefaultTimeoutSec: 0, 163 ShortTimeoutSec: 0, 164 }, 165 TimezoneString: "", 166 Graphite: GraphiteConfig{ 167 Pattern: "{prefix}.{fqdn}", 168 Host: "", 169 Interval: 60 * time.Second, 170 Prefix: "carbon.api", 171 }, 172 Cpus: 0, 173 IdleConnections: 10, 174 PidFile: "", 175 176 ResponseCache: cache.NullCache{}, 177 BackendCache: cache.NullCache{}, 178 179 DefaultTimeZone: time.Local, 180 Logger: []zapwriter.Config{DefaultLoggerConfig}, 181 182 Upstreams: zipperCfg.Config{ 183 Buckets: 10, 184 SlowLogThreshold: 1 * time.Second, 185 Timeouts: zipperTypes.Timeouts{ 186 Render: 10000 * time.Second, 187 Find: 2 * time.Second, 188 Connect: 200 * time.Millisecond, 189 }, 190 KeepAliveInterval: 30 * time.Second, 191 192 MaxIdleConnsPerHost: 100, 193 }, 194 ExpireDelaySec: 10 * 60, 195 GraphiteWeb09Compatibility: false, 196 Prefix: "", 197 Expvar: ExpvarConfig{ 198 Listen: "", 199 Enabled: true, 200 PProfEnabled: false, 201 }, 202 NotFoundStatusCode: 200, 203 HTTPResponseStackTrace: true, 204 UseCachingDNSResolver: false, 205 CachingDNSRefreshTime: 1 * time.Minute, 206 }