Skip to content
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

Implement cli support for record/replay. #9669

Closed
wants to merge 5 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 24 additions & 2 deletions core/dbt/cli/requires.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import os

import dbt.tracking
from dbt_common.context import set_invocation_context

from dbt_common.context import set_invocation_context, get_invocation_context
from dbt_common.record import Recorder, RecorderMode, get_record_mode_from_env
from dbt_common.clients.system import get_env
from dbt_common.invocation import reset_invocation_id

from dbt.version import installed as installed_version
Expand Down Expand Up @@ -44,6 +47,7 @@
import importlib.util
import time
import traceback
from typing import Optional


def preflight(func):
Expand All @@ -52,7 +56,18 @@ def wrapper(*args, **kwargs):
assert isinstance(ctx, Context)
ctx.obj = ctx.obj or {}

set_invocation_context(os.environ)
rec_mode = get_record_mode_from_env()

recorder: Optional[Recorder] = None
if rec_mode == RecorderMode.REPLAY:
recording_path = os.environ["DBT_REPLAY"]
recorder = Recorder(RecorderMode.REPLAY, recording_path)
elif rec_mode == RecorderMode.RECORD:
recorder = Recorder(RecorderMode.RECORD)

set_invocation_context({})
get_invocation_context().recorder = recorder
get_invocation_context()._env = get_env()

# Flags
flags = Flags(ctx)
Expand Down Expand Up @@ -146,6 +161,13 @@ def wrapper(*args, **kwargs):
)
)

recorder = get_invocation_context().recorder
if recorder is not None:
if recorder.mode == RecorderMode.RECORD:
recorder.write("recording.json")
elif recorder.mode == RecorderMode.REPLAY:
recorder.write_diffs("replay_diffs.json")

if not success:
raise ResultExit(result)

Expand Down