Skip to content

Commit

Permalink
Revert "Revert "[filebeat] Fix long filepaths in diagnostics exceedin…
Browse files Browse the repository at this point in the history
…g max pa…" (#40996)

This reverts commit dbbfb5b.
  • Loading branch information
ycombinator authored Sep 26, 2024
1 parent 07360ca commit 138e43c
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 11 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,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*

Expand Down
1 change: 1 addition & 0 deletions filebeat/input/v2/compat/compat.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions filebeat/input/v2/input-cursor/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
4 changes: 4 additions & 0 deletions filebeat/input/v2/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion x-pack/filebeat/input/cel/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,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)
}

Expand Down
8 changes: 5 additions & 3 deletions x-pack/filebeat/input/cel/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1740,10 +1740,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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion x-pack/filebeat/input/http_endpoint/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down
2 changes: 1 addition & 1 deletion x-pack/filebeat/input/httpjson/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
7 changes: 4 additions & 3 deletions x-pack/filebeat/input/httpjson/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 138e43c

Please sign in to comment.