Dynamic Sampler
This is a collection of samplers that can be used to provide sample rates when sending data to services like honeycomb
Usage
With defaults:
;const sampler = ; const rate = sampler;
With options
;const sampler = clearFrequencySec: 100 perKeyThroughputSec: 2;
Choosing a Sampler
TODO
Implementing New Samplers
The Sampler
class includes:
- timer setup
- construction of initial state (
Map
s) getSampleRate
returns the rate for a given key
You can extend it to create new samplers. updateMaps
is the only
function that needs to be defined, but it is often useful to collect
additional configuration from the constructor:
; { superopts; thisperKeyThroughputSec = optsperKeyThroughputSec || 5; } { if thiscurrentCountssize == 0 //no traffic in the last 30s. clear the result Map thissavedSampleRatesclear; return; const actualPerKeyRate = thisperKeyThroughputSec * thisclearFrequencySec; const newRates = ; thiscurrentCounts; thissavedSampleRates = newRates; }
Modifying getSampleRate
Sometimes it makes sense to check additional state in getSampleRate
and return a different result based on that. When overriding the
function call super.getSampleRate
.
{ superopts; thishasReceivedTraffic = false; } { // other logic thishasReceivedTraffic = true; } { const superSampleRate = super; if !thishasReceivedTraffic return thisgoalSampleRate; else return superSampleRate; }