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

query-frontend: Added support of auto_discovery for memcached #7004

Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ We use *breaking :warning:* to mark changes that are not backward compatible (re

### Fixed

- [#7004](https://github.com/thanos-io/thanos/pull/7004) Query Frontend: support documented auto discovery for memcached
yeya24 marked this conversation as resolved.
Show resolved Hide resolved
- [#6817](https://github.com/thanos-io/thanos/pull/6817) Store Gateway: fix `matchersToPostingGroups` label values variable got shadowed bug.

### Added
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.
AutoDicovery bool `yaml:"auto_dicovery"`

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be AutoDiscovery?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanx, fixed.

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.AutoDicovery {
addressProvider = memcacheDiscovery.NewProvider(
logger,
extprom.WrapRegistererWithPrefix("thanos_memcached_", r),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it better to use the same metric prefix here? cortex_

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was copied from thanos store code. I did as you suggested.

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, ","),
AutoDicovery: config.Memcached.AutoDiscovery,
UpdateInterval: config.Memcached.DNSProviderUpdateInterval,
MaxItemSize: int(config.Memcached.MaxItemSize),
},
Expand Down
Loading