Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

querier: per-endpoint configuration #4785

Closed
wants to merge 29 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
cec274d
loadConfig
Namanl2001 Jun 30, 2021
0b35270
helperFunc
Namanl2001 Jun 30, 2021
a0561e7
iterating endpoints
Namanl2001 Jun 30, 2021
aba6f10
addressed comments for config.go
Namanl2001 Jul 6, 2021
91718f5
addressed comments for querier
Namanl2001 Jul 6, 2021
3b07fe4
use either old or new config option
Namanl2001 Jul 8, 2021
6c8e643
small nits to green
Namanl2001 Jul 12, 2021
88a8084
making separate loops
Namanl2001 Jul 12, 2021
781fac5
added e2e-test
Namanl2001 Jul 13, 2021
bb5a0c6
more store configs
Namanl2001 Jul 20, 2021
a464c53
test mTLS in querier (failing)
Namanl2001 Jul 21, 2021
593401c
Added name to per-endpoint yaml config
Namanl2001 Jul 23, 2021
8b0ae4a
tested with new certs
Namanl2001 Jul 25, 2021
fd8e660
separate fileSDCache
Namanl2001 Jul 28, 2021
e48140a
configuring TLS in sidecar testing
Namanl2001 Jul 29, 2021
83185e4
failing fast for --secure
Namanl2001 Jul 30, 2021
18c830e
allow --store with --endpoint-config with noTLS
Namanl2001 Aug 10, 2021
1a0f2ed
generating temp certs while testing from create.sh
Namanl2001 Aug 11, 2021
e6ad5e9
added --store-strict (noTLS) and some comments to code
Namanl2001 Aug 12, 2021
81e1f19
amending flag description
Namanl2001 Aug 25, 2021
1a81f80
removing conflicts-1
Namanl2001 Oct 1, 2021
2bd35ca
removing errors-2
Namanl2001 Oct 1, 2021
94a2f17
removing errors-3
Namanl2001 Oct 1, 2021
61d2dc5
removing errors-4
Namanl2001 Oct 1, 2021
81a5b8d
removing errors-5
Namanl2001 Oct 1, 2021
88fef2a
ƒpkg/store/config.go -> pkg/query/config.go
Namanl2001 Oct 5, 2021
4d9cc57
store -> query
Namanl2001 Oct 5, 2021
f19a67b
single func for loading endpoint config
Namanl2001 Oct 5, 2021
d6a7988
Proposed changes to endpoint.config.
bwplotka Oct 14, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#4679](https://github.com/thanos-io/thanos/pull/4679) Added `enable-feature` flag to enable negative offsets and @ modifier, similar to Prometheus.
- [#4696](https://github.com/thanos-io/thanos/pull/4696) Query: add cache name to tracing spans.
- [#4764](https://github.com/thanos-io/thanos/pull/4764) Compactor: add `block-viewer.global.sync-block-timeout` flag to set the timeout of synchronization block metas.
- [#4389](https://github.com/thanos-io/thanos/pull/4389) Querier: add `endpoint.configuration` and `endpoint.configuration-file` for granular endpoint configuration YAML content or file.
- *:warning:* This also deprecates the following flags `store.sd-interval`, `store.sd-dns-interval`, `store.sd-dns-resolver`, `store.sd-files` and all `grpc-client-.*`. They will be removed in v0.27.0.

### Fixed

Expand Down
330 changes: 124 additions & 206 deletions cmd/thanos/query.go

Large diffs are not rendered by default.

14 changes: 10 additions & 4 deletions cmd/thanos/receive.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/pkg/labels"
"github.com/prometheus/prometheus/tsdb"
"github.com/thanos-io/thanos/pkg/exthttp"

"github.com/thanos-io/thanos/pkg/block/metadata"
"github.com/thanos-io/thanos/pkg/exemplars"
Expand Down Expand Up @@ -120,16 +121,21 @@ func runReceive(
return err
}

TLSConfig := exthttp.TLSConfig{
CertFile: conf.rwClientCert,
KeyFile: conf.rwClientKey,
CAFile: conf.rwClientServerCA,
ServerName: conf.rwClientServerName,
}

dialOpts, err := extgrpc.StoreClientGRPCOpts(
logger,
reg,
tracer,
"",
*conf.grpcCert != "",
*conf.grpcClientCA == "",
conf.rwClientCert,
conf.rwClientKey,
conf.rwClientServerCA,
conf.rwClientServerName,
TLSConfig,
)
if err != nil {
return err
Expand Down
40 changes: 19 additions & 21 deletions cmd/thanos/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ import (
"github.com/prometheus/prometheus/tsdb"
"github.com/prometheus/prometheus/util/strutil"
"github.com/thanos-io/thanos/pkg/errutil"
"github.com/thanos-io/thanos/pkg/exthttp"
"github.com/thanos-io/thanos/pkg/extkingpin"
"github.com/thanos-io/thanos/pkg/httpconfig"

extflag "github.com/efficientgo/tools/extkingpin"
"github.com/thanos-io/thanos/pkg/alert"
Expand Down Expand Up @@ -265,29 +265,29 @@ func runRule(
) error {
metrics := newRuleMetrics(reg)

var queryCfg []httpconfig.Config
var queryCfg []exthttp.Config
var err error
if len(conf.queryConfigYAML) > 0 {
queryCfg, err = httpconfig.LoadConfigs(conf.queryConfigYAML)
queryCfg, err = exthttp.LoadConfigs(conf.queryConfigYAML)
if err != nil {
return err
}
} else {
queryCfg, err = httpconfig.BuildConfig(conf.query.addrs)
queryCfg, err = exthttp.BuildConfig(conf.query.addrs)
if err != nil {
return errors.Wrap(err, "query configuration")
}

// Build the query configuration from the legacy query flags.
var fileSDConfigs []httpconfig.FileSDConfig
var fileSDConfigs []exthttp.FileSDConfig
if len(conf.query.sdFiles) > 0 {
fileSDConfigs = append(fileSDConfigs, httpconfig.FileSDConfig{
fileSDConfigs = append(fileSDConfigs, exthttp.FileSDConfig{
Files: conf.query.sdFiles,
RefreshInterval: model.Duration(conf.query.sdInterval),
})
queryCfg = append(queryCfg,
httpconfig.Config{
EndpointsConfig: httpconfig.EndpointsConfig{
exthttp.Config{
EndpointsConfig: exthttp.EndpointsConfig{
Scheme: "http",
FileSDConfigs: fileSDConfigs,
},
Expand All @@ -301,22 +301,21 @@ func runRule(
extprom.WrapRegistererWithPrefix("thanos_rule_query_apis_", reg),
dns.ResolverType(conf.query.dnsSDResolver),
)
var queryClients []*httpconfig.Client
var queryClients []*exthttp.Client
queryClientMetrics := extpromhttp.NewClientMetrics(extprom.WrapRegistererWith(prometheus.Labels{"client": "query"}, reg))
for _, cfg := range queryCfg {
cfg.HTTPClientConfig.ClientMetrics = queryClientMetrics
c, err := httpconfig.NewHTTPClient(cfg.HTTPClientConfig, "query")
c, err := exthttp.NewHTTPClient(cfg.HTTPClientConfig, "query", queryClientMetrics)
if err != nil {
return err
}
c.Transport = tracing.HTTPTripperware(logger, c.Transport)
queryClient, err := httpconfig.NewClient(logger, cfg.EndpointsConfig, c, queryProvider.Clone())
queryClient, err := exthttp.NewClient(logger, cfg.EndpointsConfig, c, queryProvider.Clone())
if err != nil {
return err
}
queryClients = append(queryClients, queryClient)
// Discover and resolve query addresses.
addDiscoveryGroups(g, queryClient, conf.query.dnsSDInterval)
addDiscoveryGroups(g, queryClient.Discoverer, conf.query.dnsSDInterval)
}

db, err := tsdb.Open(conf.dataDir, log.With(logger, "component", "tsdb"), reg, tsdbOpts, nil)
Expand Down Expand Up @@ -379,19 +378,18 @@ func runRule(
extprom.WrapRegistererWith(prometheus.Labels{"client": "alertmanager"}, reg),
)
for _, cfg := range alertingCfg.Alertmanagers {
cfg.HTTPClientConfig.ClientMetrics = amClientMetrics
c, err := httpconfig.NewHTTPClient(cfg.HTTPClientConfig, "alertmanager")
c, err := exthttp.NewHTTPClient(cfg.HTTPClientConfig, "alertmanager", amClientMetrics)
if err != nil {
return err
}
c.Transport = tracing.HTTPTripperware(logger, c.Transport)
// Each Alertmanager client has a different list of targets thus each needs its own DNS provider.
amClient, err := httpconfig.NewClient(logger, cfg.EndpointsConfig, c, amProvider.Clone())
amClient, err := exthttp.NewClient(logger, cfg.EndpointsConfig, c, amProvider.Clone())
if err != nil {
return err
}
// Discover and resolve Alertmanager addresses.
addDiscoveryGroups(g, amClient, conf.alertmgr.alertmgrsDNSSDInterval)
addDiscoveryGroups(g, amClient.Discoverer, conf.alertmgr.alertmgrsDNSSDInterval)

alertmgrs = append(alertmgrs, alert.NewAlertmanager(logger, amClient, time.Duration(cfg.Timeout), cfg.APIVersion))
}
Expand Down Expand Up @@ -705,7 +703,7 @@ func removeDuplicateQueryEndpoints(logger log.Logger, duplicatedQueriers prometh

func queryFuncCreator(
logger log.Logger,
queriers []*httpconfig.Client,
queriers []*exthttp.Client,
duplicatedQuery prometheus.Counter,
ruleEvalWarnings *prometheus.CounterVec,
httpMethod string,
Expand Down Expand Up @@ -761,18 +759,18 @@ func queryFuncCreator(
}
}

func addDiscoveryGroups(g *run.Group, c *httpconfig.Client, interval time.Duration) {
func addDiscoveryGroups(g *run.Group, d *exthttp.Discoverer, interval time.Duration) {
ctx, cancel := context.WithCancel(context.Background())
g.Add(func() error {
c.Discover(ctx)
d.Discover(ctx)
return nil
}, func(error) {
cancel()
})

g.Add(func() error {
return runutil.Repeat(interval, ctx.Done(), func() error {
return c.Resolve(ctx)
return d.Resolve(ctx)
})
}, func(error) {
cancel()
Expand Down
3 changes: 1 addition & 2 deletions cmd/thanos/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"github.com/thanos-io/thanos/pkg/exthttp"
"github.com/thanos-io/thanos/pkg/extkingpin"
"github.com/thanos-io/thanos/pkg/extprom"
"github.com/thanos-io/thanos/pkg/httpconfig"
"github.com/thanos-io/thanos/pkg/logging"
meta "github.com/thanos-io/thanos/pkg/metadata"
thanosmodel "github.com/thanos-io/thanos/pkg/model"
Expand Down Expand Up @@ -228,7 +227,7 @@ func runSidecar(
t := exthttp.NewTransport()
t.MaxIdleConnsPerHost = conf.connection.maxIdleConnsPerHost
t.MaxIdleConns = conf.connection.maxIdleConns
c := promclient.NewClient(&http.Client{Transport: tracing.HTTPTripperware(logger, t)}, logger, httpconfig.ThanosUserAgent)
c := promclient.NewClient(&http.Client{Transport: tracing.HTTPTripperware(logger, t)}, logger, exthttp.ThanosUserAgent)

promStore, err := store.NewPrometheusStore(logger, reg, c, conf.prometheus.url, component.Sidecar, m.Labels, m.Timestamps, m.Version)
if err != nil {
Expand Down
12 changes: 12 additions & 0 deletions docs/components/query.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,18 @@ Flags:
--enable-feature= ... Comma separated experimental feature names to
enable.The current list of features is
promql-negative-offset and promql-at-modifier.
--endpoint.config=<content>
Alternative to 'endpoint.config-file' flag
(mutually exclusive). Content of YAML file that
contains set of endpoints (e.g Store API) with
optional TLS options. To enable TLS either use
this option or deprecated ones
--grpc-client-tls* .
--endpoint.config-file=<file-path>
Path to YAML file that contains set of
endpoints (e.g Store API) with optional TLS
options. To enable TLS either use this option
or deprecated ones --grpc-client-tls* .
--grpc-address="0.0.0.0:10901"
Listen ip:port address for gRPC endpoints
(StoreAPI). Make sure this address is routable
Expand Down
30 changes: 15 additions & 15 deletions pkg/alert/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/pkg/errors"
"github.com/prometheus/common/model"
"github.com/prometheus/prometheus/pkg/relabel"
"github.com/thanos-io/thanos/pkg/httpconfig"
"github.com/thanos-io/thanos/pkg/exthttp"
"gopkg.in/yaml.v2"

"github.com/thanos-io/thanos/pkg/discovery/dns"
Expand All @@ -25,10 +25,10 @@ type AlertingConfig struct {

// AlertmanagerConfig represents a client to a cluster of Alertmanager endpoints.
type AlertmanagerConfig struct {
HTTPClientConfig httpconfig.ClientConfig `yaml:"http_config"`
EndpointsConfig httpconfig.EndpointsConfig `yaml:",inline"`
Timeout model.Duration `yaml:"timeout"`
APIVersion APIVersion `yaml:"api_version"`
HTTPClientConfig exthttp.ClientConfig `yaml:"http_config"`
EndpointsConfig exthttp.EndpointsConfig `yaml:",inline"`
Timeout model.Duration `yaml:"timeout"`
APIVersion APIVersion `yaml:"api_version"`
}

// APIVersion represents the API version of the Alertmanager endpoint.
Expand Down Expand Up @@ -61,10 +61,10 @@ func (v *APIVersion) UnmarshalYAML(unmarshal func(interface{}) error) error {

func DefaultAlertmanagerConfig() AlertmanagerConfig {
return AlertmanagerConfig{
EndpointsConfig: httpconfig.EndpointsConfig{
Scheme: "http",
StaticAddresses: []string{},
FileSDConfigs: []httpconfig.FileSDConfig{},
EndpointsConfig: exthttp.EndpointsConfig{
Scheme: "http",
Addresses: []string{},
FileSDConfigs: []exthttp.FileSDConfig{},
},
Timeout: model.Duration(time.Second * 10),
APIVersion: APIv1,
Expand Down Expand Up @@ -111,21 +111,21 @@ func BuildAlertmanagerConfig(address string, timeout time.Duration) (Alertmanage
break
}
}
var basicAuth httpconfig.BasicAuth
var basicAuth exthttp.BasicAuth
if parsed.User != nil && parsed.User.String() != "" {
basicAuth.Username = parsed.User.Username()
pw, _ := parsed.User.Password()
basicAuth.Password = pw
}

return AlertmanagerConfig{
HTTPClientConfig: httpconfig.ClientConfig{
HTTPClientConfig: exthttp.ClientConfig{
BasicAuth: basicAuth,
},
EndpointsConfig: httpconfig.EndpointsConfig{
PathPrefix: parsed.Path,
Scheme: scheme,
StaticAddresses: []string{host},
EndpointsConfig: exthttp.EndpointsConfig{
PathPrefix: parsed.Path,
Scheme: scheme,
Addresses: []string{host},
},
Timeout: model.Duration(timeout),
APIVersion: APIv1,
Expand Down
62 changes: 0 additions & 62 deletions pkg/extgrpc/client.go

This file was deleted.

53 changes: 53 additions & 0 deletions pkg/extgrpc/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) The Thanos Authors.
// Licensed under the Apache License 2.0.

package extgrpc

import (
"strings"

"github.com/pkg/errors"
"github.com/thanos-io/thanos/pkg/exthttp"
)

// Config is a structure that allows pointing to various gRPC endpoint, e.g Querier connecting to StoreAPI.
type Config struct {
GRPCClientConfig exthttp.ClientConfig `yaml:"grpc_config"`
EndpointsConfig EndpointsConfig `yaml:",inline"`
}

func DefaultConfig() Config {
return Config{
EndpointsConfig: EndpointsConfig{
Addresses: []string{},
FileSDConfigs: []exthttp.FileSDConfig{},
},
}
}

// UnmarshalYAML implements the yaml.Unmarshaler interface.
func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
*c = DefaultConfig()
type plain Config
return unmarshal((*plain)(c))
}

// BuildConfig returns a configuration from a static addresses.
func BuildConfig(addrs []string) ([]Config, error) {
configs := make([]Config, 0, len(addrs))
for i, addr := range addrs {
if addr == "" {
return nil, errors.Errorf("static address cannot be empty, but was at index %d", i)
}
if strings.Contains(addr, "/") {
return nil, errors.Errorf("gRPC address either has HTTP scheme or path. We expect only host+port with optional dns+ dnssrv+ prefix in it. Got %v", addr)
}

configs = append(configs, Config{
EndpointsConfig: EndpointsConfig{
Addresses: []string{addr},
},
})
}
return configs, nil
}
Loading