Skip to content

Commit

Permalink
query-frontend: Added support of auto_discovery for memcached (thanos…
Browse files Browse the repository at this point in the history
…-io#7004)

* query-frontend: Added support of auto_discovery for memcached

Signed-off-by: Vasiliy Rumyantsev <[email protected]>

* adjustments to build on main branch

Signed-off-by: Vasiliy Rumyantsev <[email protected]>

* CHANGELOG.md

Signed-off-by: Vasiliy Rumyantsev <[email protected]>

* typo fixed

Signed-off-by: Vasiliy Rumyantsev <[email protected]>

* minor fixex after review

Signed-off-by: Vasiliy Rumyantsev <[email protected]>

---------

Signed-off-by: Vasiliy Rumyantsev <[email protected]>
Signed-off-by: hanyuting8 <[email protected]>
  • Loading branch information
xBazilio authored and hanyuting8 committed Jan 19, 2024
1 parent 4e2fdec commit 7260643
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re
- [#6605](https://github.com/thanos-io/thanos/pull/6605) Query Frontend: Support vertical sharding binary expression with metric name when no matching labels specified.
- [#6308](https://github.com/thanos-io/thanos/pull/6308) Ruler: Support configuration flag that allows customizing template for alert message.
- [#6760](https://github.com/thanos-io/thanos/pull/6760) Query Frontend: Added TLS support in `--query-frontend.downstream-tripper-config` and `--query-frontend.downstream-tripper-config-file`
- [#7004](https://github.com/thanos-io/thanos/pull/7004) Query Frontend: Support documented auto discovery for memcached
- [#6749](https://github.com/thanos-io/thanos/pull/6749) Store Gateway: Added `thanos_store_index_cache_fetch_duration_seconds` histogram for tracking latency of fetching data from index cache.
- [#6690](https://github.com/thanos-io/thanos/pull/6690) Store: *breaking :warning:* Add tenant label to relevant exported metrics. Note that this change may cause some pre-existing dashboard queries to be incorrect due to the added label.
- [#6530](https://github.com/thanos-io/thanos/pull/6530) / [#6690](https://github.com/thanos-io/thanos/pull/6690) Query: Add command line arguments for configuring tenants and forward tenant information to Store Gateway.
Expand Down
24 changes: 19 additions & 5 deletions internal/cortex/chunk/cache/memcached_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/sony/gobreaker"
"github.com/thanos-io/thanos/pkg/clientconfig"
"github.com/thanos-io/thanos/pkg/discovery/dns"
memcacheDiscovery "github.com/thanos-io/thanos/pkg/discovery/memcache"
"github.com/thanos-io/thanos/pkg/extprom"
)

// MemcachedClient interface exists for mocking memcacheClient.
Expand All @@ -45,7 +48,7 @@ type memcachedClient struct {
service string

addresses []string
provider *dns.Provider
provider clientconfig.AddressProvider

cbs map[ /*address*/ string]*gobreaker.CircuitBreaker
cbFailures uint
Expand All @@ -68,6 +71,7 @@ type MemcachedClientConfig struct {
Host string `yaml:"host"`
Service string `yaml:"service"`
Addresses string `yaml:"addresses"` // EXPERIMENTAL.
AutoDiscovery bool `yaml:"auto_discovery"`
Timeout time.Duration `yaml:"timeout"`
MaxIdleConns int `yaml:"max_idle_conns"`
MaxItemSize int `yaml:"max_item_size"`
Expand Down Expand Up @@ -107,9 +111,19 @@ func NewMemcachedClient(cfg MemcachedClientConfig, name string, r prometheus.Reg
client.Timeout = cfg.Timeout
client.MaxIdleConns = cfg.MaxIdleConns

dnsProviderRegisterer := prometheus.WrapRegistererWithPrefix("cortex_", prometheus.WrapRegistererWith(prometheus.Labels{
"name": name,
}, r))
var addressProvider clientconfig.AddressProvider
if cfg.AutoDiscovery {
addressProvider = memcacheDiscovery.NewProvider(
logger,
extprom.WrapRegistererWithPrefix("cortex_", r),
cfg.Timeout,
)
} else {
dnsProviderRegisterer := prometheus.WrapRegistererWithPrefix("cortex_", prometheus.WrapRegistererWith(prometheus.Labels{
"name": name,
}, r))
addressProvider = dns.NewProvider(logger, dnsProviderRegisterer, dns.GolangResolverType)
}

newClient := &memcachedClient{
name: name,
Expand All @@ -118,7 +132,7 @@ func NewMemcachedClient(cfg MemcachedClientConfig, name string, r prometheus.Reg
hostname: cfg.Host,
service: cfg.Service,
logger: logger,
provider: dns.NewProvider(logger, dnsProviderRegisterer, dns.GolangResolverType),
provider: addressProvider,
cbs: make(map[string]*gobreaker.CircuitBreaker),
cbFailures: cfg.CBFailures,
cbInterval: cfg.CBInterval,
Expand Down
1 change: 1 addition & 0 deletions pkg/queryfrontend/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ func NewCacheConfig(logger log.Logger, confContentYaml []byte) (*cortexcache.Con
Timeout: config.Memcached.Timeout,
MaxIdleConns: config.Memcached.MaxIdleConnections,
Addresses: strings.Join(config.Memcached.Addresses, ","),
AutoDiscovery: config.Memcached.AutoDiscovery,
UpdateInterval: config.Memcached.DNSProviderUpdateInterval,
MaxItemSize: int(config.Memcached.MaxItemSize),
},
Expand Down

0 comments on commit 7260643

Please sign in to comment.