Skip to content

Commit

Permalink
fix passing validate apply v2 flag to segment (#3677)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feroze Mohideen authored Sep 28, 2023
1 parent 095ec3e commit 5636bb4
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
7 changes: 4 additions & 3 deletions api/server/handlers/porter_app/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ func TrackStackBuildStatus(
stackName string,
errorMessage string,
status types.PorterAppEventStatus,
validateApplyV2 bool,
) error {
_, span := telemetry.NewSpan(ctx, "track-build-status")
defer span.End()
Expand All @@ -126,7 +127,7 @@ func TrackStackBuildStatus(
FirstName: user.FirstName,
LastName: user.LastName,
CompanyName: user.CompanyName,
ValidateApplyV2: project.ValidateApplyV2,
ValidateApplyV2: validateApplyV2,
}))
}

Expand All @@ -138,7 +139,7 @@ func TrackStackBuildStatus(
FirstName: user.FirstName,
LastName: user.LastName,
CompanyName: user.CompanyName,
ValidateApplyV2: project.ValidateApplyV2,
ValidateApplyV2: validateApplyV2,
}))
}

Expand All @@ -151,7 +152,7 @@ func TrackStackBuildStatus(
FirstName: user.FirstName,
LastName: user.LastName,
CompanyName: user.CompanyName,
ValidateApplyV2: project.ValidateApplyV2,
ValidateApplyV2: validateApplyV2,
}))
}

Expand Down
7 changes: 4 additions & 3 deletions api/server/handlers/porter_app/create_and_update_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ func (p *CreateUpdatePorterAppEventHandler) ServeHTTP(w http.ResponseWriter, r *
)

if request.Type == types.PorterAppEventType_Build {
reportBuildStatus(ctx, request, p.Config(), user, project, appName)
validateApplyV2 := project.GetFeatureFlag(models.ValidateApplyV2, p.Config().LaunchDarklyClient)
reportBuildStatus(ctx, request, p.Config(), user, project, appName, validateApplyV2)
}

if request.ID == "" {
Expand All @@ -88,7 +89,7 @@ func (p *CreateUpdatePorterAppEventHandler) ServeHTTP(w http.ResponseWriter, r *
p.WriteResult(w, r, event)
}

func reportBuildStatus(ctx context.Context, request *types.CreateOrUpdatePorterAppEventRequest, config *config.Config, user *models.User, project *models.Project, stackName string) {
func reportBuildStatus(ctx context.Context, request *types.CreateOrUpdatePorterAppEventRequest, config *config.Config, user *models.User, project *models.Project, stackName string, validateApplyV2 bool) {
ctx, span := telemetry.NewSpan(ctx, "report-build-status")
defer span.End()

Expand All @@ -113,7 +114,7 @@ func reportBuildStatus(ctx context.Context, request *types.CreateOrUpdatePorterA
}
}

_ = TrackStackBuildStatus(ctx, config, user, project, stackName, errStr, request.Status)
_ = TrackStackBuildStatus(ctx, config, user, project, stackName, errStr, request.Status, validateApplyV2)
}

// createNewAppEvent will create a new app event for the given porter app name. If the app event is an agent event, then it will be created only if there is no existing event which has the agent ID. In the case that an existing event is found, that will be returned instead
Expand Down
8 changes: 5 additions & 3 deletions api/server/handlers/porter_app/list_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ func (p *PorterAppEventListHandler) updateExistingAppEvent(

// TODO: get rid of this block and related methods if still here after 08-04-2023
if appEvent.Type == string(types.PorterAppEventType_Build) && appEvent.TypeExternalSource == "GITHUB" {
err = p.updateBuildEvent_Github(ctx, &event, user, project, stackName)
validateApplyV2 := project.GetFeatureFlag(models.ValidateApplyV2, p.Config().LaunchDarklyClient)
err = p.updateBuildEvent_Github(ctx, &event, user, project, stackName, validateApplyV2)
if err != nil {
return appEvent, telemetry.Error(ctx, span, err, "error updating porter app event for github build")
}
Expand All @@ -158,6 +159,7 @@ func (p *PorterAppEventListHandler) updateBuildEvent_Github(
user *models.User,
project *models.Project,
stackName string,
validateApplyV2 bool,
) error {
ctx, span := telemetry.NewSpan(ctx, "update-porter-app-build-event")
defer span.End()
Expand Down Expand Up @@ -220,10 +222,10 @@ func (p *PorterAppEventListHandler) updateBuildEvent_Github(
if *actionRun.Status == "completed" {
if *actionRun.Conclusion == "success" {
event.Status = string(types.PorterAppEventStatus_Success)
_ = TrackStackBuildStatus(ctx, p.Config(), user, project, stackName, "", types.PorterAppEventStatus_Success)
_ = TrackStackBuildStatus(ctx, p.Config(), user, project, stackName, "", types.PorterAppEventStatus_Success, validateApplyV2)
} else {
event.Status = string(types.PorterAppEventStatus_Failed)
_ = TrackStackBuildStatus(ctx, p.Config(), user, project, stackName, "", types.PorterAppEventStatus_Failed)
_ = TrackStackBuildStatus(ctx, p.Config(), user, project, stackName, "", types.PorterAppEventStatus_Failed, validateApplyV2)
}
event.Metadata["end_time"] = actionRun.GetUpdatedAt().Time
}
Expand Down

0 comments on commit 5636bb4

Please sign in to comment.