Skip to content

Commit 9a35c7d

Browse files
committed
add test
1 parent c72dc2e commit 9a35c7d

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

pkg/ha/ha_tracker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ func (c *HATracker) CleanupHATrackerMetricsForUser(userID string) {
530530
level.Warn(c.logger).Log("msg", "failed to remove cortex_ha_tracker_kv_store_cas_total metric for user", "user", userID, "err", err)
531531
}
532532
if err := util.DeleteMatchingLabels(c.userReplicaGroupCount, filter); err != nil {
533-
level.Warn(c.logger).Log("msg", "failed to remove ha_tracker_user_replica_group_count metric for user", "user", userID, "err", err)
533+
level.Warn(c.logger).Log("msg", "failed to remove cortex_ha_tracker_user_replica_group_count metric for user", "user", userID, "err", err)
534534
}
535535
}
536536

pkg/ha/ha_tracker_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,7 @@ func TestHATracker_MetricsCleanup(t *testing.T) {
629629
"cortex_ha_tracker_elected_replica_changes_total",
630630
"cortex_ha_tracker_elected_replica_timestamp_seconds",
631631
"cortex_ha_tracker_kv_store_cas_total",
632+
"cortex_ha_tracker_user_replica_group_count",
632633
}
633634

634635
tr.electedReplicaChanges.WithLabelValues("userA", "replicaGroup1").Add(5)
@@ -640,6 +641,7 @@ func TestHATracker_MetricsCleanup(t *testing.T) {
640641
tr.kvCASCalls.WithLabelValues("userA", "replicaGroup1").Add(5)
641642
tr.kvCASCalls.WithLabelValues("userA", "replicaGroup2").Add(8)
642643
tr.kvCASCalls.WithLabelValues("userB", "replicaGroup").Add(10)
644+
tr.userReplicaGroupCount.WithLabelValues("userA").Add(5)
643645

644646
require.NoError(t, testutil.GatherAndCompare(reg, strings.NewReader(`
645647
# HELP cortex_ha_tracker_elected_replica_changes_total The total number of times the elected replica has changed for a user ID/cluster.
@@ -659,6 +661,10 @@ func TestHATracker_MetricsCleanup(t *testing.T) {
659661
cortex_ha_tracker_kv_store_cas_total{cluster="replicaGroup",user="userB"} 10
660662
cortex_ha_tracker_kv_store_cas_total{cluster="replicaGroup1",user="userA"} 5
661663
cortex_ha_tracker_kv_store_cas_total{cluster="replicaGroup2",user="userA"} 8
664+
665+
# HELP cortex_ha_tracker_user_replica_group_count Number of HA replica groups tracked for each user.
666+
# TYPE cortex_ha_tracker_user_replica_group_count gauge
667+
cortex_ha_tracker_user_replica_group_count{user="userA"} 5
662668
`), metrics...))
663669

664670
tr.CleanupHATrackerMetricsForUser("userA")

0 commit comments

Comments
 (0)