-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
feat: remove og lts recording storage #25945
Open
pauldambra
wants to merge
7
commits into
master
Choose a base branch
from
feat/remove-og-lts
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
77e2247
feat: remove og lts recording storage
pauldambra 593ec65
slightly less logging
pauldambra 5b3070c
unused class
pauldambra 0141691
make the names more similar
pauldambra 47f69ff
a little fix
pauldambra fe6bcfa
fix
pauldambra d5b96b7
this could be better but these comments at least store the info for t…
pauldambra 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
import gzip | ||
from datetime import timedelta, datetime, UTC | ||
from secrets import token_urlsafe | ||
from unittest.mock import patch, MagicMock | ||
from uuid import uuid4 | ||
|
||
from boto3 import resource | ||
from botocore.config import Config | ||
from freezegun import freeze_time | ||
|
||
from ee.session_recordings.session_recording_extensions import ( | ||
load_persisted_recording, | ||
persist_recording, | ||
save_recording_with_new_content, | ||
) | ||
from posthog.models.signals import mute_selected_signals | ||
from posthog.session_recordings.models.session_recording import SessionRecording | ||
from posthog.session_recordings.queries.test.session_replay_sql import ( | ||
produce_replay_summary, | ||
|
@@ -24,7 +19,7 @@ | |
OBJECT_STORAGE_SECRET_ACCESS_KEY, | ||
OBJECT_STORAGE_BUCKET, | ||
) | ||
from posthog.storage.object_storage import write, list_objects | ||
from posthog.storage.object_storage import write, list_objects, object_storage_client | ||
from posthog.test.base import APIBaseTest, ClickhouseTestMixin | ||
|
||
long_url = f"https://app.posthog.com/my-url?token={token_urlsafe(600)}" | ||
|
@@ -64,21 +59,19 @@ def test_does_not_persist_too_recent_recording(self): | |
|
||
assert not recording.object_storage_path | ||
|
||
def test_can_build_different_object_storage_paths(self) -> None: | ||
def test_can_build_object_storage_paths(self) -> None: | ||
produce_replay_summary( | ||
session_id="test_can_build_different_object_storage_paths-s1", | ||
team_id=self.team.pk, | ||
) | ||
|
||
recording: SessionRecording = SessionRecording.objects.create( | ||
team=self.team, | ||
session_id="test_can_build_different_object_storage_paths-s1", | ||
) | ||
|
||
assert ( | ||
recording.build_object_storage_path("2022-12-22") | ||
== f"session_recordings_lts/team-{self.team.pk}/session-test_can_build_different_object_storage_paths-s1" | ||
) | ||
assert ( | ||
recording.build_object_storage_path("2023-08-01") | ||
recording.build_blob_lts_storage_path("2023-08-01") | ||
== f"session_recordings_lts/team_id/{self.team.pk}/session_id/test_can_build_different_object_storage_paths-s1/data" | ||
) | ||
|
||
|
@@ -100,14 +93,21 @@ def test_persists_recording_from_blob_ingested_storage(self): | |
|
||
# this recording already has several files stored from Mr. Blobby | ||
# these need to be written before creating the recording object | ||
blob_path = f"{TEST_BUCKET}/team_id/{self.team.pk}/session_id/{session_id}/data" | ||
for file in ["a", "b", "c"]: | ||
blob_path = f"{TEST_BUCKET}/team_id/{self.team.pk}/session_id/{session_id}/data" | ||
file_name = f"{blob_path}/{file}" | ||
write(file_name, f"my content-{file}".encode()) | ||
|
||
assert object_storage_client().list_objects(OBJECT_STORAGE_BUCKET, blob_path) == [ | ||
f"{blob_path}/a", | ||
f"{blob_path}/b", | ||
f"{blob_path}/c", | ||
] | ||
|
||
Comment on lines
+101
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. my change at first broke this test but it failed elsewhere... added this assertion so that i got a meaningful failure |
||
recording: SessionRecording = SessionRecording.objects.create(team=self.team, session_id=session_id) | ||
|
||
assert recording.created_at == two_minutes_ago | ||
assert recording.storage_version is None | ||
|
||
persist_recording(recording.session_id, recording.team_id) | ||
recording.refresh_from_db() | ||
|
@@ -126,47 +126,9 @@ def test_persists_recording_from_blob_ingested_storage(self): | |
assert recording.keypress_count == 0 | ||
assert recording.start_url == "https://app.posthog.com/my-url" | ||
|
||
# recordings which were blob ingested can not be loaded with this mechanism | ||
assert load_persisted_recording(recording) is None | ||
|
||
stored_objects = list_objects(recording.build_object_storage_path("2023-08-01")) | ||
stored_objects = list_objects(recording.build_blob_lts_storage_path("2023-08-01")) | ||
assert stored_objects == [ | ||
f"{recording.build_object_storage_path('2023-08-01')}/a", | ||
f"{recording.build_object_storage_path('2023-08-01')}/b", | ||
f"{recording.build_object_storage_path('2023-08-01')}/c", | ||
f"{recording.build_blob_lts_storage_path('2023-08-01')}/a", | ||
f"{recording.build_blob_lts_storage_path('2023-08-01')}/b", | ||
f"{recording.build_blob_lts_storage_path('2023-08-01')}/c", | ||
] | ||
|
||
@patch("ee.session_recordings.session_recording_extensions.object_storage.write") | ||
def test_can_save_content_to_new_location(self, mock_write: MagicMock): | ||
# mute selected signals so the post create signal does not try to persist the recording | ||
with self.settings(OBJECT_STORAGE_SESSION_RECORDING_BLOB_INGESTION_FOLDER=TEST_BUCKET), mute_selected_signals(): | ||
session_id = f"{uuid4()}" | ||
|
||
recording = SessionRecording.objects.create( | ||
team=self.team, | ||
session_id=session_id, | ||
start_time=datetime.fromtimestamp(12345), | ||
end_time=datetime.fromtimestamp(12346), | ||
object_storage_path="some_starting_value", | ||
# None, but that would trigger the persistence behavior, and we don't want that | ||
storage_version="None", | ||
) | ||
|
||
new_key = save_recording_with_new_content(recording, "the new content") | ||
|
||
recording.refresh_from_db() | ||
|
||
expected_path = f"session_recordings_lts/team_id/{self.team.pk}/session_id/{recording.session_id}/data" | ||
assert new_key == f"{expected_path}/12345000-12346000" | ||
|
||
assert recording.object_storage_path == expected_path | ||
assert recording.storage_version == "2023-08-01" | ||
|
||
mock_write.assert_called_with( | ||
f"{expected_path}/12345000-12346000", | ||
gzip.compress(b"the new content"), | ||
extras={ | ||
"ContentEncoding": "gzip", | ||
"ContentType": "application/json", | ||
}, | ||
) |
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
Oops, something went wrong.
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've not looked at these logs in a year, let's remove them