Skip to content

Commit

Permalink
platform agnostic lb ep hash (#10396)
Browse files Browse the repository at this point in the history
Co-authored-by: Yuval Kohavi <[email protected]>
  • Loading branch information
stevenctl and yuval-k authored Nov 26, 2024
1 parent 7afa8dc commit 19c92ba
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
6 changes: 6 additions & 0 deletions changelog/v1.18.0-rc3/platform-agnostic-lbephash.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
changelog:
- type: NON_USER_FACING
description: >-
Don't use native endian-ness when generating hashes.
This creates difficulty reproducing tests on different machines
where the hashes end up in goldenfiles.
4 changes: 2 additions & 2 deletions projects/gateway2/krtcollections/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ func hashEndpoints(l PodLocality, emd EndpointWithMd) uint64 {
func hash(a, b uint64) uint64 {
hasher := fnv.New64a()
var buf [16]byte
binary.NativeEndian.PutUint64(buf[:8], a)
binary.NativeEndian.PutUint64(buf[8:], b)
binary.LittleEndian.PutUint64(buf[:8], a)
binary.LittleEndian.PutUint64(buf[8:], b)
hasher.Write(buf[:])
return hasher.Sum64()
}
Expand Down
3 changes: 0 additions & 3 deletions projects/gateway2/krtcollections/endpoints_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ func TestEndpointsForUpstreamOrderDoesntMatter(t *testing.T) {
Zone: "zone2",
}, emd2)
g.Expect(result1.Equals(*result4)).To(BeFalse(), "not expected %v, got %v", result1, result2)

}

func TestEndpointsForUpstreamWithDiscoveredUpstream(t *testing.T) {
Expand Down Expand Up @@ -239,7 +238,6 @@ func TestEndpointsForUpstreamWithDiscoveredUpstream(t *testing.T) {
h2 := result3.LbEpsEqualityHash ^ result4.LbEpsEqualityHash

g.Expect(h1).NotTo(Equal(h2), "not expected %v, got %v", h1, h2)

}

func TestEndpoints(t *testing.T) {
Expand Down Expand Up @@ -960,5 +958,4 @@ func TestEndpoints(t *testing.T) {
g.Expect(eps.Equals(*res)).To(BeTrue(), "expected %v, got %v", res, eps)
})
}

}
2 changes: 1 addition & 1 deletion projects/gateway2/utils/hash.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func hashValue(newhash func() hash.Hash64, h hash.Hash, value *structpb.Value) e

func HashUint64(hasher io.Writer, value uint64) {
var bytes [8]byte
binary.NativeEndian.PutUint64(bytes[:], value)
binary.LittleEndian.PutUint64(bytes[:], value)
hasher.Write(bytes[:])
}

Expand Down

0 comments on commit 19c92ba

Please sign in to comment.