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

x-pack/filebeat/input/httpjson: make sure interval data clearing happens before processing #30730

Merged
merged 1 commit into from
Mar 29, 2022

Conversation

efd6
Copy link
Contributor

@efd6 efd6 commented Mar 8, 2022

What does this PR do?

This change ensures that request interval data is not cleared after a request has begun.

Why is it important?

Although extremely unlikely, there is otherwise no happens before relationship between the clearing of request interval data and the processing of the obtained data. If the interval data has been cleared during a request, spurious default first and last event, and last response values in the transform context can be set in the resulting published event.

The conditions for this to happen are that the request manages to progress at least one page of the pagination iterator before the call to trCtx.clearIntervalData() can complete. The chances of this happening are vanishingly small. However...

[2022-02-27T03:07:14.640Z] === Failed
[2022-02-27T03:07:14.640Z] === FAIL: x-pack/filebeat/input/httpjson TestInput/Test_first_event (2.02s)
[2022-02-27T03:07:14.640Z]     input_test.go:441: 
[2022-02-27T03:07:14.640Z]         	Error Trace:	input_test.go:441
[2022-02-27T03:07:14.640Z]         	Error:      	Not equal: 
[2022-02-27T03:07:14.640Z]         	            	expected: map[string]interface {}{"first":"a", "foo":"b"}
[2022-02-27T03:07:14.640Z]         	            	actual  : map[string]interface {}{"first":"none", "foo":"b"}
[2022-02-27T03:07:14.640Z]         	            	
[2022-02-27T03:07:14.640Z]         	            	Diff:
[2022-02-27T03:07:14.640Z]         	            	--- Expected
[2022-02-27T03:07:14.640Z]         	            	+++ Actual
[2022-02-27T03:07:14.640Z]         	            	@@ -1,3 +1,3 @@
[2022-02-27T03:07:14.640Z]         	            	 (map[string]interface {}) (len=2) {
[2022-02-27T03:07:14.640Z]         	            	- (string) (len=5) "first": (string) (len=1) "a",
[2022-02-27T03:07:14.640Z]         	            	+ (string) (len=5) "first": (string) (len=4) "none",
[2022-02-27T03:07:14.640Z]         	            	  (string) (len=3) "foo": (string) (len=1) "b"
[2022-02-27T03:07:14.640Z]         	Test:       	TestInput/Test_first_event
[2022-02-27T03:07:14.640Z]     --- FAIL: TestInput/Test_first_event (2.02s)
[2022-02-27T03:07:14.640Z] 
[2022-02-27T03:07:14.640Z] === FAIL: x-pack/filebeat/input/httpjson TestInput (7.20s)
[2022-02-27T03:07:14.640Z] 
[2022-02-27T03:07:14.640Z] DONE 801 tests, 7 skipped, 2 failures in 189.135s
[2022-02-27T03:07:14.640Z] Error: go test returned a non-zero value: exit status 1

Placing the call within (*responseProcessor).startProcessing provides an HB relationship between the interval clearing and the initiation of the pagination iteration and so precludes clearing the data before the events have been published.

I have not been able to replicate the failure over ~1000 test iterations in the original state, which is consistent with the analysis, though still unsatisfying.

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.

Author's Checklist

  • Backport prior to 7.17?

How to test this PR locally

Related issues

Use cases

Screenshots

Logs

@efd6 efd6 added bug Team:Security-External Integrations backport-v8.0.0 Automated backport with mergify 8.2-candidate backport-v8.1.0 Automated backport with mergify backport-7.17 Automated backport to the 7.17 branch with mergify labels Mar 8, 2022
@efd6 efd6 requested review from ruflin, marc-gr and a team March 8, 2022 07:33
@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 Mar 8, 2022
@mergify mergify bot assigned efd6 Mar 8, 2022
@efd6 efd6 force-pushed the happensbeforerequest branch 2 times, most recently from 24ed62b to fb0eb11 Compare March 8, 2022 07:35
@efd6 efd6 changed the title x-pack/filebeal/input/httpjson: make sure interval data clearing happens before processing x-pack/filebeat/input/httpjson: make sure interval data clearing happens before processing Mar 8, 2022
@elasticmachine
Copy link
Collaborator

elasticmachine commented Mar 8, 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-03-29T01:50:26.102+0000

  • Duration: 23 min 54 sec

❕ Flaky test report

No test was executed to be analysed.

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

@mergify
Copy link
Contributor

mergify bot commented Mar 9, 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 happensbeforerequest upstream/happensbeforerequest
git merge upstream/main
git push upstream happensbeforerequest

@efd6 efd6 force-pushed the happensbeforerequest branch from fb0eb11 to 4adb2f6 Compare March 15, 2022 00:37
@mergify
Copy link
Contributor

mergify bot commented Mar 22, 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 happensbeforerequest upstream/happensbeforerequest
git merge upstream/main
git push upstream happensbeforerequest

@efd6 efd6 force-pushed the happensbeforerequest branch from 4adb2f6 to 082398b Compare March 28, 2022 00:01
Copy link
Member

@andrewkroh andrewkroh left a comment

Choose a reason for hiding this comment

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

LGTM

CHANGELOG.next.asciidoc Outdated Show resolved Hide resolved
@efd6
Copy link
Contributor Author

efd6 commented Mar 28, 2022

This will need to be rebased onto the delint change after it is merged.

@efd6 efd6 force-pushed the happensbeforerequest branch from a67ec8d to c9af60b Compare March 29, 2022 00:24
@efd6
Copy link
Contributor Author

efd6 commented Mar 29, 2022

/package

@efd6
Copy link
Contributor Author

efd6 commented Mar 29, 2022

/test

@efd6 efd6 merged commit 043cab9 into elastic:main Mar 29, 2022
mergify bot pushed a commit that referenced this pull request Mar 29, 2022
…ens before processing (#30730)

(cherry picked from commit 043cab9)

# Conflicts:
#	x-pack/filebeat/input/httpjson/internal/v2/request.go
#	x-pack/filebeat/input/httpjson/internal/v2/response.go
mergify bot pushed a commit that referenced this pull request Mar 29, 2022
…ens before processing (#30730)

(cherry picked from commit 043cab9)

# Conflicts:
#	x-pack/filebeat/input/httpjson/request.go
#	x-pack/filebeat/input/httpjson/response.go
mergify bot pushed a commit that referenced this pull request Mar 29, 2022
…ens before processing (#30730)

(cherry picked from commit 043cab9)

# Conflicts:
#	x-pack/filebeat/input/httpjson/request.go
#	x-pack/filebeat/input/httpjson/response.go
efd6 added a commit that referenced this pull request Mar 31, 2022
…erval data clearing happens before processing (#31029)

* x-pack/filebeat/input/httpjson: make sure interval data clearing happens before processing (#30730)

(cherry picked from commit 043cab9)

# Conflicts:
#	x-pack/filebeat/input/httpjson/internal/v2/request.go
#	x-pack/filebeat/input/httpjson/internal/v2/response.go

* fix conflicts

Co-authored-by: Dan Kortschak <90160302+efd6@users.noreply.github.com>
Co-authored-by: Dan Kortschak <dan.kortschak@elastic.co>
efd6 added a commit that referenced this pull request Mar 31, 2022
…rval data clearing happens before processing (#31030)

* x-pack/filebeat/input/httpjson: make sure interval data clearing happens before processing (#30730)

(cherry picked from commit 043cab9)

# Conflicts:
#	x-pack/filebeat/input/httpjson/request.go
#	x-pack/filebeat/input/httpjson/response.go

* fix conflicts

Co-authored-by: Dan Kortschak <90160302+efd6@users.noreply.github.com>
Co-authored-by: Dan Kortschak <dan.kortschak@elastic.co>
efd6 added a commit that referenced this pull request Mar 31, 2022
…rval data clearing happens before processing (#31031)

* x-pack/filebeat/input/httpjson: make sure interval data clearing happens before processing (#30730)

(cherry picked from commit 043cab9)

# Conflicts:
#	x-pack/filebeat/input/httpjson/request.go
#	x-pack/filebeat/input/httpjson/response.go

* fix conflicts

Co-authored-by: Dan Kortschak <90160302+efd6@users.noreply.github.com>
Co-authored-by: Dan Kortschak <dan.kortschak@elastic.co>
kush-elastic pushed a commit to kush-elastic/beats that referenced this pull request May 2, 2022
leweafan pushed a commit to leweafan/beats that referenced this pull request Apr 28, 2023
…re interval data clearing happens before processing (elastic#31030)

* x-pack/filebeat/input/httpjson: make sure interval data clearing happens before processing (elastic#30730)

(cherry picked from commit 1b40352)

# Conflicts:
#	x-pack/filebeat/input/httpjson/request.go
#	x-pack/filebeat/input/httpjson/response.go

* fix conflicts

Co-authored-by: Dan Kortschak <90160302+efd6@users.noreply.github.com>
Co-authored-by: Dan Kortschak <dan.kortschak@elastic.co>
chrisberkhout pushed a commit that referenced this pull request Jun 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.2-candidate backport-7.17 Automated backport to the 7.17 branch with mergify backport-v8.0.0 Automated backport with mergify backport-v8.1.0 Automated backport with mergify bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants