Skip to content

Commit

Permalink
feat: speakeasy status speed up matching target card query (#1170)
Browse files Browse the repository at this point in the history
https://linear.app/speakeasy/issue/SPE-4390/feature-speakeasy-status-speed-up

Makes speakeasy status work only off of target card queries similar to
the dashboard. There is only a small bit of information loss, but we can
add to the target sdk query.

Using exceptionally large internal workspace

**Original**

https://www.loom.com/share/f8f63ad7005143aab8505c4a14b7eb19?sid=119394b5-4c56-4351-8416-74aa23decc4f

**New**

https://www.loom.com/share/0535f7ebeadb4b31ae34aa0287fbe10d?sid=e6de5462-89c2-4be0-b832-dbe3747121e6

(Not quite as big of a speed improvement as we may have expected due to
parallelization that was already there

**Here's what status would look like on a normal largeish workspace**

https://www.loom.com/share/9619022c018940dd894144272abcf45b?sid=3c92596f-5d03-42fd-9723-dc31b76ddb04
  • Loading branch information
ryan-timothy-albert authored Dec 20, 2024
1 parent 00bc304 commit 8c42208
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 132 deletions.
156 changes: 30 additions & 126 deletions cmd/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -387,22 +387,27 @@ type statusWorkspaceEventModel struct {
publishPackageRegistryName *string
publishPackageURL *string
publishPackageVersion *string
lastPublishCreatedAt time.Time
success bool
}

func newStatusWorkspaceEventModel(event shared.CliEvent) *statusWorkspaceEventModel {
func newStatusWorkspaceEventModel(target shared.TargetSDK) *statusWorkspaceEventModel {
result := &statusWorkspaceEventModel{
continuousIntegrationEnvironment: event.ContinuousIntegrationEnvironment,
createdAt: event.CreatedAt,
ghActionRunLink: event.GhActionRunLink,
gitUserEmail: event.GitUserEmail,
gitUserName: event.GitUserName,
hostname: event.Hostname,
publishPackageName: event.PublishPackageName,
publishPackageRegistryName: event.PublishPackageRegistryName,
publishPackageURL: event.PublishPackageURL,
publishPackageVersion: event.PublishPackageVersion,
success: event.Success,
continuousIntegrationEnvironment: target.ContinuousIntegrationEnvironment,
createdAt: target.LastEventCreatedAt,
ghActionRunLink: target.GhActionRunLink,
gitUserEmail: target.GitUserEmail,
gitUserName: target.GitUserName,
hostname: target.Hostname,
publishPackageName: target.PublishPackageName,
publishPackageRegistryName: target.PublishPackageRegistryName,
publishPackageURL: target.PublishPackageURL,
publishPackageVersion: target.PublishPackageVersion,
success: target.Success != nil && *target.Success,
}

if target.LastPublishCreatedAt != nil {
result.lastPublishCreatedAt = *target.LastPublishCreatedAt
}

return result
Expand Down Expand Up @@ -447,7 +452,7 @@ func (m statusWorkspaceEventModel) PublishInfo() string {
result.WriteString("locally at ")
}

result.WriteString(m.createdAt.Format(time.RFC3339))
result.WriteString(m.lastPublishCreatedAt.Format(time.RFC3339))
result.WriteString(" by ")

if m.ghActionRunLink != nil {
Expand Down Expand Up @@ -489,13 +494,7 @@ type statusWorkspaceTargetModel struct {
lastEventCreatedAt time.Time
success *bool

// Generate events
generateLastEvent *statusWorkspaceEventModel
generateLastSuccessEvent *statusWorkspaceEventModel

// Publish events
publishLastEvent *statusWorkspaceEventModel
publishLastSuccessEvent *statusWorkspaceEventModel
workspaceEventCompilation *statusWorkspaceEventModel

// Speakeasy URL
speakeasyURL string
Expand Down Expand Up @@ -532,58 +531,7 @@ func newStatusWorkspaceTargetModel(ctx context.Context, client *speakeasyclients
result.upgradeDocumentationURL = &upgradeURL
}

lastGenerateEvent, err := searchWorkspaceTargetLastEvent(ctx, client, workspace.id, target.ID, shared.InteractionTypeTargetGenerate, false)

if err != nil {
return result, fmt.Errorf("error searching last Speakeasy target generate event: %w", err)
}

if lastGenerateEvent != nil {
result.generateLastEvent = newStatusWorkspaceEventModel(*lastGenerateEvent)

if lastGenerateEvent.Success {
result.generateLastSuccessEvent = result.generateLastEvent
}
}

if result.generateLastSuccessEvent == nil {
lastGenerateSuccessEvent, err := searchWorkspaceTargetLastEvent(ctx, client, workspace.id, target.ID, shared.InteractionTypeTargetGenerate, true)

if err != nil {
return result, fmt.Errorf("error searching last Speakeasy target generate success event: %w", err)
}

if lastGenerateSuccessEvent != nil {
result.generateLastSuccessEvent = newStatusWorkspaceEventModel(*lastGenerateSuccessEvent)
}
}

lastPublishEvent, err := searchWorkspaceTargetLastEvent(ctx, client, workspace.id, target.ID, shared.InteractionTypePublish, false)

if err != nil {
return result, fmt.Errorf("error searching last Speakeasy target publish event: %w", err)
}

if lastPublishEvent != nil {
result.publishLastEvent = newStatusWorkspaceEventModel(*lastPublishEvent)

if lastPublishEvent.Success {
result.publishLastSuccessEvent = result.publishLastEvent
}
}

if result.publishLastSuccessEvent == nil {
lastPublishSuccessEvent, err := searchWorkspaceTargetLastEvent(ctx, client, workspace.id, target.ID, shared.InteractionTypePublish, true)

if err != nil {
return result, fmt.Errorf("error searching last Speakeasy target publish success event: %w", err)
}

if lastPublishSuccessEvent != nil {
result.publishLastSuccessEvent = newStatusWorkspaceEventModel(*lastPublishSuccessEvent)
}
}

result.workspaceEventCompilation = newStatusWorkspaceEventModel(target)
return result, nil
}

Expand Down Expand Up @@ -628,15 +576,7 @@ func (m statusWorkspaceTargetModel) RepositoryURL() string {
}

func (m statusWorkspaceTargetModel) Success() bool {
if event := m.publishLastEvent; event != nil && !event.success {
return false
}

if event := m.generateLastEvent; event != nil && !event.success {
return false
}

return true
return m.workspaceEventCompilation.success
}

func (m statusWorkspaceTargetModel) TargetHeading() string {
Expand All @@ -653,7 +593,7 @@ func (m statusWorkspaceTargetModel) TargetHeading() string {
result.WriteString("Unconfigured")
}

if event := m.publishLastSuccessEvent; event != nil && event.publishPackageName != nil && event.publishPackageVersion != nil {
if event := m.workspaceEventCompilation; event != nil && event.publishPackageName != nil && event.publishPackageVersion != nil {
result.WriteString(": ")
result.WriteString(*event.publishPackageVersion)
} else if m.generateConfigPostVersion != nil {
Expand All @@ -671,28 +611,14 @@ func (m statusWorkspaceTargetModel) TargetHeading() string {

func (m statusWorkspaceTargetModel) TargetInfo(ctx context.Context) []string {
var result []string

if m.publishLastEvent != nil && !m.publishLastEvent.success {
var message strings.Builder

message.WriteString(renderAlertErrorText("✖ Last Publish Failed"))

if m.publishLastEvent.ghActionRunLink != nil {
message.WriteString(renderAlertErrorText(": "))
message.WriteString(renderAlertErrorURL(links.Shorten(ctx, *m.publishLastEvent.ghActionRunLink)))
}

result = append(result, message.String())
}

if m.generateLastEvent != nil && !m.generateLastEvent.success {
if m.workspaceEventCompilation != nil && !m.workspaceEventCompilation.success {
var message strings.Builder

message.WriteString(renderAlertErrorText("✖ Last Generate Failed"))

if m.generateLastEvent.ghActionRunLink != nil {
if m.workspaceEventCompilation.ghActionRunLink != nil {
message.WriteString(renderAlertErrorText(": "))
message.WriteString(renderAlertErrorURL(links.Shorten(ctx, *m.generateLastEvent.ghActionRunLink)))
message.WriteString(renderAlertErrorURL(links.Shorten(ctx, *m.workspaceEventCompilation.ghActionRunLink)))
}

result = append(result, message.String())
Expand All @@ -702,8 +628,8 @@ func (m statusWorkspaceTargetModel) TargetInfo(ctx context.Context) []string {
result = append(result, renderAlertWarningText("⚠ Target Upgrade Available: ")+renderAlertWarningURL(*m.upgradeDocumentationURL))
}

if m.publishLastSuccessEvent != nil && m.publishLastSuccessEvent.publishPackageURL != nil {
result = append(result, renderInfoText("Publish URL: ")+renderInfoURL(*m.publishLastSuccessEvent.publishPackageURL))
if m.workspaceEventCompilation != nil && m.workspaceEventCompilation.publishPackageURL != nil {
result = append(result, renderInfoText("Publish URL: ")+renderInfoURL(*m.workspaceEventCompilation.publishPackageURL))
}

if m.RepositoryURL() != "" {
Expand All @@ -712,33 +638,11 @@ func (m statusWorkspaceTargetModel) TargetInfo(ctx context.Context) []string {

result = append(result, renderInfoText("Speakeasy URL: "+renderInfoURL(m.speakeasyURL)))

if m.publishLastEvent != nil {
if !m.publishLastEvent.success {
result = append(result, renderInfoText("Last Publish Attempt: "+m.publishLastEvent.PublishInfo()))

if m.publishLastSuccessEvent != nil {
result = append(result, renderInfoText("Last Publish Success: "+m.publishLastSuccessEvent.GenerateInfo()))
} else {
result = append(result, renderInfoText("Last Publish Success: Unknown"))
}
} else {
result = append(result, renderInfoText("Last Publish: "+m.publishLastEvent.PublishInfo()))
}
if m.workspaceEventCompilation != nil && m.workspaceEventCompilation.publishPackageName != nil {
result = append(result, renderInfoText("Last Publish: "+m.workspaceEventCompilation.PublishInfo()))
}

if m.generateLastEvent != nil {
if !m.generateLastEvent.success {
result = append(result, renderInfoText("Last Generate Attempt: "+m.generateLastEvent.GenerateInfo()))

if m.generateLastSuccessEvent != nil {
result = append(result, renderInfoText("Last Generate Success: "+m.generateLastSuccessEvent.GenerateInfo()))
} else {
result = append(result, renderInfoText("Last Generate Success: Unknown"))
}
} else {
result = append(result, renderInfoText("Last Generate: "+m.generateLastEvent.GenerateInfo()))
}
} else {
if m.workspaceEventCompilation != nil {
result = append(result, renderInfoText("Last Generate: "+m.GenerateInfo()))
}

Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ require (
github.com/speakeasy-api/openapi-generation/v2 v2.483.1
github.com/speakeasy-api/openapi-overlay v0.9.0
github.com/speakeasy-api/sdk-gen-config v1.29.1
github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.17.0
github.com/speakeasy-api/speakeasy-core v0.17.5
github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.18.1
github.com/speakeasy-api/speakeasy-core v0.17.6
github.com/speakeasy-api/speakeasy-proxy v0.0.2
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -583,10 +583,10 @@ github.com/speakeasy-api/openapi-overlay v0.9.0 h1:Wrz6NO02cNlLzx1fB093lBlYxSI54
github.com/speakeasy-api/openapi-overlay v0.9.0/go.mod h1:f5FloQrHA7MsxYg9djzMD5h6dxrHjVVByWKh7an8TRc=
github.com/speakeasy-api/sdk-gen-config v1.29.1 h1:oi//Zx9cIdL2KClrySYgNVU/ta4oYt8okies5bcQ+wI=
github.com/speakeasy-api/sdk-gen-config v1.29.1/go.mod h1:e9PjnCRHGa4K4EFKVU+kKmihOZjJ2V4utcU+274+bnQ=
github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.17.0 h1:Yk5pTcbpjbdUbGM9T+xfMu3n2L5Cq0hNav8TUj4mPcE=
github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.17.0/go.mod h1:k9JD6Rj0+Iizc5COoLZHyRIOGGITpKZ2qBuFFO8SqNI=
github.com/speakeasy-api/speakeasy-core v0.17.5 h1:hce3XR3laPsGRJ+Nw8G1kvtm118tGI0JC3k3UlBLVjI=
github.com/speakeasy-api/speakeasy-core v0.17.5/go.mod h1:0U4gDvmCjWVzteXXPhdKcktzTwggyHBSU8EvBpgTA7I=
github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.18.1 h1:6yMA7JQmBrkjsZbP9yEPCKq2xZfieHS47nKCI9DgWVo=
github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.18.1/go.mod h1:k9JD6Rj0+Iizc5COoLZHyRIOGGITpKZ2qBuFFO8SqNI=
github.com/speakeasy-api/speakeasy-core v0.17.6 h1:+BglRNsWuwvdWkcuUCsa9k2UrqRXdbUAheZLvSJmLDE=
github.com/speakeasy-api/speakeasy-core v0.17.6/go.mod h1:iwQqMncf0XfZ6tWLL3F+L4BIdkIZMNzkPw9Zf9e02rE=
github.com/speakeasy-api/speakeasy-go-sdk v1.8.1 h1:atzohw12oQ5ipaLb1q7ntTu4vvAgKDJsrvaUoOu6sw0=
github.com/speakeasy-api/speakeasy-go-sdk v1.8.1/go.mod h1:XbzaM0sMjj8bGooz/uEtNkOh1FQiJK7RFuNG3LPBSAU=
github.com/speakeasy-api/speakeasy-proxy v0.0.2 h1:u4rQ8lXvuYRCSxiLQGb5JxkZRwNIDlyh+pMFYD6OGjA=
Expand Down

0 comments on commit 8c42208

Please sign in to comment.