-
Notifications
You must be signed in to change notification settings - Fork 2.2k
feat: opt-in event log retention #33863
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
Open
bhark
wants to merge
8
commits into
dagster-io:master
Choose a base branch
from
bhark:feat/event-log-retention
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 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
3664052
feat(storage): add event log retention config and purge_events method
bhark 74cc9b2
feat(daemon): add event log retention daemon
bhark 024b350
test: cover event log purge semantics and daemon iteration
bhark e4ecea9
feat(storage): index event_logs.timestamp for retention purges
bhark 469a812
perf(storage): scan purge_events oldest-first via order by id
bhark da65677
feat(daemon): warn once when event log retention runs against per-run…
bhark 0b1b5b9
feat(daemon): demote zero-deletion event log retention log to debug
bhark 6b2f6ec
fix(storage): strip tzinfo on event log purge cutoff to match stored …
bhark 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
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
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
29 changes: 29 additions & 0 deletions
29
python_modules/dagster/dagster/_daemon/event_log_retention.py
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 |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| import datetime | ||
| import os | ||
|
|
||
| from dagster._core.workspace.context import IWorkspaceProcessContext | ||
| from dagster._daemon.daemon import IntervalDaemon | ||
| from dagster._time import get_current_datetime | ||
|
|
||
| _INTERVAL_SECONDS = int(os.environ.get("EVENT_LOG_RETENTION_DAEMON_INTERVAL_SECONDS", "3600")) | ||
|
|
||
|
|
||
| class EventLogRetentionDaemon(IntervalDaemon): | ||
| def __init__(self, interval_seconds: int = _INTERVAL_SECONDS): | ||
| super().__init__(interval_seconds=interval_seconds) | ||
|
|
||
| @classmethod | ||
| def daemon_type(cls): | ||
| return "EVENT_LOG_RETENTION" | ||
|
|
||
| def run_iteration(self, workspace_process_context: IWorkspaceProcessContext): | ||
| yield | ||
| instance = workspace_process_context.instance | ||
| days = instance.event_log_retention_days | ||
| if days is None: | ||
| return | ||
| cutoff = (get_current_datetime() - datetime.timedelta(days=days)).timestamp() | ||
| deleted = instance.event_log_storage.purge_events(cutoff) | ||
| self._logger.info( | ||
| f"Purged {deleted} non-asset event log row(s) older than {days} day(s).", | ||
| ) | ||
|
bhark marked this conversation as resolved.
Outdated
|
||
78 changes: 78 additions & 0 deletions
78
python_modules/dagster/dagster_tests/daemon_tests/test_event_log_retention_daemon.py
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 |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| import os | ||
| import tempfile | ||
| import time | ||
| from types import SimpleNamespace | ||
|
|
||
| import dagster as dg | ||
| from dagster._core.events import DagsterEventType, EngineEventData, StepMaterializationData | ||
| from dagster._core.execution.plan.objects import StepSuccessData | ||
| from dagster._core.utils import make_new_run_id | ||
| from dagster._daemon.event_log_retention import EventLogRetentionDaemon | ||
|
|
||
|
|
||
| def _entry(run_id, timestamp, event_type, event_specific_data=None): | ||
| return dg.EventLogEntry( | ||
| error_info=None, | ||
| user_message="", | ||
| level="debug", | ||
| run_id=run_id, | ||
| timestamp=timestamp, | ||
| dagster_event=dg.DagsterEvent( | ||
| event_type_value=event_type.value, | ||
| job_name="nonce", | ||
| event_specific_data=event_specific_data, | ||
| ), | ||
| ) | ||
|
|
||
|
|
||
| def test_event_log_retention_daemon_iteration_purges_per_config(): | ||
| """One full daemon iteration with retention configured deletes old non-asset rows only.""" | ||
| run_id = make_new_run_id() | ||
| old_ts = time.time() - 60 * 60 * 24 * 30 # 30 days ago | ||
| recent_ts = time.time() | ||
|
|
||
| with ( | ||
| tempfile.TemporaryDirectory(dir=os.getcwd()) as tmpdir, | ||
| dg.instance_for_test( | ||
| temp_dir=tmpdir, | ||
| overrides={ | ||
| "retention": {"event_logs": {"purge_after_days": 7}}, | ||
| "event_log_storage": { | ||
| "module": "dagster._core.storage.event_log", | ||
| "class": "ConsolidatedSqliteEventLogStorage", | ||
| "config": {"base_dir": tmpdir}, | ||
| }, | ||
| }, | ||
| ) as instance, | ||
| ): | ||
| instance.store_event( | ||
| _entry( | ||
| run_id, | ||
| old_ts, | ||
| DagsterEventType.ASSET_MATERIALIZATION, | ||
| StepMaterializationData(dg.AssetMaterialization(asset_key=dg.AssetKey("a"))), | ||
| ) | ||
| ) | ||
| instance.store_event( | ||
| _entry( | ||
| run_id, | ||
| old_ts, | ||
| DagsterEventType.ENGINE_EVENT, | ||
| EngineEventData.in_process(1), | ||
| ) | ||
| ) | ||
| instance.store_event( | ||
| _entry( | ||
| run_id, | ||
| recent_ts, | ||
| DagsterEventType.STEP_SUCCESS, | ||
| StepSuccessData(duration_ms=1.0), | ||
| ) | ||
| ) | ||
|
|
||
| list(EventLogRetentionDaemon().run_iteration(SimpleNamespace(instance=instance))) | ||
|
|
||
| remaining = {entry.dagster_event.event_type_value for entry in instance.all_logs(run_id)} | ||
| assert DagsterEventType.ASSET_MATERIALIZATION.value in remaining | ||
| assert DagsterEventType.STEP_SUCCESS.value in remaining | ||
| assert DagsterEventType.ENGINE_EVENT.value not in remaining |
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.
Uh oh!
There was an error while loading. Please reload this page.