Skip to content

Commit

Permalink
feat: improve apps describe (#328)
Browse files Browse the repository at this point in the history
* feat: improve apps describe

* chore: update upstream meroxa-go
  • Loading branch information
raulb authored Apr 19, 2022
1 parent f98708a commit fcedaf1
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 15 deletions.
41 changes: 31 additions & 10 deletions cmd/meroxa/root/apps/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ limitations under the License.
package apps

import (
"bytes"
"context"
"errors"
"net/http"

"github.com/meroxa/cli/cmd/meroxa/builder"
"github.com/meroxa/cli/log"
Expand All @@ -37,6 +39,7 @@ var (

type describeApplicationClient interface {
GetApplication(ctx context.Context, nameOrUUID string) (*meroxa.Application, error)
GetFunctionLogs(ctx context.Context, nameOrUUID string) (*http.Response, error)
GetResourceByNameOrID(ctx context.Context, nameOrID string) (*meroxa.Resource, error)
GetConnectorByNameOrID(ctx context.Context, nameOrID string) (*meroxa.Connector, error)
GetFunction(ctx context.Context, nameOrUUID string) (*meroxa.Function, error)
Expand Down Expand Up @@ -70,43 +73,61 @@ func (d *Describe) Docs() builder.Docs {
}

func (d *Describe) Execute(ctx context.Context) error {
extended := d.flags.Extended
var output string

app, err := d.client.GetApplication(ctx, d.args.NameOrUUID)
if err != nil {
return err
}

output := utils.AppTable(app)
if extended {
if d.flags.Extended {
resources := make([]*meroxa.Resource, 0)
connectors := make(map[string]*meroxa.Connector)
functions := make([]*meroxa.Function, 0)

for _, id := range app.Resources {
resource, err := d.client.GetResourceByNameOrID(ctx, id.Name.String)
for _, rr := range app.Resources {
resource, err := d.client.GetResourceByNameOrID(ctx, rr.Name.String)
if err != nil {
return err
}
resources = append(resources, resource)
}
for _, id := range app.Connectors {
connector, err := d.client.GetConnectorByNameOrID(ctx, id.Name.String)
for _, cc := range app.Connectors {
connector, err := d.client.GetConnectorByNameOrID(ctx, cc.Name.String)
if err != nil {
return err
}
connectors[connector.ResourceName] = connector
}
for _, id := range app.Functions {
function, err := d.client.GetFunction(ctx, id.UUID.String)
for _, ff := range app.Functions {
function, err := d.client.GetFunction(ctx, ff.UUID.String)
if err != nil {
return err
}

// Include logs
resp, err := d.client.GetFunctionLogs(ctx, ff.Name.String)
if err != nil {
return err
}
defer resp.Body.Close() //nolint:gocritic

buf := new(bytes.Buffer)
_, err = buf.ReadFrom(resp.Body)
if err != nil {
return err
}

function.Logs = buf.String()

functions = append(functions, function)
}

output = utils.ExtendedAppTable(app, resources, connectors, functions)
output = utils.AppExtendedTable(app, resources, connectors, functions)
} else {
output = utils.AppTable(app)
}

d.logger.Info(ctx, output)
d.logger.JSON(ctx, app)

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ require (
github.com/manifoldco/promptui v0.8.0
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-runewidth v0.0.10 // indirect
github.com/meroxa/meroxa-go v0.0.0-20220419000706-05a93c79cc6e
github.com/meroxa/meroxa-go v0.0.0-20220419150435-19df16177640
github.com/nirasan/go-oauth-pkce-code-verifier v0.0.0-20170819232839-0fbfe93532da
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4
github.com/rivo/uniseg v0.2.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -574,8 +574,8 @@ github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182aff
github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2/go.mod h1:eD9eIE7cdwcMi9rYluz88Jz2VyhSmden33/aXg4oVIY=
github.com/meroxa/funtime v0.0.0-20220113012133-85e6e898fc73/go.mod h1:K2y2GvcA4Cg3dJtckcwYWnwnJzF63FDdtAQI0fToU0Q=
github.com/meroxa/meroxa-go v0.0.0-20220208195203-71ddc3133fab/go.mod h1:HDFszURCM1cOpKE699o5Hs0T2tEIXqY+vFcsur3RiwY=
github.com/meroxa/meroxa-go v0.0.0-20220419000706-05a93c79cc6e h1:z5wOdhit1nuDyevydXW4/c2dwQW2BbAamBar1vJ4nhw=
github.com/meroxa/meroxa-go v0.0.0-20220419000706-05a93c79cc6e/go.mod h1:BsqYa9jqfyGOAgfkggfK567b2Ahkb+RCH3lXDQGgrh8=
github.com/meroxa/meroxa-go v0.0.0-20220419150435-19df16177640 h1:keSIQO3busIkUlHT/Q7p0ij3VcbjeOrXs1vvSJm33J0=
github.com/meroxa/meroxa-go v0.0.0-20220419150435-19df16177640/go.mod h1:BsqYa9jqfyGOAgfkggfK567b2Ahkb+RCH3lXDQGgrh8=
github.com/meroxa/turbine-go v0.0.0-20220419083802-4f83d9343ce6 h1:vMXfEM3/9+Q4wOKMoYYFbCe0d3bOW3iCiLRhW5blmgo=
github.com/meroxa/turbine-go v0.0.0-20220419083802-4f83d9343ce6/go.mod h1:F4ODyjX+tn5dYFRc1bQlHLUnTtlJIxs09AKHqfCD5Cg=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
Expand Down
10 changes: 9 additions & 1 deletion utils/display.go
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ func AppTable(app *meroxa.Application) string {
return mainTable.String()
}

func ExtendedAppTable(app *meroxa.Application, resources []*meroxa.Resource, connectors map[string]*meroxa.Connector,
func AppExtendedTable(app *meroxa.Application, resources []*meroxa.Resource, connectors map[string]*meroxa.Connector,
functions []*meroxa.Function) string {
mainTable := simpletable.New()
mainTable.Body.Cells = [][]*simpletable.Cell{
Expand Down Expand Up @@ -940,6 +940,10 @@ func extendedResourcesTable(resources []*meroxa.Resource, connectors map[string]
subTable += fmt.Sprintf("\t\t%5s: %s\n", "Type", string(r.Type))
subTable += fmt.Sprintf("\t\t%5s: %s\n", "State", string(c.State))
subTable += fmt.Sprintf("\t\t%5s: %s\n", "As", string(c.Type))

if c.Trace != "" {
subTable += fmt.Sprintf("\t\t%5s: %s\n", "Trace", c.Trace)
}
}

return subTable
Expand All @@ -955,6 +959,10 @@ func extendedFunctionsTable(functions []*meroxa.Function) string {
subTable += fmt.Sprintf("\t %s\n", f.Name)
subTable += fmt.Sprintf("\t\t%5s: %s\n", "UUID", f.UUID)
subTable += fmt.Sprintf("\t\t%5s: %s\n", "State", f.Status.State)

if f.Logs != "" {
subTable += fmt.Sprintf("\t\t%5s: %s\n", "Logs", f.Logs)
}
}

return subTable
Expand Down
1 change: 1 addition & 0 deletions vendor/github.com/meroxa/meroxa-go/pkg/meroxa/function.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ github.com/mattn/go-runewidth
# github.com/mattn/go-shellwords v1.0.12
## explicit; go 1.13
github.com/mattn/go-shellwords
# github.com/meroxa/meroxa-go v0.0.0-20220419000706-05a93c79cc6e
# github.com/meroxa/meroxa-go v0.0.0-20220419150435-19df16177640
## explicit; go 1.17
github.com/meroxa/meroxa-go/pkg/meroxa
github.com/meroxa/meroxa-go/pkg/mock
Expand Down

0 comments on commit fcedaf1

Please sign in to comment.