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

Fix httpjson split issue on empty root array #32001

Merged
merged 8 commits into from
Sep 15, 2022

Conversation

kcreddy
Copy link
Contributor

@kcreddy kcreddy commented Jun 21, 2022

What does this PR do?

Fix httpjson split issue on empty root array. This fix publishes the event with key in case of empty root array

Why is it important?

This is a bug fix on filebeat httpjson input where no event is being published when splitting empty root array. The desired outcome is to publish event with array.

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 change to the default configuration files
  • I have made corresponding changes to the documentation
  • 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

cd x-pack/filebeat/input/httpjson; go test -v -run TestSplit

=== RUN   TestSplit
=== RUN   TestSplit/Two_nested_Split_Arrays_with_keep_parent
=== RUN   TestSplit/A_nested_array_with_a_nested_map
=== RUN   TestSplit/A_nested_array_with_a_nested_map_with_transforms
=== RUN   TestSplit/A_nested_array_with_a_nested_array_in_an_object
=== RUN   TestSplit/A_nested_array_with_an_empty_nested_array_in_an_object_publishes_without_the_key
=== RUN   TestSplit/First_level_split_publishes_with_key_if_no_events
=== RUN   TestSplit/Changes_must_be_local_to_parent_when_nested_splits
=== RUN   TestSplit/Split_string
=== RUN   TestSplit/An_empty_array_in_an_object
=== RUN   TestSplit/A_missing_array_in_an_object
=== RUN   TestSplit/An_empty_map_in_an_object
=== RUN   TestSplit/A_missing_map_in_an_object
=== RUN   TestSplit/An_empty_string
=== RUN   TestSplit/A_missing_string
--- PASS: TestSplit (0.00s)
    --- PASS: TestSplit/Two_nested_Split_Arrays_with_keep_parent (0.00s)
    --- PASS: TestSplit/A_nested_array_with_a_nested_map (0.00s)
    --- PASS: TestSplit/A_nested_array_with_a_nested_map_with_transforms (0.00s)
    --- PASS: TestSplit/A_nested_array_with_a_nested_array_in_an_object (0.00s)
    --- PASS: TestSplit/A_nested_array_with_an_empty_nested_array_in_an_object_publishes_without_the_key (0.00s)
    --- PASS: TestSplit/First_level_split_publishes_with_key_if_no_events (0.00s)
    --- PASS: TestSplit/Changes_must_be_local_to_parent_when_nested_splits (0.00s)
    --- PASS: TestSplit/Split_string (0.00s)
    --- PASS: TestSplit/An_empty_array_in_an_object (0.00s)
    --- PASS: TestSplit/A_missing_array_in_an_object (0.00s)
    --- PASS: TestSplit/An_empty_map_in_an_object (0.00s)
    --- PASS: TestSplit/A_missing_map_in_an_object (0.00s)
    --- PASS: TestSplit/An_empty_string (0.00s)
    --- PASS: TestSplit/A_missing_string (0.00s)
PASS
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/httpjson      0.289s

Related issues

@elasticmachine
Copy link
Collaborator

Pinging @elastic/security-external-integrations (Team:Security-External Integrations)

@botelastic botelastic bot added needs_team Indicates that the issue/PR needs a Team:* label and removed needs_team Indicates that the issue/PR needs a Team:* label labels Jun 21, 2022
@kcreddy kcreddy requested a review from marc-gr June 21, 2022 05:36
@elasticmachine
Copy link
Collaborator

elasticmachine commented Jun 21, 2022

💚 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: 2022-09-15T08:57:39.478+0000

  • Duration: 72 min 37 sec

Test stats 🧪

Test Results
Failed 0
Passed 2237
Skipped 166
Total 2403

💚 Flaky test report

Tests succeeded.

🤖 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!)

Copy link
Contributor

@efd6 efd6 left a comment

Choose a reason for hiding this comment

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

This should have a line in CHANGELOG.next.asciidoc and probably wants a backport to the relevant versions.

@P1llus
Copy link
Member

P1llus commented Jun 22, 2022

@marc-gr does this only need to be applied for split on Array, or also on map/string?

@mergify
Copy link
Contributor

mergify bot commented Jun 23, 2022

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 httpjson_split_empty_root_arr upstream/httpjson_split_empty_root_arr
git merge upstream/main
git push upstream httpjson_split_empty_root_arr

@mergify
Copy link
Contributor

mergify bot commented Jun 28, 2022

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 httpjson_split_empty_root_arr upstream/httpjson_split_empty_root_arr
git merge upstream/main
git push upstream httpjson_split_empty_root_arr

@kcreddy kcreddy added backport-v8.3.0 Automated backport with mergify backport-7.17 Automated backport to the 7.17 branch with mergify labels Jul 4, 2022
@mergify
Copy link
Contributor

mergify bot commented Jul 5, 2022

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 httpjson_split_empty_root_arr upstream/httpjson_split_empty_root_arr
git merge upstream/main
git push upstream httpjson_split_empty_root_arr

@mergify
Copy link
Contributor

mergify bot commented Jul 11, 2022

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 httpjson_split_empty_root_arr upstream/httpjson_split_empty_root_arr
git merge upstream/main
git push upstream httpjson_split_empty_root_arr

@ShourieG
Copy link
Contributor

