From accea5469c2a512c5d53910b0c51deb75f0e550f Mon Sep 17 00:00:00 2001 From: Shaunak Kashyap Date: Thu, 26 Sep 2024 07:26:23 -0700 Subject: [PATCH] =?UTF-8?q?Revert=20"Revert=20"[filebeat]=20Fix=20long=20f?= =?UTF-8?q?ilepaths=20in=20diagnostics=20exceeding=20max=20pa=E2=80=A6"=20?= =?UTF-8?q?(#40996)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit dbbfb5ba581bb8127417bb080bede3ab7a7a9b66. (cherry picked from commit 138e43cad7eda93c1414641682056b6c88efcf1d) --- CHANGELOG.next.asciidoc | 2 ++ filebeat/input/v2/compat/compat.go | 1 + filebeat/input/v2/input-cursor/input.go | 2 ++ filebeat/input/v2/input.go | 4 ++++ x-pack/filebeat/input/cel/input.go | 2 +- x-pack/filebeat/input/cel/input_test.go | 8 +++++--- .../filebeat/input/entityanalytics/provider/jamf/jamf.go | 2 +- .../filebeat/input/entityanalytics/provider/okta/okta.go | 2 +- x-pack/filebeat/input/http_endpoint/input.go | 2 +- x-pack/filebeat/input/httpjson/input.go | 2 +- x-pack/filebeat/input/httpjson/input_test.go | 7 ++++--- 11 files changed, 23 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.next.asciidoc b/CHANGELOG.next.asciidoc index e5df9167b8d..a4fd8abc951 100644 --- a/CHANGELOG.next.asciidoc +++ b/CHANGELOG.next.asciidoc @@ -169,6 +169,8 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff] - Fix publication of group data from the Okta entity analytics provider. {pull}40681[40681] - Ensure netflow custom field configuration is applied. {issue}40735[40735] {pull}40730[40730] - Fix replace processor handling of zero string replacement validation. {pull}40751[40751] +- Fix long filepaths in diagnostics exceeding max path limits on Windows. {pull}40909[40909] + *Heartbeat* diff --git a/filebeat/input/v2/compat/compat.go b/filebeat/input/v2/compat/compat.go index d84c9e39bfd..416b6628e19 100644 --- a/filebeat/input/v2/compat/compat.go +++ b/filebeat/input/v2/compat/compat.go @@ -128,6 +128,7 @@ func (r *runner) Start() { err := r.input.Run( v2.Context{ ID: r.id, + IDWithoutName: r.id, Agent: *r.agent, Logger: log, Cancelation: r.sig, diff --git a/filebeat/input/v2/input-cursor/input.go b/filebeat/input/v2/input-cursor/input.go index c1d4cec0762..547c7721c3b 100644 --- a/filebeat/input/v2/input-cursor/input.go +++ b/filebeat/input/v2/input-cursor/input.go @@ -115,6 +115,8 @@ func (inp *managedInput) Run( grp.Go(func() (err error) { // refine per worker context inpCtx := ctx + // Preserve IDWithoutName, in case the context was constructed who knows how + inpCtx.IDWithoutName = ctx.ID inpCtx.ID = ctx.ID + "::" + source.Name() inpCtx.Logger = ctx.Logger.With("input_source", source.Name()) diff --git a/filebeat/input/v2/input.go b/filebeat/input/v2/input.go index 9b78bc427ae..f62cc149a93 100644 --- a/filebeat/input/v2/input.go +++ b/filebeat/input/v2/input.go @@ -79,6 +79,10 @@ type Context struct { // The input ID. ID string + // The input ID without name. Some inputs append sourcename, we need the id to be untouched + // https://github.com/elastic/beats/blob/43d80af2aea60b0c45711475d114e118d90c4581/filebeat/input/v2/input-cursor/input.go#L118 + IDWithoutName string + // Agent provides additional Beat info like instance ID or beat name. Agent beat.Info diff --git a/x-pack/filebeat/input/cel/input.go b/x-pack/filebeat/input/cel/input.go index 466950836ee..10b87447b06 100644 --- a/x-pack/filebeat/input/cel/input.go +++ b/x-pack/filebeat/input/cel/input.go @@ -142,7 +142,7 @@ func (i input) run(env v2.Context, src *source, cursor map[string]interface{}, p ctx := ctxtool.FromCanceller(env.Cancelation) if cfg.Resource.Tracer != nil { - id := sanitizeFileName(env.ID) + id := sanitizeFileName(env.IDWithoutName) cfg.Resource.Tracer.Filename = strings.ReplaceAll(cfg.Resource.Tracer.Filename, "*", id) } diff --git a/x-pack/filebeat/input/cel/input_test.go b/x-pack/filebeat/input/cel/input_test.go index 6ef9dcbc824..02daa1148d7 100644 --- a/x-pack/filebeat/input/cel/input_test.go +++ b/x-pack/filebeat/input/cel/input_test.go @@ -1690,10 +1690,12 @@ func TestInput(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() + id := "test_id:" + test.name v2Ctx := v2.Context{ - Logger: logp.NewLogger("cel_test"), - ID: "test_id:" + test.name, - Cancelation: ctx, + Logger: logp.NewLogger("cel_test"), + ID: id, + IDWithoutName: id, + Cancelation: ctx, } var client publisher client.done = func() { diff --git a/x-pack/filebeat/input/entityanalytics/provider/jamf/jamf.go b/x-pack/filebeat/input/entityanalytics/provider/jamf/jamf.go index 0affa5b553d..8534187f6ac 100644 --- a/x-pack/filebeat/input/entityanalytics/provider/jamf/jamf.go +++ b/x-pack/filebeat/input/entityanalytics/provider/jamf/jamf.go @@ -109,7 +109,7 @@ func (p *jamfInput) Run(inputCtx v2.Context, store *kvstore.Store, client beat.C updateTimer := time.NewTimer(updateWaitTime) if p.cfg.Tracer != nil { - id := sanitizeFileName(inputCtx.ID) + id := sanitizeFileName(inputCtx.IDWithoutName) p.cfg.Tracer.Filename = strings.ReplaceAll(p.cfg.Tracer.Filename, "*", id) } diff --git a/x-pack/filebeat/input/entityanalytics/provider/okta/okta.go b/x-pack/filebeat/input/entityanalytics/provider/okta/okta.go index 70f9a8f3a55..404f069a7ec 100644 --- a/x-pack/filebeat/input/entityanalytics/provider/okta/okta.go +++ b/x-pack/filebeat/input/entityanalytics/provider/okta/okta.go @@ -113,7 +113,7 @@ func (p *oktaInput) Run(inputCtx v2.Context, store *kvstore.Store, client beat.C p.lim = rate.NewLimiter(1, 1) if p.cfg.Tracer != nil { - id := sanitizeFileName(inputCtx.ID) + id := sanitizeFileName(inputCtx.IDWithoutName) p.cfg.Tracer.Filename = strings.ReplaceAll(p.cfg.Tracer.Filename, "*", id) } diff --git a/x-pack/filebeat/input/http_endpoint/input.go b/x-pack/filebeat/input/http_endpoint/input.go index 43adfa0b469..b4ad07e7626 100644 --- a/x-pack/filebeat/input/http_endpoint/input.go +++ b/x-pack/filebeat/input/http_endpoint/input.go @@ -108,7 +108,7 @@ func (e *httpEndpoint) Run(ctx v2.Context, pipeline beat.Pipeline) error { defer metrics.Close() if e.config.Tracer != nil { - id := sanitizeFileName(ctx.ID) + id := sanitizeFileName(ctx.IDWithoutName) e.config.Tracer.Filename = strings.ReplaceAll(e.config.Tracer.Filename, "*", id) } diff --git a/x-pack/filebeat/input/httpjson/input.go b/x-pack/filebeat/input/httpjson/input.go index 67daa7ef849..ad61aceff89 100644 --- a/x-pack/filebeat/input/httpjson/input.go +++ b/x-pack/filebeat/input/httpjson/input.go @@ -123,7 +123,7 @@ func run(ctx v2.Context, cfg config, pub inputcursor.Publisher, crsr *inputcurso stdCtx := ctxtool.FromCanceller(ctx.Cancelation) if cfg.Request.Tracer != nil { - id := sanitizeFileName(ctx.ID) + id := sanitizeFileName(ctx.IDWithoutName) cfg.Request.Tracer.Filename = strings.ReplaceAll(cfg.Request.Tracer.Filename, "*", id) // Propagate tracer behaviour to all chain children. diff --git a/x-pack/filebeat/input/httpjson/input_test.go b/x-pack/filebeat/input/httpjson/input_test.go index dac538b54dd..4f09d8f057f 100644 --- a/x-pack/filebeat/input/httpjson/input_test.go +++ b/x-pack/filebeat/input/httpjson/input_test.go @@ -1660,9 +1660,10 @@ func newChainPaginationTestServer( func newV2Context(id string) (v2.Context, func()) { ctx, cancel := context.WithCancel(context.Background()) return v2.Context{ - Logger: logp.NewLogger("httpjson_test"), - ID: id, - Cancelation: ctx, + Logger: logp.NewLogger("httpjson_test"), + ID: id, + IDWithoutName: id, + Cancelation: ctx, }, cancel }