Returns true, if we should keep latest metrics. Returns false if we failed to gather latest metrics, and this can be removed completely.
(ur *UserRegistry)
| 638 | // Returns true, if we should keep latest metrics. Returns false if we failed to gather latest metrics, |
| 639 | // and this can be removed completely. |
| 640 | func (r *UserRegistries) softRemoveUserRegistry(ur *UserRegistry) bool { |
| 641 | last, err := ur.reg.Gather() |
| 642 | if err != nil { |
| 643 | level.Warn(util_log.Logger).Log("msg", "failed to gather metrics from registry", "user", ur.user, "err", err) |
| 644 | return false |
| 645 | } |
| 646 | |
| 647 | for ix := 0; ix < len(last); { |
| 648 | // Only keep metrics for which we don't want to go down, since that indicates reset (counter, summary, histogram). |
| 649 | switch last[ix].GetType() { |
| 650 | case dto.MetricType_COUNTER, dto.MetricType_SUMMARY, dto.MetricType_HISTOGRAM: |
| 651 | ix++ |
| 652 | default: |
| 653 | // Remove gauges and unknowns. |
| 654 | last = append(last[:ix], last[ix+1:]...) |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | // No metrics left. |
| 659 | if len(last) == 0 { |
| 660 | return false |
| 661 | } |
| 662 | |
| 663 | gatheredMetrics, err := NewMetricFamilyMap(last) |
| 664 | if err != nil { |
| 665 | level.Warn(util_log.Logger).Log("msg", "failed to gather metrics from registry", "user", ur.user, "err", err) |
| 666 | return false |
| 667 | } |
| 668 | |
| 669 | aggregatedMetrics, err := MergeMetricFamilies([]MetricFamilyMap{gatheredMetrics, r.removedMetrics}) |
| 670 | if err != nil { |
| 671 | level.Warn(util_log.Logger).Log("msg", "failed to merge metrics", "user", ur.user, "err", err) |
| 672 | return false |
| 673 | } |
| 674 | r.removedMetrics = aggregatedMetrics |
| 675 | ur.user = "" |
| 676 | ur.reg = nil |
| 677 | return false |
| 678 | } |
| 679 | |
| 680 | // Registries returns a copy of the user registries list. |
| 681 | func (r *UserRegistries) Registries() []UserRegistry { |
no test coverage detected