From 94adfcd79d83370d09967f1036bb18ae312b8a90 Mon Sep 17 00:00:00 2001 From: Dan Jaglowski Date: Wed, 21 Jul 2021 15:56:46 -0400 Subject: [PATCH 1/4] Allow otel log levels to be used as keys in a severity mapping --- operator/helper/severity_builder.go | 50 ++++++++++++++------------ operator/helper/severity_test.go | 54 +++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 22 deletions(-) diff --git a/operator/helper/severity_builder.go b/operator/helper/severity_builder.go index 1b5ebef8..f6dbc572 100644 --- a/operator/helper/severity_builder.go +++ b/operator/helper/severity_builder.go @@ -35,47 +35,53 @@ func getBuiltinMapping(name string) severityMap { return map[string]entry.Severity{ "default": entry.Default, "trace": entry.Trace, + "trace2": entry.Trace2, + "trace3": entry.Trace3, + "trace4": entry.Trace4, "debug": entry.Debug, + "debug2": entry.Debug2, + "debug3": entry.Debug3, + "debug4": entry.Debug4, "info": entry.Info, + "info2": entry.Info2, + "info3": entry.Info3, + "info4": entry.Info4, "notice": entry.Notice, "warning": entry.Warning, + "warning2": entry.Warning2, + "warning3": entry.Warning3, + "warning4": entry.Warning4, "error": entry.Error, + "error2": entry.Error2, + "error3": entry.Error3, + "error4": entry.Error4, "critical": entry.Critical, "alert": entry.Alert, "emergency": entry.Emergency, + "emergency2": entry.Emergency2, + "emergency3": entry.Emergency3, + "emergency4": entry.Emergency4, "catastrophe": entry.Catastrophe, } default: + // Add some additional values that are automatically recognized mapping := getBuiltinMapping("aliases") - - mapping.add(entry.Trace2, "trace2") - mapping.add(entry.Trace3, "trace3") - mapping.add(entry.Trace4, "trace4") - - mapping.add(entry.Debug2, "debug2") - mapping.add(entry.Debug3, "debug3") - mapping.add(entry.Debug4, "debug4") - - mapping.add(entry.Info2, "info2") - mapping.add(entry.Info3, "info3") - mapping.add(entry.Info4, "info4") - mapping.add(entry.Warning, "warn") - mapping.add(entry.Warning2, "warning2", "warn2") - mapping.add(entry.Warning3, "warning3", "warn3") - mapping.add(entry.Warning4, "warning4", "warn4") + mapping.add(entry.Warning2, "warn2") + mapping.add(entry.Warning3, "warn3") + mapping.add(entry.Warning4, "warn4") mapping.add(entry.Error, "err") - mapping.add(entry.Error2, "error2") - mapping.add(entry.Error3, "error3") - mapping.add(entry.Error4, "error4") + mapping.add(entry.Error2, "err2") + mapping.add(entry.Error3, "err3") + mapping.add(entry.Error4, "err4") mapping.add(entry.Critical, "crit") mapping.add(entry.Emergency, "fatal") - mapping.add(entry.Emergency2, "emergency2", "fatal2") - mapping.add(entry.Emergency3, "emergency3", "fatal3") - mapping.add(entry.Emergency4, "emergency4", "fatal4") + mapping.add(entry.Emergency2, "fatal2") + mapping.add(entry.Emergency3, "fatal3") + mapping.add(entry.Emergency4, "fatal4") return mapping } diff --git a/operator/helper/severity_test.go b/operator/helper/severity_test.go index 0b1ecfd1..0cfae456 100644 --- a/operator/helper/severity_test.go +++ b/operator/helper/severity_test.go @@ -38,6 +38,59 @@ type severityTestCase struct { expected entry.Severity } +// These tests ensure that users may build a mapping that +// maps values into any of the predefined keys. +// For example, this ensures that users can do this: +// mapping: +// warning3: warn_three +func validMappingKeyCases() []severityTestCase { + aliasedMapping := map[string]entry.Severity{ + "trace": entry.Trace, + "trace2": entry.Trace2, + "trace3": entry.Trace3, + "trace4": entry.Trace4, + "debug": entry.Debug, + "debug2": entry.Debug2, + "debug3": entry.Debug3, + "debug4": entry.Debug4, + "info": entry.Info, + "info2": entry.Info2, + "info3": entry.Info3, + "info4": entry.Info4, + "notice": entry.Notice, + "warning": entry.Warning, + "warning2": entry.Warning2, + "warning3": entry.Warning3, + "warning4": entry.Warning4, + "error": entry.Error, + "error2": entry.Error2, + "error3": entry.Error3, + "error4": entry.Error4, + "critical": entry.Critical, + "alert": entry.Alert, + "emergency": entry.Emergency, + "emergency2": entry.Emergency2, + "emergency3": entry.Emergency3, + "emergency4": entry.Emergency4, + "catastrophe": entry.Catastrophe, + } + + cases := []severityTestCase{} + for k, v := range aliasedMapping { + cases = append(cases, + severityTestCase{ + name: k, + sample: "my_custom_value", + mapping: map[interface{}]interface{}{k: "my_custom_value"}, + expected: v, + }) + } + + return cases +} + +// These cases ensure that text representing OTLP severity +// levels are automatically recognized by the default mapping. func otlpSevCases() []severityTestCase { mustParse := map[string]entry.Severity{ "tRaCe": entry.Trace, @@ -359,6 +412,7 @@ func TestSeverityParser(t *testing.T) { } testCases = append(testCases, otlpSevCases()...) + testCases = append(testCases, validMappingKeyCases()...) rootField := entry.NewBodyField() someField := entry.NewBodyField("some_field") From c20841577088997ff227786a00a26b8396681909 Mon Sep 17 00:00:00 2001 From: Dan Jaglowski Date: Wed, 21 Jul 2021 16:06:48 -0400 Subject: [PATCH 2/4] Updated severity docs to reflect newly allowed mapping keys --- docs/types/severity.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/docs/types/severity.md b/docs/types/severity.md index 214a8d7e..5ebd4d56 100644 --- a/docs/types/severity.md +++ b/docs/types/severity.md @@ -10,14 +10,32 @@ The following named severity levels are supported. | --- | --- | --- | | Default | 0 | `default` | | Trace | 10 | `trace` | +| Trace2 | 12 | `trace2` | +| Trace3 | 13 | `trace3` | +| Trace4 | 14 | `trace4` | | Debug | 20 | `debug` | +| Debug2 | 22 | `debug2` | +| Debug3 | 23 | `debug3` | +| Debug4 | 24 | `debug4` | | Info | 30 | `info` | +| Info2 | 32 | `info2` | +| Info3 | 33 | `info3` | +| Info4 | 34 | `info4` | | Notice | 40 | `notice` | | Warning | 50 | `warning` | +| Warning2 | 52 | `warning2` | +| Warning3 | 53 | `warning3` | +| Warning4 | 54 | `warning4` | | Error | 60 | `error` | +| Error2 | 62 | `error2` | +| Error3 | 63 | `error3` | +| Error4 | 64 | `error4` | | Critical | 70 | `critical` | | Alert | 80 | `alert` | | Emergency | 90 | `emergency` | +| Emergency2 | 92 | `emergency2` | +| Emergency3 | 93 | `emergency3` | +| Emergency4 | 94 | `emergency4` | | Catastrophe | 100 | `catastrophe` | @@ -102,21 +120,39 @@ The following configurations are equivalent: preset: none mapping: trace: trace + trace2: trace2 + trace3: trace3 + trace4: trace4 debug: debug + debug2: debug2 + debug3: debug3 + debug4: debug4 info: info + info2: info2 + info3: info3 + info4: info4 notice: notice warning: - warning - warn + warning2: warning2 + warning3: warning3 + warning4: warning4 error: - error - err - 404 + error2: error2 + error3: error3 + error4: error4 critical: - critical - crit alert: alert emergency: emergency + emergency2: emergency2 + emergency3: emergency3 + emergency4: emergency4 catastrophe: catastrophe ``` From 8aac08ceef62c51a03f2f593c68921cd1fab14da Mon Sep 17 00:00:00 2001 From: Dan Jaglowski Date: Thu, 22 Jul 2021 11:24:51 -0400 Subject: [PATCH 3/4] Only support OTel severity levels --- entry/severity.go | 188 +++++-------- entry/severity_test.go | 21 +- logger/parser.go | 6 +- operator/builtin/input/windows/xml.go | 4 +- operator/builtin/input/windows/xml_test.go | 4 +- .../builtin/parser/severity/severity_test.go | 137 +++------- operator/builtin/parser/syslog/data.go | 6 +- operator/builtin/parser/syslog/syslog.go | 10 +- operator/helper/parser_test.go | 12 +- operator/helper/severity_builder.go | 72 +++-- operator/helper/severity_test.go | 255 +++++++----------- 11 files changed, 275 insertions(+), 440 deletions(-) diff --git a/entry/severity.go b/entry/severity.go index a2c5a5fc..96aca40e 100644 --- a/entry/severity.go +++ b/entry/severity.go @@ -21,131 +21,79 @@ import ( // Severity indicates the seriousness of a log entry type Severity int -var namedLevels = map[Severity]string{ - Default: "default", - Trace: "trace", - Trace2: "trace2", - Trace3: "trace3", - Trace4: "trace4", - Debug: "debug", - Debug2: "debug2", - Debug3: "debug3", - Debug4: "debug4", - Info: "info", - Info2: "info2", - Info3: "info3", - Info4: "info4", - Notice: "notice", - Warning: "warning", - Warning2: "warning2", - Warning3: "warning3", - Warning4: "warning4", - Error: "error", - Error2: "error2", - Error3: "error3", - Error4: "error4", - Critical: "critical", - Alert: "alert", - Emergency: "emergency", - Emergency2: "emergency2", - Emergency3: "emergency3", - Emergency4: "emergency4", - Catastrophe: "catastrophe", +const ( + // Default indicates an unknown severity + Default Severity = iota + + // A fine-grained debugging event. Typically disabled in default configurations. + Trace + Trace2 + Trace3 + Trace4 + + // A debugging event. + Debug + Debug2 + Debug3 + Debug4 + + // An informational event. Indicates that an event happened. + Info + Info2 + Info3 + Info4 + + // A warning event. Not an error but is likely more important than an informational event. + Warn + Warn2 + Warn3 + Warn4 + + // An error event. Something went wrong. + Error + Error2 + Error3 + Error4 + + // An error event. Something went wrong. + Fatal + Fatal2 + Fatal3 + Fatal4 +) + +var sevText = map[Severity]string{ + Default: "default", + Trace: "trace", + Trace2: "trace2", + Trace3: "trace3", + Trace4: "trace4", + Debug: "debug", + Debug2: "debug2", + Debug3: "debug3", + Debug4: "debug4", + Info: "info", + Info2: "info2", + Info3: "info3", + Info4: "info4", + Warn: "warn", + Warn2: "warn2", + Warn3: "warn3", + Warn4: "warn4", + Error: "error", + Error2: "error2", + Error3: "error3", + Error4: "error4", + Fatal: "fatal", + Fatal2: "fatal2", + Fatal3: "fatal3", + Fatal4: "fatal4", } // ToString converts a severity to a string func (s Severity) String() string { - if str, ok := namedLevels[s]; ok { + if str, ok := sevText[s]; ok { return str } return strconv.Itoa(int(s)) } - -const ( - // Default indicates an unknown severity - Default Severity = 0 - - // Trace indicates that the log may be useful for detailed debugging - Trace Severity = 10 - - // Trace2 indicates that the log may be useful for detailed debugging - Trace2 Severity = 12 - - // Trace3 indicates that the log may be useful for detailed debugging - Trace3 Severity = 13 - - // Trace4 indicates that the log may be useful for detailed debugging - Trace4 Severity = 14 - - // Debug indicates that the log may be useful for debugging purposes - Debug Severity = 20 - - // Debug2 indicates that the log may be useful for debugging purposes - Debug2 Severity = 22 - - // Debug3 indicates that the log may be useful for debugging purposes - Debug3 Severity = 23 - - // Debug4 indicates that the log may be useful for debugging purposes - Debug4 Severity = 24 - - // Info indicates that the log may be useful for understanding high level details about an application - Info Severity = 30 - - // Info2 indicates that the log may be useful for understanding high level details about an application - Info2 Severity = 32 - - // Info3 indicates that the log may be useful for understanding high level details about an application - Info3 Severity = 33 - - // Info4 indicates that the log may be useful for understanding high level details about an application - Info4 Severity = 34 - - // Notice indicates that the log should be noticed - Notice Severity = 40 - - // Warning indicates that someone should look into an issue - Warning Severity = 50 - - // Warning2 indicates that someone should look into an issue - Warning2 Severity = 52 - - // Warning3 indicates that someone should look into an issue - Warning3 Severity = 53 - - // Warning4 indicates that someone should look into an issue - Warning4 Severity = 54 - - // Error indicates that something undesirable has actually happened - Error Severity = 60 - - // Error2 indicates that something undesirable has actually happened - Error2 Severity = 62 - - // Error3 indicates that something undesirable has actually happened - Error3 Severity = 63 - - // Error4 indicates that something undesirable has actually happened - Error4 Severity = 64 - - // Critical indicates that a problem requires attention immediately - Critical Severity = 70 - - // Alert indicates that action must be taken immediately - Alert Severity = 80 - - // Emergency indicates that the application is unusable - Emergency Severity = 90 - - // Emergency2 indicates that the application is unusable - Emergency2 Severity = 92 - - // Emergency3 indicates that the application is unusable - Emergency3 Severity = 93 - - // Emergency4 indicates that the application is unusable - Emergency4 Severity = 94 - - // Catastrophe indicates that it is already too late - Catastrophe Severity = 100 -) diff --git a/entry/severity_test.go b/entry/severity_test.go index 4f6dc296..faed5dc8 100644 --- a/entry/severity_test.go +++ b/entry/severity_test.go @@ -34,21 +34,16 @@ func TestStringer(t *testing.T) { require.Equal(t, "info2", Info2.String()) require.Equal(t, "info3", Info3.String()) require.Equal(t, "info4", Info4.String()) - require.Equal(t, "notice", Notice.String()) - require.Equal(t, "warning", Warning.String()) - require.Equal(t, "warning2", Warning2.String()) - require.Equal(t, "warning3", Warning3.String()) - require.Equal(t, "warning4", Warning4.String()) + require.Equal(t, "warn", Warn.String()) + require.Equal(t, "warn2", Warn2.String()) + require.Equal(t, "warn3", Warn3.String()) + require.Equal(t, "warn4", Warn4.String()) require.Equal(t, "error", Error.String()) require.Equal(t, "error2", Error2.String()) require.Equal(t, "error3", Error3.String()) require.Equal(t, "error4", Error4.String()) - require.Equal(t, "critical", Critical.String()) - require.Equal(t, "alert", Alert.String()) - require.Equal(t, "emergency", Emergency.String()) - require.Equal(t, "emergency2", Emergency2.String()) - require.Equal(t, "emergency3", Emergency3.String()) - require.Equal(t, "emergency4", Emergency4.String()) - require.Equal(t, "catastrophe", Catastrophe.String()) - require.Equal(t, "19", Severity(19).String()) + require.Equal(t, "fatal", Fatal.String()) + require.Equal(t, "fatal2", Fatal2.String()) + require.Equal(t, "fatal3", Fatal3.String()) + require.Equal(t, "fatal4", Fatal4.String()) } diff --git a/logger/parser.go b/logger/parser.go index e2f6c100..affdead4 100644 --- a/logger/parser.go +++ b/logger/parser.go @@ -49,13 +49,13 @@ func parseSeverity(zapEntry zapcore.Entry) entry.Severity { case zapcore.InfoLevel: return entry.Info case zapcore.WarnLevel: - return entry.Warning + return entry.Warn case zapcore.ErrorLevel: return entry.Error case zapcore.PanicLevel: - return entry.Critical + return entry.Error4 case zapcore.FatalLevel: - return entry.Catastrophe + return entry.Fatal default: return entry.Default } diff --git a/operator/builtin/input/windows/xml.go b/operator/builtin/input/windows/xml.go index b6d778e1..5ba2553c 100644 --- a/operator/builtin/input/windows/xml.go +++ b/operator/builtin/input/windows/xml.go @@ -49,11 +49,11 @@ func (e *EventXML) parseTimestamp() time.Time { func (e *EventXML) parseSeverity() entry.Severity { switch e.Level { case "Critical": - return entry.Critical + return entry.Fatal case "Error": return entry.Error case "Warning": - return entry.Warning + return entry.Warn case "Information": return entry.Info default: diff --git a/operator/builtin/input/windows/xml_test.go b/operator/builtin/input/windows/xml_test.go index c3b25659..a50cbf8b 100644 --- a/operator/builtin/input/windows/xml_test.go +++ b/operator/builtin/input/windows/xml_test.go @@ -52,9 +52,9 @@ func TestParseSeverity(t *testing.T) { xmlWarning := EventXML{Level: "Warning"} xmlInformation := EventXML{Level: "Information"} xmlUnknown := EventXML{Level: "Unknown"} - require.Equal(t, entry.Critical, xmlCritical.parseSeverity()) + require.Equal(t, entry.Fatal, xmlCritical.parseSeverity()) require.Equal(t, entry.Error, xmlError.parseSeverity()) - require.Equal(t, entry.Warning, xmlWarning.parseSeverity()) + require.Equal(t, entry.Warn, xmlWarning.parseSeverity()) require.Equal(t, entry.Info, xmlInformation.parseSeverity()) require.Equal(t, entry.Default, xmlUnknown.parseSeverity()) } diff --git a/operator/builtin/parser/severity/severity_test.go b/operator/builtin/parser/severity/severity_test.go index 39ef1221..24852f5e 100644 --- a/operator/builtin/parser/severity/severity_test.go +++ b/operator/builtin/parser/severity/severity_test.go @@ -38,6 +38,18 @@ type severityTestCase struct { } func TestSeverityParser(t *testing.T) { + allTheThingsMap := map[interface{}]interface{}{ + "info": "3xx", + "error3": "4xx", + "debug4": "5xx", + "trace2": []interface{}{ + "ttttttracer", + []byte{100, 100, 100}, + map[interface{}]interface{}{"min": 1111, "max": 1234}, + }, + "fatal2": "", + } + testCases := []severityTestCase{ { name: "unknown", @@ -93,18 +105,7 @@ func TestSeverityParser(t *testing.T) { mapping: map[interface{}]interface{}{"error": []interface{}{"NOOOOOOO", "this is bad", 1234}}, expected: entry.Error, }, - { - name: "overload-int-key", - sample: "E", - mapping: map[interface{}]interface{}{60: "E"}, - expected: entry.Error, // 60 - }, - { - name: "overload-native", - sample: "E", - mapping: map[interface{}]interface{}{int(entry.Error): "E"}, - expected: entry.Error, // 60 - }, + // TODO { name: "custom-level", sample: "weird", @@ -204,87 +205,37 @@ func TestSeverityParser(t *testing.T) { { name: "Http-All", sample: "301", - mapping: map[interface{}]interface{}{20: "2xx", 30: "3xx", 40: "4xx", 50: "5xx"}, - expected: 30, - }, - { - name: "all-the-things-midrange", - sample: 1234, - mapping: map[interface{}]interface{}{ - "30": "3xx", - int(entry.Error): "4xx", - "critical": "5xx", - int(entry.Trace): []interface{}{ - "ttttttracer", - []byte{100, 100, 100}, - map[interface{}]interface{}{"min": 1111, "max": 1234}, - }, - 77: "", - }, - expected: entry.Trace, - }, - { - name: "all-the-things-bytes", - sample: []byte{100, 100, 100}, - mapping: map[interface{}]interface{}{ - "30": "3xx", - int(entry.Error): "4xx", - "critical": "5xx", - int(entry.Trace): []interface{}{ - "ttttttracer", - []byte{100, 100, 100}, - map[interface{}]interface{}{"min": 1111, "max": 1234}, - }, - 77: "", - }, - expected: entry.Trace, - }, - { - name: "all-the-things-empty", - sample: "", - mapping: map[interface{}]interface{}{ - "30": "3xx", - int(entry.Error): "4xx", - "critical": "5xx", - int(entry.Trace): []interface{}{ - "ttttttracer", - []byte{100, 100, 100}, - map[interface{}]interface{}{"min": 1111, "max": 1234}, - }, - 77: "", - }, - expected: 77, - }, - { - name: "all-the-things-3xx", - sample: "399", - mapping: map[interface{}]interface{}{ - "30": "3xx", - int(entry.Error): "4xx", - "critical": "5xx", - int(entry.Trace): []interface{}{ - "ttttttracer", - []byte{100, 100, 100}, - map[interface{}]interface{}{"min": 1111, "max": 1234}, - }, - 77: "", - }, - expected: 30, - }, - { - name: "all-the-things-miss", - sample: "miss", - mapping: map[interface{}]interface{}{ - "30": "3xx", - int(entry.Error): "4xx", - "critical": "5xx", - int(entry.Trace): []interface{}{ - "ttttttracer", - []byte{100, 100, 100}, - map[interface{}]interface{}{"min": 1111, "max": 2000}, - }, - 77: "", - }, + mapping: map[interface{}]interface{}{"debug": "2xx", "info": "3xx", "error": "4xx", "warn": "5xx"}, + expected: entry.Info, + }, + { + name: "all-the-things-midrange", + sample: 1234, + mapping: allTheThingsMap, + expected: entry.Trace2, + }, + { + name: "all-the-things-bytes", + sample: []byte{100, 100, 100}, + mapping: allTheThingsMap, + expected: entry.Trace2, + }, + { + name: "all-the-things-empty", + sample: "", + mapping: allTheThingsMap, + expected: entry.Fatal2, + }, + { + name: "all-the-things-3xx", + sample: "399", + mapping: allTheThingsMap, + expected: entry.Info, + }, + { + name: "all-the-things-miss", + sample: "miss", + mapping: allTheThingsMap, expected: entry.Default, }, { diff --git a/operator/builtin/parser/syslog/data.go b/operator/builtin/parser/syslog/data.go index 021ce169..89c73fa3 100644 --- a/operator/builtin/parser/syslog/data.go +++ b/operator/builtin/parser/syslog/data.go @@ -71,7 +71,7 @@ func CreateCases(basicConfig func() *SyslogParserConfig) ([]Case, error) { "message": "test message", "priority": 34, }, - entry.Critical, + entry.Error2, "crit", }, { @@ -91,7 +91,7 @@ func CreateCases(basicConfig func() *SyslogParserConfig) ([]Case, error) { "message": "test message", "priority": 34, }, - entry.Critical, + entry.Error2, "crit", }, { @@ -111,7 +111,7 @@ func CreateCases(basicConfig func() *SyslogParserConfig) ([]Case, error) { "message": "test message", "priority": 34, }, - entry.Critical, + entry.Error2, "crit", }, { diff --git a/operator/builtin/parser/syslog/syslog.go b/operator/builtin/parser/syslog/syslog.go index c6f0828e..f0d234d9 100644 --- a/operator/builtin/parser/syslog/syslog.go +++ b/operator/builtin/parser/syslog/syslog.go @@ -219,12 +219,12 @@ func toBytes(value interface{}) ([]byte, error) { } var severityMapping = [...]entry.Severity{ - 0: entry.Emergency, - 1: entry.Alert, - 2: entry.Critical, + 0: entry.Fatal, + 1: entry.Error3, + 2: entry.Error2, 3: entry.Error, - 4: entry.Warning, - 5: entry.Notice, + 4: entry.Warn, + 5: entry.Info3, 6: entry.Info, 7: entry.Debug, } diff --git a/operator/helper/parser_test.go b/operator/helper/parser_test.go index 8fdb1593..c5439208 100644 --- a/operator/helper/parser_test.go +++ b/operator/helper/parser_test.go @@ -430,8 +430,8 @@ func NewTestParserConfig() ParserConfig { tp := NewTimeParser() sp := NewSeverityParserConfig() sp.Mapping = map[interface{}]interface{}{ - "30": "3xx", - int(entry.Error): "4xx"} + "info": "3xx", + "warn": "4xx"} except.TimeParser = &tp except.SeverityParserConfig = &sp @@ -451,8 +451,8 @@ func TestMapStructureDecodeParserConfigWithHook(t *testing.T) { }, "severity": map[string]interface{}{ "mapping": map[interface{}]interface{}{ - "30": "3xx", - 60: "4xx", + "info": "3xx", + "warn": "4xx", }, }, } @@ -479,8 +479,8 @@ func TestMapStructureDecodeParserConfig(t *testing.T) { }, "severity": map[string]interface{}{ "mapping": map[interface{}]interface{}{ - "30": "3xx", - 60: "4xx", + "info": "3xx", + "warn": "4xx", }, }, } diff --git a/operator/helper/severity_builder.go b/operator/helper/severity_builder.go index f6dbc572..cef3ce5d 100644 --- a/operator/helper/severity_builder.go +++ b/operator/helper/severity_builder.go @@ -33,55 +33,49 @@ func getBuiltinMapping(name string) severityMap { return map[string]entry.Severity{} case "aliases": return map[string]entry.Severity{ - "default": entry.Default, - "trace": entry.Trace, - "trace2": entry.Trace2, - "trace3": entry.Trace3, - "trace4": entry.Trace4, - "debug": entry.Debug, - "debug2": entry.Debug2, - "debug3": entry.Debug3, - "debug4": entry.Debug4, - "info": entry.Info, - "info2": entry.Info2, - "info3": entry.Info3, - "info4": entry.Info4, - "notice": entry.Notice, - "warning": entry.Warning, - "warning2": entry.Warning2, - "warning3": entry.Warning3, - "warning4": entry.Warning4, - "error": entry.Error, - "error2": entry.Error2, - "error3": entry.Error3, - "error4": entry.Error4, - "critical": entry.Critical, - "alert": entry.Alert, - "emergency": entry.Emergency, - "emergency2": entry.Emergency2, - "emergency3": entry.Emergency3, - "emergency4": entry.Emergency4, - "catastrophe": entry.Catastrophe, + "default": entry.Default, + "trace": entry.Trace, + "trace2": entry.Trace2, + "trace3": entry.Trace3, + "trace4": entry.Trace4, + "debug": entry.Debug, + "debug2": entry.Debug2, + "debug3": entry.Debug3, + "debug4": entry.Debug4, + "info": entry.Info, + "info2": entry.Info2, + "info3": entry.Info3, + "info4": entry.Info4, + "warn": entry.Warn, + "warn2": entry.Warn2, + "warn3": entry.Warn3, + "warn4": entry.Warn4, + "error": entry.Error, + "error2": entry.Error2, + "error3": entry.Error3, + "error4": entry.Error4, + "fatal": entry.Fatal, + "fatal2": entry.Fatal2, + "fatal3": entry.Fatal3, + "fatal4": entry.Fatal4, } default: // Add some additional values that are automatically recognized mapping := getBuiltinMapping("aliases") - mapping.add(entry.Warning, "warn") - mapping.add(entry.Warning2, "warn2") - mapping.add(entry.Warning3, "warn3") - mapping.add(entry.Warning4, "warn4") + mapping.add(entry.Warn, "warning") + mapping.add(entry.Warn2, "warning2") + mapping.add(entry.Warn3, "warning3") + mapping.add(entry.Warn4, "warning4") mapping.add(entry.Error, "err") mapping.add(entry.Error2, "err2") mapping.add(entry.Error3, "err3") mapping.add(entry.Error4, "err4") - mapping.add(entry.Critical, "crit") - - mapping.add(entry.Emergency, "fatal") - mapping.add(entry.Emergency2, "fatal2") - mapping.add(entry.Emergency3, "fatal3") - mapping.add(entry.Emergency4, "fatal4") + mapping.add(entry.Fatal, "fatal") + mapping.add(entry.Fatal2, "fatal2") + mapping.add(entry.Fatal3, "fatal3") + mapping.add(entry.Fatal4, "fatal4") return mapping } diff --git a/operator/helper/severity_test.go b/operator/helper/severity_test.go index 0cfae456..6ef22285 100644 --- a/operator/helper/severity_test.go +++ b/operator/helper/severity_test.go @@ -42,37 +42,33 @@ type severityTestCase struct { // maps values into any of the predefined keys. // For example, this ensures that users can do this: // mapping: -// warning3: warn_three +// warn3: warn_three func validMappingKeyCases() []severityTestCase { aliasedMapping := map[string]entry.Severity{ - "trace": entry.Trace, - "trace2": entry.Trace2, - "trace3": entry.Trace3, - "trace4": entry.Trace4, - "debug": entry.Debug, - "debug2": entry.Debug2, - "debug3": entry.Debug3, - "debug4": entry.Debug4, - "info": entry.Info, - "info2": entry.Info2, - "info3": entry.Info3, - "info4": entry.Info4, - "notice": entry.Notice, - "warning": entry.Warning, - "warning2": entry.Warning2, - "warning3": entry.Warning3, - "warning4": entry.Warning4, - "error": entry.Error, - "error2": entry.Error2, - "error3": entry.Error3, - "error4": entry.Error4, - "critical": entry.Critical, - "alert": entry.Alert, - "emergency": entry.Emergency, - "emergency2": entry.Emergency2, - "emergency3": entry.Emergency3, - "emergency4": entry.Emergency4, - "catastrophe": entry.Catastrophe, + "trace": entry.Trace, + "trace2": entry.Trace2, + "trace3": entry.Trace3, + "trace4": entry.Trace4, + "debug": entry.Debug, + "debug2": entry.Debug2, + "debug3": entry.Debug3, + "debug4": entry.Debug4, + "info": entry.Info, + "info2": entry.Info2, + "info3": entry.Info3, + "info4": entry.Info4, + "warn": entry.Warn, + "warn2": entry.Warn2, + "warn3": entry.Warn3, + "warn4": entry.Warn4, + "error": entry.Error, + "error2": entry.Error2, + "error3": entry.Error3, + "error4": entry.Error4, + "fatal": entry.Fatal, + "fatal2": entry.Fatal2, + "fatal3": entry.Fatal3, + "fatal4": entry.Fatal4, } cases := []severityTestCase{} @@ -105,18 +101,18 @@ func otlpSevCases() []severityTestCase { "iNFo2": entry.Info2, "iNFo3": entry.Info3, "iNFo4": entry.Info4, - "wARn": entry.Warning, - "wARn2": entry.Warning2, - "wARn3": entry.Warning3, - "wARn4": entry.Warning4, + "wARn": entry.Warn, + "wARn2": entry.Warn2, + "wARn3": entry.Warn3, + "wARn4": entry.Warn4, "eRrOr": entry.Error, "eRrOr2": entry.Error2, "eRrOr3": entry.Error3, "eRrOr4": entry.Error4, - "fAtAl": entry.Emergency, - "fAtAl2": entry.Emergency2, - "fAtAl3": entry.Emergency3, - "fAtAl4": entry.Emergency4, + "fAtAl": entry.Fatal, + "fAtAl2": entry.Fatal2, + "fAtAl3": entry.Fatal3, + "fAtAl4": entry.Fatal4, } cases := []severityTestCase{} @@ -147,6 +143,18 @@ func otlpSevCases() []severityTestCase { } func TestSeverityParser(t *testing.T) { + allTheThingsMap := map[interface{}]interface{}{ + "info": "3xx", + "error3": "4xx", + "debug4": "5xx", + "trace2": []interface{}{ + "ttttttracer", + []byte{100, 100, 100}, + map[interface{}]interface{}{"min": 1111, "max": 1234}, + }, + "fatal2": "", + } + testCases := []severityTestCase{ { name: "unknown", @@ -208,48 +216,37 @@ func TestSeverityParser(t *testing.T) { mapping: map[interface{}]interface{}{"error": []interface{}{"NOOOOOOO", "this is bad", 1234}}, expected: entry.Error, }, - { - name: "overload-int-key", - sample: "E", - mapping: map[interface{}]interface{}{60: "E"}, - expected: entry.Error, // 60 - }, - { - name: "overload-native", - sample: "E", - mapping: map[interface{}]interface{}{int(entry.Error): "E"}, - expected: entry.Error, // 60 - }, - { - name: "custom-level", - sample: "weird", - mapping: map[interface{}]interface{}{12: "weird"}, - expected: 12, - }, - { - name: "custom-level-list", - sample: "hey!", - mapping: map[interface{}]interface{}{16: []interface{}{"hey!", 1234}}, - expected: 16, - }, - { - name: "custom-level-list-unfound", - sample: "not-in-the-list-but-thats-ok", - mapping: map[interface{}]interface{}{16: []interface{}{"hey!", 1234}}, - expected: entry.Default, - }, - { - name: "custom-level-unbuildable", - sample: "not-in-the-list-but-thats-ok", - mapping: map[interface{}]interface{}{16: []interface{}{"hey!", 1234, 12.34}}, - buildErr: true, - }, - { - name: "custom-level-list-unparseable", - sample: 12.34, - mapping: map[interface{}]interface{}{16: []interface{}{"hey!", 1234}}, - parseErr: true, - }, + // TODO replace custom level tests with level2,3,4 tests + // { + // name: "custom-level", + // sample: "weird", + // mapping: map[interface{}]interface{}{12: "weird"}, + // expected: 12, + // }, + // { + // name: "custom-level-list", + // sample: "hey!", + // mapping: map[interface{}]interface{}{16: []interface{}{"hey!", 1234}}, + // expected: 16, + // }, + // { + // name: "custom-level-list-unfound", + // sample: "not-in-the-list-but-thats-ok", + // mapping: map[interface{}]interface{}{16: []interface{}{"hey!", 1234}}, + // expected: entry.Default, + // }, + // { + // name: "custom-level-unbuildable", + // sample: "not-in-the-list-but-thats-ok", + // mapping: map[interface{}]interface{}{16: []interface{}{"hey!", 1234, 12.34}}, + // buildErr: true, + // }, + // { + // name: "custom-level-list-unparseable", + // sample: 12.34, + // mapping: map[interface{}]interface{}{16: []interface{}{"hey!", 1234}}, + // parseErr: true, + // }, { name: "in-range", sample: 123, @@ -323,83 +320,33 @@ func TestSeverityParser(t *testing.T) { expected: 30, }, { - name: "all-the-things-midrange", - sample: 1234, - mapping: map[interface{}]interface{}{ - "30": "3xx", - int(entry.Error): "4xx", - "critical": "5xx", - int(entry.Trace): []interface{}{ - "ttttttracer", - []byte{100, 100, 100}, - map[interface{}]interface{}{"min": 1111, "max": 1234}, - }, - 77: "", - }, - expected: entry.Trace, - }, - { - name: "all-the-things-bytes", - sample: []byte{100, 100, 100}, - mapping: map[interface{}]interface{}{ - "30": "3xx", - int(entry.Error): "4xx", - "critical": "5xx", - int(entry.Trace): []interface{}{ - "ttttttracer", - []byte{100, 100, 100}, - map[interface{}]interface{}{"min": 1111, "max": 1234}, - }, - 77: "", - }, - expected: entry.Trace, - }, - { - name: "all-the-things-empty", - sample: "", - mapping: map[interface{}]interface{}{ - "30": "3xx", - int(entry.Error): "4xx", - "critical": "5xx", - int(entry.Trace): []interface{}{ - "ttttttracer", - []byte{100, 100, 100}, - map[interface{}]interface{}{"min": 1111, "max": 1234}, - }, - 77: "", - }, - expected: 77, - }, - { - name: "all-the-things-3xx", - sample: "399", - mapping: map[interface{}]interface{}{ - "30": "3xx", - int(entry.Error): "4xx", - "critical": "5xx", - int(entry.Trace): []interface{}{ - "ttttttracer", - []byte{100, 100, 100}, - map[interface{}]interface{}{"min": 1111, "max": 1234}, - }, - 77: "", - }, - expected: 30, + name: "all-the-things-midrange", + sample: 1234, + mapping: allTheThingsMap, + expected: entry.Trace2, }, { - name: "all-the-things-miss", - sample: "miss", - mapping: map[interface{}]interface{}{ - "30": "3xx", - int(entry.Error): "4xx", - "critical": "5xx", - int(entry.Trace): []interface{}{ - "ttttttracer", - []byte{100, 100, 100}, - map[interface{}]interface{}{"min": 1111, "max": 2000}, - }, - 77: "", - }, + name: "all-the-things-bytes", + sample: []byte{100, 100, 100}, + mapping: allTheThingsMap, + expected: entry.Trace2, + }, + { + name: "all-the-things-empty", + sample: "", + mapping: allTheThingsMap, + expected: entry.Fatal2, + }, + { + name: "all-the-things-3xx", + sample: "399", + mapping: allTheThingsMap, + expected: entry.Info, + }, + { + name: "all-the-things-miss", + sample: "miss", + mapping: allTheThingsMap, expected: entry.Default, }, { From 6fe0737a610813322e4d8fc42ff682551c72c31b Mon Sep 17 00:00:00 2001 From: Dan Jaglowski Date: Mon, 26 Jul 2021 15:25:48 -0400 Subject: [PATCH 4/4] Update severity docs. Remove support for int levels --- docs/types/severity.md | 184 ++++++++---------- .../builtin/parser/severity/severity_test.go | 31 --- operator/helper/severity_builder.go | 79 +++----- operator/helper/severity_test.go | 71 +++---- 4 files changed, 149 insertions(+), 216 deletions(-) diff --git a/docs/types/severity.md b/docs/types/severity.md index 5ebd4d56..0ac739f5 100644 --- a/docs/types/severity.md +++ b/docs/types/severity.md @@ -1,43 +1,8 @@ ## Severity Parsing -`stanza` uses a flexible severity parsing system based on the integers 0 to 100. Standard severities are provided at multiples of 10. - -This severity system allows each output operator to interpret the values 0 to 100 as appropriate for the corresponding backend. - -The following named severity levels are supported. - -| Severity | Numeric Value | Alias | -| --- | --- | --- | -| Default | 0 | `default` | -| Trace | 10 | `trace` | -| Trace2 | 12 | `trace2` | -| Trace3 | 13 | `trace3` | -| Trace4 | 14 | `trace4` | -| Debug | 20 | `debug` | -| Debug2 | 22 | `debug2` | -| Debug3 | 23 | `debug3` | -| Debug4 | 24 | `debug4` | -| Info | 30 | `info` | -| Info2 | 32 | `info2` | -| Info3 | 33 | `info3` | -| Info4 | 34 | `info4` | -| Notice | 40 | `notice` | -| Warning | 50 | `warning` | -| Warning2 | 52 | `warning2` | -| Warning3 | 53 | `warning3` | -| Warning4 | 54 | `warning4` | -| Error | 60 | `error` | -| Error2 | 62 | `error2` | -| Error3 | 63 | `error3` | -| Error4 | 64 | `error4` | -| Critical | 70 | `critical` | -| Alert | 80 | `alert` | -| Emergency | 90 | `emergency` | -| Emergency2 | 92 | `emergency2` | -| Emergency3 | 93 | `emergency3` | -| Emergency4 | 94 | `emergency4` | -| Catastrophe | 100 | `catastrophe` | +Severity is represented as a number from 1 to 24. The meaning of these severity levels are defined in the [OpenTelemetry Logs Data Model](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/logs/data-model.md#field-severitynumber). +> Note: A `default` severity level is also supported, and is used when a value cannot be mapped to any other level. ### `severity` parsing parameters @@ -58,9 +23,39 @@ Severity parsing behavior is defined in a config file using a severity `mapping` ```yaml ... mapping: - severity_as_int_or_alias: value | list of values | range | special - severity_as_int_or_alias: value | list of values | range | special -``` + severity_alias: value | list of values | range | special + severity_alias: value | list of values | range | special +``` + +The following aliases are used to represent the possible severity levels: + +| Severity Number | Alias | +| --- | --- | +| 0 | `default` | +| 1 | `trace` | +| 2 | `trace2` | +| 3 | `trace3` | +| 4 | `trace4` | +| 5 | `debug` | +| 6 | `debug2` | +| 7 | `debug3` | +| 8 | `debug4` | +| 9 | `info` | +| 10 | `info2` | +| 11 | `info3` | +| 12 | `info4` | +| 13 | `warn` | +| 14 | `warn2` | +| 15 | `warn3` | +| 16 | `warn4` | +| 17 | `error` | +| 18 | `error2` | +| 19 | `error3` | +| 20 | `error4` | +| 21 | `fatal` | +| 22 | `fatal2` | +| 23 | `fatal3` | +| 24 | `fatal4` | The following example illustrates many of the ways in which mapping can configured: ```yaml @@ -70,8 +65,8 @@ The following example illustrates many of the ways in which mapping can configur # single value to be parsed as "error" error: oops - # list of values to be parsed as "warning" - warning: + # list of values to be parsed as "warn" + warn: - hey! - YSK @@ -83,11 +78,11 @@ The following example illustrates many of the ways in which mapping can configur # special value representing the range 200-299, to be parsed as "debug" debug: 2xx - # single value to be parsed as a custom level of 36 - 36: medium + # single value to be parsed as a "info3" + info3: medium # mix and match the above concepts - 95: + fatal: - really serious - min: 9001 max: 9050 @@ -131,29 +126,20 @@ The following configurations are equivalent: info2: info2 info3: info3 info4: info4 - notice: notice - warning: - - warning - - warn - warning2: warning2 - warning3: warning3 - warning4: warning4 + warn: warn + warn2: warn2 + warn3: warn3 + warn4: warn4 error: - error - - err - 404 error2: error2 error3: error3 error4: error4 - critical: - - critical - - crit - alert: alert - emergency: emergency - emergency2: emergency2 - emergency3: emergency3 - emergency4: emergency4 - catastrophe: catastrophe + fatal: fatal + fatal2: fatal2 + fatal3: fatal3 + fatal4: fatal4 ``` Additional built-in presets coming soon @@ -171,7 +157,7 @@ If a severity block is specified, the parser operator will perform the severity severity: parse_from: severity_field mapping: - critical: 5xx + warn: 5xx error: 4xx info: 3xx debug: 2xx @@ -184,7 +170,7 @@ As a special case, the [`severity_parser`](/docs/operators/severity_parser.md) o - type: severity_parser parse_from: severity_field mapping: - critical: 5xx + warn: 5xx error: 4xx info: 3xx debug: 2xx @@ -209,7 +195,7 @@ Note that the default `preset` is in place, and no additional values have been s ```json { - "severity": 0, + "severity": "default", "body": { "severity_field": "ERROR" } @@ -221,7 +207,7 @@ Note that the default `preset` is in place, and no additional values have been s ```json { - "severity": 60, + "severity": "error", "body": {} } ``` @@ -249,7 +235,7 @@ Note that the default `preset` is in place, and one additional values has been s ```json { - "severity": 0, + "severity": "default", "body": { "severity_field": "nooo!" } @@ -261,7 +247,7 @@ Note that the default `preset` is in place, and one additional values has been s ```json { - "severity": 60, + "severity": "error", "body": {} } ``` @@ -273,7 +259,7 @@ Note that the default `preset` is in place, and one additional values has been s ```json { - "severity": 0, + "severity": "default", "body": { "severity_field": "ERROR" } @@ -285,7 +271,7 @@ Note that the default `preset` is in place, and one additional values has been s ```json { - "severity": 60, + "severity": "error", "body": {} } ``` @@ -315,7 +301,7 @@ Configuration: ```json { - "severity": 0, + "severity": "default", "body": { "severity_field": "nooo!" } @@ -327,7 +313,7 @@ Configuration: ```json { - "severity": 60, + "severity": "error", "body": {} } ``` @@ -339,7 +325,7 @@ Configuration: ```json { - "severity": 0, + "severity": "default", "body": { "severity_field": "nooooooo" } @@ -351,7 +337,7 @@ Configuration: ```json { - "severity": 60, + "severity": "error", "body": {} } ``` @@ -363,7 +349,7 @@ Configuration: ```json { - "severity": 0, + "severity": "default", "body": { "severity_field": "hey" } @@ -375,7 +361,7 @@ Configuration: ```json { - "severity": 30, + "severity": "info", "body": {} } ``` @@ -387,7 +373,7 @@ Configuration: ```json { - "severity": 0, + "severity": "default", "body": { "severity_field": 1234 } @@ -399,7 +385,7 @@ Configuration: ```json { - "severity": 20, + "severity": "debug", "body": {} } ``` @@ -411,7 +397,7 @@ Configuration: ```json { - "severity": 0, + "severity": "default", "body": { "severity_field": "unknown" } @@ -423,7 +409,7 @@ Configuration: ```json { - "severity": 0, + "severity": "default", "body": {} } ``` @@ -442,7 +428,7 @@ Configuration: error: - min: 1 max: 5 - alert: + fatal: - min: 6 max: 10 ``` @@ -454,7 +440,7 @@ Configuration: ```json { - "severity": 0, + "severity": "default", "body": { "severity_field": 3 } @@ -466,7 +452,7 @@ Configuration: ```json { - "severity": 60, + "severity": "error", "body": {} } ``` @@ -478,7 +464,7 @@ Configuration: ```json { - "severity": 0, + "severity": "default", "body": { "severity_field": 9 } @@ -490,7 +476,7 @@ Configuration: ```json { - "severity": 80, + "severity": "fatal", "body": {} } ``` @@ -502,7 +488,7 @@ Configuration: ```json { - "severity": 0, + "severity": "default", "body": { "severity_field": 12 } @@ -514,7 +500,7 @@ Configuration: ```json { - "severity": 0, + "severity": "default", "body": {} } ``` @@ -539,7 +525,7 @@ Configuration: - type: severity_parser parse_from: severity_field mapping: - critical: 5xx + warn: 5xx error: 4xx info: 3xx debug: 2xx @@ -551,7 +537,7 @@ Equivalent Configuration: type: severity_parser parse_from: severity_field mapping: - critical: + warn: - min: 500 max: 599 error: @@ -573,7 +559,7 @@ Equivalent Configuration: ```json { - "severity": 0, + "severity": "default", "body": { "severity_field": 302 } @@ -585,7 +571,7 @@ Equivalent Configuration: ```json { - "severity": 30, + "severity": "info", "body": {} } ``` @@ -597,7 +583,7 @@ Equivalent Configuration: ```json { - "severity": 0, + "severity": "default", "body": { "severity_field": 404 } @@ -609,7 +595,7 @@ Equivalent Configuration: ```json { - "severity": 60, + "severity": "error", "body": {} } ``` @@ -621,7 +607,7 @@ Equivalent Configuration: ```json { - "severity": 0, + "severity": "default", "body": { "severity_field": 200 } @@ -633,7 +619,7 @@ Equivalent Configuration: ```json { - "severity": 20, + "severity": "debug", "body": {} } ``` @@ -660,7 +646,7 @@ Configuration: ```json { - "severity": 0, + "severity": "default", "body": { "severity_field": "nooo!" } @@ -672,7 +658,7 @@ Configuration: ```json { - "severity": 60, + "severity": "error", "body": {} } ``` @@ -684,7 +670,7 @@ Configuration: ```json { - "severity": 0, + "severity": "default", "body": { "severity_field": "ERROR" } @@ -696,7 +682,7 @@ Configuration: ```json { - "severity": 0, + "severity": "default", "body": {} } ``` diff --git a/operator/builtin/parser/severity/severity_test.go b/operator/builtin/parser/severity/severity_test.go index 24852f5e..3b9427f0 100644 --- a/operator/builtin/parser/severity/severity_test.go +++ b/operator/builtin/parser/severity/severity_test.go @@ -105,37 +105,6 @@ func TestSeverityParser(t *testing.T) { mapping: map[interface{}]interface{}{"error": []interface{}{"NOOOOOOO", "this is bad", 1234}}, expected: entry.Error, }, - // TODO - { - name: "custom-level", - sample: "weird", - mapping: map[interface{}]interface{}{12: "weird"}, - expected: 12, - }, - { - name: "custom-level-list", - sample: "hey!", - mapping: map[interface{}]interface{}{16: []interface{}{"hey!", 1234}}, - expected: 16, - }, - { - name: "custom-level-list-unfound", - sample: "not-in-the-list-but-thats-ok", - mapping: map[interface{}]interface{}{16: []interface{}{"hey!", 1234}}, - expected: entry.Default, - }, - { - name: "custom-level-unbuildable", - sample: "not-in-the-list-but-thats-ok", - mapping: map[interface{}]interface{}{16: []interface{}{"hey!", 1234, 12.34}}, - buildErr: true, - }, - { - name: "custom-level-list-unparseable", - sample: 12.34, - mapping: map[interface{}]interface{}{16: []interface{}{"hey!", 1234}}, - parseErr: true, - }, { name: "in-range", sample: 123, diff --git a/operator/helper/severity_builder.go b/operator/helper/severity_builder.go index 72bf08dd..1923cc0e 100644 --- a/operator/helper/severity_builder.go +++ b/operator/helper/severity_builder.go @@ -23,9 +23,6 @@ import ( "github.com/open-telemetry/opentelemetry-log-collection/operator" ) -const minSeverity = 0 -const maxSeverity = 100 - // map[string or int input]sev-level func getBuiltinMapping(name string) severityMap { switch name { @@ -33,31 +30,30 @@ func getBuiltinMapping(name string) severityMap { return map[string]entry.Severity{} case "aliases": return map[string]entry.Severity{ - "default": entry.Default, - "trace": entry.Trace, - "trace2": entry.Trace2, - "trace3": entry.Trace3, - "trace4": entry.Trace4, - "debug": entry.Debug, - "debug2": entry.Debug2, - "debug3": entry.Debug3, - "debug4": entry.Debug4, - "info": entry.Info, - "info2": entry.Info2, - "info3": entry.Info3, - "info4": entry.Info4, - "warn": entry.Warn, - "warn2": entry.Warn2, - "warn3": entry.Warn3, - "warn4": entry.Warn4, - "error": entry.Error, - "error2": entry.Error2, - "error3": entry.Error3, - "error4": entry.Error4, - "fatal": entry.Fatal, - "fatal2": entry.Fatal2, - "fatal3": entry.Fatal3, - "fatal4": entry.Fatal4, + "trace": entry.Trace, + "trace2": entry.Trace2, + "trace3": entry.Trace3, + "trace4": entry.Trace4, + "debug": entry.Debug, + "debug2": entry.Debug2, + "debug3": entry.Debug3, + "debug4": entry.Debug4, + "info": entry.Info, + "info2": entry.Info2, + "info3": entry.Info3, + "info4": entry.Info4, + "warn": entry.Warn, + "warn2": entry.Warn2, + "warn3": entry.Warn3, + "warn4": entry.Warn4, + "error": entry.Error, + "error2": entry.Error2, + "error3": entry.Error3, + "error4": entry.Error4, + "fatal": entry.Fatal, + "fatal2": entry.Fatal2, + "fatal3": entry.Fatal3, + "fatal4": entry.Fatal4, } default: // Add some additional values that are automatically recognized @@ -149,31 +145,8 @@ func (c *SeverityParserConfig) Build(context operator.BuildContext) (SeverityPar } func validateSeverity(severity interface{}) (entry.Severity, error) { - if sev, _, err := getBuiltinMapping("aliases").find(severity); err != nil { - return entry.Default, err - } else if sev != entry.Default { - return sev, nil - } - - // If integer between 0 and 100 - var intSev int - switch s := severity.(type) { - case int: - intSev = s - case string: - i, err := strconv.ParseInt(s, 10, 8) - if err != nil { - return entry.Default, fmt.Errorf("%s cannot be used as a severity", severity) - } - intSev = int(i) - default: - return entry.Default, fmt.Errorf("type %T cannot be used as a severity (%v)", severity, severity) - } - - if intSev < minSeverity || intSev > maxSeverity { - return entry.Default, fmt.Errorf("severity must be between %d and %d", minSeverity, maxSeverity) - } - return entry.Severity(intSev), nil + sev, _, err := getBuiltinMapping("aliases").find(severity) + return sev, err } func isRange(value interface{}) (int, int, bool) { diff --git a/operator/helper/severity_test.go b/operator/helper/severity_test.go index 6ef22285..b1452ec0 100644 --- a/operator/helper/severity_test.go +++ b/operator/helper/severity_test.go @@ -168,6 +168,24 @@ func TestSeverityParser(t *testing.T) { mapping: nil, expected: entry.Error, }, + { + name: "error2", + sample: "error2", + mapping: nil, + expected: entry.Error2, + }, + { + name: "error3", + sample: "error3", + mapping: nil, + expected: entry.Error3, + }, + { + name: "error4", + sample: "error4", + mapping: nil, + expected: entry.Error4, + }, { name: "error-capitalized", sample: "Error", @@ -216,37 +234,24 @@ func TestSeverityParser(t *testing.T) { mapping: map[interface{}]interface{}{"error": []interface{}{"NOOOOOOO", "this is bad", 1234}}, expected: entry.Error, }, - // TODO replace custom level tests with level2,3,4 tests - // { - // name: "custom-level", - // sample: "weird", - // mapping: map[interface{}]interface{}{12: "weird"}, - // expected: 12, - // }, - // { - // name: "custom-level-list", - // sample: "hey!", - // mapping: map[interface{}]interface{}{16: []interface{}{"hey!", 1234}}, - // expected: 16, - // }, - // { - // name: "custom-level-list-unfound", - // sample: "not-in-the-list-but-thats-ok", - // mapping: map[interface{}]interface{}{16: []interface{}{"hey!", 1234}}, - // expected: entry.Default, - // }, - // { - // name: "custom-level-unbuildable", - // sample: "not-in-the-list-but-thats-ok", - // mapping: map[interface{}]interface{}{16: []interface{}{"hey!", 1234, 12.34}}, - // buildErr: true, - // }, - // { - // name: "custom-level-list-unparseable", - // sample: 12.34, - // mapping: map[interface{}]interface{}{16: []interface{}{"hey!", 1234}}, - // parseErr: true, - // }, + { + name: "numbered-level", + sample: "critical", + mapping: map[interface{}]interface{}{"error2": "critical"}, + expected: entry.Error2, + }, + { + name: "override-standard", + sample: "error", + mapping: map[interface{}]interface{}{"error3": []interface{}{"error"}}, + expected: entry.Error3, + }, + { + name: "level-unfound", + sample: "not-in-the-list-but-thats-ok", + mapping: map[interface{}]interface{}{"error4": []interface{}{"hey!", 1234}}, + expected: entry.Default, + }, { name: "in-range", sample: 123, @@ -316,8 +321,8 @@ func TestSeverityParser(t *testing.T) { { name: "Http-All", sample: "301", - mapping: map[interface{}]interface{}{20: "2xx", 30: "3xx", 40: "4xx", 50: "5xx"}, - expected: 30, + mapping: map[interface{}]interface{}{"debug": "2xx", "info": "3xx", "error": "4xx", "warn": "5xx"}, + expected: entry.Info, }, { name: "all-the-things-midrange",