-
Notifications
You must be signed in to change notification settings - Fork 464
box_events: fix handling of large cursor offsets #14319
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 all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,20 @@ rules: | |
Content-Type: | ||
- "application/json" | ||
body: |- | ||
{"access_token":"c3FIOG9vSGV4VHo4QzAyg5T1JvNnJoZ3ExaVNyQWw6WjRsanRKZG5lQk9qUE1BVQ","expires_in":3600,"token_type":"bearer","refresh_token":"c3FIOG9vSGV4VHo4QzAyg5T1JvNnJoZ3ExaVNyQWw6WjRsanRKZG5lQk9qUE1BVQ","issued_token_type":"urn:ietf:params:oauth:token-type:access_token"} | ||
{{ minify_json ` | ||
{ | ||
"access_token": "c3FIOG9vSGV4VHo4QzAyg5T1JvNnJoZ3ExaVNyQWw6WjRsanRKZG5lQk9qUE1BVQ", | ||
"expires_in": 3600, | ||
"token_type": "bearer", | ||
"refresh_token": "c3FIOG9vSGV4VHo4QzAyg5T1JvNnJoZ3ExaVNyQWw6WjRsanRKZG5lQk9qUE1BVQ", | ||
"issued_token_type": "urn:ietf:params:oauth:token-type:access_token" | ||
} | ||
`}} | ||
- path: /2.0/events | ||
methods: [GET] | ||
query_params: | ||
stream_type: all | ||
stream_position: null | ||
request_headers: | ||
Authorization: | ||
- "Bearer c3FIOG9vSGV4VHo4QzAyg5T1JvNnJoZ3ExaVNyQWw6WjRsanRKZG5lQk9qUE1BVQ" | ||
|
@@ -30,4 +39,315 @@ rules: | |
Content-Type: | ||
- "application/json; charset=utf-8" | ||
body: |- | ||
{"chunk_size":2,"entries":[{"source":null,"created_by":{"type":"user","id":"2","name":"Unknown User","login":""},"action_by":null,"created_at":"2019-12-20T11:38:56-08:00","event_id":"97f1b31f-f143-4777-81f8-1b557b39ca33","event_type":"SHIELD_ALERT","ip_address":"10.1.2.3","type":"event","session_id":null,"additional_details":{"shield_alert":{"rule_category":"Anomalous Download","rule_id":123,"rule_name":"Anomalous Download Rule","risk_score":77,"alert_summary":{"description":"Significant increase in download content week over week, 9200% (25.04 MB) more than last week 12 additional files downloaded week over week)","download_delta_size":"25 Mb","download_delta_percent":9200,"historical_period":{"date_range":{"start_date":"2019-12-01T01:01:00-08:00","end_date":"2019-12-08T01:01:00-08:00"},"download_size":"0 Mb","downloaded_files_count":1},"anomaly_period":{"date_range":{"start_date":"2019-12-08T01:01:00-08:00","end_date":"2019-12-15T01:01:00-08:00"},"download_size":"25 Mb","downloaded_files_count":13},"download_ips":[{"ip":"1.128.0.0"},{"ip":"175.16.199.0"}]},"alert_id":444,"priority":"medium","user":{"id":567,"name":"Some user","email":"[email protected]"},"link":"https://cloud.app.box.com/master/shield/alerts/444","created_at":"2019-12-20T11:38:16-08:00"}}},{"created_at":"2022-06-27T05:09:40-07:00","created_by":{"id":"19530772260","login":"[email protected]","name":"Elastic Integrations","type":"user"},"event_id":"e1cb161d5fbd3f3a80fd560f39a0f52a2cff3db9","event_type":"ITEM_CREATE","recorded_at":"2022-06-27T05:09:41-07:00","session_id":"rzraadh3n273zc5f","source":{"content_created_at":"2022-06-27T05:09:40-07:00","content_modified_at":"2022-06-27T05:09:40-07:00","created_at":"2022-06-27T05:09:40-07:00","created_by":{"id":"19530772260","login":"[email protected]","name":"Elastic Integrations","type":"user"},"description":"","etag":"0","folder_upload_email":null,"id":"166233012413","item_status":"active","modified_at":"2022-06-27T05:09:40-07:00","modified_by":{"id":"19530772260","login":"[email protected]","name":"Elastic Integrations","type":"user"},"name":"Platform App Diagnostics run on 2022-06-27 05-09-38 PDT","owned_by":{"id":"19530772260","login":"[email protected]","name":"Elastic Integrations","type":"user"},"parent":{"etag":"0","id":"166232910591","name":"Box Reports","sequence_id":"0","type":"folder"},"path_collection":{"entries":[{"etag":null,"id":"0","name":"All Files","sequence_id":null,"type":"folder"},{"etag":"0","id":"166232910591","name":"Box Reports","sequence_id":"0","type":"folder"}],"total_count":2},"purged_at":null,"sequence_id":"0","shared_link":null,"size":0,"synced":false,"trashed_at":null,"type":"folder"},"type":"event"}],"next_stream_position":1152922976252290800} | ||
{{ minify_json ` | ||
{ | ||
"chunk_size": 2, | ||
"entries": [ | ||
{ | ||
"source": null, | ||
"created_by": { | ||
"type": "user", | ||
"id": "2", | ||
"name": "Unknown User", | ||
"login": "" | ||
}, | ||
"action_by": null, | ||
"created_at": "2019-12-20T11:38:56-08:00", | ||
"event_id": "97f1b31f-f143-4777-81f8-1b557b39ca31", | ||
"event_type": "SHIELD_ALERT", | ||
"ip_address": "10.1.2.3", | ||
"type": "event", | ||
"session_id": null, | ||
"additional_details": { | ||
"shield_alert": { | ||
"rule_category": "Anomalous Download", | ||
"rule_id": 123, | ||
"rule_name": "Anomalous Download Rule", | ||
"risk_score": 77, | ||
"alert_summary": { | ||
"description": "Significant increase in download content week over week, 9200% (25.04 MB) more than last week 12 additional files downloaded week over week)", | ||
"download_delta_size": "25 Mb", | ||
"download_delta_percent": 9200, | ||
"historical_period": { | ||
"date_range": { | ||
"start_date": "2019-12-01T01:01:00-08:00", | ||
"end_date": "2019-12-08T01:01:00-08:00" | ||
}, | ||
"download_size": "0 Mb", | ||
"downloaded_files_count": 1 | ||
}, | ||
"anomaly_period": { | ||
"date_range": { | ||
"start_date": "2019-12-08T01:01:00-08:00", | ||
"end_date": "2019-12-15T01:01:00-08:00" | ||
}, | ||
"download_size": "25 Mb", | ||
"downloaded_files_count": 13 | ||
}, | ||
"download_ips": [ | ||
{ | ||
"ip": "1.128.0.0" | ||
}, | ||
{ | ||
"ip": "175.16.199.0" | ||
} | ||
] | ||
}, | ||
"alert_id": 444, | ||
"priority": "medium", | ||
"user": { | ||
"id": 567, | ||
"name": "Some user", | ||
"email": "[email protected]" | ||
}, | ||
"link": "https://cloud.app.box.com/master/shield/alerts/444", | ||
"created_at": "2019-12-20T11:38:16-08:00" | ||
} | ||
} | ||
}, | ||
{ | ||
"created_at": "2022-06-27T05:09:40-07:00", | ||
"created_by": { | ||
"id": "19530772260", | ||
"login": "[email protected]", | ||
"name": "Elastic Integrations", | ||
"type": "user" | ||
}, | ||
"event_id": "e1cb161d5fbd3f3a80fd560f39a0f52a2cff3db9", | ||
"event_type": "ITEM_CREATE", | ||
"recorded_at": "2022-06-27T05:09:41-07:00", | ||
"session_id": "rzraadh3n273zc5f", | ||
"source": { | ||
"content_created_at": "2022-06-27T05:09:40-07:00", | ||
"content_modified_at": "2022-06-27T05:09:40-07:00", | ||
"created_at": "2022-06-27T05:09:40-07:00", | ||
"created_by": { | ||
"id": "19530772260", | ||
"login": "[email protected]", | ||
"name": "Elastic Integrations", | ||
"type": "user" | ||
}, | ||
"description": "", | ||
"etag": "0", | ||
"folder_upload_email": null, | ||
"id": "166233012413", | ||
"item_status": "active", | ||
"modified_at": "2022-06-27T05:09:40-07:00", | ||
"modified_by": { | ||
"id": "19530772260", | ||
"login": "[email protected]", | ||
"name": "Elastic Integrations", | ||
"type": "user" | ||
}, | ||
"name": "Platform App Diagnostics run on 2022-06-27 05-09-38 PDT", | ||
"owned_by": { | ||
"id": "19530772260", | ||
"login": "[email protected]", | ||
"name": "Elastic Integrations", | ||
"type": "user" | ||
}, | ||
"parent": { | ||
"etag": "0", | ||
"id": "166232910591", | ||
"name": "Box Reports", | ||
"sequence_id": "0", | ||
"type": "folder" | ||
}, | ||
"path_collection": { | ||
"entries": [ | ||
{ | ||
"etag": null, | ||
"id": "0", | ||
"name": "All Files", | ||
"sequence_id": null, | ||
"type": "folder" | ||
}, | ||
{ | ||
"etag": "0", | ||
"id": "166232910591", | ||
"name": "Box Reports", | ||
"sequence_id": "0", | ||
"type": "folder" | ||
} | ||
], | ||
"total_count": 2 | ||
}, | ||
"purged_at": null, | ||
"sequence_id": "0", | ||
"shared_link": null, | ||
"size": 0, | ||
"synced": false, | ||
"trashed_at": null, | ||
"type": "folder" | ||
}, | ||
"type": "event" | ||
} | ||
], | ||
"next_stream_position": 1152922976252290800 | ||
} | ||
`}} | ||
- path: /2.0/events | ||
methods: [GET] | ||
query_params: | ||
stream_type: all | ||
# This is a consequence of loss of exact representation of ints in floats. | ||
# There is no good way to deal with this. The least worst approach to fix | ||
# it without changing the cursor state store's type handling is to have | ||
# a nextafter template helper. That is obviously a terrible solution. | ||
stream_position: 1152922976252290816 | ||
request_headers: | ||
Authorization: | ||
- "Bearer c3FIOG9vSGV4VHo4QzAyg5T1JvNnJoZ3ExaVNyQWw6WjRsanRKZG5lQk9qUE1BVQ" | ||
responses: | ||
- status_code: 200 | ||
headers: | ||
Content-Type: | ||
- "application/json; charset=utf-8" | ||
body: |- | ||
{{ minify_json ` | ||
{ | ||
"chunk_size": 2, | ||
"entries": [ | ||
{ | ||
"source": null, | ||
"created_by": { | ||
"type": "user", | ||
"id": "2", | ||
"name": "Unknown User", | ||
"login": "" | ||
}, | ||
"action_by": null, | ||
"created_at": "2019-12-20T11:38:56-08:00", | ||
"event_id": "97f1b31f-f143-4777-81f8-1b557b39ca32", | ||
"event_type": "SHIELD_ALERT", | ||
"ip_address": "10.1.2.3", | ||
"type": "event", | ||
"session_id": null, | ||
"additional_details": { | ||
"shield_alert": { | ||
"rule_category": "Anomalous Download", | ||
"rule_id": 123, | ||
"rule_name": "Anomalous Download Rule", | ||
"risk_score": 77, | ||
"alert_summary": { | ||
"description": "Significant increase in download content week over week, 9200% (25.04 MB) more than last week 12 additional files downloaded week over week)", | ||
"download_delta_size": "25 Mb", | ||
"download_delta_percent": 9200, | ||
"historical_period": { | ||
"date_range": { | ||
"start_date": "2019-12-01T01:01:00-08:00", | ||
"end_date": "2019-12-08T01:01:00-08:00" | ||
}, | ||
"download_size": "0 Mb", | ||
"downloaded_files_count": 1 | ||
}, | ||
"anomaly_period": { | ||
"date_range": { | ||
"start_date": "2019-12-08T01:01:00-08:00", | ||
"end_date": "2019-12-15T01:01:00-08:00" | ||
}, | ||
"download_size": "25 Mb", | ||
"downloaded_files_count": 13 | ||
}, | ||
"download_ips": [ | ||
{ | ||
"ip": "1.128.0.0" | ||
}, | ||
{ | ||
"ip": "175.16.199.0" | ||
} | ||
] | ||
}, | ||
"alert_id": 444, | ||
"priority": "medium", | ||
"user": { | ||
"id": 567, | ||
"name": "Some user", | ||
"email": "[email protected]" | ||
}, | ||
"link": "https://cloud.app.box.com/master/shield/alerts/444", | ||
"created_at": "2019-12-20T11:38:16-08:00" | ||
} | ||
} | ||
}, | ||
{ | ||
"created_at": "2022-06-27T05:09:40-07:00", | ||
"created_by": { | ||
"id": "19530772260", | ||
"login": "[email protected]", | ||
"name": "Elastic Integrations", | ||
"type": "user" | ||
}, | ||
"event_id": "e1cb161d5fbd3f3a80fd560f39a0f52a2cff3db8", | ||
"event_type": "ITEM_CREATE", | ||
"recorded_at": "2022-06-27T05:09:41-07:00", | ||
"session_id": "rzraadh3n273zc5f", | ||
"source": { | ||
"content_created_at": "2022-06-27T05:09:40-07:00", | ||
"content_modified_at": "2022-06-27T05:09:40-07:00", | ||
"created_at": "2022-06-27T05:09:40-07:00", | ||
"created_by": { | ||
"id": "19530772260", | ||
"login": "[email protected]", | ||
"name": "Elastic Integrations", | ||
"type": "user" | ||
}, | ||
"description": "", | ||
"etag": "0", | ||
"folder_upload_email": null, | ||
"id": "166233012413", | ||
"item_status": "active", | ||
"modified_at": "2022-06-27T05:09:40-07:00", | ||
"modified_by": { | ||
"id": "19530772260", | ||
"login": "[email protected]", | ||
"name": "Elastic Integrations", | ||
"type": "user" | ||
}, | ||
"name": "Platform App Diagnostics run on 2022-06-27 05-09-38 PDT", | ||
"owned_by": { | ||
"id": "19530772260", | ||
"login": "[email protected]", | ||
"name": "Elastic Integrations", | ||
"type": "user" | ||
}, | ||
"parent": { | ||
"etag": "0", | ||
"id": "166232910591", | ||
"name": "Box Reports", | ||
"sequence_id": "0", | ||
"type": "folder" | ||
}, | ||
"path_collection": { | ||
"entries": [ | ||
{ | ||
"etag": null, | ||
"id": "0", | ||
"name": "All Files", | ||
"sequence_id": null, | ||
"type": "folder" | ||
}, | ||
{ | ||
"etag": "0", | ||
"id": "166232910591", | ||
"name": "Box Reports", | ||
"sequence_id": "0", | ||
"type": "folder" | ||
} | ||
], | ||
"total_count": 2 | ||
}, | ||
"purged_at": null, | ||
"sequence_id": "0", | ||
"shared_link": null, | ||
"size": 0, | ||
"synced": false, | ||
"trashed_at": null, | ||
"type": "folder" | ||
}, | ||
"type": "event" | ||
} | ||
], | ||
"next_stream_position": 2152922976252290800 | ||
} | ||
`}} |
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
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.
In the request tracer logs I see
?stream_position=2152922976252290816
so I think we have lost precision.This cursor on disk has:
{"k":"httpjson::httpjson-box_events.events-20eb7aed-40ef-4cca-bccb-d27053fcd2dc::http://svc-box-http:8080/2.0/events","v":{"ttl":1800000000000,"updated":[809677759,1751046234],"cursor":{"next_stream_position":"2.1529229762522908e+18"}}}
So I assume that
httpjson
is not unmarshaling withjson.UseNumber
. Without usingjson.Number
and avoiding the number -> float64 -> int64 conversion, I'm not sure we can fix this with configuration only.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.
Yes, the fix here is a reasonably non-invasive fix to something that is the consequence of some quite unfortunate decisions that are spread throughout the agent, the JSON serialisation spec and the data source. This is all discussed in the issue.