Skip to content

Commit

Permalink
[filebeat] Check for duplicate ID for filestream metrics (#35972) (#3…
Browse files Browse the repository at this point in the history
…5987)

- If a duplicate ID was used for filestream, set the ID for metrics
to an empty string to prevent a panic.
- A valid metrics instance will still be generated, but collection of
metrics will not occur.

(cherry picked from commit f7fa407)

Co-authored-by: Taylor Swanson <90622908+taylor-swanson@users.noreply.github.com>
  • Loading branch information
mergify[bot] and taylor-swanson authored Jul 3, 2023
1 parent e4c84f4 commit cbfc78d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ https://github.com/elastic/beats/compare/v8.8.1\...main[Check the HEAD diff]
- Fix CEL input JSON marshalling of nested objects. {issue}35763[35763] {pull}35774[35774]
- Fix metric collection in GCPPubSub input. {pull}35773[35773]
- Fix end point deregistration in http_endpoint input. {issue}35899[35899] {pull}35903[35903]
- Fix duplicate ID panic in filestream metrics. {issue}35964[35964] {pull}35972[35972]

*Heartbeat*

Expand Down
3 changes: 2 additions & 1 deletion filebeat/input/filestream/internal/input-logfile/input.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (

type managedInput struct {
userID string
metricsID string
manager *InputManager
ackCH *updateChan
sourceIdentifier *sourceIdentifier
Expand Down Expand Up @@ -61,7 +62,7 @@ func (inp *managedInput) Run(
defer cancel()
ctx.Cancelation = cancelCtx

metrics := NewMetrics(ctx.ID)
metrics := NewMetrics(inp.metricsID)
defer metrics.Close()

hg := &defaultHarvesterGroup{
Expand Down
6 changes: 5 additions & 1 deletion filebeat/input/filestream/internal/input-logfile/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,13 @@ func (cim *InputManager) Create(config *conf.C) (v2.Input, error) {
" duplication, please add an ID and restart Filebeat")
}

metricsID := settings.ID
cim.idsMux.Lock()
if _, exists := cim.ids[settings.ID]; exists {
cim.Logger.Errorf("filestream input with ID '%s' already exists, this "+
"will lead to data duplication, please use a different ID", settings.ID)
"will lead to data duplication, please use a different ID. Metrics "+
"collection has been disabled on this input.", settings.ID)
metricsID = ""
}

// TODO: improve how inputs with empty IDs are tracked.
Expand Down Expand Up @@ -223,6 +226,7 @@ func (cim *InputManager) Create(config *conf.C) (v2.Input, error) {
manager: cim,
ackCH: cim.ackCH,
userID: settings.ID,
metricsID: metricsID,
prospector: prospector,
harvester: harvester,
sourceIdentifier: sourceIdentifier,
Expand Down

0 comments on commit cbfc78d

Please sign in to comment.