From fd08baf18c7626ef8e6f2fe1f444c22bddc3b022 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 6 Apr 2023 16:45:13 +0200 Subject: [PATCH] [8.7](backport #35024) x-pack/filebeat: Add Instance Id to trace filename (#35037) * x-pack/filebeat: Add Instance Id to trace filename (#35024) * Add Instance Id to trace filename * Add for CEL input * Add changelog * fix lint issues * restore lint changes * Make * placeholder * add docs * update note (cherry picked from commit 545f0f80ae1ae7b954e6a26f2cd1fe40436bb696) * Update CHANGELOG.next.asciidoc * Update CHANGELOG.next.asciidoc --------- Co-authored-by: Bharat Pasupula <123897612+bhapas@users.noreply.github.com> --- CHANGELOG.next.asciidoc | 1 + x-pack/filebeat/docs/inputs/input-cel.asciidoc | 3 +++ x-pack/filebeat/docs/inputs/input-httpjson.asciidoc | 3 +++ x-pack/filebeat/input/cel/input.go | 4 ++++ x-pack/filebeat/input/httpjson/input.go | 4 ++++ 5 files changed, 15 insertions(+) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index 98700ce9414e..38be0f82f638 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -43,6 +43,7 @@ https://github.com/elastic/beats/compare/v8.2.0\...main[Check the HEAD diff] *Filebeat* [Gcs Input] - Added missing locks for safe concurrency {pull}34914[34914] +- Add input instance id to request trace filename for httpjson and cel inputs {pull}35037[35037] *Heartbeat* diff --git a/x-pack/filebeat/docs/inputs/input-cel.asciidoc b/x-pack/filebeat/docs/inputs/input-cel.asciidoc index 03859f5281d5..37605964a5b5 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. +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 92fd6d159362..87efc658dc05 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. +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/input/cel/input.go b/x-pack/filebeat/input/cel/input.go index c0648bcfa2a8..b45ff36d0636 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, "*", env.ID) + } + client, err := newClient(ctx, cfg, log) if err != nil { return err diff --git a/x-pack/filebeat/input/httpjson/input.go b/x-pack/filebeat/input/httpjson/input.go index 2abf2d7e7307..c10c2e800986 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, "*", ctx.ID) + } + httpClient, err := newHTTPClient(stdCtx, config, log) if err != nil { return err