d-g-town 2 лет назад
Родитель
Сommit
78a29ecdfb

+ 1 - 1
api/server/handlers/deployment_target/create.go

@@ -87,7 +87,7 @@ func (c *CreateDeploymentTargetHandler) ServeHTTP(w http.ResponseWriter, r *http
 		return
 	}
 	if ccpResp.Msg.DeploymentTargetId == "" {
-		err := telemetry.Error(ctx, span, err, "deployment target id is empty")
+		err := telemetry.Error(ctx, span, nil, "deployment target id is empty")
 		c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError))
 		return
 	}

+ 1 - 1
api/server/handlers/porter_app/apply.go

@@ -127,7 +127,7 @@ func (c *ApplyPorterAppHandler) ServeHTTP(w http.ResponseWriter, r *http.Request
 		}
 
 		if request.DeploymentTargetId == "" {
-			err := telemetry.Error(ctx, span, err, "deployment target id is empty")
+			err := telemetry.Error(ctx, span, nil, "deployment target id is empty")
 			c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
 			return
 		}

+ 25 - 7
api/server/handlers/porter_app/create_and_update_events.go

@@ -177,7 +177,7 @@ func (p *CreateUpdatePorterAppEventHandler) createNewAppEvent(ctx context.Contex
 					return types.PorterAppEvent{}, telemetry.Error(ctx, span, err, "error parsing deployment target id")
 				}
 				if deploymentTargetUUID == uuid.Nil {
-					return types.PorterAppEvent{}, telemetry.Error(ctx, span, err, "deployment target id cannot be nil")
+					return types.PorterAppEvent{}, telemetry.Error(ctx, span, nil, "deployment target id cannot be nil")
 				}
 
 				existingEvents, _, err = p.Repo().PorterAppEvent().ListEventsByPorterAppIDAndDeploymentTargetID(ctx, app.ID, deploymentTargetUUID)
@@ -242,9 +242,32 @@ func (p *CreateUpdatePorterAppEventHandler) createNewAppEvent(ctx context.Contex
 			return types.PorterAppEvent{}, telemetry.Error(ctx, span, err, "error parsing deployment target id")
 		}
 		if deploymentTargetUUID == uuid.Nil {
-			return types.PorterAppEvent{}, telemetry.Error(ctx, span, err, "deployment target id cannot be nil")
+			return types.PorterAppEvent{}, telemetry.Error(ctx, span, nil, "deployment target id cannot be nil")
 		}
+
+		// hacky way to get the app instance id into the build event
+		revision, err := p.Config().ClusterControlPlaneClient.CurrentAppRevision(ctx, connect.NewRequest(&porterv1.CurrentAppRevisionRequest{
+			ProjectId:          int64(cluster.ProjectID),
+			AppId:              int64(app.ID),
+			DeploymentTargetId: deploymentTargetID,
+		}))
+		if err != nil {
+			return types.PorterAppEvent{}, telemetry.Error(ctx, span, err, "error getting current app revision from cluster control plane client")
+		}
+		if revision.Msg.AppRevision == nil {
+			return types.PorterAppEvent{}, telemetry.Error(ctx, span, nil, "app revision is nil")
+		}
+
+		appInstanceUUID, err := uuid.Parse(revision.Msg.AppRevision.AppInstanceId)
+		if err != nil {
+			return types.PorterAppEvent{}, telemetry.Error(ctx, span, err, "error parsing app instance id")
+		}
+		if appInstanceUUID == uuid.Nil {
+			return types.PorterAppEvent{}, telemetry.Error(ctx, span, err, "app instance id cannot be nil")
+		}
+
 		event.DeploymentTargetID = deploymentTargetUUID
+		event.AppInstanceID = appInstanceUUID
 	}
 
 	for k, v := range requestMetadata {
@@ -267,12 +290,7 @@ func (p *CreateUpdatePorterAppEventHandler) updateExistingAppEvent(ctx context.C
 	ctx, span := telemetry.NewSpan(ctx, "update-porter-app-event")
 	defer span.End()
 
-	app, err := p.Repo().PorterApp().ReadPorterAppByName(cluster.ID, porterAppName)
-	if err != nil {
-		return types.PorterAppEvent{}, telemetry.Error(ctx, span, err, "error retrieving porter app by name for cluster")
-	}
 	telemetry.WithAttributes(span,
-		telemetry.AttributeKV{Key: "porter-app-id", Value: app.ID},
 		telemetry.AttributeKV{Key: "porter-app-name", Value: porterAppName},
 		telemetry.AttributeKV{Key: "cluster-id", Value: int(cluster.ID)},
 		telemetry.AttributeKV{Key: "project-id", Value: int(cluster.ProjectID)},

+ 1 - 1
api/server/handlers/porter_app/latest_app_revisions.go

@@ -69,7 +69,7 @@ func (c *LatestAppRevisionsHandler) ServeHTTP(w http.ResponseWriter, r *http.Req
 		return
 	}
 	if deploymentTargetID == uuid.Nil {
-		err := telemetry.Error(ctx, span, err, "deployment target id is nil")
+		err := telemetry.Error(ctx, span, nil, "deployment target id is nil")
 		c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
 		return
 	}

+ 1 - 1
api/server/handlers/webhook/app_v2_github.go

@@ -161,7 +161,7 @@ func (c *GithubWebhookHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
 		telemetry.WithAttributes(span, telemetry.AttributeKV{Key: "deployment-target-id", Value: deploymentTarget.ID.String()})
 
 		if deploymentTarget.ClusterID != webhook.ClusterID {
-			err := telemetry.Error(ctx, span, err, "deployment target cluster id does not match")
+			err := telemetry.Error(ctx, span, nil, "deployment target cluster id does not match")
 			c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest))
 			return
 		}

+ 2 - 2
internal/deployment_target/get.go

@@ -58,12 +58,12 @@ func DeploymentTargetDetails(ctx context.Context, inp DeploymentTargetDetailsInp
 	}
 
 	if deploymentTargetDetailsResp == nil || deploymentTargetDetailsResp.Msg == nil {
-		return deploymentTarget, telemetry.Error(ctx, span, err, "deployment target details resp is nil")
+		return deploymentTarget, telemetry.Error(ctx, span, nil, "deployment target details resp is nil")
 	}
 
 	target := deploymentTargetDetailsResp.Msg.DeploymentTarget
 	if target.ClusterId != inp.ClusterID {
-		return deploymentTarget, telemetry.Error(ctx, span, err, "deployment target details resp cluster id does not match cluster id")
+		return deploymentTarget, telemetry.Error(ctx, span, nil, "deployment target details resp cluster id does not match cluster id")
 	}
 
 	deploymentTarget = DeploymentTarget{