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 conditions to decode_json_fields and which pipeline to run #35268

Merged

Conversation

crespocarlos
Copy link
Contributor

@crespocarlos crespocarlos commented May 1, 2023

What does this PR do?

This PR fixes a problem with the ingest pipeline failing to use the correct ingest pipeline when json.keys_under_root is set to true

Why is it important?

The Kibana logs on ECS deployments constantly show field [json] doesn't exist message in error.message field. That happens because cloud deployments automatically set json.keys_under_root to true for versions > 8.0.0 and the pipeline didn't properly cover such scenario after this change

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

  • Start local Kibana and add logging config to kibana.yml
logging:
  appenders:
    console:
      type: console
      layout:
        type: pattern
        highlight: true
    file:
      type: file
      fileName: ./logs/kibana-json.log
      layout:
        type: json
  root:
    appenders: [default, console, file]
    level: debug

Pull this branch and start filebeat from the source https://github.com/elastic/kibana/blob/main/x-pack/plugins/monitoring/dev_docs/how_to/running_components_from_source.md#filebeat

  • On filebeat.yml, enable Kibana module.
- module: kibana
    log:
      enabled: true
      var.paths:
        - PATH_TO_KIBANA_LOG
      input:
        fields:
          ecs.version: "9.0.0" # existing field
          log.level: "TEST" # existing field
          service.name: "Kibana" # new field
          cloud.availability_zone: "danger-zone" # new field
        fields_under_root: true
        json.fields_under_root: true

The ingest pipeline has to properly override the original log content when there are custom field values on filebeat.yml input.fields settings. Therefore, these test scenarios have to work as following :

  • fields_under_root: true and json.fields_under_root: true -> input.fields override original log content
  • fields_under_root: true and json.fields_under_root: false -> input.fields override original log content
  • fields_under_root: false and json.fields_under_root: true -> input.fields override original log content
  • fields_under_root: false and json.fields_under_root: false -> input.fields override original log content
  • Remove input object altogether -> original log content is kept

The fact that json.fields_under_root is true, shouldn't cause error.message field to be present.

image

Related issues

closes #34210

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label May 1, 2023
@mergify
Copy link
Contributor

mergify bot commented May 1, 2023

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @crespocarlos? 🙏.
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-v8./d.0 is the label to automatically backport to the 8./d branch. /d is the digit

@crespocarlos crespocarlos added Team:Infra Monitoring UI - DEPRECATED Infrastructure Monitoring UI team - DEPRECATED - Use Team:Monitoring backport-v8.4.0 Automated backport with mergify backport-v8.5.0 Automated backport with mergify backport-v8.6.0 Automated backport with mergify backport-v8.7.0 Automated backport with mergify backport-v8.8.0 Automated backport with mergify labels May 1, 2023
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label May 1, 2023
@crespocarlos crespocarlos added bug Module:kibana Kibana Beats modules labels May 1, 2023
@crespocarlos crespocarlos changed the title Fix conditions to decode_json_fields and which pipeline to run [Filebeat] Fix conditions to decode_json_fields and which pipeline to run May 1, 2023
@@ -8,7 +8,11 @@ exclude_files: [".gz$"]
processors:
# non-ECS: same as json.keys_under_root: false, allows compatibility with non-ecs logs.
- decode_json_fields:
when:
Copy link
Contributor Author

@crespocarlos crespocarlos May 1, 2023

Choose a reason for hiding this comment

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

Ensure this only runs if it's a json log

@crespocarlos crespocarlos removed backport-v8.4.0 Automated backport with mergify backport-v8.5.0 Automated backport with mergify backport-v8.6.0 Automated backport with mergify labels May 1, 2023
@elasticmachine
Copy link
Collaborator

elasticmachine commented May 1, 2023

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview preview

Expand to view the summary

Build stats

  • Start Time: 2023-05-03T22:55:08.436+0000

  • Duration: 69 min 12 sec

