zap icon indicating copy to clipboard operation
zap copied to clipboard

Allow thereafter in sampler to be zero

Open gunnihinn opened this issue 6 years ago • 3 comments

When creating a new Sampler, there is nothing stopping us from passing in 0 as a value for thereafter. One might expect this to be legal -- as the documentation doesn't say thereafter should be greater than zero and no error is returned when passing in this configuration -- and to mean "drop all messages after the first n". What actually happens is a

panic: runtime error: integer divide by zero

when we try to log a message.

This patch avoids the division by zero and enforces the behavior described above.

This fixes issue 632.

gunnihinn avatar Sep 07 '18 10:09 gunnihinn

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


Gunnar Þór Magnússon seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

CLAassistant avatar Sep 07 '18 10:09 CLAassistant

Codecov Report

Merging #633 into master will not change coverage. The diff coverage is 100%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #633   +/-   ##
=======================================
  Coverage   97.38%   97.38%           
=======================================
  Files          40       40           
  Lines        2102     2102           
=======================================
  Hits         2047     2047           
  Misses         47       47           
  Partials        8        8
Impacted Files Coverage Δ
zapcore/sampler.go 100% <100%> (ø) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 67bc79d...3392ebd. Read the comment docs.

codecov[bot] avatar Sep 07 '18 10:09 codecov[bot]

since using 0 means we're disabling sampling.

Did I miss where we can choose to log only the first first messages?

gunnihinn avatar Sep 07 '18 16:09 gunnihinn