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][CometD] Add CometD input for Salesforce connector #31492

Merged
merged 69 commits into from
May 6, 2022

Conversation

kush-elastic
Copy link
Collaborator

  • Enhancement

What does this PR do?

Real-time logs from the Salesforce Streaming API can be collected using the cometD input. For example, live Login & Logout related logs.

Right now with this PR, when the cometd input is enabled, you can start seeing the authentication log messages that are retrieved after successful authentication using the credentials provided as a part of the configuration. You will also be able to see the real-time data being collected from the Salesforce Steaming API.
For configuration:

- type: cometd
  channel_name: /event/LoginEventStream
  auth.oauth2:
    client.id: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    client.secret: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    token_url: https://login.salesforce.com/services/oauth2/token
    user: [email protected]
    password: P@$$W0₹D

Why is it important?

  • It is a prerequisite for the Salesforce Observability Connector for the collection of real-time data from the Streaming APIs.
  • With all the different logs in cometD from different services, it will be good to have a dedicated Filebeat input to retrieve the same using cometD.

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.

@kush-elastic
Copy link
Collaborator Author

kush-elastic commented May 3, 2022

Hey @cmacknz, this is the new PR for CometD input.

E2E test are still in pending state.
image

All other checks are passing successfully.
Still I will re-trigger CI and see if tests are passing or not again.

@kush-elastic
Copy link
Collaborator Author

/test

@cmacknz
Copy link
Member

cmacknz commented May 3, 2022

If I check out this PR locally and run the tests it is still flaky for me. For flaky tests you need to run them more then once, I usually put them in a shell while loop with a go test flag that will disable test caching like -count 1:

~/go/src/github.com/elastic/beats pr/kush-elastic/31492-1:salesforce_cometd_input ?1 ···· 7s 11:49:18 AMwhile go test -count 1 ./x-pack/filebeat/input/cometd/...; do :; done
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        5.426s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        5.436s
--- FAIL: TestMultiInput (5.00s)
    input_test.go:339: 
                Error Trace:    input_test.go:339
                Error:          Received unexpected error:
                                not able to get events.
                Test:           TestMultiInput
FAIL
FAIL    github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        5.434s
FAIL

@cmacknz
Copy link
Member

cmacknz commented May 3, 2022

Also odd, in a Jenkins run where the build is green I can see this test actually failed. Looking at the console text for https://beats-ci.elastic.co/job/Beats/job/beats/job/PR-31492/5/ I can see the following:

[2022-05-03T10:24:36.970Z] === Failed
[2022-05-03T10:24:36.970Z] === FAIL: x-pack/filebeat/input/cometd TestMultiInput (5.00s)
[2022-05-03T10:24:36.970Z]     input_test.go:339: 
[2022-05-03T10:24:36.970Z]         	Error Trace:	input_test.go:339
[2022-05-03T10:24:36.970Z]         	Error:      	Received unexpected error:
[2022-05-03T10:24:36.970Z]         	            	not able to get events.
[2022-05-03T10:24:36.970Z]         	Test:       	TestMultiInput
[2022-05-03T10:24:36.970Z] 
[2022-05-03T10:24:36.970Z] DONE 832 tests, 7 skipped, 1 failure in 190.543s
[2022-05-03T10:24:36.970Z] Error: go test returned a non-zero value: exit status 1
[2022-05-03T10:24:36.978Z] [Pipeline] }
[2022-05-03T10:24:36.979Z] ERROR: script returned exit code 1
[2022-05-03T10:24:36.979Z] Retrying

I think Jenkins might have some built in retries here

@kush-elastic
Copy link
Collaborator Author

Thanks for the details, I looked into those tests. there were some problems with immediate starting of all the tests. and cause of server issues. I have updated those. let's see if that works for Jenkins or not.

Here's what you suggested.
image

@cmacknz
Copy link
Member

cmacknz commented May 3, 2022

Thanks, I left it in the background for a while and managed to get it to fail:

❯ while go test -count 1 ./x-pack/filebeat/input/cometd/...; do :; done
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.458s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.427s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.443s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.457s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.452s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.439s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.397s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.446s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.446s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.449s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.395s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.403s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.412s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.440s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.455s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.377s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.445s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.471s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.375s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.412s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.449s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.453s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.443s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.397s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.440s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.458s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.437s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.454s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.442s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.448s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.427s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.462s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.442s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.440s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.442s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.435s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.453s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.458s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.435s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.477s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.447s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.434s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.420s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.484s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.408s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.403s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.441s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.411s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.448s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.440s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.452s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.443s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.448s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.435s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.459s
ok      github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.428s
--- FAIL: TestMultiInput (2.01s)
    input_test.go:310: 
                Error Trace:    input_test.go:310
                Error:          Received unexpected error:
                                not able to get events.
                Test:           TestMultiInput
