Skip to content

Commit

Permalink
only show nil deployment target id app events for v1 (#3727)
Browse files Browse the repository at this point in the history
Co-authored-by: David Townley <[email protected]>
  • Loading branch information
d-g-town and David Townley authored Oct 4, 2023
1 parent b821a9f commit 770ce7b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
3 changes: 2 additions & 1 deletion api/server/handlers/porter_app/list_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
18 changes: 12 additions & 6 deletions internal/repository/gorm/porter_app_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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{})
Expand All @@ -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")
}
}

Expand Down

0 comments on commit 770ce7b

Please sign in to comment.