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][httpjson] Initial implementation of httpjson v2 #22320

Merged
merged 35 commits into from
Dec 4, 2020

Conversation

marc-gr
Copy link
Contributor

@marc-gr marc-gr commented Oct 30, 2020

What does this PR do?

Creates an initial implementation of the new Httpjson input.

Why is it important?

HTTPJSON is too specific to our particular modules use cases and is hard to extend or reuse out of them. For this we wanted to do an effort to generalize the input so it can be used in a more flexible way.

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

  • The possible values that a transform modifies are defined by where it is configured
  • Load cursor from registry
  • Store cursor in registry
  • Custom cursor values
  • Supports oauth
  • Supports basic auth
  • Supports automatic retries
  • Rate limit with custom values
  • Values can have a default in case of empty or failure
  • Value templates use predefined helper functions
    • now
    • parseDuration
    • parseDate
    • formatDate
    • parseTimestamp
    • parseTimestampMilli
    • parseTimestamlNano
    • getRFC5988Link
  • Request transforms
    • Set
    • Append
    • Delete
  • Response transforms
    • Set
    • Append
    • Delete
    • Split
      • Arrays
      • Maps
  • Response pagination
    • Set
    • Append
    • Delete
  • Redirects can forward headers
  • Documentation for the new input
  • Update old documentation to mention deprecation and migration steps
  • Add missing tests

How to test this PR locally

  • Set a mock endpoint to respond to http requests
  • Set up a config that uses the new input
- type: httpjson
  is_v2: true
  interval: 10s
  request.method: post
  request.url: https://example.com
  request.transforms:
    - set:
        target: body.foo
        value: bazz
  response.transforms:
    - delete:
        target: body.this_is_private
  response.pagination:
    - set:
        target: url.value
        value: "https://example.com/page"
    - set:
        target: url.params.p
        value: "{{.last_response.body.page}}"

output.console:
  pretty: true

Then in x-pack/filebeat run mage build && ./filebeat -e -v and check the output.

Related issues

@marc-gr marc-gr added enhancement in progress Pull request is currently in progress. labels Oct 30, 2020
@botelastic botelastic bot added the needs_team Indicates that the issue/PR needs a Team:* label label Oct 30, 2020
@botelastic botelastic bot removed the needs_team Indicates that the issue/PR needs a Team:* label label Oct 30, 2020
@marc-gr
Copy link
Contributor Author

marc-gr commented Oct 30, 2020

cc @P1llus @epixa

@elasticmachine
Copy link
Collaborator

elasticmachine commented Oct 30, 2020

🐛 Flaky test report

❕ There are test failures but not known flaky tests.

Expand to view the summary

Test stats 🧪

Test Results
Failed 24
Passed 1270
Skipped 14
Total 1308

Genuine test errors 24

💔 There are test failures but not known flaky tests, most likely a genuine test failure.

  • Name: Build&Test / x-pack/filebeat-build / TestNewAppend – v2
  • Name: Build&Test / x-pack/filebeat-build / TestNewAppend/newAppendResponse_targets_something_else – v2
  • Name: Build&Test / x-pack/filebeat-build / TestNewAppend/newAppendRequest_targets_something_else – v2
  • Name: Build&Test / x-pack/filebeat-build / TestNewAppend/newAppendPagination_targets_something_else – v2
  • Name: Build&Test / x-pack/filebeat-build / TestNewDelete – v2
  • Name: Build&Test / x-pack/filebeat-build / TestNewDelete/newDeleteResponse_targets_something_else – v2
  • Name: Build&Test / x-pack/filebeat-build / TestNewDelete/newDeleteRequest_targets_something_else – v2
  • Name: Build&Test / x-pack/filebeat-build / TestNewDelete/newDeletePagination_targets_something_else – v2
  • Name: Build&Test / x-pack/filebeat-build / TestNewSet – v2
  • Name: Build&Test / x-pack/filebeat-build / TestNewSet/newSetResponse_targets_something_else – v2
  • Name: Build&Test / x-pack/filebeat-build / TestNewSet/newSetRequest_targets_something_else – v2
  • Name: Build&Test / x-pack/filebeat-build / TestNewSet/newSetPagination_targets_something_else – v2
  • Name: Build&Test / x-pack/filebeat-windows-windows-2019 / TestNewAppend – v2
  • Name: Build&Test / x-pack/filebeat-windows-windows-2019 / TestNewAppend/newAppendResponse_targets_something_else – v2
  • Name: Build&Test / x-pack/filebeat-windows-windows-2019 / TestNewAppend/newAppendRequest_targets_something_else – v2
  • Name: Build&Test / x-pack/filebeat-windows-windows-2019 / TestNewAppend/newAppendPagination_targets_something_else – v2
  • Name: Build&Test / x-pack/filebeat-windows-windows-2019 / TestNewDelete – v2
  • Name: Build&Test / x-pack/filebeat-windows-windows-2019 / TestNewDelete/newDeleteResponse_targets_something_else – v2
  • Name: Build&Test / x-pack/filebeat-windows-windows-2019 / TestNewDelete/newDeleteRequest_targets_something_else – v2
  • Name: Build&Test / x-pack/filebeat-windows-windows-2019 / TestNewDelete/newDeletePagination_targets_something_else – v2
  • Name: Build&Test / x-pack/filebeat-windows-windows-2019 / TestNewSet – v2
  • Name: Build&Test / x-pack/filebeat-windows-windows-2019 / TestNewSet/newSetResponse_targets_something_else – v2
  • Name: Build&Test / x-pack/filebeat-windows-windows-2019 / TestNewSet/newSetRequest_targets_something_else – v2
  • Name: Build&Test / x-pack/filebeat-windows-windows-2019 / TestNewSet/newSetPagination_targets_something_else – v2

