Skip to content

Commit

Permalink
Support for taskID flag in registry tool (#303)
Browse files Browse the repository at this point in the history
* Add taskid flag to the rootCmd
* Make the controller pass a taskID to the 1p subCommands. This will create a connection from the action computed by the controller to it's execution logs
* Remove registry exec command
* Add a logger to handle logs generated by third party commands
  • Loading branch information
shrutiparabgoogle authored Sep 23, 2021
1 parent 68016fa commit 0b152b0
Show file tree
Hide file tree
Showing 16 changed files with 113 additions and 195 deletions.
54 changes: 0 additions & 54 deletions cmd/registry/cmd/exec/exec.go

This file was deleted.

66 changes: 0 additions & 66 deletions cmd/registry/cmd/exec/exec_test.go

This file was deleted.

5 changes: 3 additions & 2 deletions cmd/registry/cmd/resolve/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/apigee/registry/cmd/registry/core"
"github.com/apigee/registry/connection"
"github.com/apigee/registry/rpc"
"github.com/google/uuid"
"github.com/spf13/cobra"
"google.golang.org/protobuf/proto"
)
Expand Down Expand Up @@ -93,10 +94,10 @@ func Command(ctx context.Context) *cobra.Command {
taskQueue, wait := core.WorkerPool(ctx, 64)
defer wait()
// Submit tasks to taskQueue
for i, a := range actions {
for _, a := range actions {
taskQueue <- &controller.ExecCommandTask{
Action: a,
TaskID: fmt.Sprintf("task%d", i),
TaskID: fmt.Sprintf("%.8s", uuid.New()),
}
}
},
Expand Down
2 changes: 1 addition & 1 deletion cmd/registry/cmd/resolve/testdata/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ generated_resources:
dependencies:
- pattern: $resource.spec
filter: "mime_type.contains('openapi')"
action: "compute complexity $resource.spec"
action: "registry compute complexity $resource.spec"
2 changes: 1 addition & 1 deletion cmd/registry/cmd/resolve/testdata/manifest_receipt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ generated_resources:
receipt: true
dependencies:
- pattern: $resource.spec
action: "exec echo test-receipt-artifact"
action: "echo test-receipt-artifact"
19 changes: 17 additions & 2 deletions cmd/registry/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ package cmd
import (
"context"

"fmt"
"github.com/apex/log"
"github.com/apex/log/handlers/text"
"github.com/apigee/registry/cmd/registry/cmd/annotate"
"github.com/apigee/registry/cmd/registry/cmd/compute"
"github.com/apigee/registry/cmd/registry/cmd/delete"
"github.com/apigee/registry/cmd/registry/cmd/exec"
"github.com/apigee/registry/cmd/registry/cmd/export"
"github.com/apigee/registry/cmd/registry/cmd/get"
"github.com/apigee/registry/cmd/registry/cmd/index"
Expand All @@ -30,20 +32,32 @@ import (
"github.com/apigee/registry/cmd/registry/cmd/search"
"github.com/apigee/registry/cmd/registry/cmd/upload"
"github.com/apigee/registry/cmd/registry/cmd/vocabulary"
"github.com/google/uuid"
"github.com/spf13/cobra"
)

func Command(ctx context.Context) *cobra.Command {
var logID string
var cmd = &cobra.Command{
Use: "registry",
Short: "A simple and eclectic utility for working with the API Registry",
PersistentPreRun: func(cmd *cobra.Command, args []string) {
// Initialize global default logger with unique process identifier.
if len(logID) == 0 {
logID = fmt.Sprintf("[ %.8s ] ", uuid.New())
}
logger := &log.Logger{
Level: log.DebugLevel,
Handler: text.Default,
}
log.Log = logger.WithField("uid", logID)
},
}

cmd.AddCommand(annotate.Command(ctx))
cmd.AddCommand(compute.Command(ctx))
cmd.AddCommand(resolve.Command(ctx))
cmd.AddCommand(delete.Command(ctx))
cmd.AddCommand(exec.Command(ctx))
cmd.AddCommand(export.Command(ctx))
cmd.AddCommand(get.Command(ctx))
cmd.AddCommand(index.Command(ctx))
Expand All @@ -53,5 +67,6 @@ func Command(ctx context.Context) *cobra.Command {
cmd.AddCommand(upload.Command(ctx))
cmd.AddCommand(vocabulary.Command(ctx))

cmd.PersistentFlags().StringVar(&logID, "log_id", "", "Assign an ID which gets attached to the log produced")
return cmd
}
2 changes: 1 addition & 1 deletion cmd/registry/cmd/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestCommandCoverage(t *testing.T) {
}
task := &controller.ExecCommandTask{
Action: &controller.Action{
Command: cmd.Name() + " --help",
Command: fmt.Sprintf("registry %s --help", cmd.Name()),
},
TaskID: fmt.Sprintf("task%d", i),
}
Expand Down
16 changes: 8 additions & 8 deletions cmd/registry/controller/controller-error-path_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func TestControllerErrors(t *testing.T) {
Pattern: "$resource.spec", // Correct pattern should be: $resource.version/specs/-
},
},
Action: "compute lint $resource.spec --linter gnostic",
Action: "registry compute lint $resource.spec --linter gnostic",
},
},
{
Expand All @@ -36,7 +36,7 @@ func TestControllerErrors(t *testing.T) {
Pattern: "$resource.apispec", // Correct pattern should be: $resource.spec
},
},
Action: "compute lint $resource.apispec --linter gnostic",
Action: "registry compute lint $resource.apispec --linter gnostic",
},
},
{
Expand All @@ -48,7 +48,7 @@ func TestControllerErrors(t *testing.T) {
Pattern: "$resource.version/artifacts/lint-gnostic", // There is no version level lint-gnostic artifact in the registry
},
},
Action: "compute lintstats $resource.version/artifacts/lint-gnostic --linter gnostic",
Action: "registry compute lintstats $resource.version/artifacts/lint-gnostic --linter gnostic",
},
},
{
Expand All @@ -60,7 +60,7 @@ func TestControllerErrors(t *testing.T) {
Pattern: "$resource.spec",
},
},
Action: "compute lintstats $resource.artifact --linter gnostic", // Correct reference should be: $artifact.spec/artifacts/lint-gnostic
Action: "registry compute lintstats $resource.artifact --linter gnostic", // Correct reference should be: $artifact.spec/artifacts/lint-gnostic
},
},
{
Expand All @@ -72,7 +72,7 @@ func TestControllerErrors(t *testing.T) {
Pattern: "$resource.spec",
},
},
Action: "compute lintstats $resource.specs/artifacts/lint-gnostic --linter gnostic",
Action: "registry compute lintstats $resource.specs/artifacts/lint-gnostic --linter gnostic",
},
},
{
Expand All @@ -87,7 +87,7 @@ func TestControllerErrors(t *testing.T) {
Pattern: "$resource.version/artifacts/vocabulary",
},
},
Action: "compute summary $resource.version",
Action: "registry compute summary $resource.version",
},
},
{
Expand All @@ -100,7 +100,7 @@ func TestControllerErrors(t *testing.T) {
},
},
// Correct action should be: "compute summary $resource.version/artifacts/complexity"
Action: "compute summary $resource.api/versions/-/artifacts/complexity",
Action: "registry compute summary $resource.api/versions/-/artifacts/complexity",
},
},
{
Expand All @@ -115,7 +115,7 @@ func TestControllerErrors(t *testing.T) {
Pattern: "$resource.api/versions/-/artifacts/vocabulary",
},
},
Action: "compute summary $resource", // Correct action should be: compute summary $resource.api
Action: "registry compute summary $resource", // Correct action should be: compute summary $resource.api
},
},
}
Expand Down
Loading

0 comments on commit 0b152b0

Please sign in to comment.