@kcreddy , please resolve the conflict , otherwise LGTM

Comment on lines 48 to 58
- Do not emit error log when filestream reader reaches EOF and `close.reader.on_eof` is enabled. {pull}31109[31109]
- sophos.xg: Update module to handle new log fields. {issue}31038[31038] {pull}31388[31388]
- Fix MISP documentation for `var.filters` config option. {pull}31434[31434]
- Fix type mapping of client.as.number in okta module. {pull}31676[31676]
- Fix handling of empty array in httpjson input. {pull}32001[32001]
- Fix last write pagination commit checkpoint on `aws-s3` input for s3 direct polling when using the same bucket and different list prefixes. {pull}31776[31776]
- If a file is ignored by `filestream` because of ignore_older settings, when it is updated, only the new lines are shipped to the output. {issue}31924[31924] {pull}31972[31972]
- Adding a fix for threatintel module where MISP was paginating forever. {pull}31784[31784]xs
- Fix deduplication in Google workspace module by changing fingerprint processor target field from `@metadata.id` to `@metadata._id`. {pull}31898[31898]
- Fix handling and mapping of syslog priority, facility and severity values in Cisco module. {pull}32025[32025]
- Fix http_endpoint input TLS handshake failures. {pull}32105[32105]
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- Do not emit error log when filestream reader reaches EOF and `close.reader.on_eof` is enabled. {pull}31109[31109]
- sophos.xg: Update module to handle new log fields. {issue}31038[31038] {pull}31388[31388]
- Fix MISP documentation for `var.filters` config option. {pull}31434[31434]
- Fix type mapping of client.as.number in okta module. {pull}31676[31676]
- Fix handling of empty array in httpjson input. {pull}32001[32001]
- Fix last write pagination commit checkpoint on `aws-s3` input for s3 direct polling when using the same bucket and different list prefixes. {pull}31776[31776]
- If a file is ignored by `filestream` because of ignore_older settings, when it is updated, only the new lines are shipped to the output. {issue}31924[31924] {pull}31972[31972]
- Adding a fix for threatintel module where MISP was paginating forever. {pull}31784[31784]xs
- Fix deduplication in Google workspace module by changing fingerprint processor target field from `@metadata.id` to `@metadata._id`. {pull}31898[31898]
- Fix handling and mapping of syslog priority, facility and severity values in Cisco module. {pull}32025[32025]
- Fix http_endpoint input TLS handshake failures. {pull}32105[32105]
- Fix handling of empty array in httpjson input. {pull}32001[32001]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added the line at the end

@andrewkroh
Copy link
Member

Other than the changelog conflicts, does this need anything else before merging? @kcreddy

@andrewkroh andrewkroh added backport-v8.4.0 Automated backport with mergify and removed backport-v8.3.0 Automated backport with mergify labels Sep 13, 2022
@kcreddy
Copy link
Contributor Author

kcreddy commented Sep 13, 2022

@andrewkroh Sorry my bad, I thought this was merged long back. Resolved merge conflicts. This can be merged once approved

@kcreddy kcreddy requested a review from efd6 September 14, 2022 09:41
Copy link
Contributor

@ShourieG ShourieG left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@efd6 efd6 left a comment

Choose a reason for hiding this comment

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

LGTM after changelog is fixed.

CHANGELOG.next.asciidoc Outdated Show resolved Hide resolved
@kcreddy kcreddy merged commit 0334634 into elastic:main Sep 15, 2022
mergify bot pushed a commit that referenced this pull request Sep 15, 2022
* Fix httpjson split issue on empty root arrayPublish events

* update asciidoc

* update changelog

* remove old lines

(cherry picked from commit 0334634)

# Conflicts:
#	x-pack/filebeat/input/httpjson/split.go
#	x-pack/filebeat/input/httpjson/split_test.go
mergify bot pushed a commit that referenced this pull request Sep 15, 2022
* Fix httpjson split issue on empty root arrayPublish events

* update asciidoc

* update changelog

* remove old lines

(cherry picked from commit 0334634)
kcreddy added a commit that referenced this pull request Sep 20, 2022
* Fix httpjson split issue on empty root arrayPublish events

* update asciidoc

* update changelog

* remove old lines

(cherry picked from commit 0334634)

Co-authored-by: Krishna Chaitanya Reddy Burri <krish.reddy91@gmail.com>
kcreddy added a commit that referenced this pull request Sep 21, 2022
…33102)

* Fix httpjson split issue on empty root array (#32001)

* Fix httpjson split issue on empty root arrayPublish events

* update asciidoc

* update changelog

* remove old lines

(cherry picked from commit 0334634)

# Conflicts:
#	x-pack/filebeat/input/httpjson/split.go
#	x-pack/filebeat/input/httpjson/split_test.go

* move to internal/v2

* remove as duplicated in internal/v2

* linting error never wrapped

Co-authored-by: Krishna Chaitanya Reddy Burri <krish.reddy91@gmail.com>
chrisberkhout pushed a commit that referenced this pull request Jun 1, 2023
* Fix httpjson split issue on empty root arrayPublish events

* update asciidoc

* update changelog

* remove old lines
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-7.17 Automated backport to the 7.17 branch with mergify backport-v8.4.0 Automated backport with mergify bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Filebeat httpjson cursor not saved when splitting on empty array.
7 participants