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/inputs/filestream: add metric for messages truncated #41667

Merged
merged 23 commits into from
Dec 31, 2024

Conversation

mauri870
Copy link
Member

@mauri870 mauri870 commented Nov 18, 2024

Proposed commit message

While investigating an SDH, I noticed that although we add the truncated label to log fields, there is no feedback on the amount of messages that are truncated. It often happens that almost all messages are truncated because of a misconfigured input.

This PR adds a input metric that counts the total number of truncated messages.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding change to the default configuration files
  • I have added tests that prove my fix is effective or that my feature works
  • I have added an entry in CHANGELOG.next.asciidoc or CHANGELOG-developer.next.asciidoc.

How to test this PR locally

Create a log file with multiline logs:

cat <<EOF > /tmp/in.log
[beat-logstash-some-name-832-2015.11.28] IndexNotFoundException[no such index]
    at org.elasticsearch.cluster.metadata.IndexNameExpressionResolver\$WildcardExpressionResolver.resolve(IndexNameExpressionResolver.java:566)
    at org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.concreteIndices(IndexNameExpressionResolver.java:133)
    at org.elasticsearch.cluster.metadata.IndexNameExpressionResolver.concreteIndices(IndexNameExpressionResolver.java:77)
    at org.elasticsearch.action.admin.indices.delete.TransportDeleteIndexAction.checkBlock(TransportDeleteIndexAction.java:75)
EOF

Configure filebeat to parse the multiline logs with max_lines:

filebeat.inputs:
- type: filestream
  id: foo-bar
  enabled: true
  paths:
    - "/tmp/in.log"
  parsers:
    - multiline:
        type: pattern
        pattern: '^\['
        negate: true
        match: after
        max_lines: 3

output.discard:
  enabled: true
http.enabled: true

Check the metrics:

$ curl -XGET 'localhost:5066/inputs/' | jq
[
  {
    "bytes_processed_total": 596,
    "events_processed_total": 1,
    "files_active": 1,
    "files_closed_total": 0,
    "files_opened_total": 1,
    "id": "foo-bar",
    "input": "filestream",
    "messages_read_total": 1,
    "messages_truncated_total": 1,
    "processing_errors_total": 0,
    "processing_time": {
      "histogram": {
        "count": 1,
        "max": 5000516503,
        "mean": 5000516503,
        "median": 5000516503,
        "min": 5000516503,
        "p75": 5000516503,
        "p95": 5000516503,
        "p99": 5000516503,
        "p999": 5000516503,
        "stddev": 0
      }
    }
  }
]

Related issues

@mauri870 mauri870 self-assigned this Nov 18, 2024
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Nov 18, 2024
Copy link
Contributor

mergify bot commented Nov 18, 2024

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @mauri870? 🙏.
For such, you'll need to label your PR with:

  • The upcoming major version of the Elastic Stack
  • The upcoming minor version of the Elastic Stack (if you're not pushing a breaking change)

To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit

Copy link
Contributor

mergify bot commented Nov 18, 2024

backport-8.x has been added to help with the transition to the new branch 8.x.
If you don't need it please use backport-skip label and remove the backport-8.x label.

@mergify mergify bot added the backport-8.x Automated backport to the 8.x branch with mergify label Nov 18, 2024
@mauri870 mauri870 added Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team and removed needs_team Indicates that the issue/PR needs a Team:* label labels Nov 18, 2024
@mauri870 mauri870 marked this pull request as ready for review November 18, 2024 17:41
@mauri870 mauri870 requested a review from a team as a code owner November 18, 2024 17:41
@elasticmachine
Copy link
Collaborator

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

@pierrehilbert pierrehilbert requested review from belimawr and removed request for khushijain21 November 18, 2024 18:06
@mauri870 mauri870 force-pushed the filebeat-multine-trunc-log branch from 126fd1e to ed485a4 Compare November 18, 2024 18:07
Copy link
Contributor

@belimawr belimawr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. I didn't have time to test it today, but the code is pretty simple. If it has not been merged by tomorrow morning, I'll test it.

@mauri870 mauri870 marked this pull request as draft November 19, 2024 11:00
@mauri870 mauri870 marked this pull request as ready for review November 29, 2024 16:05
@mauri870 mauri870 marked this pull request as draft December 3, 2024 17:04
@mauri870 mauri870 force-pushed the filebeat-multine-trunc-log branch 2 times, most recently from e4a16c7 to d125a58 Compare December 13, 2024 14:00
@mauri870 mauri870 changed the title filebeat: log when multiline reader truncates messages filebeat/inputs/filestream: add metric for messages truncated Dec 13, 2024
@mauri870 mauri870 marked this pull request as ready for review December 13, 2024 16:56
@mauri870 mauri870 requested a review from a team as a code owner December 13, 2024 16:56
@mauri870 mauri870 requested review from cmacknz and belimawr December 13, 2024 16:58
Copy link
Contributor

@belimawr belimawr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good, but I'm not managing to test it... Filebeat won't start.

Here is the full filebeat.yml I'm using:

filebeat.inputs:
- type: filestream
  id: foo-bar
  enabled: true
  paths:
    - "/tmp/flog.log"
  parsers:
    - multiline:
        type: pattern
        pattern: '^LINESTART$"),'
        negate: true
        match: after
        max_bytes: 20

output.discard:
  enabled: true
http.enabled: true

Whenever I run, I get the following error:

Exiting: Failed to start crawler: starting input failed: error while initializing input: error while parsing multiline parser config: error parsing regexp: unexpected ): `^LINESTART$"),` accessing 'filebeat.inputs.0.parsers.0.multiline.pattern' (source:'filebeat.yml') accessing 'filebeat.inputs.0' (source:'filebeat.yml')
exit status 1

