Skip to content

Commit

Permalink
x-pack/filebeat/input/http_endpoint: fix request trace logging file n…
Browse files Browse the repository at this point in the history
…ames

This is a partial backport of #39410 to fix the missing replacement of
"*" with the input ID.
  • Loading branch information
efd6 committed May 22, 2024
1 parent 9768842 commit c139120
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Upgrade azure-event-hubs-go and azure-storage-blob-go dependencies. {pull}38861[38861]
- Fix concurrency/error handling bugs in the AWS S3 input that could drop data and prevent ingestion of large buckets. {pull}39131[39131]
- Fix EntraID query handling. {issue}39419[39419] {pull}39420[39420]
- Expand ID patterns in request trace logger for HTTP Endpoint. {pull}[]

*Heartbeat*

Expand Down
17 changes: 17 additions & 0 deletions x-pack/filebeat/input/http_endpoint/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ import (
"net"
"net/http"
"net/url"
"path/filepath"
"reflect"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -101,13 +103,28 @@ func (e *httpEndpoint) Test(_ v2.TestContext) error {
func (e *httpEndpoint) Run(ctx v2.Context, publisher stateless.Publisher) error {
metrics := newInputMetrics(ctx.ID)
defer metrics.Close()

if e.config.Tracer != nil {
id := sanitizeFileName(ctx.ID)
e.config.Tracer.Filename = strings.ReplaceAll(e.config.Tracer.Filename, "*", id)
}

err := servers.serve(ctx, e, publisher, metrics)
if err != nil && !errors.Is(err, http.ErrServerClosed) {
return fmt.Errorf("unable to start server due to error: %w", err)
}
return nil
}

// sanitizeFileName returns name with ":" and "/" replaced with "_", removing repeated instances.
// The request.tracer.filename may have ":" when a http_endpoint input has cursor config and
// the macOS Finder will treat this as path-separator and causes to show up strange filepaths.
func sanitizeFileName(name string) string {
name = strings.ReplaceAll(name, ":", string(filepath.Separator))
name = filepath.Clean(name)
return strings.ReplaceAll(name, string(filepath.Separator), "_")
}

// servers is the package-level server pool.
var servers = pool{servers: make(map[string]*server)}

Expand Down

0 comments on commit c139120

Please sign in to comment.