@elasticmachine
Copy link
Collaborator

elasticmachine commented Oct 30, 2020

💚 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

Expand to view the summary

Build stats

  • Build Cause: Pull request #22320 updated

  • Start Time: 2020-12-04T08:47:00.374+0000

  • Duration: 46 min 37 sec

Test stats 🧪

Test Results
Failed 0
Passed 2420
Skipped 259
Total 2679

💚 Flaky test report

Tests succeeded.

Expand to view the summary

Test stats 🧪

Test Results
Failed 0
Passed 2420
Skipped 259
Total 2679

@elasticmachine
Copy link
Collaborator

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

@marc-gr marc-gr merged commit 47d8941 into elastic:master Dec 4, 2020
@marc-gr marc-gr deleted the httpjson_v2 branch December 4, 2020 10:33
@marc-gr marc-gr added the v7.11.0 label Dec 4, 2020
marc-gr added a commit to marc-gr/beats that referenced this pull request Dec 9, 2020
…2320)

* Add oauth config

* Add stateless input

* Add request and basic config

* Create v2 input and basic transforms

* Refactor and set up basic requester structure

* Run fmt

* Set tests and fix tpl

* basic processing structure

* Add pagination mechanism

* Publish the events

* Add check redirect and oauth tests

* Deprecate old httpjson and include both

* Return default value if execution is empty

* wip

* Add split

* Handle request errors and pagination end

* Add date functions for templates and tests

* Add getRFC5988Link functionality to templates

* Switch between v1/v2 based on config flag

* Add cursor

* Add rate limit

* Put back original filebeat.yml

* Add deprecation warning for old httpjson version

* Add transform tests

* Initial doc changes

* Add more debug logs and split tests

* Ignore empty values on set and append

* Allow content type and accept override and change redirect default

* Add add and toInt functions

* Support array responses

* Add tests cases and minor changes

* Add changelog entry

* Do not copy mutex on delete transform

* Add PR suggestions:
  - Modify context done error log
  - Change is_v2 config bool for string config_version
  - Change retryable logger to be created from input logger

* Documentation fixes

(cherry picked from commit 47d8941)
marc-gr added a commit that referenced this pull request Dec 9, 2020
…22920)

* Add oauth config

* Add stateless input

* Add request and basic config

* Create v2 input and basic transforms

* Refactor and set up basic requester structure

* Run fmt

* Set tests and fix tpl

* basic processing structure

* Add pagination mechanism

* Publish the events

* Add check redirect and oauth tests

* Deprecate old httpjson and include both

* Return default value if execution is empty

* wip

* Add split

* Handle request errors and pagination end

* Add date functions for templates and tests

* Add getRFC5988Link functionality to templates

* Switch between v1/v2 based on config flag

* Add cursor

* Add rate limit

* Put back original filebeat.yml

* Add deprecation warning for old httpjson version

* Add transform tests

* Initial doc changes

* Add more debug logs and split tests

* Ignore empty values on set and append

* Allow content type and accept override and change redirect default

* Add add and toInt functions

* Support array responses

* Add tests cases and minor changes

* Add changelog entry

* Do not copy mutex on delete transform

* Add PR suggestions:
  - Modify context done error log
  - Change is_v2 config bool for string config_version
  - Change retryable logger to be created from input logger

* Documentation fixes

(cherry picked from commit 47d8941)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement in progress Pull request is currently in progress. v7.11.0
Projects
None yet
5 participants