github.com/thanos-io/thanos@v0.32.5/cmd/thanos/config.go (about) 1 // Copyright (c) The Thanos Authors. 2 // Licensed under the Apache License 2.0. 3 4 // TODO(kakkoyun): Fix linter issues - The pattern we use makes linter unhappy (returning unused config pointers). 5 // 6 //nolint:unparam 7 package main 8 9 import ( 10 "net/url" 11 "time" 12 13 extflag "github.com/efficientgo/tools/extkingpin" 14 15 "github.com/prometheus/common/model" 16 17 "github.com/thanos-io/thanos/pkg/extkingpin" 18 ) 19 20 type grpcConfig struct { 21 bindAddress string 22 tlsSrvCert string 23 tlsSrvKey string 24 tlsSrvClientCA string 25 gracePeriod time.Duration 26 maxConnectionAge time.Duration 27 } 28 29 func (gc *grpcConfig) registerFlag(cmd extkingpin.FlagClause) *grpcConfig { 30 cmd.Flag("grpc-address", 31 "Listen ip:port address for gRPC endpoints (StoreAPI). Make sure this address is routable from other components."). 32 Default("0.0.0.0:10901").StringVar(&gc.bindAddress) 33 cmd.Flag("grpc-server-tls-cert", 34 "TLS Certificate for gRPC server, leave blank to disable TLS"). 35 Default("").StringVar(&gc.tlsSrvCert) 36 cmd.Flag("grpc-server-tls-key", 37 "TLS Key for the gRPC server, leave blank to disable TLS"). 38 Default("").StringVar(&gc.tlsSrvKey) 39 cmd.Flag("grpc-server-tls-client-ca", 40 "TLS CA to verify clients against. If no client CA is specified, there is no client verification on server side. (tls.NoClientCert)"). 41 Default("").StringVar(&gc.tlsSrvClientCA) 42 cmd.Flag("grpc-server-max-connection-age", "The grpc server max connection age. This controls how often to re-establish connections and redo TLS handshakes."). 43 Default("60m").DurationVar(&gc.maxConnectionAge) 44 cmd.Flag("grpc-grace-period", 45 "Time to wait after an interrupt received for GRPC Server."). 46 Default("2m").DurationVar(&gc.gracePeriod) 47 48 return gc 49 } 50 51 type httpConfig struct { 52 bindAddress string 53 tlsConfig string 54 gracePeriod model.Duration 55 } 56 57 func (hc *httpConfig) registerFlag(cmd extkingpin.FlagClause) *httpConfig { 58 cmd.Flag("http-address", 59 "Listen host:port for HTTP endpoints."). 60 Default("0.0.0.0:10902").StringVar(&hc.bindAddress) 61 cmd.Flag("http-grace-period", 62 "Time to wait after an interrupt received for HTTP Server."). 63 Default("2m").SetValue(&hc.gracePeriod) 64 cmd.Flag( 65 "http.config", 66 "[EXPERIMENTAL] Path to the configuration file that can enable TLS or authentication for all HTTP endpoints.", 67 ).Default("").StringVar(&hc.tlsConfig) 68 return hc 69 } 70 71 type prometheusConfig struct { 72 url *url.URL 73 readyTimeout time.Duration 74 getConfigInterval time.Duration 75 getConfigTimeout time.Duration 76 httpClient *extflag.PathOrContent 77 } 78 79 func (pc *prometheusConfig) registerFlag(cmd extkingpin.FlagClause) *prometheusConfig { 80 cmd.Flag("prometheus.url", 81 "URL at which to reach Prometheus's API. For better performance use local network."). 82 Default("http://localhost:9090").URLVar(&pc.url) 83 cmd.Flag("prometheus.ready_timeout", 84 "Maximum time to wait for the Prometheus instance to start up"). 85 Default("10m").DurationVar(&pc.readyTimeout) 86 cmd.Flag("prometheus.get_config_interval", 87 "How often to get Prometheus config"). 88 Default("30s").DurationVar(&pc.getConfigInterval) 89 cmd.Flag("prometheus.get_config_timeout", 90 "Timeout for getting Prometheus config"). 91 Default("5s").DurationVar(&pc.getConfigTimeout) 92 pc.httpClient = extflag.RegisterPathOrContent( 93 cmd, 94 "prometheus.http-client", 95 "YAML file or string with http client configs. See Format details: https://thanos.io/tip/components/sidecar.md/#configuration.", 96 ) 97 98 return pc 99 } 100 101 type tsdbConfig struct { 102 path string 103 } 104 105 func (tc *tsdbConfig) registerFlag(cmd extkingpin.FlagClause) *tsdbConfig { 106 cmd.Flag("tsdb.path", "Data directory of TSDB.").Default("./data").StringVar(&tc.path) 107 return tc 108 } 109 110 type reloaderConfig struct { 111 confFile string 112 envVarConfFile string 113 ruleDirectories []string 114 watchInterval time.Duration 115 retryInterval time.Duration 116 } 117 118 func (rc *reloaderConfig) registerFlag(cmd extkingpin.FlagClause) *reloaderConfig { 119 cmd.Flag("reloader.config-file", 120 "Config file watched by the reloader."). 121 Default("").StringVar(&rc.confFile) 122 cmd.Flag("reloader.config-envsubst-file", 123 "Output file for environment variable substituted config file."). 124 Default("").StringVar(&rc.envVarConfFile) 125 cmd.Flag("reloader.rule-dir", 126 "Rule directories for the reloader to refresh (repeated field)."). 127 StringsVar(&rc.ruleDirectories) 128 cmd.Flag("reloader.watch-interval", 129 "Controls how often reloader re-reads config and rules."). 130 Default("3m").DurationVar(&rc.watchInterval) 131 cmd.Flag("reloader.retry-interval", 132 "Controls how often reloader retries config reload in case of error."). 133 Default("5s").DurationVar(&rc.retryInterval) 134 135 return rc 136 } 137 138 type shipperConfig struct { 139 uploadCompacted bool 140 ignoreBlockSize bool 141 allowOutOfOrderUpload bool 142 hashFunc string 143 } 144 145 func (sc *shipperConfig) registerFlag(cmd extkingpin.FlagClause) *shipperConfig { 146 cmd.Flag("shipper.upload-compacted", 147 "If true shipper will try to upload compacted blocks as well. Useful for migration purposes. Works only if compaction is disabled on Prometheus. Do it once and then disable the flag when done."). 148 Default("false").BoolVar(&sc.uploadCompacted) 149 cmd.Flag("shipper.ignore-unequal-block-size", 150 "If true shipper will not require prometheus min and max block size flags to be set to the same value. Only use this if you want to keep long retention and compaction enabled on your Prometheus instance, as in the worst case it can result in ~2h data loss for your Thanos bucket storage."). 151 Default("false").Hidden().BoolVar(&sc.ignoreBlockSize) 152 cmd.Flag("shipper.allow-out-of-order-uploads", 153 "If true, shipper will skip failed block uploads in the given iteration and retry later. This means that some newer blocks might be uploaded sooner than older blocks."+ 154 "This can trigger compaction without those blocks and as a result will create an overlap situation. Set it to true if you have vertical compaction enabled and wish to upload blocks as soon as possible without caring"+ 155 "about order."). 156 Default("false").Hidden().BoolVar(&sc.allowOutOfOrderUpload) 157 cmd.Flag("hash-func", "Specify which hash function to use when calculating the hashes of produced files. If no function has been specified, it does not happen. This permits avoiding downloading some files twice albeit at some performance cost. Possible values are: \"\", \"SHA256\"."). 158 Default("").EnumVar(&sc.hashFunc, "SHA256", "") 159 return sc 160 } 161 162 type webConfig struct { 163 routePrefix string 164 externalPrefix string 165 prefixHeaderName string 166 disableCORS bool 167 } 168 169 func (wc *webConfig) registerFlag(cmd extkingpin.FlagClause) *webConfig { 170 cmd.Flag("web.route-prefix", 171 "Prefix for API and UI endpoints. This allows thanos UI to be served on a sub-path. This option is analogous to --web.route-prefix of Prometheus."). 172 Default("").StringVar(&wc.routePrefix) 173 cmd.Flag("web.external-prefix", 174 "Static prefix for all HTML links and redirect URLs in the bucket web UI interface. Actual endpoints are still served on / or the web.route-prefix. This allows thanos bucket web UI to be served behind a reverse proxy that strips a URL sub-path."). 175 Default("").StringVar(&wc.externalPrefix) 176 cmd.Flag("web.prefix-header", "Name of HTTP request header used for dynamic prefixing of UI links and redirects. This option is ignored if web.external-prefix argument is set. Security risk: enable this option only if a reverse proxy in front of thanos is resetting the header. The --web.prefix-header=X-Forwarded-Prefix option can be useful, for example, if Thanos UI is served via Traefik reverse proxy with PathPrefixStrip option enabled, which sends the stripped prefix value in X-Forwarded-Prefix header. This allows thanos UI to be served on a sub-path."). 177 Default("").StringVar(&wc.prefixHeaderName) 178 cmd.Flag("web.disable-cors", "Whether to disable CORS headers to be set by Thanos. By default Thanos sets CORS headers to be allowed by all.").Default("false").BoolVar(&wc.disableCORS) 179 return wc 180 } 181 182 type queryConfig struct { 183 addrs []string 184 sdFiles []string 185 sdInterval time.Duration 186 configPath *extflag.PathOrContent 187 dnsSDInterval time.Duration 188 httpMethod string 189 dnsSDResolver string 190 step time.Duration 191 doNotAddThanosParams bool 192 } 193 194 func (qc *queryConfig) registerFlag(cmd extkingpin.FlagClause) *queryConfig { 195 cmd.Flag("query", "Addresses of statically configured query API servers (repeatable). The scheme may be prefixed with 'dns+' or 'dnssrv+' to detect query API servers through respective DNS lookups."). 196 PlaceHolder("<query>").StringsVar(&qc.addrs) 197 qc.configPath = extflag.RegisterPathOrContent(cmd, "query.config", "YAML file that contains query API servers configuration. See format details: https://thanos.io/tip/components/rule.md/#configuration. If defined, it takes precedence over the '--query' and '--query.sd-files' flags.", extflag.WithEnvSubstitution()) 198 cmd.Flag("query.sd-files", "Path to file that contains addresses of query API servers. The path can be a glob pattern (repeatable)."). 199 PlaceHolder("<path>").StringsVar(&qc.sdFiles) 200 cmd.Flag("query.sd-interval", "Refresh interval to re-read file SD files. (used as a fallback)"). 201 Default("5m").DurationVar(&qc.sdInterval) 202 cmd.Flag("query.sd-dns-interval", "Interval between DNS resolutions."). 203 Default("30s").DurationVar(&qc.dnsSDInterval) 204 cmd.Flag("query.http-method", "HTTP method to use when sending queries. Possible options: [GET, POST]"). 205 Default("POST").EnumVar(&qc.httpMethod, "GET", "POST") 206 cmd.Flag("query.sd-dns-resolver", "Resolver to use. Possible options: [golang, miekgdns]"). 207 Default("miekgdns").Hidden().StringVar(&qc.dnsSDResolver) 208 cmd.Flag("query.default-step", "Default range query step to use. This is only used in stateless Ruler and alert state restoration."). 209 Default("1s").DurationVar(&qc.step) 210 cmd.Flag("query.only-prometheus-params", "Disable adding Thanos parameters (e.g dedup, partial_response) when querying metrics. Some non-Thanos systems have strict API validation.").Hidden(). 211 Default("false").BoolVar(&qc.doNotAddThanosParams) 212 return qc 213 } 214 215 type alertMgrConfig struct { 216 configPath *extflag.PathOrContent 217 alertmgrURLs []string 218 alertmgrsTimeout time.Duration 219 alertmgrsDNSSDInterval time.Duration 220 alertExcludeLabels []string 221 alertQueryURL *string 222 alertRelabelConfigPath *extflag.PathOrContent 223 } 224 225 func (ac *alertMgrConfig) registerFlag(cmd extflag.FlagClause) *alertMgrConfig { 226 ac.configPath = extflag.RegisterPathOrContent(cmd, "alertmanagers.config", "YAML file that contains alerting configuration. See format details: https://thanos.io/tip/components/rule.md/#configuration. If defined, it takes precedence over the '--alertmanagers.url' and '--alertmanagers.send-timeout' flags.", extflag.WithEnvSubstitution()) 227 cmd.Flag("alertmanagers.url", "Alertmanager replica URLs to push firing alerts. Ruler claims success if push to at least one alertmanager from discovered succeeds. The scheme should not be empty e.g `http` might be used. The scheme may be prefixed with 'dns+' or 'dnssrv+' to detect Alertmanager IPs through respective DNS lookups. The port defaults to 9093 or the SRV record's value. The URL path is used as a prefix for the regular Alertmanager API path."). 228 StringsVar(&ac.alertmgrURLs) 229 cmd.Flag("alertmanagers.send-timeout", "Timeout for sending alerts to Alertmanager").Default("10s"). 230 DurationVar(&ac.alertmgrsTimeout) 231 cmd.Flag("alertmanagers.sd-dns-interval", "Interval between DNS resolutions of Alertmanager hosts."). 232 Default("30s").DurationVar(&ac.alertmgrsDNSSDInterval) 233 ac.alertQueryURL = cmd.Flag("alert.query-url", "The external Thanos Query URL that would be set in all alerts 'Source' field").String() 234 cmd.Flag("alert.label-drop", "Labels by name to drop before sending to alertmanager. This allows alert to be deduplicated on replica label (repeated). Similar Prometheus alert relabelling"). 235 StringsVar(&ac.alertExcludeLabels) 236 ac.alertRelabelConfigPath = extflag.RegisterPathOrContent(cmd, "alert.relabel-config", "YAML file that contains alert relabelling configuration.", extflag.WithEnvSubstitution()) 237 return ac 238 }