Skip to content

[integrations][Cloudflare Logpull] - Fixed invalid time range issue #7726

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

Merged
merged 18 commits into from
Oct 16, 2023

Conversation

ShourieG
Copy link
Contributor

@ShourieG ShourieG commented Sep 8, 2023

Type of change

  • Bug

What does this PR do?

This PR uses a certain time range constraint discussed here to address the issue. The main concept lies in the following time constraints :

now - start <= 168h
now - end > 1m
start < end
end - stard <= 1h
 
start = max(time_of_last_event, now - 168h)  # This Always satisfies the 168h requirement.
end = min(start + 1h, now - 1m)  # Always satisfies the 1h window requirement, and never requests earlier data.

The integration uses the above constraints while calculating the value of the start & end query params.

NOTE:

  1. HTTPJSON does not have any mechanism to store values internally while setting parameters via the config. It also does not have the capability to pull values from the .url.* objects, only .last_response.url.* works. This creates a problem we need to work around. For the calculation of end using the logic end = min(start + 1h, now - 1m), the value of start needs to be calculated here since we cannot use [[.url.params.Get "start"]]. Similarly we are unable to store a singular value for now and it gets computed everywhere it's used. This creates very minor deviations in the timestamps of a few milliseconds to maybe a max of 1 second. We can probably live by this. This re-calculation of values effectively transforms the internal logic for computing the value of end to:
end = min(max(time_of_last_event, now - 168h) + 1h, now - 1m)
  1. This was tested manually with a local server and all of the constraints passed.
  2. A mock service has been integrated via docker-compose which simulates the exact api constraints during the system test
    with a hit_count of 3 responses. The service sends a rolling response similar to elastic stream http servers.

Checklist

  • I have reviewed tips for building integrations and this pull request is aligned with them.
  • I have verified that all data streams collect metrics or logs.
  • I have added an entry to my package's changelog.yml file.
  • I have verified that Kibana version constraints are current according to guidelines.

Author's Checklist

  • [ ]

How to test this PR locally

Related issues

Screenshots

cf_logbull_tests

@ShourieG ShourieG requested a review from a team as a code owner September 8, 2023 13:19
@ShourieG ShourieG self-assigned this Sep 8, 2023
@ShourieG ShourieG added 8.11 candidate integration Label used for meta issues tracking each integration bugfix Pull request that fixes a bug issue Team:Security-External Integrations labels Sep 8, 2023
@elasticmachine
Copy link

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

@ShourieG ShourieG requested a review from andrewkroh September 8, 2023 13:23
@elasticmachine
Copy link

elasticmachine commented Sep 8, 2023

💚 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: 2023-10-12T09:52:18.492+0000

  • Duration: 19 min 58 sec

Test stats 🧪

Test Results
Failed 0
Passed 21
Skipped 0
Total 21

🤖 GitHub comments

Expand to view the GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@elasticmachine
Copy link

elasticmachine commented Sep 8, 2023

🌐 Coverage report

Name Metrics % (covered/total) Diff
Packages 100.0% (2/2) 💚
Files 100.0% (3/3) 💚
Classes 100.0% (3/3) 💚
Methods 100.0% (37/37) 💚 4.762
Lines 94.772% (707/746) 👍 17.64
Conditionals 100.0% (0/0) 💚

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.

You'll need to bump the stack version to pick up the max and min functions.

@ShourieG
Copy link
Contributor Author

ShourieG commented Sep 14, 2023

@andrewkroh I've added a mock service that simulates the api constraints during system tests and resolved rest of the suggestions.

@ShourieG ShourieG requested a review from andrewkroh September 15, 2023 01:41
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.

The mock server you added is helpful, but it's hard to prove the httpjson config is working correctly because it does not appear that the min/max range protections get exercised. So I think it would be good if we can find a way to test these cases.

@ShourieG
Copy link
Contributor Author

ShourieG commented Oct 10, 2023

@andrewkroh resolved all the suggested changes, introduced a new test that works over 2 iterations so cursor value is used. Modified the server code to match a specific criteria for the new test case to validate cursor value.

@ShourieG ShourieG merged commit 43088cb into elastic:main Oct 16, 2023
@ShourieG ShourieG deleted the bugfix/cf_logpull branch October 16, 2023 08:14
@elasticmachine
Copy link

Package cloudflare - 2.20.0 containing this change is available at https://epr.elastic.co/search?package=cloudflare

@andrewkroh andrewkroh added the Integration:cloudflare Cloudflare (Community supported) label Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.11 candidate bugfix Pull request that fixes a bug issue Integration:cloudflare Cloudflare (Community supported) integration Label used for meta issues tracking each integration
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Cloudflare Logpull][Meta] invalid time range: too early: logs older than 168h0m0s are not available
4 participants