- Notifications
You must be signed in to change notification settings - Fork 127
Description
There's a bug when configuring sampling rules.
Using the following configuration:
const api = Api( logger: { level: 'error', sampling: { target: 1, rate: 0.2, period: 30, rules: [ { route: '/report', target: 0, rate: 0, period: 1 }, ] }, } );requests for the /report route would still end up using the default sampling configuration, instead of the route specific one.
The bug lies in the lines
Lines 222 to 230 in 5ca6870
| let ref = map['__' + req.method] | |
| ? map['__' + req.method] | |
| : map['__ANY'] | |
| ? map['__ANY'] | |
| : wildcard['__' + req.method] | |
| ? wildcard['__' + req.method] | |
| : wildcard['__ANY'] | |
| ? wildcard['__ANY'] | |
| : -1; |
The code attempts to check whether there is a specific sampling rule specified for the request's route, by looking it up in the rulesMap. The rulesMap is an object, in the example above is { __ANY: 0 }. 0 is the index into the rules array.
However, the code in the lines above evaluates to -1 because 0 is falsy.
ref is then -1, which is treated as no specific rule matching, so you get the default configuration.
As a work around, one can simply specify a dummy rule before any import rules in the sample configuration, which will then happily be ignored.