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

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

Closed
andrewkroh opened this issue Oct 6, 2022 · 8 comments · Fixed by #7726
Assignees
Labels
bug Something isn't working, use only for issues Integration:cloudflare Cloudflare

Comments

@andrewkroh
Copy link
Member

The cloudflare.logpull integration is failing due to an invalid time range.

Error while processing http request: failed to execute rf.collectResponse: failed to execute http client.Do: server responded with status code 400: bad query: error parsing time: invalid time range: too early: logs older than 168h0m0s are not available

@andrewkroh andrewkroh added bug Something isn't working, use only for issues Team:Security-External Integrations Integration:cloudflare Cloudflare labels Oct 6, 2022
@elasticmachine
Copy link

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

@jamiehynds
Copy link

@andrewkroh I've seen this come up a few times recently. Do we know what it will take to fix or what do we need from customers to allow us to make progress?

@andrewkroh
Copy link
Member Author

andrewkroh commented May 11, 2023

From https://developers.cloudflare.com/logs/logpull/requesting-logs/, some of the highlights are

start Must be no more than 7 days earlier than now
end Must be at least 1 minute earlier than now and later than start
Note: The maximum time range from start to end cannot exceed 1 hour.

This is our current config:

- set:
target: url.params.start
value: "[[.cursor.last_execution_datetime]]"
default: '[[formatDate (((now).Add (parseDuration "-1m")).Add (parseDuration "-{{interval}}"))]]'
- set:
target: url.params.end
value: '[[formatDate ((parseDate .cursor.last_execution_datetime).Add (parseDuration "{{interval}}"))]]'
default: '[[formatDate ((now).Add (parseDuration "-1m"))]]'

cursor:
last_execution_datetime:
value: '[[.last_response.url.params.Get "end"]]'


So there are four constraints that we must ensure are always true.

  • now - start <= 168h
  • now - end > 1m
  • start < end
  • start - end <= 1h

If we used exactly start = now - 168h, then by the time the request was processed the start time would greater than 7 days old and in theory would be invalid. So some tolerance should be built in.

Here's a simplified summary of the current logic. There are no protections to guard against some of the constraints. You can imagine hitting some of those constraints if the input is stopped for a week, uses an interval greater than 1h, and probably more.

interval = 5m
start = now - 1m - interval
end = now - 1m

do
  response = do_request()
  start = response.time_of_last_event
  end = start + interval
while sleep interval

@andrewkroh
Copy link
Member Author

andrewkroh commented May 11, 2023

I think we would need to add some protections like

start = max(time_of_last_event, now - 168h) # Always satisfy the 168h requirement.
end = min(start + 1h, now - 1m) # Always satisfy the 1h window requirement. And never request too new of data.

We need to investigate if this can be achieved in httpjson. I don't see any helper functions that would allow min or max.

@vulnerabivoro
Copy link

Hey @andrewkroh , using latest cloudflare integration we are getting this:

Error while processing http request: failed to execute rf.collectResponse: failed to execute http client.Do: server responded with status code 400: bad query: error parsing time: invalid time range: too recent: minimum delay in serving logs is 1m0s

@andrewkroh
Copy link
Member Author

@vulnerabivoro What collection interval do you have the integration configured for?

@vulnerabivoro
Copy link

10m in the Cloudflare logs settings option.

image

@ShourieG ShourieG changed the title [Cloudflare Logpull] invalid time range: too early: logs older than 168h0m0s are not available [Cloudflare Logpull][Meta] invalid time range: too early: logs older than 168h0m0s are not available Jul 31, 2023
@ShourieG
Copy link
Contributor

ShourieG commented Aug 9, 2023

The integration PR will be put up soon since we cannot merge it before 8.10 public release, as it will have dependency on the new min/max funcs added to httpjson in 8.10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working, use only for issues Integration:cloudflare Cloudflare
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants