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

Method GetClientForInstance

ring/client/pool.go:140–165  ·  view source on GitHub ↗

GetClientForInstance gets the client for the specified ring member. If it does not exist it will make a new client for that instance.

(inst ring.InstanceDesc)

Source from the content-addressed store, hash-verified

138// GetClientForInstance gets the client for the specified ring member. If it does not exist
139// it will make a new client for that instance.
140func (p *Pool) GetClientForInstance(inst ring.InstanceDesc) (PoolClient, error) {
141 member, ok := p.fromCache(inst.Addr)
142 if ok {
143 return member.client, nil
144 }
145
146 // No client in cache so create one
147 p.Lock()
148 defer p.Unlock()
149
150 // Check if a client has been created just after checking the cache and before acquiring the lock.
151 member, ok = p.members[inst.Addr]
152 if ok {
153 return member.client, nil
154 }
155
156 client, err := p.factory.FromInstance(inst)
157 if err != nil {
158 return nil, err
159 }
160 p.members[inst.Addr] = &poolMember{client: client}
161 if p.clientsMetric != nil {
162 p.clientsMetric.Add(1)
163 }
164 return client, nil
165}
166
167// RemoveClientFor removes the client with the specified address
168func (p *Pool) RemoveClientFor(addr string) {

Callers 1

GetClientForMethod · 0.95

Calls 3

fromCacheMethod · 0.95
FromInstanceMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected