log: add log sampling
Created by: bobheadxi
Enables log sampling by default for Sourcegraph components that use the new internal logging library - the first 100 identical log entries per second will always be output, but thereafter only every 100th identical message will be output. It can be configured for each service using the environment variables SRC_LOG_SAMPLING_INITIAL
and SRC_LOG_SAMPLING_THEREAFTER
, and if SRC_LOG_SAMPLING_INITIAL
is set to 0
or -1
the sampling will be disabled entirely.
The hope is to mitigate uncontrolled logspam's impact on both billing costs (recent logspam was causing us over $250 per day in GCP logging expenses) as well as mitigating its impact on a service's performance if it gets really bad.
https://github.com/sourcegraph/log/pull/20
Test plan
sg start
- normal logs output happily. This feature is built on an upstream Zap feature that is extensively tested.