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][input] - Websocket Input with CEL engine #37774

Merged
merged 39 commits into from
Feb 12, 2024

Conversation

ShourieG
Copy link
Contributor

@ShourieG ShourieG commented Jan 29, 2024

Type of change

  • Enhancement
  • Docs

Proposed commit message

Websocket input implementation based on Gorilla websockets. It uses the CEL engine and the mito library
for processing of responses and maintaining the cursor. This input can be used to ingest data from any modern websocket server.

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

  • Added tests for config validation
  • Added tests for Websocket input

How to test this PR locally

  1. Clone the beats repo locally and make sure you have golang env setup.
  2. Perform a go mod tidy to fetch any missing libraries.
  3. Move to the x-pack/filebeat directory by doing cd x-pack/filebeat.
  4. Configure the filebeat.yml according to the websocket documentation and customise it to your needs.
  5. Run go run main.go -e -d "websocket" to start the input with filtering out relevant logs.

Sample config:

- type: websocket
  url: ws://localhost:443/v1/stream
  program: |
    bytes(state.response).decode_json().as(inner_body,{
      "events": {
        "message":  inner_body.encode_json(),
      }
    })

To enable pretty printing on console, configure the following attributes in the filebeat.yml config:

output.console:
  enabled: true
  pretty: true

Related issues

Use cases

Screenshots

Logs

@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Jan 29, 2024
Copy link
Contributor

mergify bot commented Jan 29, 2024

This pull request does not have a backport label.
If this is a bug or security fix, could you label this PR @ShourieG? 🙏.
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

@ShourieG ShourieG changed the title Feature/websocket [filebeat][input] - Websocket Input with CEL engine Jan 29, 2024
@ShourieG ShourieG added Team:Security-Service Integrations Security Service Integrations Team and removed needs_team Indicates that the issue/PR needs a Team:* label labels Jan 29, 2024
@elasticmachine
Copy link
Collaborator

❕ Build Aborted

There is a new build on-going so the previous on-going builds have been aborted.

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

Expand to view the summary

Build stats

  • Start Time: 2024-01-29T12:40:10.758+0000

  • Duration: 20 min 2 sec

Test stats 🧪

Test Results
Failed 1
Passed 1288
Skipped 11
Total 1300

Test errors 1

Expand to view the tests failures

Build&Test / x-pack/filebeat-goIntegTest / TestBenchmarkInputS3 – github.com/elastic/beats/v7/x-pack/filebeat/input/awss3
    Expand to view the error details

     Failed 
    

    Expand to view the stacktrace

     === RUN   TestBenchmarkInputS3
    signal: terminated
     
    

Steps errors 1

Expand to view the steps failures

Error signal
  • Took 0 min 0 sec . View more details here
  • Description: Error 'org.jenkinsci.plugins.workflow.steps.FlowInterruptedException'

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

@elasticmachine
Copy link
Collaborator

💚 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: 2024-01-29T12:52:55.913+0000

  • Duration: 178 min 8 sec

Test stats 🧪

Test Results
Failed 0
Passed 28778
Skipped 2014
Total 30792

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

@elasticmachine
Copy link
Collaborator

❕ Build Aborted

Either there was a build timeout or someone aborted the build.

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

Expand to view the summary

Build stats

  • Duration: 43 min 20 sec

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

@elasticmachine
Copy link
Collaborator

❕ Build Aborted

Either there was a build timeout or someone aborted the build.

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

Expand to view the summary

Build stats

  • Duration: 182 min 0 sec

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

@elasticmachine
Copy link
Collaborator

💚 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: 2024-01-30T14:50:59.922+0000

  • Duration: 181 min 31 sec

Test stats 🧪

Test Results
Failed 0
Passed 28778
Skipped 2014
Total 30792

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

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.

Is a cursor a meaningful concept in this context? Aren't we at the whim of what the ws server sends us?

x-pack/filebeat/input/websocket/config.go Outdated Show resolved Hide resolved
x-pack/filebeat/input/websocket/input.go Outdated Show resolved Hide resolved
x-pack/filebeat/input/websocket/input.go Outdated Show resolved Hide resolved
x-pack/filebeat/input/websocket/input.go Outdated Show resolved Hide resolved
@ShourieG
Copy link
Contributor Author

ShourieG commented Feb 1, 2024

Is a cursor a meaningful concept in this context? Aren't we at the whim of what the ws server sends us?

Yes indeed we are at the mercy of what the websocket sends us, but incase it sends a timestamp Along with the event, we could include a cursor based condition in the cel program to process events accordingly. This would be upto the end user to configure.

x-pack/filebeat/docs/inputs/input-websocket.asciidoc Outdated Show resolved Hide resolved
x-pack/filebeat/docs/inputs/input-websocket.asciidoc Outdated Show resolved Hide resolved
x-pack/filebeat/docs/inputs/input-websocket.asciidoc Outdated Show resolved Hide resolved
x-pack/filebeat/docs/inputs/input-websocket.asciidoc Outdated Show resolved Hide resolved
x-pack/filebeat/docs/inputs/input-websocket.asciidoc Outdated Show resolved Hide resolved
x-pack/filebeat/input/websocket/metrics.go Outdated Show resolved Hide resolved
x-pack/filebeat/input/websocket/metrics.go Outdated Show resolved Hide resolved
x-pack/filebeat/input/websocket/config.go Show resolved Hide resolved
x-pack/filebeat/input/websocket/redact_test.go Outdated Show resolved Hide resolved
x-pack/filebeat/input/websocket/metrics.go Outdated Show resolved Hide resolved
@ShourieG
Copy link
Contributor Author

ShourieG commented Feb 9, 2024

@efd6 I've addressed all the PR suggestions and added the config tests

@ShourieG ShourieG requested a review from efd6 February 9, 2024 15:50
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.

doc nits then LGTM

x-pack/filebeat/docs/inputs/input-websocket.asciidoc Outdated Show resolved Hide resolved
x-pack/filebeat/docs/inputs/input-websocket.asciidoc Outdated Show resolved Hide resolved
x-pack/filebeat/docs/inputs/input-websocket.asciidoc Outdated Show resolved Hide resolved
@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @ShourieG

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @ShourieG

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @ShourieG

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @ShourieG

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @ShourieG

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @ShourieG

@ShourieG ShourieG merged commit e5000b6 into elastic:main Feb 12, 2024
146 of 149 checks passed
@ShourieG ShourieG deleted the feature/websocket branch February 12, 2024 07:51
@ShourieG ShourieG added the new input (filebeat) A new input for file beat label Feb 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.13-candidate enhancement Filebeat Filebeat new input (filebeat) A new input for file beat Team:Security-Service Integrations Security Service Integrations Team
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Filebeat] Input to ingest data from WebSocket API
6 participants