From 3b6d9c0abefcd8819be8d7ba229bffcac35a38b5 Mon Sep 17 00:00:00 2001 From: george pogosyan Date: Tue, 9 Jul 2024 13:17:49 +0300 Subject: [PATCH] Edit doc. Delete fatal, add warnings --- plugin/README.md | 42 +++++++++ plugin/action/README.md | 42 +++++++++ plugin/action/remove_fields/README.md | 10 +-- plugin/action/remove_fields/remove_fields.go | 91 +++++++++++--------- 4 files changed, 137 insertions(+), 48 deletions(-) diff --git a/plugin/README.md b/plugin/README.md index e31c8496d..e729888ee 100755 --- a/plugin/README.md +++ b/plugin/README.md @@ -616,6 +616,48 @@ It parses string from the event field using re2 expression with named subgroups [More details...](plugin/action/parse_re2/README.md) ## remove_fields It removes the list of the event fields and keeps others. +Nested fields supported: list subfield names separated with dot. +Example: +``` +fields: ["a.b.c"] + +# event before processing +{ + "a": { + "b": { + "c": 100, + "d": "some" + } + } +} + +# event after processing +{ + "a": { + "b": { + "d": "some" # "c" removed + } + } +} +``` + +If field name contains dots use backslash for escaping. +Example: +``` +fields: + - exception\.type + +# event before processing +{ + "message": "Exception occurred", + "exception.type": "SomeType" +} + +# event after processing +{ + "message": "Exception occurred" # "exception.type" removed +} +``` [More details...](plugin/action/remove_fields/README.md) ## rename diff --git a/plugin/action/README.md b/plugin/action/README.md index 11bd41711..8cb543fe8 100755 --- a/plugin/action/README.md +++ b/plugin/action/README.md @@ -447,6 +447,48 @@ It parses string from the event field using re2 expression with named subgroups [More details...](plugin/action/parse_re2/README.md) ## remove_fields It removes the list of the event fields and keeps others. +Nested fields supported: list subfield names separated with dot. +Example: +``` +fields: ["a.b.c"] + +# event before processing +{ + "a": { + "b": { + "c": 100, + "d": "some" + } + } +} + +# event after processing +{ + "a": { + "b": { + "d": "some" # "c" removed + } + } +} +``` + +If field name contains dots use backslash for escaping. +Example: +``` +fields: + - exception\.type + +# event before processing +{ + "message": "Exception occurred", + "exception.type": "SomeType" +} + +# event after processing +{ + "message": "Exception occurred" # "exception.type" removed +} +``` [More details...](plugin/action/remove_fields/README.md) ## rename diff --git a/plugin/action/remove_fields/README.md b/plugin/action/remove_fields/README.md index ec6339486..5ad611e25 100755 --- a/plugin/action/remove_fields/README.md +++ b/plugin/action/remove_fields/README.md @@ -1,10 +1,5 @@ # Remove fields plugin It removes the list of the event fields and keeps others. - -### Config params -**`fields`** *`[]string`* - -The list of the fields to remove. Nested fields supported: list subfield names separated with dot. Example: ``` @@ -48,6 +43,11 @@ fields: } ``` +### Config params +**`fields`** *`[]string`* + +The list of the fields to remove. +
diff --git a/plugin/action/remove_fields/remove_fields.go b/plugin/action/remove_fields/remove_fields.go index d32ed410c..3eea02deb 100644 --- a/plugin/action/remove_fields/remove_fields.go +++ b/plugin/action/remove_fields/remove_fields.go @@ -12,6 +12,48 @@ import ( /*{ introduction It removes the list of the event fields and keeps others. +Nested fields supported: list subfield names separated with dot. +Example: +``` +fields: ["a.b.c"] + +# event before processing +{ + "a": { + "b": { + "c": 100, + "d": "some" + } + } +} + +# event after processing +{ + "a": { + "b": { + "d": "some" # "c" removed + } + } +} +``` + +If field name contains dots use backslash for escaping. +Example: +``` +fields: + - exception\.type + +# event before processing +{ + "message": "Exception occurred", + "exception.type": "SomeType" +} + +# event after processing +{ + "message": "Exception occurred" # "exception.type" removed +} +``` }*/ type Plugin struct { @@ -25,48 +67,6 @@ type Config struct { // > @3@4@5@6 // > // > The list of the fields to remove. - // > Nested fields supported: list subfield names separated with dot. - // > Example: - // > ``` - // > fields: ["a.b.c"] - // > - // > # event before processing - // > { - // > "a": { - // > "b": { - // > "c": 100, - // > "d": "some" - // > } - // > } - // > } - // > - // > # event after processing - // > { - // > "a": { - // > "b": { - // > "d": "some" # "c" removed - // > } - // > } - // > } - // > ``` - // > - // > If field name contains dots use backslash for escaping. - // > Example: - // > ``` - // > fields: - // > - exception\.type - // > - // > # event before processing - // > { - // > "message": "Exception occurred", - // > "exception.type": "SomeType" - // > } - // > - // > # event after processing - // > { - // > "message": "Exception occurred" # "exception.type" removed - // > } - // > ``` Fields []string `json:"fields"` // * } @@ -96,7 +96,8 @@ func (p *Plugin) Start(config pipeline.AnyConfig, _ *pipeline.ActionPluginParams for i, f1 := range fields { if f1 == "" { - logger.Fatal("empty field found") + logger.Warn("empty field found") + continue } ok := true @@ -112,6 +113,10 @@ func (p *Plugin) Start(config pipeline.AnyConfig, _ *pipeline.ActionPluginParams p.fieldPaths = append(p.fieldPaths, cfg.ParseFieldSelector(f1)) } } + + if len(p.fieldPaths) == 0 { + logger.Warn("no fields will be removed") + } } func (p *Plugin) Stop() {