From 962d29d8931fb37de1e0bdb0cbec9733ec099755 Mon Sep 17 00:00:00 2001 From: "Wei-Chun, Chang" Date: Wed, 15 Jan 2025 23:34:17 +0700 Subject: [PATCH 1/2] Add telemetry Signed-off-by: Wei-Chun, Chang --- .../lineage/PresetCheckRecommendation.tsx | 54 +++++++++++++++---- js/src/lib/api/sessionStorageKeys.ts | 1 + js/src/lib/api/track.ts | 9 ++++ 3 files changed, 53 insertions(+), 11 deletions(-) diff --git a/js/src/components/lineage/PresetCheckRecommendation.tsx b/js/src/components/lineage/PresetCheckRecommendation.tsx index 76441ee0..cdc90cbf 100644 --- a/js/src/components/lineage/PresetCheckRecommendation.tsx +++ b/js/src/components/lineage/PresetCheckRecommendation.tsx @@ -24,6 +24,7 @@ import { submitRunFromCheck } from "@/lib/api/runs"; import { useRecceActionContext } from "@/lib/hooks/RecceActionContext"; import { sessionStorageKeys } from "@/lib/api/sessionStorageKeys"; import { useRecceServerFlag } from "@/lib/hooks/useRecceServerFlag"; +import { trackRecommendCheck } from "@/lib/api/track"; const usePresetCheckRecommendation = () => { const queryChecks = useQuery({ @@ -98,17 +99,18 @@ export const PresetCheckRecommendation = () => { const [affectedModels, setAffectedModels] = useState(); const [performedRecommend, setPerformedRecommend] = useState(false); const [ignoreRecommend, setIgnoreRecommend] = useState(false); - const [recommendRefresh, setRecommendRefresh] = useState(false); + const [recommendRerun, setRecommendRerun] = useState(false); const { isOpen, onOpen, onClose } = useDisclosure(); - const recommendationKey = sessionStorageKeys.recommendationIgnored; + const recommendIgnoreKey = sessionStorageKeys.recommendationIgnored; + const recommendShowKey = sessionStorageKeys.recommendationShowed; const prevRefreshKey = sessionStorageKeys.prevRefreshTimeStamp; useEffect(() => { - const ignored = sessionStorage.getItem(recommendationKey); + const ignored = sessionStorage.getItem(recommendIgnoreKey); if (ignored) { setIgnoreRecommend(true); } - }, [recommendationKey]); + }, [recommendIgnoreKey]); useEffect(() => { if (!recommendedCheck || !selectedNodes) { @@ -135,18 +137,20 @@ export const PresetCheckRecommendation = () => { setPerformedRecommend(true); return; } + setPerformedRecommend(false); + setRecommendRerun(true); + // Check if the env has been refreshed since the last run const prevEnvTimeStamp = sessionStorage.getItem(prevRefreshKey); if ( prevEnvTimeStamp === null || parseInt(prevEnvTimeStamp) !== envTimeStamp ) { sessionStorage.setItem(prevRefreshKey, envTimeStamp.toString()); - sessionStorage.removeItem(sessionStorageKeys.recommendationIgnored); + sessionStorage.removeItem(recommendIgnoreKey); + sessionStorage.removeItem(recommendShowKey); setIgnoreRecommend(false); } - setPerformedRecommend(false); - setRecommendRefresh(true); } const check = recommendedCheck; @@ -182,11 +186,21 @@ export const PresetCheckRecommendation = () => { } else { setAffectedModels(`${selectedNodes.length} models`); } + + if (!sessionStorage.getItem(recommendShowKey)) { + const prevEnvTimeStamp = sessionStorage.getItem(prevRefreshKey); + sessionStorage.setItem(recommendShowKey, "true"); + trackRecommendCheck({ + action: "recommend", + from: prevEnvTimeStamp === null ? "initial" : "rerun", + }); + } }, [ recommendedCheck, selectedNodes, lineageGraph, - recommendationKey, + recommendIgnoreKey, + recommendShowKey, prevRefreshKey, envInfo, ]); @@ -216,7 +230,7 @@ export const PresetCheckRecommendation = () => { <> - {!recommendRefresh ? ( + {!recommendRerun ? ( <> @@ -238,12 +252,26 @@ export const PresetCheckRecommendation = () => { size="xs" onClick={() => { setIgnoreRecommend(true); - sessionStorage.setItem(recommendationKey, "true"); + sessionStorage.setItem(recommendIgnoreKey, "true"); + trackRecommendCheck({ + action: "ignore", + from: recommendRerun ? "rerun" : "initial", + }); }} > Ignore - @@ -275,6 +303,10 @@ export const PresetCheckRecommendation = () => { onClose(); performPresetCheck(); setPerformedRecommend(true); + trackRecommendCheck({ + action: "execute", + from: recommendRerun ? "rerun" : "initial", + }); }} > Execute on {numNodes} models diff --git a/js/src/lib/api/sessionStorageKeys.ts b/js/src/lib/api/sessionStorageKeys.ts index 1860c78d..76da7548 100644 --- a/js/src/lib/api/sessionStorageKeys.ts +++ b/js/src/lib/api/sessionStorageKeys.ts @@ -2,5 +2,6 @@ const prefix = "recce"; export const sessionStorageKeys = { recommendationIgnored: `${prefix}-recommendation-ignored`, + recommendationShowed: `${prefix}-recommendation-showed`, prevRefreshTimeStamp: `${prefix}-prev-refresh-timestamp`, }; diff --git a/js/src/lib/api/track.ts b/js/src/lib/api/track.ts index 4b625ed2..4b268e8c 100644 --- a/js/src/lib/api/track.ts +++ b/js/src/lib/api/track.ts @@ -72,3 +72,12 @@ interface SingleEnvironmentProps { export function trackSingleEnvironment(props: SingleEnvironmentProps) { amplitude.track("[Experiment] single_environment", props); } + +interface RecommendPresetCheckProps { + action: "recommend" | "ignore" | "perform" | "execute"; + from?: "initial" | "rerun"; +} + +export function trackRecommendCheck(props: RecommendPresetCheckProps) { + amplitude.track("[Experiment] recommend_preset_check", props); +} From 91ed5661adcc3f6f591170e2c36f9b2e5461b8f2 Mon Sep 17 00:00:00 2001 From: "Wei-Chun, Chang" Date: Wed, 15 Jan 2025 23:53:33 +0700 Subject: [PATCH 2/2] Track number of nodes executed Signed-off-by: Wei-Chun, Chang --- .../lineage/PresetCheckRecommendation.tsx | 68 +++++++++++-------- js/src/lib/api/track.ts | 3 +- 2 files changed, 43 insertions(+), 28 deletions(-) diff --git a/js/src/components/lineage/PresetCheckRecommendation.tsx b/js/src/components/lineage/PresetCheckRecommendation.tsx index cdc90cbf..79e9913a 100644 --- a/js/src/components/lineage/PresetCheckRecommendation.tsx +++ b/js/src/components/lineage/PresetCheckRecommendation.tsx @@ -122,15 +122,13 @@ export const PresetCheckRecommendation = () => { recommendedCheck.last_run?.run_at ).getTime(); - let currEnvTimeStamp = 0; - let baseEnvTimeStamp = 0; const dbtInfo = envInfo?.dbt; - if (dbtInfo?.current?.generated_at) { - currEnvTimeStamp = new Date(dbtInfo.current?.generated_at).getTime(); - } - if (dbtInfo?.base?.generated_at) { - baseEnvTimeStamp = new Date(dbtInfo?.base?.generated_at).getTime(); - } + const currEnvTimeStamp = dbtInfo?.current?.generated_at + ? new Date(dbtInfo.current.generated_at).getTime() + : 0; + const baseEnvTimeStamp = dbtInfo?.base?.generated_at + ? new Date(dbtInfo.base.generated_at).getTime() + : 0; const envTimeStamp = Math.max(currEnvTimeStamp, baseEnvTimeStamp); if (runTimeStamp >= envTimeStamp) { @@ -140,7 +138,7 @@ export const PresetCheckRecommendation = () => { setPerformedRecommend(false); setRecommendRerun(true); - // Check if the env has been refreshed since the last run + // Check if the env has been refreshed const prevEnvTimeStamp = sessionStorage.getItem(prevRefreshKey); if ( prevEnvTimeStamp === null || @@ -154,29 +152,19 @@ export const PresetCheckRecommendation = () => { } const check = recommendedCheck; + const extractNodeNames = (nodeIds: string[]) => { + const nodes = nodeIds.map((nodeId) => lineageGraph?.nodes[nodeId]?.name); + return nodes.join(", "); + }; if (selectedNodes.length > 0 && selectedNodes.length <= 3) { if (check.params?.node_names) { const nodeNames = check.params?.node_names.join(", "); setAffectedModels(`'${nodeNames}'`); } else if (check.params?.node_ids) { - const nodes = []; - for (const nodeId of check.params?.node_ids) { - const node = lineageGraph?.nodes[nodeId]; - if (node) { - nodes.push(node.name); - } - } - const nodeNames = nodes.join(", "); + const nodeNames = extractNodeNames(check.params?.node_ids); setAffectedModels(`'${nodeNames}'`); } else if (selectedNodes) { - const nodes = []; - for (const nodeId of selectedNodes) { - const node = lineageGraph?.nodes[nodeId]; - if (node) { - nodes.push(node.name); - } - } - const nodeNames = nodes.join(", "); + const nodeNames = extractNodeNames(selectedNodes); setAffectedModels(`'${nodeNames}'`); } } else if (lineageGraph?.modifiedSet?.length === selectedNodes.length) { @@ -187,6 +175,7 @@ export const PresetCheckRecommendation = () => { setAffectedModels(`${selectedNodes.length} models`); } + // Track recommendation is shown the first time if (!sessionStorage.getItem(recommendShowKey)) { const prevEnvTimeStamp = sessionStorage.getItem(prevRefreshKey); sessionStorage.setItem(recommendShowKey, "true"); @@ -256,6 +245,7 @@ export const PresetCheckRecommendation = () => { trackRecommendCheck({ action: "ignore", from: recommendRerun ? "rerun" : "initial", + nodes: numNodes, }); }} > @@ -269,6 +259,7 @@ export const PresetCheckRecommendation = () => { trackRecommendCheck({ action: "perform", from: recommendRerun ? "rerun" : "initial", + nodes: numNodes, }); }} > @@ -276,7 +267,18 @@ export const PresetCheckRecommendation = () => { - + { + onClose(); + trackRecommendCheck({ + action: "close", + from: recommendRerun ? "rerun" : "initial", + nodes: numNodes, + }); + }} + isCentered + > Row Count Check @@ -296,7 +298,18 @@ export const PresetCheckRecommendation = () => { - +