From c4aa438353b269c32e555f58b622af33c7601b18 Mon Sep 17 00:00:00 2001 From: Bharat Pasupula Date: Wed, 5 Apr 2023 15:07:20 +0200 Subject: [PATCH 1/8] Add Instance Id to trace filename --- x-pack/filebeat/input/httpjson/input.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x-pack/filebeat/input/httpjson/input.go b/x-pack/filebeat/input/httpjson/input.go index 2abf2d7e730..957c733be94 100644 --- a/x-pack/filebeat/input/httpjson/input.go +++ b/x-pack/filebeat/input/httpjson/input.go @@ -112,6 +112,10 @@ func run( stdCtx := ctxtool.FromCanceller(ctx.Cancelation) + if config.Request.Tracer != nil { + config.Request.Tracer.Filename = strings.ReplaceAll(config.Request.Tracer.Filename, "[[id]]", ctx.ID) + } + httpClient, err := newHTTPClient(stdCtx, config, log) if err != nil { return err From 844e439fb95049a1b3dfa9efec02738041b9a99f Mon Sep 17 00:00:00 2001 From: Bharat Pasupula Date: Wed, 5 Apr 2023 15:49:17 +0200 Subject: [PATCH 2/8] Add for CEL input --- x-pack/filebeat/input/cel/input.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/x-pack/filebeat/input/cel/input.go b/x-pack/filebeat/input/cel/input.go index 716e581da72..f7f3659a048 100644 --- a/x-pack/filebeat/input/cel/input.go +++ b/x-pack/filebeat/input/cel/input.go @@ -110,6 +110,10 @@ func (input) run(env v2.Context, src *source, cursor map[string]interface{}, pub ctx := ctxtool.FromCanceller(env.Cancelation) + if cfg.Resource.Tracer != nil { + cfg.Resource.Tracer.Filename = strings.ReplaceAll(cfg.Resource.Tracer.Filename, "[[id]]", env.ID) + } + client, err := newClient(ctx, cfg, log) if err != nil { return err From c8e0689ae2d406d94b642c38cf01327784c0cd4c Mon Sep 17 00:00:00 2001 From: Bharat Pasupula Date: Wed, 5 Apr 2023 15:50:17 +0200 Subject: [PATCH 3/8] Add changelog --- CHANGELOG.next.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 8b0a41c9b6b..fb8aa49dee3 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -104,6 +104,7 @@ https://github.com/elastic/beats/compare/v8.2.0\...main[Check the HEAD diff] - [Gcs Input] - Added missing locks for safe concurrency {pull}34914[34914] - Fix the ignore_inactive option being ignored in Filebeat's filestream input {pull}34770[34770] - Fix TestMultiEventForEOFRetryHandlerInput unit test of CometD input {pull}34903[34903] +- Add input instance id to request trace filename for httpjson and cel inputs {pull}35024[35024] *Heartbeat* From ee54eec741db1b51eeb9474f121754d4571f842b Mon Sep 17 00:00:00 2001 From: Bharat Pasupula Date: Wed, 5 Apr 2023 17:48:44 +0200 Subject: [PATCH 4/8] fix lint issues --- x-pack/filebeat/input/cel/input.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/x-pack/filebeat/input/cel/input.go b/x-pack/filebeat/input/cel/input.go index f7f3659a048..27b4caa2cb2 100644 --- a/x-pack/filebeat/input/cel/input.go +++ b/x-pack/filebeat/input/cel/input.go @@ -1032,7 +1032,10 @@ func cloneMap(dst, src mapstr.M) { // walkMap walks to all ends of the provided path in m and applies fn to the // final element of each walk. Nested arrays are not handled. func walkMap(m mapstr.M, path string, fn func(parent mapstr.M, key string)) { - key, rest, more := strings.Cut(path, ".") + var rest string + var key string + var more bool + key, rest, more = strings.Cut(path, ".") v, ok := m[key] if !ok { return From c3c9789d49c54db8208310cccd829a19ee9e6f47 Mon Sep 17 00:00:00 2001 From: Bharat Pasupula Date: Wed, 5 Apr 2023 18:41:59 +0200 Subject: [PATCH 5/8] restore lint changes --- x-pack/filebeat/input/cel/input.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/x-pack/filebeat/input/cel/input.go b/x-pack/filebeat/input/cel/input.go index 27b4caa2cb2..f7f3659a048 100644 --- a/x-pack/filebeat/input/cel/input.go +++ b/x-pack/filebeat/input/cel/input.go @@ -1032,10 +1032,7 @@ func cloneMap(dst, src mapstr.M) { // walkMap walks to all ends of the provided path in m and applies fn to the // final element of each walk. Nested arrays are not handled. func walkMap(m mapstr.M, path string, fn func(parent mapstr.M, key string)) { - var rest string - var key string - var more bool - key, rest, more = strings.Cut(path, ".") + key, rest, more := strings.Cut(path, ".") v, ok := m[key] if !ok { return From 36e9f128b4f7d1eb66ec34db9cea3e6ab309d242 Mon Sep 17 00:00:00 2001 From: Bharat Pasupula Date: Thu, 6 Apr 2023 11:16:33 +0200 Subject: [PATCH 6/8] Make * placeholder --- x-pack/filebeat/input/cel/input.go | 2 +- x-pack/filebeat/input/httpjson/input.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/filebeat/input/cel/input.go b/x-pack/filebeat/input/cel/input.go index f7f3659a048..07c20a3680e 100644 --- a/x-pack/filebeat/input/cel/input.go +++ b/x-pack/filebeat/input/cel/input.go @@ -111,7 +111,7 @@ func (input) run(env v2.Context, src *source, cursor map[string]interface{}, pub ctx := ctxtool.FromCanceller(env.Cancelation) if cfg.Resource.Tracer != nil { - cfg.Resource.Tracer.Filename = strings.ReplaceAll(cfg.Resource.Tracer.Filename, "[[id]]", env.ID) + cfg.Resource.Tracer.Filename = strings.ReplaceAll(cfg.Resource.Tracer.Filename, "*", env.ID) } client, err := newClient(ctx, cfg, log) diff --git a/x-pack/filebeat/input/httpjson/input.go b/x-pack/filebeat/input/httpjson/input.go index 957c733be94..c10c2e80098 100644 --- a/x-pack/filebeat/input/httpjson/input.go +++ b/x-pack/filebeat/input/httpjson/input.go @@ -113,7 +113,7 @@ func run( stdCtx := ctxtool.FromCanceller(ctx.Cancelation) if config.Request.Tracer != nil { - config.Request.Tracer.Filename = strings.ReplaceAll(config.Request.Tracer.Filename, "[[id]]", ctx.ID) + config.Request.Tracer.Filename = strings.ReplaceAll(config.Request.Tracer.Filename, "*", ctx.ID) } httpClient, err := newHTTPClient(stdCtx, config, log) From 17cbdcb9ee39855d878ca17bacbe731ae97f35c4 Mon Sep 17 00:00:00 2001 From: Bharat Pasupula Date: Thu, 6 Apr 2023 11:59:09 +0200 Subject: [PATCH 7/8] add docs --- x-pack/filebeat/docs/inputs/input-cel.asciidoc | 3 +++ x-pack/filebeat/docs/inputs/input-httpjson.asciidoc | 3 +++ 2 files changed, 6 insertions(+) diff --git a/x-pack/filebeat/docs/inputs/input-cel.asciidoc b/x-pack/filebeat/docs/inputs/input-cel.asciidoc index 83ec572d859..36d54d2943b 100644 --- a/x-pack/filebeat/docs/inputs/input-cel.asciidoc +++ b/x-pack/filebeat/docs/inputs/input-cel.asciidoc @@ -561,6 +561,9 @@ It is possible to log HTTP requests and responses in a CEL program to a local fi This option is enabled by setting the `resource.tracer.filename` value. Additional options are available to tune log rotation behavior. +NOTE: To differentiate the trace files generated from different input instances, a placeholder `*` can be added to the filename and will be replaced with the input instance id. +For Example, `http-request-trace-*.ndjson`. + Enabling this option compromises security and should only be used for debugging. [float] diff --git a/x-pack/filebeat/docs/inputs/input-httpjson.asciidoc b/x-pack/filebeat/docs/inputs/input-httpjson.asciidoc index 92fd6d15936..58b5dc8aebd 100644 --- a/x-pack/filebeat/docs/inputs/input-httpjson.asciidoc +++ b/x-pack/filebeat/docs/inputs/input-httpjson.asciidoc @@ -619,6 +619,9 @@ It is possible to log httpjson requests and responses to a local file-system for This option is enabled by setting the `request.tracer.filename` value. Additional options are available to tune log rotation behavior. +NOTE: To differentiate the trace files generated from different input instances, a placeholder `*` can be added to the filename and will be replaced with the input instance id. +For Example, `http-request-trace-*.ndjson`. + Enabling this option compromises security and should only be used for debugging. [float] From 21882770c5668f121c1eb1b2300596a8e15b4dd0 Mon Sep 17 00:00:00 2001 From: Bharat Pasupula Date: Thu, 6 Apr 2023 12:02:09 +0200 Subject: [PATCH 8/8] update note --- x-pack/filebeat/docs/inputs/input-cel.asciidoc | 2 +- x-pack/filebeat/docs/inputs/input-httpjson.asciidoc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/filebeat/docs/inputs/input-cel.asciidoc b/x-pack/filebeat/docs/inputs/input-cel.asciidoc index 36d54d2943b..0fd432b96a8 100644 --- a/x-pack/filebeat/docs/inputs/input-cel.asciidoc +++ b/x-pack/filebeat/docs/inputs/input-cel.asciidoc @@ -561,7 +561,7 @@ It is possible to log HTTP requests and responses in a CEL program to a local fi This option is enabled by setting the `resource.tracer.filename` value. Additional options are available to tune log rotation behavior. -NOTE: To differentiate the trace files generated from different input instances, a placeholder `*` can be added to the filename and will be replaced with the input instance id. +To differentiate the trace files generated from different input instances, a placeholder `*` can be added to the filename and will be replaced with the input instance id. For Example, `http-request-trace-*.ndjson`. Enabling this option compromises security and should only be used for debugging. diff --git a/x-pack/filebeat/docs/inputs/input-httpjson.asciidoc b/x-pack/filebeat/docs/inputs/input-httpjson.asciidoc index 58b5dc8aebd..87efc658dc0 100644 --- a/x-pack/filebeat/docs/inputs/input-httpjson.asciidoc +++ b/x-pack/filebeat/docs/inputs/input-httpjson.asciidoc @@ -619,7 +619,7 @@ It is possible to log httpjson requests and responses to a local file-system for This option is enabled by setting the `request.tracer.filename` value. Additional options are available to tune log rotation behavior. -NOTE: To differentiate the trace files generated from different input instances, a placeholder `*` can be added to the filename and will be replaced with the input instance id. +To differentiate the trace files generated from different input instances, a placeholder `*` can be added to the filename and will be replaced with the input instance id. For Example, `http-request-trace-*.ndjson`. Enabling this option compromises security and should only be used for debugging.