Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[filebeat] Fix long filepaths in diagnostics exceeding max path limits on Windows #40909

Merged
2 changes: 2 additions & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,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
3 changes: 2 additions & 1 deletion x-pack/filebeat/input/cel/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -1250,6 +1250,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)) {
//nolint:typecheck,nolintlint // typecheck linter is buggy and thinks rest is not used.
aleksmaus marked this conversation as resolved.
Show resolved Hide resolved
key, rest, more := strings.Cut(path, ".")
v, ok := m[key]
if !ok {
Expand Down
18 changes: 10 additions & 8 deletions x-pack/filebeat/input/cel/input_test.go
aleksmaus marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -448,9 +448,9 @@ var inputTests = []struct {
</item>
</order>
`
io.ReadAll(r.Body)
_, _ = io.ReadAll(r.Body)
r.Body.Close()
w.Write([]byte(text))
_, _ = w.Write([]byte(text))
})
server := httptest.NewServer(r)
config["resource.url"] = server.URL
Expand Down Expand Up @@ -582,7 +582,7 @@ var inputTests = []struct {
msg = fmt.Sprintf(`{"error":"expected method was %#q"}`, http.MethodGet)
}

w.Write([]byte(msg))
_, _ = w.Write([]byte(msg))
},
want: []map[string]interface{}{
{
Expand Down Expand Up @@ -630,7 +630,7 @@ var inputTests = []struct {
msg = fmt.Sprintf(`{"error":"expected method was %#q"}`, http.MethodGet)
}

w.Write([]byte(msg))
_, _ = w.Write([]byte(msg))
},
want: []map[string]interface{}{
{
Expand Down Expand Up @@ -676,7 +676,7 @@ var inputTests = []struct {
msg = fmt.Sprintf(`{"error":"expected method was %#q"}`, http.MethodGet)
}

w.Write([]byte(msg))
_, _ = w.Write([]byte(msg))
},
want: []map[string]interface{}{
{
Expand Down Expand Up @@ -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() {
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
aleksmaus marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
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 Expand Up @@ -478,7 +478,7 @@

next, err := okta.Next(h)
if err != nil {
if err == io.EOF {

Check failure on line 481 in x-pack/filebeat/input/entityanalytics/provider/okta/okta.go

View workflow job for this annotation

GitHub Actions / lint (linux)

comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint)
break
}
p.logger.Debugf("received %d users from API", len(users))
Expand Down Expand Up @@ -588,7 +588,7 @@

next, err := okta.Next(h)
if err != nil {
if err == io.EOF {

Check failure on line 591 in x-pack/filebeat/input/entityanalytics/provider/okta/okta.go

View workflow job for this annotation

GitHub Actions / lint (linux)

comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint)
break
}
p.logger.Debugf("received %d devices from API", len(devices))
Expand Down Expand Up @@ -617,7 +617,7 @@

next, err := okta.Next(h)
if err != nil {
if err == io.EOF {

Check failure on line 620 in x-pack/filebeat/input/entityanalytics/provider/okta/okta.go

View workflow job for this annotation

GitHub Actions / lint (linux)

comparing with == will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint)
break
}
p.logger.Debugf("received %d devices from API", len(devices))
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
11 changes: 6 additions & 5 deletions x-pack/filebeat/input/httpjson/input_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1357,9 +1357,9 @@ var testCases = []struct {
</item>
</order>
`
io.ReadAll(r.Body)
_, _ = io.ReadAll(r.Body)
r.Body.Close()
w.Write([]byte(text))
_, _ = w.Write([]byte(text))
aleksmaus marked this conversation as resolved.
Show resolved Hide resolved
})
server := httptest.NewServer(r)
config["request.url"] = server.URL
Expand Down 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
Loading