Skip to content

Commit 19c92ba

Browse files
stevenctlyuval-k
andauthored
platform agnostic lb ep hash (#10396)
Co-authored-by: Yuval Kohavi <[email protected]>
1 parent 7afa8dc commit 19c92ba

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
changelog:
2+
- type: NON_USER_FACING
3+
description: >-
4+
Don't use native endian-ness when generating hashes.
5+
This creates difficulty reproducing tests on different machines
6+
where the hashes end up in goldenfiles.

projects/gateway2/krtcollections/endpoints.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -170,8 +170,8 @@ func hashEndpoints(l PodLocality, emd EndpointWithMd) uint64 {
170170
func hash(a, b uint64) uint64 {
171171
hasher := fnv.New64a()
172172
var buf [16]byte
173-
binary.NativeEndian.PutUint64(buf[:8], a)
174-
binary.NativeEndian.PutUint64(buf[8:], b)
173+
binary.LittleEndian.PutUint64(buf[:8], a)
174+
binary.LittleEndian.PutUint64(buf[8:], b)
175175
hasher.Write(buf[:])
176176
return hasher.Sum64()
177177
}

projects/gateway2/krtcollections/endpoints_test.go

-3
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ func TestEndpointsForUpstreamOrderDoesntMatter(t *testing.T) {
131131
Zone: "zone2",
132132
}, emd2)
133133
g.Expect(result1.Equals(*result4)).To(BeFalse(), "not expected %v, got %v", result1, result2)
134-
135134
}
136135

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

241240
g.Expect(h1).NotTo(Equal(h2), "not expected %v, got %v", h1, h2)
242-
243241
}
244242

245243
func TestEndpoints(t *testing.T) {
@@ -960,5 +958,4 @@ func TestEndpoints(t *testing.T) {
960958
g.Expect(eps.Equals(*res)).To(BeTrue(), "expected %v, got %v", res, eps)
961959
})
962960
}
963-
964961
}

projects/gateway2/utils/hash.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ func hashValue(newhash func() hash.Hash64, h hash.Hash, value *structpb.Value) e
119119

120120
func HashUint64(hasher io.Writer, value uint64) {
121121
var bytes [8]byte
122-
binary.NativeEndian.PutUint64(bytes[:], value)
122+
binary.LittleEndian.PutUint64(bytes[:], value)
123123
hasher.Write(bytes[:])
124124
}
125125

0 commit comments

Comments
 (0)