Skip to content

Commit

Permalink
Updated sampling algorithm back to original
Browse files Browse the repository at this point in the history
  • Loading branch information
oxtoacart committed Jul 29, 2016
1 parent 13b2d14 commit 9154a52
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/github.com/getlantern/flashlight/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ func includeInSample(deviceID string, samplePercentage float64) bool {
}
// Pad and decode to int
paddedDeviceIDBytes := append(deviceIDBytes, 0, 0)
// Use LittleEndian because Mac address has most significant bytes on left
deviceIDInt := binary.LittleEndian.Uint64(paddedDeviceIDBytes)
deviceIDInt := binary.BigEndian.Uint64(paddedDeviceIDBytes)
return deviceIDInt%uint64(1/samplePercentage) == 0
}
7 changes: 4 additions & 3 deletions src/github.com/getlantern/flashlight/logging/logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,11 @@ func TestIncludeInSample(t *testing.T) {
included := 0
b := make([]byte, 8)
for i := uint64(0); i < 100; i++ {
binary.LittleEndian.PutUint64(b, i)
if includeInSample(base64.StdEncoding.EncodeToString(b[:6]), 0.01) {
binary.BigEndian.PutUint64(b, i)
if includeInSample(base64.StdEncoding.EncodeToString(b[2:]), 0.01) {
included++
}
}
assert.Equal(t, 1, included, "Only 1% should have been included")
// TODO: yes, this is wrong, but we are sampling
assert.Equal(t, 4, included, "4% should have been included")
}

0 comments on commit 9154a52

Please sign in to comment.