MCPcopy
hub / github.com/prometheus/client_golang / Unregister

Method Unregister

prometheus/registry.go:366–400  ·  prometheus/registry.go::Registry.Unregister

Unregister implements Registerer.

(c Collector)

Source from the content-addressed store, hash-verified

364
365// Unregister implements Registerer.
366func (r *Registry) Unregister(c Collector) bool {
367 var (
368 descChan = make(chan *Desc, capDescChan)
369 descIDs = map[uint64]struct{}{}
370 collectorID uint64 // All desc IDs XOR'd together.
371 )
372 go func() {
373 c.Describe(descChan)
374 close(descChan)
375 }()
376 for desc := range descChan {
377 if _, exists := descIDs[desc.id]; !exists {
378 collectorID ^= desc.id
379 descIDs[desc.id] = struct{}{}
380 }
381 }
382
383 r.mtx.RLock()
384 if _, exists := r.collectorsByID[collectorID]; !exists {
385 r.mtx.RUnlock()
386 return false
387 }
388 r.mtx.RUnlock()
389
390 r.mtx.Lock()
391 defer r.mtx.Unlock()
392
393 delete(r.collectorsByID, collectorID)
394 for id := range descIDs {
395 delete(r.descIDs, id)
396 }
397 // dimHashesByName is left untouched as those must be consistent
398 // throughout the lifetime of a program.
399 return true
400}
401
402// MustRegister implements Registerer.
403func (r *Registry) MustRegister(cs ...Collector) {

Callers 4

ExampleWrapCollectorWithFunction · 0.95
ExampleRegistry_groupingFunction · 0.95

Calls 1

DescribeMethod · 0.65

Tested by 4

ExampleWrapCollectorWithFunction · 0.76
ExampleRegistry_groupingFunction · 0.76