Test stats 🧪

Test Results
Failed 0
Passed 7783
Skipped 749
Total 8532

💚 Flaky test report

Tests succeeded.

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

  • /package : Generate the packages and run the E2E tests.

  • /beats-tester : Run the installation tests with beats-tester.

  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

@crespocarlos
Copy link
Contributor Author

/test

@crespocarlos crespocarlos force-pushed the 34210-kibana-log-pipeline-fix branch from 90d437e to 73431e0 Compare May 1, 2023 23:59
@crespocarlos crespocarlos force-pushed the 34210-kibana-log-pipeline-fix branch from 73431e0 to fa8a313 Compare May 2, 2023 01:19
@crespocarlos crespocarlos marked this pull request as ready for review May 2, 2023 11:40
@crespocarlos crespocarlos requested a review from a team as a code owner May 2, 2023 11:40
@klacabane klacabane self-requested a review May 3, 2023 09:55
@klacabane
Copy link
Contributor

It seems that we don't set the message property anymore when json.fields_under_root is set (either to true or false). Message appears to be ingested without this change, even if error.message exists

@crespocarlos
Copy link
Contributor Author

It seems that we don't set the message property anymore when json.fields_under_root is set (either to true or false). Message appears to be ingested without this change, even if error.message exists

Thanks for catching this. I've managed to fix it and also updated the description with all scenarios that this change covers.

Comment on lines +9 to +20
- script:
lang: painless
if: 'ctx.json != null'
description: Merges filebeat generated fields with ECS log content
source: |-
ctx.json.keySet().each(key -> ctx.merge(key, ctx.json.get(key), (oldValue, newValue) -> {
if (newValue instanceof Map) {
newValue.putAll(oldValue);
}

return newValue;
}))
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This way, the pipeline can properly merge the ECS log content with some fields the Filebeat adds by default (e.g log.offset)

Copy link
Contributor

@klacabane klacabane left a comment

Choose a reason for hiding this comment

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

@crespocarlos walked me through the change offline, looks great thanks!

@crespocarlos crespocarlos merged commit 3ee25d0 into elastic:main May 4, 2023
mergify bot pushed a commit that referenced this pull request May 4, 2023
… run (#35268)

* Fix conditions to decode_json_fields and which pipeline to run

* Fix pipeline condition

* Propery merge ingest log content

(cherry picked from commit 3ee25d0)
mergify bot pushed a commit that referenced this pull request May 4, 2023
… run (#35268)

* Fix conditions to decode_json_fields and which pipeline to run

* Fix pipeline condition

* Propery merge ingest log content

(cherry picked from commit 3ee25d0)
crespocarlos added a commit that referenced this pull request May 8, 2023
… run (#35268) (#35331)

* Fix conditions to decode_json_fields and which pipeline to run

* Fix pipeline condition

* Propery merge ingest log content

(cherry picked from commit 3ee25d0)

Co-authored-by: Carlos Crespo <[email protected]>
crespocarlos added a commit that referenced this pull request May 8, 2023
… run (#35268) (#35332)

* Fix conditions to decode_json_fields and which pipeline to run

* Fix pipeline condition

* Propery merge ingest log content

(cherry picked from commit 3ee25d0)

Co-authored-by: Carlos Crespo <[email protected]>
chrisberkhout pushed a commit that referenced this pull request Jun 1, 2023
… run (#35268)

* Fix conditions to decode_json_fields and which pipeline to run

* Fix pipeline condition

* Propery merge ingest log content
@reakaleek reakaleek mentioned this pull request Jul 19, 2023
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-v8.7.0 Automated backport with mergify backport-v8.8.0 Automated backport with mergify bug Module:kibana Kibana Beats modules Team:Infra Monitoring UI - DEPRECATED Infrastructure Monitoring UI team - DEPRECATED - Use Team:Monitoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Stack Monitoring] Kibana log showing field [json] doesn't exist in error.message field
3 participants