Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 72 additions & 0 deletions cli/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"regexp"
"strings"

"github.com/samber/lo"
"github.com/urfave/cli/v2"

"go.viam.com/rdk/logging"
Expand Down Expand Up @@ -189,6 +190,14 @@ var commonPartFlags = []cli.Flag{
},
}

var commonOtlpFlags = []cli.Flag{
&cli.StringFlag{
Name: "endpoint",
DefaultText: "localhost:4317",
Usage: "OTLP endpoint in host:port format",
},
}

// matches all uppercase characters that follow lowercase chars and aren't at the [0] index of a string.
// This is useful for converting camel case into kabob case when getting values out of a CLI Context
// based on a flag name, and putting them into a struct with a camel cased field name.
Expand Down Expand Up @@ -456,6 +465,69 @@ var app = &cli.App{
},
},
Commands: []*cli.Command{
{
Name: "traces",
Usage: "Work with viam-server traces",
UsageText: createUsageText("traces", nil, false, true),
Subcommands: []*cli.Command{
{
Name: "import-local",
Usage: "Import traces from a local viam server trace file to an OTLP endpoint.",
UsageText: createUsageText("traces import-local", nil, true, false, "<path>"),
ArgsUsage: "<traces file>",
Flags: commonOtlpFlags,
Action: createCommandWithT(traceImportLocalAction),
},
{
Name: "import-remote",
Description: `
In order to use the import-remote command, the machine must have a valid shell type service.
Organization and location are required flags if using name (rather than ID) for the part.
Note: There is no progress meter while copying is in progress.
`,
Usage: "Import traces from a remote viam machine to an OTLP endpoint.",
UsageText: createUsageText("traces import-remote", []string{generalFlagPart}, true, false),
Flags: lo.Flatten([][]cli.Flag{
commonOtlpFlags,
commonPartFlags,
}),
Action: createCommandWithT(traceImportRemoteAction),
},
{
Name: "print-local",
Usage: "Print traces in a local file to the console",
UsageText: createUsageText("traces print-local", nil, true, false, "<path>"),
ArgsUsage: "<traces file>",
Action: createCommandWithT(tracePrintLocalAction),
},
{
Name: "print-remote",
Usage: "Print traces from a remote viam machine to the console",
UsageText: createUsageText("traces print-remote", []string{generalFlagPart}, true, false),
Description: `
In order to use the print-remote command, the machine must have a valid shell type service.
Organization and location are required flags if using name (rather than ID) for the part.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to use createUsageText helper here (and in the other new methods) to get consistent usage text formatting. Also because currently, the usage text on viam traces get-remote --help includes USAGE: viam traces get-remote [command options] [target], but it isn't clear from this text that part is in fact a required field.

Note: There is no progress meter while copying is in progress.
`,
Flags: commonPartFlags,
Action: createCommandWithT(tracePrintRemoteAction),
},
{
Name: "get-remote",
Usage: "Download traces from a viam machine and save them to disk",
UsageText: createUsageText("traces get-remote", []string{generalFlagPart}, true, false, "[target]"),
ArgsUsage: "[target]",
Description: `
In order to use the get-remote command, the machine must have a valid shell type service.
Organization and location are required flags if using name (rather than ID) for the part.
If [target] is not specified then the traces file will be saved to the current working directory.
Note: There is no progress meter while copying is in progress.
`,
Flags: commonPartFlags,
Action: createCommandWithT(traceGetRemoteAction),
},
},
},
{
Name: "login",
// NOTE(benjirewis): maintain `auth` as an alias for backward compatibility.
Expand Down
Loading