-
Notifications
You must be signed in to change notification settings - Fork 731
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Timeout notification monitoring and debugging (#1322)
- Loading branch information
Showing
18 changed files
with
237 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package util | ||
|
||
import ( | ||
"math/rand" | ||
) | ||
|
||
type logMsg func(string, ...interface{}) | ||
|
||
type randomGenerator func() float32 | ||
|
||
// LogRandomSample will log a randam sample of the messages it is sent, based on the chance to log | ||
// chance = 1.0 => always log, | ||
// chance = 0.0 => never log | ||
func LogRandomSample(msg string, logger logMsg, chance float32) { | ||
logRandomSampleImpl(msg, logger, chance, rand.Float32) | ||
} | ||
|
||
func logRandomSampleImpl(msg string, logger logMsg, chance float32, randGenerator randomGenerator) { | ||
if chance < 1.0 && randGenerator() > chance { | ||
// this is the chance we don't log anything | ||
return | ||
} | ||
logger(msg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package util | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"math/rand" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestLogRandomSample(t *testing.T) { | ||
|
||
const expected string = `This is test line 2 | ||
This is test line 3 | ||
` | ||
|
||
myRand := rand.New(rand.NewSource(1337)) | ||
var buf bytes.Buffer | ||
|
||
mylogger := func(msg string, args ...interface{}) { | ||
buf.WriteString(fmt.Sprintf(fmt.Sprintln(msg), args...)) | ||
} | ||
|
||
logRandomSampleImpl("This is test line 1", mylogger, 0.5, myRand.Float32) | ||
logRandomSampleImpl("This is test line 2", mylogger, 0.5, myRand.Float32) | ||
logRandomSampleImpl("This is test line 3", mylogger, 0.5, myRand.Float32) | ||
logRandomSampleImpl("This is test line 4", mylogger, 0.5, myRand.Float32) | ||
logRandomSampleImpl("This is test line 5", mylogger, 0.5, myRand.Float32) | ||
|
||
assert.EqualValues(t, expected, buf.String()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.