-
Notifications
You must be signed in to change notification settings - Fork 519
mimecast: refactor CEL code to prevent memory issues and OOM failures #16308
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
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
163c402
refactored siem_logs & cloud_integrated_logs data streams according t…
ShourieG 0d58a3a
skipped httpjson system test due to health status degraded and templa…
ShourieG 9690d0c
added changelog and updated manifest
ShourieG 83f85d8
updated changelog
ShourieG 85cd034
addressed Dan's suggestions
ShourieG e0d2adb
addressed Andrew's suggestions and addressed handling of 404 error codes
ShourieG e4e9b16
removed skip, as this was used for internal testing
ShourieG File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -31,6 +31,10 @@ program: | | |||||
| // If it is changed here changes should be reflected in the other data | ||||||
| // streams. Do not differentiate the logic between these data streams | ||||||
| // lightly; use the state variable for this unless absolutely required. | ||||||
| // | ||||||
| // Memory optimization: This program processes ONE batch file per execution | ||||||
| // cycle to avoid memory pressure. Batch URLs are stored in cursor.blobs | ||||||
| // and processed one at a time. | ||||||
| state.with( | ||||||
| ( | ||||||
| (has(state.?token.expires) && now() < timestamp(state.token.expires)) ? | ||||||
|
|
@@ -73,87 +77,98 @@ program: | | |||||
| : | ||||||
| work_list | ||||||
| ).as(work_list, | ||||||
| get_request( | ||||||
| state.url.trim_right("/") + state.path + "?" + { | ||||||
| "type": [work_list[0].type], | ||||||
| ?"nextPage": work_list[0].?next.optMap(next, [next]), | ||||||
| ?"dateRangeStartsAt": state.?start.optMap(start, [start.format("2006-01-02")]), | ||||||
| ?"dateRangeEndsAt": state.?end.optMap(end, [end.format("2006-01-02")]), | ||||||
| ?"pageSize": state.?page_size.optMap(size, [string(int(size))]), | ||||||
| }.format_query() | ||||||
| ).with({ | ||||||
| "Header": { | ||||||
| "Authorization": ["Bearer " + token.access_token], | ||||||
| "Accept": ["application/json"], | ||||||
| "Content-Type": ["application/json"], | ||||||
| } | ||||||
| }).do_request().as(resp, resp.StatusCode == 200 ? | ||||||
| bytes(resp.Body).decode_json().as(body, | ||||||
| { | ||||||
| "events": body.value.map(b, has(b.url), | ||||||
| get(b.url).as(batch, batch.StatusCode == 200 ? | ||||||
| bytes(batch.Body).mime("application/gzip").mime("application/x-ndjson").map(e, | ||||||
| { | ||||||
| "message": dyn(e.encode_json()), | ||||||
| } | ||||||
| ) | ||||||
| : | ||||||
| [{ | ||||||
| "error": { | ||||||
| "code": string(batch.StatusCode), | ||||||
| "id": string(batch.Status), | ||||||
| "message": "GET " + b.url + ": " + ( | ||||||
| size(batch.Body) != 0 ? | ||||||
| string(batch.Body) | ||||||
| : | ||||||
| string(batch.Status) + ' (' + string(batch.StatusCode) + ')' | ||||||
| ), | ||||||
| }, | ||||||
| }] | ||||||
| ) | ||||||
| ).flatten(), | ||||||
| "cursor": { | ||||||
| "work_list": ( | ||||||
| "@nextPage" in body && size(body.value) != 0 ? | ||||||
| [work_list[0].with({"next": body["@nextPage"]})] | ||||||
| : | ||||||
| [] | ||||||
| ) + tail(work_list), | ||||||
| }, | ||||||
| "token": { | ||||||
| "access_token": token.access_token, | ||||||
| "expires": token.expires, | ||||||
| }, | ||||||
| "want_more": "@nextPage" in body && size(body.value) != 0, | ||||||
| }.as(to_publish, to_publish.with({ | ||||||
| "want_more": to_publish.want_more || size(to_publish.cursor.work_list) != 0, | ||||||
| })) | ||||||
| ).as(state, | ||||||
| // Check whether we still need to get more, but have | ||||||
| // no event for this type. If we do, populate events | ||||||
| // with a place-holder to be discarded by the ingest | ||||||
| // pipeline. | ||||||
| state.want_more && size(state.events) == 0 ? | ||||||
| state.with({"events": [{"message": "want_more"}]}) | ||||||
| : | ||||||
| state | ||||||
| ) | ||||||
| : | ||||||
| { | ||||||
| "events": { | ||||||
| "error": { | ||||||
| "code": string(resp.StatusCode), | ||||||
| "id": string(resp.Status), | ||||||
| "message": "GET " + state.path + ": " + ( | ||||||
| size(resp.Body) != 0 ? | ||||||
| string(resp.Body) | ||||||
| : | ||||||
| string(resp.Status) + ' (' + string(resp.StatusCode) + ')' | ||||||
| state.?cursor.blobs.orValue([]).as(blobs, | ||||||
| // Process blobs first if any are queued, otherwise fetch batch lists. | ||||||
| (size(blobs) > 0) ? | ||||||
| // Download a single batch file. | ||||||
| get(blobs[0]).as(batch, (batch.StatusCode == 200) ? | ||||||
| { | ||||||
| "events": bytes(batch.Body).mime("application/gzip").mime("application/x-ndjson").map(e, | ||||||
| { | ||||||
| "message": dyn(e.encode_json()), | ||||||
| } | ||||||
| ), | ||||||
| }, | ||||||
| }, | ||||||
| "want_more": false, | ||||||
| } | ||||||
| "cursor": { | ||||||
| "blobs": tail(blobs), | ||||||
| "work_list": work_list, | ||||||
| }, | ||||||
| "token": { | ||||||
| "access_token": token.access_token, | ||||||
| "expires": token.expires, | ||||||
| }, | ||||||
| "want_more": size(tail(blobs)) != 0 || size(work_list) != 0, | ||||||
|
||||||
| "want_more": size(tail(blobs)) != 0 || size(work_list) != 0, | |
| "want_more": size(blobs) > 1 || size(work_list) != 0, |
in both files
andrewkroh marked this conversation as resolved.
Show resolved
Hide resolved
andrewkroh marked this conversation as resolved.
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.