-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
fix: LTS playback issues #17498
Closed
Closed
fix: LTS playback issues #17498
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
932cc6d
copy over
pauldambra 999fc17
unexpected eof
pauldambra 098a740
Update UI snapshots for `chromium` (1)
github-actions[bot] a004dcc
Update UI snapshots for `chromium` (1)
github-actions[bot] f598d88
this 'successfully' loads json into the browser - although the record…
pauldambra e7b39de
Merge branch 'master' into fix/lts-playback-with-new-structure
pauldambra bd1595c
Update UI snapshots for `chromium` (1)
github-actions[bot] ef3ab47
Update UI snapshots for `chromium` (1)
github-actions[bot] c31e86e
separate the arrangement and the work
pauldambra 8d3ff61
fix
pauldambra 6868fac
Update UI snapshots for `chromium` (1)
github-actions[bot] 15985e8
Update UI snapshots for `chromium` (1)
github-actions[bot] c324784
wat
pauldambra a79dd1c
lazy version
pauldambra 3921a29
Merge branch 'master' into fix/lts-playback-with-new-structure
pauldambra f0d1c72
and now gzip
pauldambra df9d37c
fiddling
pauldambra 3e722f2
test for the entire content preparation
pauldambra 82cfc11
Update UI snapshots for `chromium` (1)
github-actions[bot] b90780a
Update UI snapshots for `chromium` (1)
github-actions[bot] c58a842
Update UI snapshots for `chromium` (1)
github-actions[bot] 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 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 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 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 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
Binary file modified
BIN
-99 Bytes
(100%)
...-snapshots/Navigation-App-Page-With-Side-Bar-Hidden-Mobile-1-chromium-linux.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains 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
73 changes: 73 additions & 0 deletions
73
posthog/session_recordings/snapshots/convert_legacy_format.py
This file contains 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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import json | ||
from typing import Dict | ||
|
||
import structlog | ||
from django.http import HttpResponse | ||
from prometheus_client import Histogram | ||
from requests import Response | ||
|
||
from posthog.session_recordings.models.session_recording import SessionRecording | ||
from posthog.session_recordings.session_recording_helpers import decompress | ||
from posthog.storage import object_storage | ||
|
||
logger = structlog.get_logger(__name__) | ||
|
||
RECORDING_CONVERSION_TIME_HISTOGRAM = Histogram( | ||
"recording_conversion_time_seconds", | ||
"We convert legacy recordings from LTS format to the latest format, how long does that take?", | ||
) | ||
|
||
|
||
def _save_converted_content_back_to_storage(converted_content: str, recording: SessionRecording) -> None: | ||
try: | ||
from ee.session_recordings.session_recording_extensions import save_recording_with_new_content | ||
|
||
save_recording_with_new_content(recording, converted_content) | ||
except ImportError: | ||
# not running in EE context... shouldn't get here | ||
logger.error("attempted_to_save_converted_content_back_to_storage_in_non_ee_context", recording_id=recording.id) | ||
return | ||
|
||
|
||
def convert_original_version_lts_recording(r: Response, recording: SessionRecording, url: str) -> HttpResponse: | ||
# the original version of the LTS recording was a single file | ||
# its contents were gzipped and then base64 encoded. | ||
# we can't simply stream it back to the requester | ||
|
||
with RECORDING_CONVERSION_TIME_HISTOGRAM.time(): | ||
converted_content = _prepare_legacy_content(r.text) | ||
|
||
original_path = recording.object_storage_path | ||
_save_converted_content_back_to_storage(converted_content, recording) | ||
# TODO we should delete the old recording from storage here, but might not have permissions | ||
object_storage.tag(str(original_path), {"converted": "true"}) | ||
|
||
return HttpResponse(content=(converted_content.encode("utf-8")), content_type="application/json") | ||
|
||
|
||
def _prepare_legacy_content(content: str) -> str: | ||
# historically we stored the recording as a single file with a base64 encoded gzipped json string | ||
# using utf-16 encoding, this `decompress` method unwinds that back to a json string | ||
decoded_content = decompress(content) | ||
json_content = json.loads(decoded_content) | ||
return _convert_legacy_format_from_lts_storage(json_content) | ||
|
||
|
||
def _convert_legacy_format_from_lts_storage(lts_formatted_data: Dict) -> str: | ||
""" | ||
The latest version is JSONL formatted data. | ||
Each line is json containing a window_id and a data array. | ||
This is equivalent to the LTS format snapshot_data_by_window_id property dumped as a single line. | ||
""" | ||
if "snapshot_data_by_window_id" not in lts_formatted_data: | ||
raise ValueError("Invalid LTS format: missing snapshot_data_by_window_id") | ||
|
||
if "version" not in lts_formatted_data or lts_formatted_data["version"] != "2022-12-22": | ||
raise ValueError(f"Invalid LTS format: version is {lts_formatted_data.get('version', 'missing')}") | ||
|
||
snapshot_data_by_window_id = lts_formatted_data["snapshot_data_by_window_id"] | ||
converted = "" | ||
for window_id, data in snapshot_data_by_window_id.items(): | ||
converted += json.dumps({"window_id": window_id, "data": data}, separators=(",", ":")) + "\n" | ||
|
||
return converted.rstrip("\n") |
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.
I couldn't cope with everything going on here 😅
Tried to separate the arrangement and the work...