MCPcopy Create free account
hub / github.com/cortexproject/cortex / softRemoveUserRegistry

Method softRemoveUserRegistry

pkg/util/metrics_helper.go:640–678  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
640func (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.
681func (r *UserRegistries) Registries() []UserRegistry {

Callers 2

AddUserRegistryMethod · 0.95
RemoveUserRegistryMethod · 0.95

Calls 4

NewMetricFamilyMapFunction · 0.85
MergeMetricFamiliesFunction · 0.85
LogMethod · 0.45
GetTypeMethod · 0.45

Tested by

no test coverage detected