Skip to content

Commit

Permalink
[Feature] DRC-986 Telemetry for single environment experiment
Browse files Browse the repository at this point in the history
Signed-off-by: Kent Huang <[email protected]>
Co-authored-by: Wei-Chun, Chang <[email protected]>
  • Loading branch information
kentwelcome and wcchang1115 committed Jan 3, 2025
1 parent 17d6541 commit 8092c1a
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 8 deletions.
7 changes: 5 additions & 2 deletions js/src/components/lineage/NodeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { is } from "date-fns/locale";
import { run } from "node:test";
import { DisableTooltipMessages } from "@/constants/tooltipMessage";
import { PreviewChangeView } from "./PreviewChangeView";
import { trackPreviewChange } from "@/lib/api/track";
import { trackPreviewChange, trackSingleEnvironment } from "@/lib/api/track";
import { useRecceServerFlag } from "@/lib/hooks/useRecceServerFlag";

interface NodeViewProps {
Expand Down Expand Up @@ -298,7 +298,10 @@ export function NodeView({ node, onCloseNode }: NodeViewProps) {
setPrimaryKeys(primaryKey !== undefined ? [primaryKey] : undefined);
}
onPreviewChangeOpen();
trackPreviewChange({ action: "explore", node: node.name });
trackSingleEnvironment({
action: "preview_changes",
node: node.name,
});
}}
>
Preview Changes
Expand Down
7 changes: 7 additions & 0 deletions js/src/components/lineage/PreviewChangeView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import { useRecceQueryContext } from "@/lib/hooks/RecceQueryContext";
import {
trackPreviewChange,
trackPreviewChangeFeedback,
trackSingleEnvironment,
} from "@/lib/api/track";
import { useGuideToast } from "@/lib/hooks/useGuideToast";
import { useRecceServerFlag } from "@/lib/hooks/useRecceServerFlag";
Expand Down Expand Up @@ -222,6 +223,12 @@ export function PreviewChangeView({
externalLink:
"https://datarecce.io/docs/get-started/#prepare-dbt-artifacts",
externalLinkText: "Learn how.",
onExternalLinkClick: () =>
trackSingleEnvironment({
action: "external_link",
from: "preview_changes",
node: current?.name,
}),
});

