Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Merge pull request #3043 from hashicorp/ceb-status
Browse files Browse the repository at this point in the history
Record and display count of entrypoint config connections in deployment status report
  • Loading branch information
catsby authored Mar 17, 2022
2 parents 34bd6ef + d279faf commit 926c659
Show file tree
Hide file tree
Showing 6 changed files with 1,237 additions and 1,158 deletions.
3 changes: 3 additions & 0 deletions .changelog/3043.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
cli: Display count of instance connections in deployment status reports
```
13 changes: 10 additions & 3 deletions internal/cli/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,7 @@ func (c *StatusCommand) refreshAppStatus(
Application: app.Name,
Project: project.Name,
}}

err := c.DoApp(c.Ctx, func(ctx context.Context, appClient *clientpkg.App) error {
// Get our API client
client := c.project.Client()
Expand Down Expand Up @@ -567,10 +568,15 @@ func (c *StatusCommand) FormatAppStatus(projectTarget string, appTarget string)
return err
}

deployHeaders := []string{
// deployment and releases use the same headers, with the exception that
// deployment lists an additional item for instances count
releaseHeaders := []string{
"App Name", "Version", "Workspace", "Platform", "Artifact", "Lifecycle State",
}

// Add "Instance Count" for deployment summary headers
deployHeaders := append(releaseHeaders, "Instances Count")

deployTbl := terminal.NewTable(deployHeaders...)

resourcesHeaders := []string{
Expand All @@ -585,7 +591,7 @@ func (c *StatusCommand) FormatAppStatus(projectTarget string, appTarget string)
if len(respDeployList.Deployments) > 0 {
deployBundle := respDeployList.Deployments[0]
deploy := deployBundle.Deployment
appDeployStatus := respDeployList.Deployments[0].LatestStatusReport
appDeployStatus := deployBundle.LatestStatusReport
statusColor := ""

var details string
Expand All @@ -608,6 +614,7 @@ func (c *StatusCommand) FormatAppStatus(projectTarget string, appTarget string)
deploy.Component.Name,
details,
deploy.Status.State.String(),
fmt.Sprintf("%d", appDeployStatus.InstancesCount),
}

// Add column data to table
Expand Down Expand Up @@ -675,7 +682,7 @@ func (c *StatusCommand) FormatAppStatus(projectTarget string, appTarget string)
}

// Same headers as deploy
releaseTbl := terminal.NewTable(deployHeaders...)
releaseTbl := terminal.NewTable(releaseHeaders...)
releaseResourcesTbl := terminal.NewTable(resourcesHeaders...)

releaseUnimplemented := true
Expand Down
49 changes: 48 additions & 1 deletion internal/core/app_status_report.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,54 @@ func (a *App) DeploymentStatusReport(
}
defer c.Close()

return a.statusReport(ctx, "deploy_statusreport", c, deployTarget, lastResp)
// Create the initial report. Assuming no error, we'll query ListInstances
// to find how many active instance connections are registered for this
// deployment. If there is a non-nil error, just return immediately.
report, rErr := a.statusReport(ctx, "deploy_statusreport", c, deployTarget, lastResp)
if rErr != nil {
return report, rErr
}

// Currently the statusReport() call above will only return a nil report if
// the error is NOT nil, but it is not an exported method so we guard here
// in case that changes.
if report != nil {
// check if we have any connected instances
resp, err := a.client.ListInstances(ctx, &pb.ListInstancesRequest{
Scope: &pb.ListInstancesRequest_DeploymentId{
DeploymentId: deployTarget.Id,
},
})
if err != nil {
a.logger.Warn("error retrieving connected instances", "error", err)
// we intentionally do not return the error from ListInstances, and
// instead simply log the error and return the original report and
// report error (if any)
return report, rErr
}

// Modify the status report with the active instance count. The
// statusReport() method called above both creates the report and saves
// it to state, so modifying it here requires us to re-upsert the report
// with the updated count.
report.InstancesCount = uint32(len(resp.Instances))
newReport, err := a.client.UpsertStatusReport(ctx, &pb.UpsertStatusReportRequest{
StatusReport: report,
})
if err != nil {
a.logger.Warn("error upserting updated status report", "error", err)
// we intentionally do not return the error from UpsertStatusReport,
// and instead simply log the error and return the original report
// and report error (if any)
return report, rErr
}

if newReport != nil && newReport.StatusReport != nil {
report = newReport.StatusReport
}
}

return report, rErr
}

func (a *App) ReleaseStatusReport(
Expand Down
Loading

0 comments on commit 926c659

Please sign in to comment.