Unregister implements Registerer.
(c Collector)
| 364 | |
| 365 | // Unregister implements Registerer. |
| 366 | func (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. |
| 403 | func (r *Registry) MustRegister(cs ...Collector) { |