MCPcopy
hub / github.com/grafana/dskit / newMemcachedClient

Function newMemcachedClient

cache/memcached_client.go:252–300  ·  view source on GitHub ↗
(
	logger log.Logger,
	client memcachedClientBackend,
	selector updatableServerSelector,
	config MemcachedClientConfig,
	reg prometheus.Registerer,
	name string,
)

Source from the content-addressed store, hash-verified

250}
251
252func newMemcachedClient(
253 logger log.Logger,
254 client memcachedClientBackend,
255 selector updatableServerSelector,
256 config MemcachedClientConfig,
257 reg prometheus.Registerer,
258 name string,
259) (*MemcachedClient, error) {
260 reg = prometheus.WrapRegistererWith(
261 prometheus.Labels{labelCacheBackend: backendValueMemcached},
262 prometheus.WrapRegistererWithPrefix(cacheMetricNamePrefix, reg))
263 addressProvider := dns.NewProvider(dns.MiekgdnsResolverType, config.AddressesLookupPoolSize, logger, reg)
264 metrics := newClientMetrics(reg)
265
266 c := &MemcachedClient{
267 metrics: metrics,
268 queue: newAsyncQueue(config.MaxAsyncBufferSize, config.MaxAsyncConcurrency),
269 logger: log.With(logger, "name", name),
270 config: config,
271 client: client,
272 selector: selector,
273 addressProvider: addressProvider,
274 stop: make(chan struct{}, 1),
275 name: name,
276 getMultiGate: gate.New(
277 prometheus.WrapRegistererWithPrefix(getMultiMetricNamePrefix, reg),
278 config.MaxGetMultiConcurrency,
279 ),
280 }
281
282 c.clientInfo = promauto.With(reg).NewGaugeFunc(prometheus.GaugeOpts{
283 Name: clientInfoMetricName,
284 Help: "A metric with a constant '1' value labeled by configuration options from which memcached client was configured.",
285 ConstLabels: prometheus.Labels{
286 "timeout": config.Timeout.String(),
287 "min_idle_connections_headroom_percentage": fmt.Sprintf("%f.2", config.MinIdleConnectionsHeadroomPercentage),
288 "max_idle_connections": strconv.Itoa(config.MaxIdleConnections),
289 "max_async_concurrency": strconv.Itoa(config.MaxAsyncConcurrency),
290 "max_async_buffer_size": strconv.Itoa(config.MaxAsyncBufferSize),
291 "max_item_size": strconv.FormatUint(uint64(config.MaxItemSize), 10),
292 "max_get_multi_concurrency": strconv.Itoa(config.MaxGetMultiConcurrency),
293 "max_get_multi_batch_size": strconv.Itoa(config.MaxGetMultiBatchSize),
294 },
295 },
296 func() float64 { return 1 },
297 )
298
299 return c, nil
300}
301
302func (c *MemcachedClient) Stop() {
303 close(c.stop)

Calls 6

NewProviderFunction · 0.92
NewFunction · 0.92
newClientMetricsFunction · 0.85
newAsyncQueueFunction · 0.85
WithMethod · 0.80
StringMethod · 0.65