Skip to content

Commit b421815

Browse files
authored
Merge pull request #1516 from cortexproject/ha-consul-spam
Reduce extra calls to Consul in HA mode
2 parents 8730883 + 08e9a88 commit b421815

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

pkg/distributor/ha_tracker.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,10 @@ func (c *haTracker) checkReplica(ctx context.Context, userID, cluster, replica s
138138
c.electedLock.RLock()
139139
entry, ok := c.elected[key]
140140
c.electedLock.RUnlock()
141-
142-
if ok && entry.Replica == replica && now.Sub(timestamp.Time(entry.ReceivedAt)) < c.cfg.UpdateTimeout {
141+
if ok && now.Sub(timestamp.Time(entry.ReceivedAt)) < c.cfg.UpdateTimeout {
142+
if entry.Replica != replica {
143+
return replicasNotMatchError(replica, entry.Replica)
144+
}
143145
return nil
144146
}
145147
return c.checkKVStore(ctx, key, replica, now)
@@ -159,7 +161,7 @@ func (c *haTracker) checkKVStore(ctx context.Context, key, replica string, now t
159161
// is less than failOver timeout amount of time since the timestamp in the KV store.
160162
if desc.Replica != replica && now.Sub(timestamp.Time(desc.ReceivedAt)) < c.cfg.FailoverTimeout {
161163
// Return a 202.
162-
return nil, false, httpgrpc.Errorf(http.StatusAccepted, "replicas did not match, rejecting sample: %s != %s", replica, desc.Replica)
164+
return nil, false, replicasNotMatchError(replica, desc.Replica)
163165
}
164166
}
165167

@@ -172,6 +174,10 @@ func (c *haTracker) checkKVStore(ctx context.Context, key, replica string, now t
172174
})
173175
}
174176

177+
func replicasNotMatchError(replica, elected string) error {
178+
return httpgrpc.Errorf(http.StatusAccepted, "replicas did not mach, rejecting sample: replica=%s, elected=%s", replica, elected)
179+
}
180+
175181
// Modifies the labels parameter in place, removing labels that match
176182
// the replica or cluster label and returning their values. Returns an error
177183
// if we find one but not both of the labels.

0 commit comments

Comments
 (0)