useEffect(() => {
Expand Down
8 changes: 8 additions & 0 deletions js/src/components/onboarding-guide/OnboardingGuide.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { useEffect, useState } from "react";
import { markOnboardingCompleted } from "@/lib/api/flag";
import { useRecceServerFlag } from "@/lib/hooks/useRecceServerFlag";
import { InfoOutlineIcon } from "@chakra-ui/icons";
import { trackSingleEnvironment } from "@/lib/api/track";

interface GuideProps {
isGuideOpen: boolean;
Expand Down Expand Up @@ -80,6 +81,12 @@ const SingleEnvGuide = ({ isGuideOpen, closeGuide }: GuideProps) => {
textDecor="underline"
isExternal
href="https://datarecce.io/docs/get-started/#prepare-dbt-artifacts"
onClick={() =>
trackSingleEnvironment({
action: "external_link",
from: "onboarding",
})
}
>
Learn how.
</Link>
Expand Down Expand Up @@ -111,6 +118,7 @@ const OnboardingGuide = () => {
const singleEnvMode = flags.single_env_onboarding;
if (singleEnvMode && showOnboardingGuide) {
setISSingleEnvGuideOpen(true);
trackSingleEnvironment({ action: "onboarding" });
return;
}

Expand Down
14 changes: 14 additions & 0 deletions js/src/lib/api/track.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,17 @@ interface PreviewChangeFeedbackProps {
export function trackPreviewChangeFeedback(props: PreviewChangeFeedbackProps) {
amplitude.track("[Experiment] preview_change", props);
}

interface SingleEnvironmentProps {
action:
| "onboarding"
| "external_link"
| "preview_changes"
| `target_base_added`;
from?: "onboarding" | "preview_changes";
node?: string;
}

export function trackSingleEnvironment(props: SingleEnvironmentProps) {
amplitude.track("[Experiment] single_environment", props);
}
3 changes: 3 additions & 0 deletions js/src/lib/hooks/LineageGraphContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import path from "path";
import { aggregateRuns, RunsAggregated } from "../api/runs";
import { markRelaunchHintCompleted } from "../api/flag";
import { useRecceServerFlag } from "./useRecceServerFlag";
import { trackSingleEnvironment } from "../api/track";

interface EnvInfo {
adapterType?: string;
Expand Down Expand Up @@ -249,7 +250,9 @@ export function LineageGraphContextProvider({ children }: LineageGraphProps) {
flags?.single_env_onboarding &&
flags?.show_relaunch_hint
) {
// User has added a target-base folder
setRelaunchHintOpen(true);
trackSingleEnvironment({ action: "target_base_added" });
} else {
setRelaunchHintOpen(false);
}
Expand Down
12 changes: 11 additions & 1 deletion js/src/lib/hooks/useGuideToast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,16 @@ export function useGuideToast(options: {
description: string;
externalLink?: string;
externalLinkText?: string;
onExternalLinkClick?: () => void;
}) {
const toast = useToast();
const { guideId, description, externalLink, externalLinkText } = options;
const {
guideId,
description,
externalLink,
externalLinkText,
onExternalLinkClick,
} = options;

function guideToast() {
if (toast.isActive(guideId)) {
Expand Down Expand Up @@ -48,6 +55,9 @@ export function useGuideToast(options: {
isExternal
href={externalLink}
onClick={() => {
if (onExternalLinkClick) {
onExternalLinkClick();
}
onClose();
}}
>
Expand Down
2 changes: 1 addition & 1 deletion recce/event/CONFIG
Original file line number Diff line number Diff line change
@@ -1 +1 @@
event_api_key: <API_KEY>
event_api_key: <API_KEY>
10 changes: 9 additions & 1 deletion recce/event/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
from recce import is_ci_env, get_version, get_runner
from recce import yaml as pyml
from recce.event.collector import Collector
from recce.git import current_branch, hosting_repo
from recce.github import is_github_codespace, get_github_codespace_info, get_github_codespace_name, \
get_github_codespace_available_at
from recce.git import current_branch, hosting_repo

USER_HOME = os.path.expanduser('~')
RECCE_USER_HOME = os.path.join(USER_HOME, '.recce')
Expand Down Expand Up @@ -249,6 +249,14 @@ def log_codespaces_events(command):
_collector.send_events()


def log_single_env_event():
prop = dict(

Check warning on line 253 in recce/event/__init__.py

View check run for this annotation

Codecov / codecov/patch

recce/event/__init__.py#L253

Added line #L253 was not covered by tests
action='launch_server',
)
log_event(prop, '[Experiment] single_environment')
_collector.send_events()

Check warning on line 257 in recce/event/__init__.py

View check run for this annotation

Codecov / codecov/patch

recce/event/__init__.py#L256-L257

Added lines #L256 - L257 were not covered by tests


def capture_exception(e):
user_id = load_user_profile().get('user_id')
if is_ci_env() is True:
Expand Down
7 changes: 4 additions & 3 deletions recce/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from .apis.run_api import run_router
from .config import RecceConfig
from .core import load_context, default_context
from .event import log_api_event
from .event import log_api_event, log_single_env_event
from .exceptions import RecceException
from .run import load_preset_checks
from .state import RecceStateLoader
Expand All @@ -48,8 +48,10 @@ async def lifespan(fastapi: FastAPI):
kwargs = app_state.kwargs
ctx = load_context(**kwargs, state_loader=state_loader)
ctx.start_monitor_artifacts(callback=dbt_artifacts_updated_callback)
if app_state.flag.get("single_env_onboarding", False):
if app_state.flag.get("single_env_onboarding", False) is True:

Check warning on line 51 in recce/server.py

View check run for this annotation

Codecov / codecov/patch

recce/server.py#L51

Added line #L51 was not covered by tests
# [Experiment 2] Start with Single Environment
ctx.start_monitor_base_env(callback=dbt_env_updated_callback)
log_single_env_event()

Check warning on line 54 in recce/server.py

View check run for this annotation

Codecov / codecov/patch

recce/server.py#L54

Added line #L54 was not covered by tests

# Initialize Recce Config
config = RecceConfig(config_file=kwargs.get('config'))
Expand Down Expand Up @@ -108,7 +110,6 @@ def dbt_artifacts_updated_callback(file_changed_event: Any):


def dbt_env_updated_callback():

logger.info("Detect 'manifest.json' and 'catalog.json' are generated under 'target-base' directory")
broadcast_command = {
'command': 'relaunch',
Expand Down

0 comments on commit 8092c1a

Please sign in to comment.