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

Method GetClientFor

pkg/ring/client/pool.go:94–116  ·  view source on GitHub ↗

GetClientFor gets the client for the specified address. If it does not exist it will make a new client at that address

(addr string)

Source from the content-addressed store, hash-verified

92// GetClientFor gets the client for the specified address. If it does not exist it will make a new client
93// at that address
94func (p *Pool) GetClientFor(addr string) (PoolClient, error) {
95 client, ok := p.fromCache(addr)
96 if ok {
97 return client, nil
98 }
99
100 p.Lock()
101 defer p.Unlock()
102 client, ok = p.clients[addr]
103 if ok {
104 return client, nil
105 }
106
107 client, err := p.factory(addr)
108 if err != nil {
109 return nil, err
110 }
111 p.clients[addr] = client
112 if p.clientsMetric != nil {
113 p.clientsMetric.Add(1)
114 }
115 return client, nil
116}
117
118// RemoveClientFor removes the client with the specified address
119func (p *Pool) RemoveClientFor(addr string) {

Callers 1

TestPoolCacheFunction · 0.95

Calls 2

fromCacheMethod · 0.95
AddMethod · 0.45

Tested by 1

TestPoolCacheFunction · 0.76