MCPcopy Create free account
hub / github.com/cortexproject/cortex / NewInMemoryClientWithConfig

Function NewInMemoryClientWithConfig

pkg/ring/kv/consul/mock.go:36–67  ·  view source on GitHub ↗

NewInMemoryClientWithConfig makes a new mock consul client with supplied Config.

(codec codec.Codec, cfg Config, logger log.Logger, registerer prometheus.Registerer)

Source from the content-addressed store, hash-verified

34
35// NewInMemoryClientWithConfig makes a new mock consul client with supplied Config.
36func NewInMemoryClientWithConfig(codec codec.Codec, cfg Config, logger log.Logger, registerer prometheus.Registerer) (*Client, io.Closer) {
37 m := mockKV{
38 kvps: map[string]*consul.KVPair{},
39 // Always start from 1, we NEVER want to report back index 0 in the responses.
40 // This is in line with Consul, and our new checks for index return value in client.go.
41 current: 1,
42 logger: logger,
43 close: make(chan struct{}),
44 }
45 m.cond = sync.NewCond(&m.mtx)
46
47 // Create a closer function used to close the main loop and wait until it's done.
48 // We need to wait until done, otherwise the goroutine leak finder used in tests
49 // may still report it as leaked.
50 closer := closerFunc(func() error {
51 close(m.close)
52 m.closeWG.Wait()
53 return nil
54 })
55
56 // Start the main loop in a dedicated goroutine.
57 m.closeWG.Add(1)
58 go m.loop()
59
60 return &Client{
61 kv: &m,
62 codec: codec,
63 cfg: cfg,
64 logger: logger,
65 consulMetrics: newConsulMetrics(registerer),
66 }, closer
67}
68
69type closerFunc func() error
70

Calls 5

loopMethod · 0.95
closerFuncFuncType · 0.85
newConsulMetricsFunction · 0.85
WaitMethod · 0.45
AddMethod · 0.45