Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(logger): resolve 1st entry in log sampling rules cfg is unused #215 #215

Merged
merged 2 commits into from
Jan 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion __tests__/sampling.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ api_rules.get('/', (req,res) => {

api_rules.get('/testNone', (req,res) => {
req.log.trace('request #'+request++)
res.send('done')
res.send({ method: req.method, rule: req._sampleRule })
})

api_rules.get('/testTarget', (req,res) => {
Expand Down Expand Up @@ -278,6 +278,18 @@ describe('Sampling Tests:', function() {
expect(data.rule.period).toBe(60)
expect(data.rule.level).toBe('debug')
})

it('Matches first rule in rules array', async () => {
let _event = Object.assign({},event,{ path: '/testNone', queryStringParameters: { test: true } })
let result = await new Promise(r => api_rules.run(_event,context,(e,res) => { r(res) }))
let data = JSON.parse(result.body)

expect(data.method).toBe('GET')
expect(data.rule.target).toBe(0)
expect(data.rule.rate).toBe(0)
expect(data.rule.period).toBe(1)
expect(data.rule.level).toBe('trace')
})
})


Expand Down
8 changes: 4 additions & 4 deletions lib/logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,13 @@ exports.sampler = (app, req) => {
}); // end for loop

// Set rule reference based on route
let ref = map['__' + req.method]
let ref = typeof map['__' + req.method] === 'number'
? map['__' + req.method]
: map['__ANY']
: typeof map['__ANY'] === 'number'
? map['__ANY']
: wildcard['__' + req.method]
: typeof wildcard['__' + req.method] === 'number'
? wildcard['__' + req.method]
: wildcard['__ANY']
: typeof wildcard['__ANY'] === 'number'
? wildcard['__ANY']
: -1;

Expand Down