Skip to content

Reduce extra calls to Consul in HA mode #1516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 24, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions pkg/distributor/ha_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,10 @@ func (c *haTracker) checkReplica(ctx context.Context, userID, cluster, replica s
c.electedLock.RLock()
entry, ok := c.elected[key]
c.electedLock.RUnlock()

if ok && entry.Replica == replica && now.Sub(timestamp.Time(entry.ReceivedAt)) < c.cfg.UpdateTimeout {
if ok && now.Sub(timestamp.Time(entry.ReceivedAt)) < c.cfg.UpdateTimeout {
if entry.Replica != replica {
return replicasNotMatchError(replica, entry.Replica)
}
return nil
}
return c.checkKVStore(ctx, key, replica, now)
Expand All @@ -159,7 +161,7 @@ func (c *haTracker) checkKVStore(ctx context.Context, key, replica string, now t
// is less than failOver timeout amount of time since the timestamp in the KV store.
if desc.Replica != replica && now.Sub(timestamp.Time(desc.ReceivedAt)) < c.cfg.FailoverTimeout {
// Return a 202.
return nil, false, httpgrpc.Errorf(http.StatusAccepted, "replicas did not match, rejecting sample: %s != %s", replica, desc.Replica)
return nil, false, replicasNotMatchError(replica, desc.Replica)
}
}

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

func replicasNotMatchError(replica, elected string) error {
return httpgrpc.Errorf(http.StatusAccepted, "replicas did not mach, rejecting sample: replica=%s, elected=%s", replica, elected)
}

// Modifies the labels parameter in place, removing labels that match
// the replica or cluster label and returning their values. Returns an error
// if we find one but not both of the labels.
Expand Down