mirror of
https://github.com/hanzoai/traces.git
synced 2026-10-30 18:20:41 +00:00
* implement simple cache GET * make better errors and add cache to tempo local * improve memcache logs * delete unused method * changelog * use new method in other places * use otel tracing * log missed and hitted keys * remove batched requests * remove span loggers from memcached
37 lines
1021 B
Go
37 lines
1021 B
Go
package memcached
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/go-kit/log"
|
|
"github.com/prometheus/client_golang/prometheus"
|
|
|
|
"github.com/grafana/tempo/pkg/cache"
|
|
)
|
|
|
|
type Config struct {
|
|
ClientConfig cache.MemcachedClientConfig `yaml:",inline"`
|
|
|
|
TTL time.Duration `yaml:"ttl"`
|
|
}
|
|
|
|
func NewClient(cfg *Config, cfgBackground *cache.BackgroundConfig, name string, logger log.Logger) cache.Cache {
|
|
if cfg.ClientConfig.MaxIdleConns == 0 {
|
|
cfg.ClientConfig.MaxIdleConns = 16
|
|
}
|
|
if cfg.ClientConfig.Timeout == 0 {
|
|
cfg.ClientConfig.Timeout = 100 * time.Millisecond
|
|
}
|
|
if cfg.ClientConfig.UpdateInterval == 0 {
|
|
cfg.ClientConfig.UpdateInterval = time.Minute
|
|
}
|
|
|
|
client := cache.NewMemcachedClient(cfg.ClientConfig, name, prometheus.DefaultRegisterer, logger)
|
|
memcachedCfg := cache.MemcachedConfig{
|
|
Expiration: cfg.TTL,
|
|
}
|
|
c := cache.NewMemcached(memcachedCfg, client, name, cfg.ClientConfig.MaxItemSize, prometheus.DefaultRegisterer, logger)
|
|
|
|
return cache.NewBackground(name, *cfgBackground, c, prometheus.DefaultRegisterer)
|
|
}
|