Skip to content

Commit

Permalink
query-frontend: Added support of auto_discovery for memcached
Browse files Browse the repository at this point in the history
Signed-off-by: Vasiliy Rumyantsev <[email protected]>
  • Loading branch information
xBazilio committed Dec 21, 2023
1 parent b16b71d commit 06b6bf8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
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 @@ -20,6 +20,9 @@ import (
"github.com/prometheus/client_golang/prometheus/promauto"
"github.com/sony/gobreaker"
"github.com/thanos-io/thanos/pkg/discovery/dns"
memcacheDiscovery "github.com/thanos-io/thanos/pkg/discovery/memcache"
"github.com/thanos-io/thanos/pkg/extprom"
"github.com/thanos-io/thanos/pkg/httpconfig"
)

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

addresses []string
provider *dns.Provider
provider httpconfig.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"`
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 httpconfig.AddressProvider
if cfg.AutoDicovery {
addressProvider = memcacheDiscovery.NewProvider(
logger,
extprom.WrapRegistererWithPrefix("thanos_memcached_", 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, ","),
AutoDicovery: config.Memcached.AutoDiscovery,
UpdateInterval: config.Memcached.DNSProviderUpdateInterval,
MaxItemSize: int(config.Memcached.MaxItemSize),
},
Expand Down

0 comments on commit 06b6bf8

Please sign in to comment.