From 770ce7bfdfa065992736c7771afce5843992bb77 Mon Sep 17 00:00:00 2001 From: d-g-town <66391417+d-g-town@users.noreply.github.com> Date: Wed, 4 Oct 2023 12:40:02 -0400 Subject: [PATCH] only show nil deployment target id app events for v1 (#3727) Co-authored-by: David Townley --- api/server/handlers/porter_app/list_events.go | 3 ++- internal/repository/gorm/porter_app_event.go | 18 ++++++++++++------ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/api/server/handlers/porter_app/list_events.go b/api/server/handlers/porter_app/list_events.go index 6f23280479..aef15bcb66 100644 --- a/api/server/handlers/porter_app/list_events.go +++ b/api/server/handlers/porter_app/list_events.go @@ -67,7 +67,8 @@ func (p *PorterAppEventListHandler) ServeHTTP(w http.ResponseWriter, r *http.Req return } - porterAppEvents, paginatedResult, err := p.Repo().PorterAppEvent().ListEventsByPorterAppID(ctx, app.ID, helpers.WithPageSize(20), helpers.WithPage(int(pr.Page))) + // legacy app events will have a nil deployment target id + porterAppEvents, paginatedResult, err := p.Repo().PorterAppEvent().ListEventsByPorterAppIDAndDeploymentTargetID(ctx, app.ID, uuid.Nil, helpers.WithPageSize(20), helpers.WithPage(int(pr.Page))) if err != nil { if !errors.Is(err, gorm.ErrRecordNotFound) { e := telemetry.Error(ctx, span, nil, "error listing porter app events by porter app id") diff --git a/internal/repository/gorm/porter_app_event.go b/internal/repository/gorm/porter_app_event.go index 0107fdfec3..e93215b603 100644 --- a/internal/repository/gorm/porter_app_event.go +++ b/internal/repository/gorm/porter_app_event.go @@ -7,6 +7,8 @@ import ( "strconv" "time" + "github.com/porter-dev/porter/internal/telemetry" + "github.com/google/uuid" "github.com/porter-dev/porter/internal/models" "github.com/porter-dev/porter/internal/repository" @@ -49,16 +51,20 @@ func (repo *PorterAppEventRepository) ListEventsByPorterAppID(ctx context.Contex // ListEventsByPorterAppIDAndDeploymentTargetID returns a list of events for a given porter app id and deployment target id func (repo *PorterAppEventRepository) ListEventsByPorterAppIDAndDeploymentTargetID(ctx context.Context, porterAppID uint, deploymentTargetID uuid.UUID, opts ...helpers.QueryOption) ([]*models.PorterAppEvent, helpers.PaginatedResult, error) { + ctx, span := telemetry.NewSpan(ctx, "list-events-by-porter-app-id-and-deployment-target-id") + defer span.End() + + telemetry.WithAttributes(span, + telemetry.AttributeKV{Key: "porter-app-id", Value: porterAppID}, + telemetry.AttributeKV{Key: "deployment-target-id", Value: deploymentTargetID}, + ) + apps := []*models.PorterAppEvent{} paginatedResult := helpers.PaginatedResult{} id := strconv.Itoa(int(porterAppID)) if id == "" { - return nil, paginatedResult, errors.New("invalid porter app id supplied") - } - - if deploymentTargetID == uuid.Nil { - return nil, paginatedResult, errors.New("invalid deployment target id supplied") + return nil, paginatedResult, telemetry.Error(ctx, span, nil, "invalid porter app id supplied") } db := repo.db.Model(&models.PorterAppEvent{}) @@ -67,7 +73,7 @@ func (repo *PorterAppEventRepository) ListEventsByPorterAppIDAndDeploymentTarget if err := resultDB.Find(&apps).Error; err != nil { if !errors.Is(err, gorm.ErrRecordNotFound) { - return nil, paginatedResult, err + return nil, paginatedResult, telemetry.Error(ctx, span, err, "error finding events by porter app id and deployment target id") } }