MCPcopy
hub / github.com/grafana/dskit / updateRingMetrics

Method updateRingMetrics

ring/ring.go:868–923  ·  view source on GitHub ↗

updateRingMetrics updates ring metrics. Caller must be holding the Write lock!

()

Source from the content-addressed store, hash-verified

866
867// updateRingMetrics updates ring metrics. Caller must be holding the Write lock!
868func (r *Ring) updateRingMetrics() {
869 numByState := map[string]int{}
870 oldestTimestampByState := map[string]int64{}
871
872 // Will emit nothing if no zones were discovered.
873 var numByZoneAndState map[string]map[string]int
874 if r.cfg.ZoneAwarenessEnabled {
875 numByZoneAndState = map[string]map[string]int{}
876 for zone := range r.trackedRingZones {
877 numByZoneAndState[zone] = map[string]int{}
878 }
879 }
880
881 // Initialized to zero so we emit zero-metrics (instead of not emitting anything)
882 for _, s := range []string{unhealthy, ACTIVE.String(), LEAVING.String(), PENDING.String(), JOINING.String()} {
883 numByState[s] = 0
884 oldestTimestampByState[s] = 0
885 if r.cfg.ZoneAwarenessEnabled {
886 for zone := range numByZoneAndState {
887 numByZoneAndState[zone][s] = 0
888 }
889 }
890 }
891
892 for _, instance := range r.ringDesc.Ingesters {
893 s := instance.State.String()
894 if !r.IsHealthy(&instance, Reporting, time.Now()) {
895 s = unhealthy
896 }
897 numByState[s]++
898 if oldestTimestampByState[s] == 0 || instance.Timestamp < oldestTimestampByState[s] {
899 oldestTimestampByState[s] = instance.Timestamp
900 }
901 if r.cfg.ZoneAwarenessEnabled {
902 if byState, ok := numByZoneAndState[instance.Zone]; ok {
903 byState[s]++
904 }
905 }
906 }
907
908 for state, count := range numByState {
909 r.numMembersGaugeVec.WithLabelValues(state).Set(float64(count))
910 }
911 for state, timestamp := range oldestTimestampByState {
912 r.oldestTimestampGaugeVec.WithLabelValues(state).Set(float64(timestamp))
913 }
914 if r.cfg.ZoneAwarenessEnabled {
915 for zone, byState := range numByZoneAndState {
916 for state, count := range byState {
917 r.numZoneMembersGaugeVec.WithLabelValues(zone, state).Set(float64(count))
918 }
919 }
920 }
921
922 r.totalTokensGauge.Set(float64(len(r.ringTokens)))
923}
924
925// ShuffleShard returns a subring for the provided identifier (eg. a tenant ID)

Callers 3

loopMethod · 0.95
updateRingStateMethod · 0.95
setRingStateFromDescMethod · 0.95

Calls 3

IsHealthyMethod · 0.95
StringMethod · 0.65
SetMethod · 0.65

Tested by

no test coverage detected