AddUserRegistry adds an user registry. If user already has a registry, previous registry is removed, but latest metric values are preserved in order to avoid counter resets.
(user string, reg *prometheus.Registry)
| 588 | // previous registry is removed, but latest metric values are preserved |
| 589 | // in order to avoid counter resets. |
| 590 | func (r *UserRegistries) AddUserRegistry(user string, reg *prometheus.Registry) { |
| 591 | r.regsMu.Lock() |
| 592 | defer r.regsMu.Unlock() |
| 593 | |
| 594 | // Soft-remove user registry, if user has one already. |
| 595 | for idx := 0; idx < len(r.regs); { |
| 596 | if r.regs[idx].user != user { |
| 597 | idx++ |
| 598 | continue |
| 599 | } |
| 600 | |
| 601 | if r.softRemoveUserRegistry(&r.regs[idx]) { |
| 602 | // Keep it. |
| 603 | idx++ |
| 604 | } else { |
| 605 | // Remove it. |
| 606 | r.regs = append(r.regs[:idx], r.regs[idx+1:]...) |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | // New registries must be added to the end of the list, to guarantee stability. |
| 611 | r.regs = append(r.regs, UserRegistry{ |
| 612 | user: user, |
| 613 | reg: reg, |
| 614 | }) |
| 615 | } |
| 616 | |
| 617 | // RemoveUserRegistry removes all Prometheus registries for a given user. |
| 618 | // If hard is true, registry is removed completely. |