Skip to content

Commit

Permalink
Scott's 2nd review
Browse files Browse the repository at this point in the history
  • Loading branch information
guscarreon committed Dec 12, 2024
1 parent 6e3ea04 commit 695ba97
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -929,7 +929,7 @@ func TestRequestLogging(t *testing.T) {
expectedLogInfo []logComponents
}{
{
name: "invalid_nagative", // must be greater or equal to zero. Expect fatal log
name: "invalid_negative", // must be greater or equal to zero. Expect fatal log
inRequestLoggingCfg: &RequestLogging{
RefererSamplingRate: -0.1,
},
Expand Down
8 changes: 4 additions & 4 deletions endpoints/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ func NewGetHandler(storage backends.Backend, metrics *metrics.Metrics, allowCust
func (e *GetHandler) handle(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
e.metrics.RecordGetTotal()

if utils.RandomPick(e.cfg.refererLogRate) == true {
if referer := r.Referer(); referer != "" {
log.Info("GET request Referer header: " + referer)
}
// If incoming request comes with a referer header, there's a e.cfg.refererLogRate percent chance
// getting it logged
if referer := r.Referer(); referer != "" && utils.RandomPick(e.cfg.refererLogRate) {
log.Info("GET request Referer header: " + referer)
}

start := time.Now()
Expand Down
8 changes: 4 additions & 4 deletions endpoints/put.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,10 @@ func logBackendError(err error) {
func (e *PutHandler) handle(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
e.metrics.RecordPutTotal()

if utils.RandomPick(e.cfg.refererLogRate) == true {
if referer := r.Referer(); referer != "" {
logrus.Info("PUT request Referer header: " + referer)
}
// If incoming request comes with a referer header, there's a e.cfg.refererLogRate percent chance
// getting it logged
if referer := r.Referer(); referer != "" && utils.RandomPick(e.cfg.refererLogRate) {
logrus.Info("PUT request Referer header: " + referer)
}

start := time.Now()
Expand Down
10 changes: 6 additions & 4 deletions utils/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,24 @@ import (

func TestRandomPick(t *testing.T) {
testCases := []struct {
desc string
name string
inPickProbability float64
expected bool
}{
{
desc: "Zero logging rate. Expect false",
name: "zero", // Zero probablity of true, expect false
inPickProbability: 0.00,
expected: false,
},
{
desc: "100% logging rate, expect true",
name: "one", // 100% probability of true, expect true
inPickProbability: 1.00,
expected: true,
},
}
for _, tc := range testCases {
assert.Equal(t, tc.expected, RandomPick(tc.inPickProbability), tc.desc)
t.Run(tc.name, func(t *testing.T) {
assert.Equal(t, tc.expected, RandomPick(tc.inPickProbability), tc.name)
})
}
}

0 comments on commit 695ba97

Please sign in to comment.