@mauri870 mauri870 force-pushed the filebeat-multine-trunc-log branch from d192597 to 37720bf Compare December 17, 2024 20:14
@cmacknz
Copy link
Member

cmacknz commented Dec 17, 2024

One thing I found interesting is that curl localhost:5066/inputs does not work, it needs a trailing slash (inputs/), is that expected?

Probably not an intentional omission

Edit: if /inputs/ is the listing of inputs it might be intentional in that it behaves more like a directory listing.

@mauri870
Copy link
Member Author

Edit: if /inputs/ is the listing of inputs it might be intentional in that it behaves more like a directory listing.

It is a bit counter intuitive when thinking about REST but it makes sense if it is supposed to be a directory listing. The docs also use /inputs/ so it is probably deliberate.

@mauri870 mauri870 requested a review from rdner December 19, 2024 11:39
Copy link
Contributor

mergify bot commented Dec 19, 2024

This pull request is now in conflicts. Could you fix it? 🙏
To fixup this pull request, you can check out it locally. See documentation: https://help.github.com/articles/checking-out-pull-requests-locally/

git fetch upstream
git checkout -b filebeat-multine-trunc-log upstream/filebeat-multine-trunc-log
git merge upstream/main
git push upstream filebeat-multine-trunc-log

@mauri870
Copy link
Member Author

/test

@mauri870
Copy link
Member Author

mauri870 commented Dec 24, 2024

For some reason, the linter is failing and pointing out issues in the metricbeat mongo module. I don't plan to modify these files to avoid introducing additional linting problems.

@mauri870
Copy link
Member Author

@elastic/obs-infraobs-integrations Kindly requesting a review. Thank you!

@mauri870 mauri870 enabled auto-merge (squash) December 24, 2024 11:05
@jlind23
Copy link
Collaborator

jlind23 commented Dec 30, 2024

@lalit-satapathy @devamanv can we get someone's eyes on this please?

@lalit-satapathy
Copy link
Contributor

@lalit-satapathy @devamanv can we get someone's eyes on this please?

@ishleenk17 will be taking a look.

@ishleenk17
Copy link
Contributor

For some reason, the linter is failing and pointing out issues in the metricbeat mongo module. I don't plan to modify these files to avoid introducing additional linting problems.

Why has the mongdb module been touched for this change? @mauri870
If you are doing that for the linter errors, you can ignore that.
Our team will take care of it in any corresponding mongod module related change.

@mauri870
Copy link
Member Author

Why has the mongdb module been touched for this change?

Thanks, I forgot I had this small change for the struct annotations, I just reverted it.

@mauri870 mauri870 merged commit 7806f1a into elastic:main Dec 31, 2024
142 checks passed
mergify bot pushed a commit that referenced this pull request Dec 31, 2024
* filebeat: log when multiline reader truncates messages

While investigating an SDH, I noticed that although we add the truncated label
to log fields, there is no feedback explaining why the messages were
truncated.

This PR adds a log statement to provide insight whenever multiline messages
are truncated.

(cherry picked from commit 7806f1a)

# Conflicts:
#	filebeat/input/filestream/metrics_integration_test.go
mauri870 added a commit that referenced this pull request Dec 31, 2024
…sages truncated (#42185)

* filebeat/inputs/filestream: add metric for messages truncated (#41667)

* filebeat: log when multiline reader truncates messages

While investigating an SDH, I noticed that although we add the truncated label
to log fields, there is no feedback explaining why the messages were
truncated.

This PR adds a log statement to provide insight whenever multiline messages
are truncated.

(cherry picked from commit 7806f1a)

# Conflicts:
#	filebeat/input/filestream/metrics_integration_test.go

* fix conflicts

---------

Co-authored-by: Mauri de Souza Meneguzzo <mauri870@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-8.x Automated backport to the 8.x branch with mergify cleanup Team:Elastic-Agent-Data-Plane Label for the Agent Data Plane team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants