Kaynağa Gözat

fix preflight analytics (#4309)

Feroze Mohideen 2 yıl önce
ebeveyn
işleme
505b9ec599

+ 2 - 0
api/server/handlers/project/update_onboarding_step.go

@@ -259,6 +259,8 @@ func (v *UpdateOnboardingStepHandler) ServeHTTP(w http.ResponseWriter, r *http.R
 			LastName:               user.LastName,
 			CompanyName:            user.CompanyName,
 			ErrorMessage:           request.ErrorMessage,
+			ClusterName:            request.ClusterName,
+			CloudProvider:          request.Provider,
 		}))
 		if err != nil {
 			_ = telemetry.Error(ctx, span, err, "error tracking cluster preflight checks failed")

+ 3 - 3
dashboard/src/lib/clusters/types.ts

@@ -396,7 +396,7 @@ const eksConfigValidator = z.object({
   clusterName: z
     .string()
     .min(1, { message: "Name must be at least 1 character" })
-    .max(31, { message: "Name must be 31 characters or less" })
+    .max(31, { message: "Name must be max 31 characters" })
     .regex(/^[a-z0-9-]{1,61}$/, {
       message: 'Lowercase letters, numbers, and "-" only.',
     }),
@@ -456,7 +456,7 @@ const gkeConfigValidator = z.object({
   clusterName: z
     .string()
     .min(1, { message: "Name must be at least 1 character" })
-    .max(31, { message: "Name must be 31 characters or less" })
+    .max(31, { message: "Name must be max 31 characters" })
     .regex(/^[a-z0-9-]{1,61}$/, {
       message: 'Lowercase letters, numbers, and "-" only.',
     }),
@@ -470,7 +470,7 @@ const aksConfigValidator = z.object({
   clusterName: z
     .string()
     .min(1, { message: "Name must be at least 1 character" })
-    .max(31, { message: "Name must be 31 characters or less" })
+    .max(31, { message: "Name must be max 31 characters" })
     .regex(/^[a-z0-9-]{1,61}$/, {
       message: 'Lowercase letters, numbers, and "-" only.',
     }),

+ 7 - 3
dashboard/src/main/home/infrastructure-dashboard/forms/aws/CreateEKSClusterForm.tsx

@@ -26,15 +26,19 @@ const CreateEKSClusterForm: React.FC<Props> = ({
   const { reportToAnalytics } = useClusterAnalytics();
 
   useEffect(() => {
+    const projectNameLimit = 31 - "-cluster-".length - 6; // 6 characters for the random suffix
+    const truncatedProjectName = projectName.substring(0, projectNameLimit);
+    const clusterName = `${truncatedProjectName}-cluster-${Math.random()
+      .toString(36)
+      .substring(2, 8)}`;
+
     reset({
       cluster: {
         projectId,
         cloudProvider: "AWS" as const,
         config: {
           kind: "EKS" as const,
-          clusterName: `${projectName}-cluster-${Math.random()
-            .toString(36)
-            .substring(2, 8)}`,
+          clusterName,
           region: "us-east-1",
           nodeGroups: [
             {

+ 7 - 3
dashboard/src/main/home/infrastructure-dashboard/forms/azure/CreateAKSClusterForm.tsx

@@ -27,15 +27,19 @@ const CreateAKSClusterForm: React.FC<Props> = ({
   const { reportToAnalytics } = useClusterAnalytics();
 
   useEffect(() => {
+    const projectNameLimit = 31 - "-cluster-".length - 6; // 6 characters for the random suffix
+    const truncatedProjectName = projectName.substring(0, projectNameLimit);
+    const clusterName = `${truncatedProjectName}-cluster-${Math.random()
+      .toString(36)
+      .substring(2, 8)}`;
+
     reset({
       cluster: {
         projectId,
         cloudProvider: "Azure" as const,
         config: {
           kind: "AKS" as const,
-          clusterName: `${projectName}-cluster-${Math.random()
-            .toString(36)
-            .substring(2, 8)}`,
+          clusterName,
           region: "eastus",
           nodeGroups: [
             {

+ 7 - 3
dashboard/src/main/home/infrastructure-dashboard/forms/gcp/CreateGKEClusterForm.tsx

@@ -28,15 +28,19 @@ const CreateGKEClusterForm: React.FC<Props> = ({
   const { reportToAnalytics } = useClusterAnalytics();
 
   useEffect(() => {
+    const projectNameLimit = 31 - "-cluster-".length - 6; // 6 characters for the random suffix
+    const truncatedProjectName = projectName.substring(0, projectNameLimit);
+    const clusterName = `${truncatedProjectName}-cluster-${Math.random()
+      .toString(36)
+      .substring(2, 8)}`;
+
     reset({
       cluster: {
         projectId,
         cloudProvider: "GCP" as const,
         config: {
           kind: "GKE" as const,
-          clusterName: `${projectName}-cluster-${Math.random()
-            .toString(36)
-            .substring(2, 8)}`,
+          clusterName,
           region: "us-east1",
           nodeGroups: [
             {

+ 9 - 5
internal/analytics/tracks.go

@@ -1068,11 +1068,13 @@ func CloudProviderPermissionsGrantedTrack(opts *CloudProviderPermissionsGrantedT
 type ClusterPreflightChecksFailedTrackOpts struct {
 	*ProjectScopedTrackOpts
 
-	Email        string
-	FirstName    string
-	LastName     string
-	CompanyName  string
-	ErrorMessage string
+	Email         string
+	FirstName     string
+	LastName      string
+	CompanyName   string
+	ErrorMessage  string
+	ClusterName   string
+	CloudProvider string
 }
 
 // ClusterPreflightChecksFailedTrack returns a track for when a user fails preflight checks
@@ -1082,6 +1084,8 @@ func ClusterPreflightChecksFailedTrack(opts *ClusterPreflightChecksFailedTrackOp
 	additionalProps["name"] = opts.FirstName + " " + opts.LastName
 	additionalProps["company"] = opts.CompanyName
 	additionalProps["error_message"] = opts.ErrorMessage
+	additionalProps["cluster_name"] = opts.ClusterName
+	additionalProps["cloud_provider"] = opts.CloudProvider
 
 	return getSegmentProjectTrack(
 		opts.ProjectScopedTrackOpts,