Skip to content

Commit

Permalink
project describe: retrieve additional project details concurrently
Browse files Browse the repository at this point in the history
For projects with an active deployment, project describe will
additionally show additional details for each service, database,
datastore, and the site for a project. Reduce interactive latency by
retrieving each concurrently.
  • Loading branch information
mikeb26 committed Nov 13, 2024
1 parent 3dd5b98 commit d980b48
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 45 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ require (
github.com/aws/aws-sdk-go-v2 v1.32.4
github.com/aws/aws-sdk-go-v2/config v1.28.3
github.com/aws/aws-sdk-go-v2/service/cognitoidentityprovider v1.46.5
github.com/bopmatic/sdk/golang v0.0.0-20241111213848-4b9c0eb651ab
github.com/bopmatic/sdk/golang v0.0.0-20241113201553-27b8d5b59bd7
github.com/docker/docker v27.3.1+incompatible
golang.org/x/sync v0.9.0
)

require (
Expand Down Expand Up @@ -67,7 +68,6 @@ require (
go.opentelemetry.io/otel/trace v1.32.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
golang.org/x/net v0.30.0 // indirect
golang.org/x/sync v0.9.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ github.com/aws/aws-sdk-go-v2/service/sts v1.32.4 h1:yDxvkz3/uOKfxnv8YhzOi9m+2OGI
github.com/aws/aws-sdk-go-v2/service/sts v1.32.4/go.mod h1:9XEUty5v5UAsMiFOBJrNibZgwCeOma73jgGwwhgffa8=
github.com/aws/smithy-go v1.22.0 h1:uunKnWlcoL3zO7q+gG2Pk53joueEOsnNB28QdMsmiMM=
github.com/aws/smithy-go v1.22.0/go.mod h1:irrKGvNn1InZwb2d7fkIRNucdfwR8R+Ts3wxYa/cJHg=
github.com/bopmatic/sdk/golang v0.0.0-20241111213848-4b9c0eb651ab h1:+8bnjdxUw5/9fMJ6JAuyAVpvkd3urao/Snxx+efToV0=
github.com/bopmatic/sdk/golang v0.0.0-20241111213848-4b9c0eb651ab/go.mod h1:s/WFl21BUdqAYk7Kg4gmpVl30yEQ4OaAqVaSKp9+TJo=
github.com/bopmatic/sdk/golang v0.0.0-20241113201553-27b8d5b59bd7 h1:ZmEDydjdBNLXXdbepG/pm5evicQzOx+UvQP3YkZeyds=
github.com/bopmatic/sdk/golang v0.0.0-20241113201553-27b8d5b59bd7/go.mod h1:s/WFl21BUdqAYk7Kg4gmpVl30yEQ4OaAqVaSKp9+TJo=
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/containerd/log v0.1.0 h1:TCJt7ioM2cr/tfR8GPbGf9/VRAX8D2B4PjzCpfX540I=
Expand Down
85 changes: 44 additions & 41 deletions project.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ import (
_ "embed"

bopsdk "github.com/bopmatic/sdk/golang"
"github.com/bopmatic/sdk/golang/pb"
"github.com/bopmatic/sdk/golang/util"
"golang.org/x/sync/errgroup"
)

type projOpts struct {
Expand Down Expand Up @@ -81,24 +83,47 @@ func projDescribeMain(args []string) {
return
}

descSiteReply, err := bopsdk.DescribeSite(opts.projectId, "", sdkOpts...)
var wg errgroup.Group
var descSiteReply *pb.DescribeSiteReply
var svcDescList []*pb.DescribeServiceReply
var dbDescList []*pb.DescribeDatabaseReply
var dstoreDescList []*pb.DescribeDatastoreReply

wg.Go(func() error {
var err error
descSiteReply, err = bopsdk.DescribeSite(projDesc.Id, "", sdkOpts...)
return err
})
wg.Go(func() error {
var err error
svcDescList, err = bopsdk.DescribeAllServices(projDesc.Id, "",
sdkOpts...)
return err
})
wg.Go(func() error {
var err error
dbDescList, err = bopsdk.DescribeAllDatabases(projDesc.Id, "",
sdkOpts...)
return err
})
wg.Go(func() error {
var err error
dstoreDescList, err = bopsdk.DescribeAllDatastores(projDesc.Id, "",
sdkOpts...)
return err
})

err = wg.Wait()
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to describe site: %v\n", err)
fmt.Fprintf(os.Stderr,
"Failed to retrieve additional project details: %v\n", err)
os.Exit(1)
}

fmt.Printf("\tWebsite: %v\n", descSiteReply.SiteEndpoint)
svcList, err := bopsdk.ListServices(opts.projectId, "", sdkOpts...)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to list services: %v\n", err)
os.Exit(1)
}
for _, svc := range svcList {
fmt.Printf("\tService %v:\n", svc)
svcDesc, err := bopsdk.DescribeService(opts.projectId, "", svc, sdkOpts...)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to describe service %v: %v\n", svc, err)
os.Exit(1)
}

for _, svcDesc := range svcDescList {
fmt.Printf("\tService %v:\n", svcDesc.Desc.SvcHeader.ServiceName)
fmt.Printf("\t\tApi Definition: %v\n", svcDesc.Desc.ApiDef)
fmt.Printf("\t\tPort: %v\n", svcDesc.Desc.Port)
if len(svcDesc.Desc.DatabaseNames) > 0 {
Expand All @@ -123,19 +148,8 @@ func projDescribeMain(args []string) {
}
}

dbList, err := bopsdk.ListDatabases(opts.projectId, "", sdkOpts...)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to list databases: %v\n", err)
os.Exit(1)
}
for _, db := range dbList {
fmt.Printf("\tDatabase %v:\n", db)
dbDesc, err := bopsdk.DescribeDatabase(opts.projectId, "", db, sdkOpts...)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to describe database %v: %v\n", db,
err)
os.Exit(1)
}
for _, dbDesc := range dbDescList {
fmt.Printf("\tDatabase %v:\n", dbDesc.Desc.DatabaseHeader.DatabaseName)
if len(dbDesc.Desc.ServiceNames) > 0 {
fmt.Printf("\t\tServices: ")
for _, svcName := range dbDesc.Desc.ServiceNames {
Expand All @@ -152,20 +166,9 @@ func projDescribeMain(args []string) {
}
}

dstoreList, err := bopsdk.ListDatastores(opts.projectId, "", sdkOpts...)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to list datastores: %v\n", err)
os.Exit(1)
}
for _, dstore := range dstoreList {
fmt.Printf("\tDatastore %v:\n", dstore)
dstoreDesc, err := bopsdk.DescribeDatastore(opts.projectId, "", dstore,
sdkOpts...)
if err != nil {
fmt.Fprintf(os.Stderr, "Failed to describe datastore %v: %v\n",
dstore, err)
os.Exit(1)
}
for _, dstoreDesc := range dstoreDescList {
fmt.Printf("\tDatastore %v:\n",
dstoreDesc.Desc.DatastoreHeader.DatastoreName)
fmt.Printf("\t\tNumObjects: %v\n", dstoreDesc.Desc.NumObjects)
fmt.Printf("\t\tSize: %v MiB\n",
dstoreDesc.Desc.CapacityConsumedInBytes/1024/1024)
Expand Down

0 comments on commit d980b48

Please sign in to comment.