Conversation
|
Pushed 'ready for review' too soon, looks like something got lost on the way to external - stand by.. |
adedc56 to
3a81e07
Compare
|
..ready to go! |
src/server.js
Outdated
| const result = status.isAllowed ? 'accepted' : 'rejected'; | ||
| const matchType = Server.getMatchType(rule); | ||
| this.instrumenter.countHit(result, matchType); | ||
| const ruleName = rule && rule.name ? rule.name : ''; |
src/instrumenter.js
Outdated
| this.statsd.increment(`hit.${status}`); | ||
| this.statsd.increment(`hit.${status}.${type}`); | ||
| this.hitCounter.labels(status, type).inc(); | ||
| this.hitCounter.labels(status, type, name || '').inc(); |
There was a problem hiding this comment.
You're handling name || '' both here and at the call-site. Doesn't hurt anything, though.
Separately, rename the name param here to label?
There was a problem hiding this comment.
Separately, rename the name param here to label?
good catch, fixed!
README.md
Outdated
|
|
||
| The following optional fields are also supported: | ||
|
|
||
| * `label`: A short, slug-like name for the rule. If set, Prometheus metrics for hits matching the rule will be labeled with `rule_label` as this value. |
There was a problem hiding this comment.
I think it would be helpful to call out explicitly that this value is ignored for statsd metrics. We can consider adding support for additional statsd counters on a per-label basis down the road?
| creditLimit: 1, | ||
| resetSeconds: 60, | ||
| actorField: '', | ||
| label: null, |
There was a problem hiding this comment.
most configs won't explicitly set label to null.
maybe specify one as undefined and another with no key for label for good measure?
| * @param {string} comment Optional diagnostic name for this rule. | ||
| */ | ||
| addRule(operation, creditLimit, resetSeconds, actorField, comment) { | ||
| addRule(operation, creditLimit, resetSeconds, actorField, label, comment) { |
There was a problem hiding this comment.
since label is an optional argument, why position it second to last?
there's a bunch of places in tests/config-test.js that will need to be updated to reflect this positional change.
alternatively, since the cardinality of this function is getting big, what are your thoughts on having it accept an arguments object instead of positional arguments?
There was a problem hiding this comment.
since label is an optional argument, why position it second to last?
Since both label and comment are optional, am guessing I somewhat arbitrarily decided labels will be more common than comments.
alternatively, since the cardinality of this function is getting big, what are your thoughts on having it accept an arguments object instead of positional arguments?
I like it, that'd definitely make it a bunch more readable! May sheepishly defer this suggestion as am running into limited cycles to iterate further. OK with you to land as is?
Adds test coverage for `countHit` with a label in `server-test`.
5a32a28 to
29b93f8
Compare
README.md
Outdated
|
|
||
| The following optional fields are also supported: | ||
|
|
||
| * `label`: A short, slug-like name for the rule. If set, Prometheus metrics for hits matching the rule will be labeled with `rule_label` as this value. |
| * @param {string} comment Optional diagnostic name for this rule. | ||
| */ | ||
| addRule(operation, creditLimit, resetSeconds, actorField, comment) { | ||
| addRule(operation, creditLimit, resetSeconds, actorField, label, comment) { |
There was a problem hiding this comment.
since label is an optional argument, why position it second to last?
Since both label and comment are optional, am guessing I somewhat arbitrarily decided labels will be more common than comments.
alternatively, since the cardinality of this function is getting big, what are your thoughts on having it accept an arguments object instead of positional arguments?
I like it, that'd definitely make it a bunch more readable! May sheepishly defer this suggestion as am running into limited cycles to iterate further. OK with you to land as is?
src/instrumenter.js
Outdated
| this.statsd.increment(`hit.${status}`); | ||
| this.statsd.increment(`hit.${status}.${type}`); | ||
| this.hitCounter.labels(status, type).inc(); | ||
| this.hitCounter.labels(status, type, name || '').inc(); |
There was a problem hiding this comment.
Separately, rename the name param here to label?
good catch, fixed!
src/server.js
Outdated
| const result = status.isAllowed ? 'accepted' : 'rejected'; | ||
| const matchType = Server.getMatchType(rule); | ||
| this.instrumenter.countHit(result, matchType); | ||
| const ruleLabel = rule && rule.label ? rule.label : ''; |
There was a problem hiding this comment.
nit: what's the order of operations here? can you clarify with parens?
const ruleLabel = (rule && rule.label) ? rule.label : '';
const ruleLabel = rule && (rule.label ? rule.label : '');
assuming it's the first since, but not clear from reading
There was a problem hiding this comment.
Can do. Ternary is pretty much lowest precedence operator in JS so its not uncommon to see 'naked' expressions like this ahead of it. (In fact your suggestion would be rejected by rules/no-extra-parens but we don't enable it.)
There was a problem hiding this comment.
d'oh! no need to include for my sake if it's an antipattern.
There was a problem hiding this comment.
i think its fine, happy to follow the "if someone asked, its probably worth doing/clarifying" school of thought here :)
i
left a comment
There was a problem hiding this comment.
LGTM. Defer to your heart with regards to leaving those parens in or out.
No description provided.