Skip to content

Commit

Permalink
fix(ha_tracker): track when there is a change during merge of Replica…
Browse files Browse the repository at this point in the history
…Desc Components (#10185)

* fix(ha_tracker): track when there is a change during merge of ReplicaDesc Components

Signed-off-by: Nikos Angelopoulos <nikolaos.angelopoulos@grafana.com>

* update changelog

Signed-off-by: Nikos Angelopoulos <nikolaos.angelopoulos@grafana.com>

---------

Signed-off-by: Nikos Angelopoulos <nikolaos.angelopoulos@grafana.com>
  • Loading branch information
NickAnge authored Dec 10, 2024
1 parent 829339b commit 615c537
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
* [BUGFIX] Querier: Fix stddev+stdvar aggregations to treat Infinity consistently. #9844
* [BUGFIX] Ingester: Chunks could have one unnecessary zero byte at the end. #9844
* [BUGFIX] OTLP receiver: Preserve colons and combine multiple consecutive underscores into one when generating metric names in suffix adding mode (`-distributor.otel-metric-suffixes-enabled`). #10075
* [BUGFIX] Distributor: Use a boolean to track changes while merging the ReplicaDesc components, rather than comparing the objects directly. #10185

### Mixin

Expand Down
7 changes: 6 additions & 1 deletion pkg/distributor/ha_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,27 +82,32 @@ func (r *ReplicaDesc) mergeWithTime(mergeable memberlist.Mergeable) (memberlist.
return nil, nil
}

changed := false
if other.Replica == r.Replica {
// Keeping the one with the most recent receivedAt timestamp
if other.ReceivedAt > r.ReceivedAt {
*r = *other
changed = true
} else if r.ReceivedAt == other.ReceivedAt && r.DeletedAt == 0 && other.DeletedAt != 0 {
*r = *other
changed = true
}
} else {
// keep the most recent ElectedAt to reach consistency
if other.ElectedAt > r.ElectedAt {
*r = *other
changed = true
} else if other.ElectedAt == r.ElectedAt {
// if the timestamps are equal we compare ReceivedAt
if other.ReceivedAt > r.ReceivedAt {
*r = *other
changed = true
}
}
}

// No changes
if *r != *other {
if !changed {
return nil, nil
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/distributor/ha_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,13 @@ func TestReplicaDescMerge(t *testing.T) {
}(),
expectedChange: nil,
},
{
name: "Merge should return no change when replica is the same",
rDesc1: firstReplica(),
rDesc2: firstReplica(),
expectedRDesc: firstReplica(),
expectedChange: nil,
},
}

for _, tt := range testsMerge {
Expand Down

0 comments on commit 615c537

Please sign in to comment.