FAIL
FAIL    github.com/elastic/beats/v7/x-pack/filebeat/input/cometd        2.435s
FAIL

@kush-elastic
Copy link
Collaborator Author

Thanks, I left it in the background for a while and managed to get it to fail:

Thanks, @cmacknz! Do you have anything on top of your head which can help us resolve this? I am also trying some things out.

@cmacknz
Copy link
Member

cmacknz commented May 3, 2022

No, but I'll look closer at the code. I have had tests like this that require 10+ minutes of continuous running to see failures, so it could be worse :)

@kush-elastic
Copy link
Collaborator Author

kush-elastic commented May 5, 2022

Hey @cmacknz,
I looked into this and found out that problem was in http test server.
here's solution:

if called < uint64(inputType) {
	atomic.AddUint64(&called, 1)
	_, _ = w.Write([]byte(`[{"data": {"payload": {"CountryIso": "IN"}, "event": {"replayId":1234}}, "channel": "channel_name"}]`))
} else {
	_, _ = w.Write([]byte(`{}`))
}

I was expecting empty response from server after few events. after receiving those I should not send more events in response based on condition. so what was missing is {}.

WDYT?

@kush-elastic
Copy link
Collaborator Author

/test

@kush-elastic
Copy link
Collaborator Author

Hey @cmacknz, The E2E tests are again failing.
Is there any specific reason for this to failures?

Still I am re-triggering CI with /package.

@kush-elastic
Copy link
Collaborator Author

/package

@kush-elastic
Copy link
Collaborator Author

/test

@kush-elastic kush-elastic requested a review from cmacknz May 5, 2022 19:03
@kush-elastic
Copy link
Collaborator Author

kush-elastic commented May 5, 2022

Hey @cmacknz,
Everything other then E2E test are passing. Can we merge this PR? If so, then can you help us merge it as we don't have rights to do it?
Or is there something else we need to do?

@mtojek
Copy link
Contributor

mtojek commented May 6, 2022

I synced with @kush-elastic regarding the status of E2E tests. We agreed to merge based on the same justification as here.

@mtojek mtojek merged commit 29c0d4c into elastic:main May 6, 2022
chrisberkhout pushed a commit that referenced this pull request Jun 1, 2023
* Add authentication mechanism for cometd input for Salesforce connector

* update based on comments: clear empty line and add error.Errorf with context

* Add data collection mechanism for Salesforce cometd input

* Update the approach of the channel

* Add asciidoc for cometd input

* Resolve review comments

* Update cometd input to import forked dependency

* Temorarily remove changelog entry

* Run mage check and update

* Update go.mod and go.sum

* Update go.mod and NOTICE.txt

* Make changes with respect to ownership transfer

* Update go.mod and go.sum

* Add two unit test cases and nit

* Add unit test cases and integration tests

* Address review comments

* Resolve some linting issues

* Resolve some linting issues

* Add unit test for input

* Add integration test

* Lint issues

* Lint

* Lint

* update bayeux v1.0.3

* Add NOTICE.txt

* Add negative test cases

* requested changes

* Resolve CI lint errors

* Update go.sum

* Update NOTICE.txt

* Update unit tests

* Update unit test name

* Update tests

* Remove test.out

* Use time.After to eliminate possible flaky test

* Add buffer of 1 in message channel

* Update tests based on bayeux client status watcher changes

* incorporate bayeux changes

* Update unit tests

* resolve unit tests

* additional tests with multiple inputs, added channel_name filed in comman cometd fields

* nit: Event struct -> event struct

* test case improvement

* update looger Error -> Errorw to print formatted errors

* update docs with reference links

* Add CHANGELOG entry and update docs

* Use mapstr.M instead of common.MapStr

* Changes based on Replace common.Config and friends with config.C

* resolve make check error

* resolve comman config errors

* update unit tests

* update multiple input unit test

* Update TestMultiInput unit test

* Update minor nit to re-trigger CI

* Resolve flanky tests

* Resolve linting issues

* Resolve tests -> send empty response {}

* nit: inputType -> expectedHTTPEventCount

* nit: wg -> waitForEventCollection

Co-authored-by: yug-crest <[email protected]>
Co-authored-by: yug-elastic <[email protected]>
Co-authored-by: Craig MacKenzie <[email protected]>
Co-authored-by: yug-elastic <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs_team Indicates that the issue/PR needs a Team:* label
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants