Skip to content

Commit

Permalink
track events with validate apply v2 ff (#3636)
Browse files Browse the repository at this point in the history
Co-authored-by: Feroze Mohideen <[email protected]>
  • Loading branch information
ianedwards and Feroze Mohideen authored Sep 22, 2023
1 parent 395f01b commit 97256e8
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 37 deletions.
6 changes: 6 additions & 0 deletions api/server/handlers/porter_app/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,15 @@ func (v *PorterAppAnalyticsHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
return
}

validateApplyV2 := project.GetFeatureFlag(models.ValidateApplyV2, v.Config().LaunchDarklyClient)
if request.Step == "stack-launch-start" {
v.Config().AnalyticsClient.Track(analytics.StackLaunchStartTrack(&analytics.StackLaunchStartOpts{
ProjectScopedTrackOpts: analytics.GetProjectScopedTrackOpts(user.ID, project.ID),
Email: user.Email,
FirstName: user.FirstName,
LastName: user.LastName,
CompanyName: user.CompanyName,
ValidateApplyV2: validateApplyV2,
}))
}

Expand All @@ -53,6 +55,7 @@ func (v *PorterAppAnalyticsHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
FirstName: user.FirstName,
LastName: user.LastName,
CompanyName: user.CompanyName,
ValidateApplyV2: validateApplyV2,
}))
}

Expand All @@ -64,6 +67,7 @@ func (v *PorterAppAnalyticsHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
FirstName: user.FirstName,
LastName: user.LastName,
CompanyName: user.CompanyName,
ValidateApplyV2: validateApplyV2,
}))
}

Expand All @@ -76,6 +80,7 @@ func (v *PorterAppAnalyticsHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
LastName: user.LastName,
CompanyName: user.CompanyName,
ErrorMessage: request.ErrorMessage,
ValidateApplyV2: validateApplyV2,
}))
}

Expand All @@ -88,6 +93,7 @@ func (v *PorterAppAnalyticsHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
LastName: user.LastName,
CompanyName: user.CompanyName,
DeleteWorkflowFile: request.DeleteWorkflowFile,
ValidateApplyV2: validateApplyV2,
}))
}

Expand Down
6 changes: 4 additions & 2 deletions dashboard/src/lib/hooks/useAppAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,16 @@ type AppStep =
| "stack-launch-failure"
| "stack-deletion";

