feat(loggly): support HTTP response code to SYSLOG severity mapping#6228
Conversation
|
|
||
| if conf.severity_map then | ||
| for k, v in pairs(conf.severity_map) do | ||
| local rcode = tonumber(k) |
There was a problem hiding this comment.
We can do part of the validation in jsonschema? Like
Line 94 in 82d17ab
| end | ||
| end | ||
|
|
||
| local message_severity = severity[conf.severity:upper()] |
There was a problem hiding this comment.
Let's do the conversion in check_schema so we don't need to do it per request.
| if not rcode or rcode < 100 or rcode >= 600 then | ||
| return nil, "expecting severity_map with http response code([100,599]) as keys" | ||
| end | ||
| cache[k] = severity[v:upper()] |
There was a problem hiding this comment.
We can convert k to a number?
There was a problem hiding this comment.
I think I avoid that due to the default behaviour of cjson encoding Cannot serialise table: excessively sparse array.
we can override the behaviour by cjson.encode_sparse_array(true). In this case, I thought I don't need it that's why I am sticking with strings. WDYT?
| type = "object", | ||
| description = "upstream response code vs syslog severity mapping", | ||
| patternProperties = { | ||
| [".*"] = { |
There was a problem hiding this comment.
We can use regex to verify the range of status code?
There was a problem hiding this comment.
Yea, I had tested. It doesn't work that way.
say for eg,
["^[1-5][0-9]{2}"] = {...} the check schema match the enums for only the set of keys where the key is a status code (regex). For other scenarios (key = "ABC", "500a") there is no matching regex, so it simply doesn't match and validate with the pattern and let it pass as valid inputs.
There was a problem hiding this comment.
Does ["^[1-5][0-9]{2}$"] = {...} work for it?
There was a problem hiding this comment.
@spacewander It works as well as doesn't work.
Example 1: Want ✔️ Got: ✔️
...
"severity_map": {
"200": "INFO"
}
...Example 2: Want ❌ Got: ❌
...
"severity_map": {
"200": "abc"
}
...Example 3: Want ❌ Got: ✔️ :
...
"severity_map": {
"abc": "def"
}
...The problem is, if the key fails to match regex, the pattern properties don't get applied. Also, the program doesn't throw an error for the key mismatch.
There was a problem hiding this comment.
Got it. What about adding additionalProperties = false,? So the mismatch key will cause an error.
There was a problem hiding this comment.
It worked! Awesome : )
// inp "severity_map": {
// "abc": "def"
// }
{
"error_msg": "failed to check the configuration of plugin loggly err: property \"severity_map\" validation failed: additional properties forbidden, found abc"
}
What this PR does / why we need it:
closed #6112 (phase 2 step 2)
Pre-submission checklist: