(t *testing.T)
| 774 | } |
| 775 | |
| 776 | func TestHATracker_MetricsCleanup(t *testing.T) { |
| 777 | t.Parallel() |
| 778 | reg := prometheus.NewPedanticRegistry() |
| 779 | tr, err := NewHATracker(HATrackerConfig{EnableHATracker: false}, nil, haTrackerStatusConfig, prometheus.WrapRegistererWithPrefix("cortex_", reg), "test-ha-tracker", log.NewNopLogger()) |
| 780 | require.NoError(t, err) |
| 781 | |
| 782 | metrics := []string{ |
| 783 | "cortex_ha_tracker_elected_replica_changes_total", |
| 784 | "cortex_ha_tracker_elected_replica_timestamp_seconds", |
| 785 | "cortex_ha_tracker_kv_store_cas_total", |
| 786 | "cortex_ha_tracker_user_replica_group_count", |
| 787 | } |
| 788 | |
| 789 | tr.electedReplicaChanges.WithLabelValues("userA", "replicaGroup1").Add(5) |
| 790 | tr.electedReplicaChanges.WithLabelValues("userA", "replicaGroup2").Add(8) |
| 791 | tr.electedReplicaChanges.WithLabelValues("userB", "replicaGroup").Add(10) |
| 792 | tr.electedReplicaTimestamp.WithLabelValues("userA", "replicaGroup1").Add(5) |
| 793 | tr.electedReplicaTimestamp.WithLabelValues("userA", "replicaGroup2").Add(8) |
| 794 | tr.electedReplicaTimestamp.WithLabelValues("userB", "replicaGroup").Add(10) |
| 795 | tr.kvCASCalls.WithLabelValues("userA", "replicaGroup1").Add(5) |
| 796 | tr.kvCASCalls.WithLabelValues("userA", "replicaGroup2").Add(8) |
| 797 | tr.kvCASCalls.WithLabelValues("userB", "replicaGroup").Add(10) |
| 798 | tr.userReplicaGroupCount.WithLabelValues("userA").Add(5) |
| 799 | |
| 800 | require.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(` |
| 801 | # HELP cortex_ha_tracker_elected_replica_changes_total The total number of times the elected replica has changed for a user ID/cluster. |
| 802 | # TYPE cortex_ha_tracker_elected_replica_changes_total counter |
| 803 | cortex_ha_tracker_elected_replica_changes_total{cluster="replicaGroup",user="userB"} 10 |
| 804 | cortex_ha_tracker_elected_replica_changes_total{cluster="replicaGroup1",user="userA"} 5 |
| 805 | cortex_ha_tracker_elected_replica_changes_total{cluster="replicaGroup2",user="userA"} 8 |
| 806 | |
| 807 | # HELP cortex_ha_tracker_elected_replica_timestamp_seconds The timestamp stored for the currently elected replica, from the KVStore. |
| 808 | # TYPE cortex_ha_tracker_elected_replica_timestamp_seconds gauge |
| 809 | cortex_ha_tracker_elected_replica_timestamp_seconds{cluster="replicaGroup",user="userB"} 10 |
| 810 | cortex_ha_tracker_elected_replica_timestamp_seconds{cluster="replicaGroup1",user="userA"} 5 |
| 811 | cortex_ha_tracker_elected_replica_timestamp_seconds{cluster="replicaGroup2",user="userA"} 8 |
| 812 | |
| 813 | # HELP cortex_ha_tracker_kv_store_cas_total The total number of CAS calls to the KV store for a user ID/cluster. |
| 814 | # TYPE cortex_ha_tracker_kv_store_cas_total counter |
| 815 | cortex_ha_tracker_kv_store_cas_total{cluster="replicaGroup",user="userB"} 10 |
| 816 | cortex_ha_tracker_kv_store_cas_total{cluster="replicaGroup1",user="userA"} 5 |
| 817 | cortex_ha_tracker_kv_store_cas_total{cluster="replicaGroup2",user="userA"} 8 |
| 818 | |
| 819 | # HELP cortex_ha_tracker_user_replica_group_count Number of HA replica groups tracked for each user. |
| 820 | # TYPE cortex_ha_tracker_user_replica_group_count gauge |
| 821 | cortex_ha_tracker_user_replica_group_count{user="userA"} 5 |
| 822 | `), metrics...)) |
| 823 | |
| 824 | tr.CleanupHATrackerMetricsForUser("userA") |
| 825 | |
| 826 | require.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(` |
| 827 | # HELP cortex_ha_tracker_elected_replica_changes_total The total number of times the elected replica has changed for a user ID/cluster. |
| 828 | # TYPE cortex_ha_tracker_elected_replica_changes_total counter |
| 829 | cortex_ha_tracker_elected_replica_changes_total{cluster="replicaGroup",user="userB"} 10 |
| 830 | |
| 831 | # HELP cortex_ha_tracker_elected_replica_timestamp_seconds The timestamp stored for the currently elected replica, from the KVStore. |
| 832 | # TYPE cortex_ha_tracker_elected_replica_timestamp_seconds gauge |
| 833 | cortex_ha_tracker_elected_replica_timestamp_seconds{cluster="replicaGroup",user="userB"} 10 |
nothing calls this directly
no test coverage detected