export const useAppAnalytics = (appName?: string) => {
export const useAppAnalytics = () => {
const { currentCluster, currentProject } = useContext(Context);

const updateAppStep = async ({
appName,
step,
errorMessage = "",
deleteWorkflow = false,
}: {
appName?: string;
step: AppStep;
errorMessage?: string;
deleteWorkflow?: boolean;
Expand All @@ -38,7 +40,7 @@ export const useAppAnalytics = (appName?: string) => {
project_id: currentProject.id,
}
);
} catch (err) {}
} catch (err) { }
};

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const Settings: React.FC = () => {
const history = useHistory();
const [isDeleteModalOpen, setIsDeleteModalOpen] = useState(false);
const { porterApp, clusterId, projectId } = useLatestRevision();
const { updateAppStep } = useAppAnalytics(porterApp.name);
const { updateAppStep } = useAppAnalytics();
const [isDeleting, setIsDeleting] = useState(false);

const githubWorkflowFilename = `porter_stack_${porterApp.name}.yml`;
Expand Down Expand Up @@ -98,7 +98,7 @@ const Settings: React.FC = () => {
window.open(res.data.url, "_blank", "noreferrer");
}

updateAppStep({ step: "stack-deletion", deleteWorkflow: true });
updateAppStep({ step: "stack-deletion", deleteWorkflow: true, appName: porterApp.name });
history.push("/apps");
return;
}
Expand Down
14 changes: 7 additions & 7 deletions dashboard/src/main/home/app-dashboard/create-app/CreateApp.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ const CreateApp: React.FC<CreateAppProps> = ({ history }) => {
appName: "", // only want to know if porter.yaml has name set, otherwise use name from input
});
const deploymentTarget = useDefaultDeploymentTarget();
const { updateAppStep } = useAppAnalytics(name.value);
const { updateAppStep } = useAppAnalytics();
const { validateApp } = useAppValidation({
deploymentTargetID: deploymentTarget?.deployment_target_id,
creating: true,
Expand Down Expand Up @@ -238,7 +238,7 @@ const CreateApp: React.FC<CreateAppProps> = ({ history }) => {
}) => {
setIsDeploying(true);
// log analytics event that we started form submission
updateAppStep({ step: "stack-launch-complete" });
updateAppStep({ step: "stack-launch-complete", appName: name.value });

try {
if (!currentProject?.id || !currentCluster?.id) {
Expand Down Expand Up @@ -308,7 +308,7 @@ const CreateApp: React.FC<CreateAppProps> = ({ history }) => {
);

// log analytics event that we successfully deployed
updateAppStep({ step: "stack-launch-success" });
updateAppStep({ step: "stack-launch-success", appName: name.value });

if (source.type === "docker-registry") {
history.push(`/apps/${app.name}`);
Expand All @@ -320,14 +320,15 @@ const CreateApp: React.FC<CreateAppProps> = ({ history }) => {
updateAppStep({
step: "stack-launch-failure",
errorMessage: err.response?.data?.error,
appName: name.value,
});
setDeployError(err.response?.data?.error);
return false;
}

const msg =
"An error occurred while deploying your application. Please try again.";
updateAppStep({ step: "stack-launch-failure", errorMessage: msg });
updateAppStep({ step: "stack-launch-failure", errorMessage: msg, appName: name.value });
setDeployError(msg);
return false;
} finally {
Expand Down Expand Up @@ -593,9 +594,8 @@ const CreateApp: React.FC<CreateAppProps> = ({ history }) => {
}
>
{detectedServices.count > 0
? `Detected ${detectedServices.count} service${
detectedServices.count > 1 ? "s" : ""
} from porter.yaml.`
? `Detected ${detectedServices.count} service${detectedServices.count > 1 ? "s" : ""
} from porter.yaml.`
: `Could not detect any services from porter.yaml. Make sure it exists in the root of your repo.`}
</Text>
</AppearingDiv>
Expand Down
66 changes: 40 additions & 26 deletions internal/analytics/tracks.go
Original file line number Diff line number Diff line change
Expand Up @@ -783,10 +783,11 @@ func ClusterDestroyingSuccessTrack(opts *ClusterDestroyingSuccessTrackOpts) segm
type StackLaunchStartOpts struct {
*ProjectScopedTrackOpts

Email string
FirstName string
LastName string
CompanyName string
Email string
FirstName string
LastName string
CompanyName string
ValidateApplyV2 bool
}

// StackLaunchStartTrack returns a track for when a user starts creating a stack
Expand All @@ -795,6 +796,7 @@ func StackLaunchStartTrack(opts *StackLaunchStartOpts) segmentTrack {
additionalProps["email"] = opts.Email
additionalProps["name"] = opts.FirstName + " " + opts.LastName
additionalProps["company"] = opts.CompanyName
additionalProps["validate_apply_v2"] = opts.ValidateApplyV2

return getSegmentProjectTrack(
opts.ProjectScopedTrackOpts,
Expand All @@ -806,11 +808,12 @@ func StackLaunchStartTrack(opts *StackLaunchStartOpts) segmentTrack {
type StackLaunchCompleteOpts struct {
*ProjectScopedTrackOpts

StackName string
Email string
FirstName string
LastName string
CompanyName string
StackName string
Email string
FirstName string
LastName string
CompanyName string
ValidateApplyV2 bool
}

// StackLaunchCompleteTrack returns a track for when a user completes creating a stack
Expand All @@ -820,6 +823,7 @@ func StackLaunchCompleteTrack(opts *StackLaunchCompleteOpts) segmentTrack {
additionalProps["email"] = opts.Email
additionalProps["name"] = opts.FirstName + " " + opts.LastName
additionalProps["company"] = opts.CompanyName
additionalProps["validate_apply_v2"] = opts.ValidateApplyV2

return getSegmentProjectTrack(
opts.ProjectScopedTrackOpts,
Expand All @@ -831,11 +835,12 @@ func StackLaunchCompleteTrack(opts *StackLaunchCompleteOpts) segmentTrack {
type StackLaunchSuccessOpts struct {
*ProjectScopedTrackOpts

StackName string
Email string
FirstName string
LastName string
CompanyName string
StackName string
Email string
FirstName string
LastName string
CompanyName string
ValidateApplyV2 bool
}

// StackLaunchCompleteTrack returns a track for when a user completes creating a stack
Expand All @@ -845,6 +850,7 @@ func StackLaunchSuccessTrack(opts *StackLaunchSuccessOpts) segmentTrack {
additionalProps["email"] = opts.Email
additionalProps["name"] = opts.FirstName + " " + opts.LastName
additionalProps["company"] = opts.CompanyName
additionalProps["validate_apply_v2"] = opts.ValidateApplyV2

return getSegmentProjectTrack(
opts.ProjectScopedTrackOpts,
Expand All @@ -856,12 +862,13 @@ func StackLaunchSuccessTrack(opts *StackLaunchSuccessOpts) segmentTrack {
type StackLaunchFailureOpts struct {
*ProjectScopedTrackOpts

StackName string
Email string
FirstName string
LastName string
CompanyName string
ErrorMessage string
StackName string
Email string
FirstName string
LastName string
CompanyName string
ErrorMessage string
ValidateApplyV2 bool
}

// StackLaunchFailureTrack returns a track for when a user fails creating a stack
Expand All @@ -872,6 +879,7 @@ func StackLaunchFailureTrack(opts *StackLaunchFailureOpts) segmentTrack {
additionalProps["name"] = opts.FirstName + " " + opts.LastName
additionalProps["company"] = opts.CompanyName
additionalProps["error_message"] = opts.ErrorMessage
additionalProps["validate_apply_v2"] = opts.ValidateApplyV2

return getSegmentProjectTrack(
opts.ProjectScopedTrackOpts,
Expand All @@ -889,6 +897,7 @@ type StackDeletionOpts struct {
LastName string
CompanyName string
DeleteWorkflowFile bool
ValidateApplyV2 bool
}

// StackDeletionTrack returns a track for when a user deletes a stack
Expand All @@ -899,6 +908,7 @@ func StackDeletionTrack(opts *StackDeletionOpts) segmentTrack {
additionalProps["name"] = opts.FirstName + " " + opts.LastName
additionalProps["company"] = opts.CompanyName
additionalProps["delete_workflow_file"] = opts.DeleteWorkflowFile
additionalProps["validate_apply_v2"] = opts.ValidateApplyV2

return getSegmentProjectTrack(
opts.ProjectScopedTrackOpts,
Expand All @@ -910,12 +920,13 @@ func StackDeletionTrack(opts *StackDeletionOpts) segmentTrack {
type StackBuildOpts struct {
*ProjectScopedTrackOpts

StackName string
ErrorMessage string
Email string
FirstName string
LastName string
CompanyName string
StackName string
ErrorMessage string
Email string
FirstName string
LastName string
CompanyName string
ValidateApplyV2 bool
}

// StackBuildFailureTrack returns a track for when a stack fails to build
Expand All @@ -926,6 +937,7 @@ func StackBuildFailureTrack(opts *StackBuildOpts) segmentTrack {
additionalProps["email"] = opts.Email
additionalProps["name"] = opts.FirstName + " " + opts.LastName
additionalProps["company"] = opts.CompanyName
additionalProps["validate_apply_v2"] = opts.ValidateApplyV2

return getSegmentProjectTrack(
opts.ProjectScopedTrackOpts,
Expand All @@ -940,6 +952,7 @@ func StackBuildSuccessTrack(opts *StackBuildOpts) segmentTrack {
additionalProps["email"] = opts.Email
additionalProps["name"] = opts.FirstName + " " + opts.LastName
additionalProps["company"] = opts.CompanyName
additionalProps["validate_apply_v2"] = opts.ValidateApplyV2

return getSegmentProjectTrack(
opts.ProjectScopedTrackOpts,
Expand All @@ -954,6 +967,7 @@ func StackBuildProgressingTrack(opts *StackBuildOpts) segmentTrack {
additionalProps["email"] = opts.Email
additionalProps["name"] = opts.FirstName + " " + opts.LastName
additionalProps["company"] = opts.CompanyName
additionalProps["validate_apply_v2"] = opts.ValidateApplyV2

return getSegmentProjectTrack(
opts.ProjectScopedTrackOpts,
Expand Down

0 comments on commit 97256e8

Please sign in to comment.