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

Handle the edge case when several globs in Filebeat path match #36253

Closed
rdner opened this issue Aug 7, 2023 · 1 comment · Fixed by #36256
Closed

Handle the edge case when several globs in Filebeat path match #36253

rdner opened this issue Aug 7, 2023 · 1 comment · Fixed by #36256
Assignees
Labels
bug Filebeat Filebeat Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team

Comments

@rdner
Copy link
Member

rdner commented Aug 7, 2023

Currently we can have a lot of log message at warn level produced by this

if knownFilename, exists := uniqueIDs[fileID]; exists {
s.log.Warnf("%q points to an already known ingest target %q [%s==%s]. Skipping", fd.Filename, knownFilename, fileID, fileID)
continue
}

This check is supposed to protect from having symlinks resolved to the same files that are being already ingested by Filebeat.

Seems like it's triggered not just by symlinks but also by duplicate path entries.

For example, monitoring in Elastic Agent has 2 globs and one of them is a superset of another:

https://github.com/elastic/elastic-agent/blob/dfd9554406f581660747663d15476c636095fa20/internal/pkg/agent/application/monitoring/v1_monitor.go#L301-L304

This causes flood of warning messages when Elastic Agent monitoring is enabled:

{
  "log.level": "warn",
  "@timestamp": "2023-08-07T16:44:03.445Z",
  "message": "\"/opt/Elastic/Agent/data/elastic-agent-0790a4/logs/elastic-agent-watcher-20230807.ndjson\" points to an already known ingest target \"/opt/Elastic/Agent/data/elastic-agent-0790a4/logs/elastic-agent-watcher-20230807.ndjson\" [1298191-66305==1298191-66305]. Skipping",
  "component": {
    "binary": "filebeat",
    "dataset": "elastic_agent.filebeat",
    "id": "filestream-monitoring",
    "type": "filestream"
  },
  "log": {
    "source": "filestream-monitoring"
  },
  "service.name": "filebeat",
  "ecs.version": "1.6.0",
  "log.logger": "scanner",
  "log.origin": {
    "file.line": 383,
    "file.name": "filestream/fswatch.go"
  }
}
{
  "log.level": "warn",
  "@timestamp": "2023-08-07T16:44:13.445Z",
  "message": "\"/opt/Elastic/Agent/data/elastic-agent-0790a4/logs/elastic-agent-watcher-20230807-1.ndjson\" points to an already known ingest target \"/opt/Elastic/Agent/data/elastic-agent-0790a4/logs/elastic-agent-watcher-20230807-1.ndjson\" [1298202-66305==1298202-66305]. Skipping",
  "component": {
    "binary": "filebeat",
    "dataset": "elastic_agent.filebeat",
    "id": "filestream-monitoring",
    "type": "filestream"
  },
  "log": {
    "source": "filestream-monitoring"
  },
  "log.logger": "scanner",
  "log.origin": {
    "file.line": 383,
    "file.name": "filestream/fswatch.go"
  },
  "service.name": "filebeat",
  "ecs.version": "1.6.0"
}
{
  "log.level": "warn",
  "@timestamp": "2023-08-07T16:44:13.445Z",
  "message": "\"/opt/Elastic/Agent/data/elastic-agent-0790a4/logs/elastic-agent-watcher-20230807.ndjson\" points to an already known ingest target \"/opt/Elastic/Agent/data/elastic-agent-0790a4/logs/elastic-agent-watcher-20230807.ndjson\" [1298191-66305==1298191-66305]. Skipping",
  "component": {
    "binary": "filebeat",
    "dataset": "elastic_agent.filebeat",
    "id": "filestream-monitoring",
    "type": "filestream"
  },
  "log": {
    "source": "filestream-monitoring"
  },
  "log.logger": "scanner",
  "log.origin": {
    "file.line": 383,
    "file.name": "filestream/fswatch.go"
  },
  "service.name": "filebeat",
  "ecs.version": "1.6.0"
}
{
  "log.level": "warn",
  "@timestamp": "2023-08-07T16:44:23.445Z",
  "message": "\"/opt/Elastic/Agent/data/elastic-agent-0790a4/logs/elastic-agent-watcher-20230807-1.ndjson\" points to an already known ingest target \"/opt/Elastic/Agent/data/elastic-agent-0790a4/logs/elastic-agent-watcher-20230807-1.ndjson\" [1298202-66305==1298202-66305]. Skipping",
  "component": {
    "binary": "filebeat",
    "dataset": "elastic_agent.filebeat",
    "id": "filestream-monitoring",
    "type": "filestream"
  },
  "log": {
    "source": "filestream-monitoring"
  },
  "log.origin": {
    "file.line": 383,
    "file.name": "filestream/fswatch.go"
  },
  "service.name": "filebeat",
  "ecs.version": "1.6.0",
  "log.logger": "scanner"
}
{
  "log.level": "warn",
  "@timestamp": "2023-08-07T16:44:23.445Z",
  "message": "\"/opt/Elastic/Agent/data/elastic-agent-0790a4/logs/elastic-agent-watcher-20230807.ndjson\" points to an already known ingest target \"/opt/Elastic/Agent/data/elastic-agent-0790a4/logs/elastic-agent-watcher-20230807.ndjson\" [1298191-66305==1298191-66305]. Skipping",
  "component": {
    "binary": "filebeat",
    "dataset": "elastic_agent.filebeat",
    "id": "filestream-monitoring",
    "type": "filestream"
  },
  "log": {
    "source": "filestream-monitoring"
  },
  "log.logger": "scanner",
  "log.origin": {
    "file.line": 383,
    "file.name": "filestream/fswatch.go"
  },
  "service.name": "filebeat",
  "ecs.version": "1.6.0"
}

This might be due to https://pkg.go.dev/path/filepath@go1.20.7#Glob returning duplicate entries (subject to testing).

We should log warning ONLY in the symlink edge case, duplicate paths from Glob should be filtered out. New test case must be introduced.

@rdner rdner added bug Filebeat Filebeat labels Aug 7, 2023
@rdner rdner self-assigned this Aug 7, 2023
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Aug 7, 2023
@rdner rdner added the Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team label Aug 7, 2023
@elasticmachine
Copy link
Collaborator

Pinging @elastic/elastic-agent-data-plane (Team:Elastic-Agent-Data-Plane)

@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Aug 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Filebeat Filebeat Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants