In metrics, send context type, not context name (metrics for Moby calls)

Signed-off-by: Guillaume Tardif <guillaume.tardif@docker.com>
This commit is contained in:
Guillaume Tardif 2020-09-23 16:12:09 +02:00
parent 64cd8ebf8c
commit 8302266212
2 changed files with 5 additions and 5 deletions

View File

@ -209,7 +209,7 @@ $ docker context create %s <name>`, cc.Type(), store.EcsContextType), ctype)
}
mobycli.ExecIfDefaultCtxType(ctx, root)
checkIfUnknownCommandExistInDefaultContext(err, currentContext, root)
checkIfUnknownCommandExistInDefaultContext(err, currentContext, root, ctype)
exit(root, currentContext, err, ctype)
}
@ -242,14 +242,14 @@ func fatal(err error) {
os.Exit(1)
}
func checkIfUnknownCommandExistInDefaultContext(err error, currentContext string, root *cobra.Command) {
func checkIfUnknownCommandExistInDefaultContext(err error, currentContext string, root *cobra.Command, contextType string) {
submatch := unknownCommandRegexp.FindSubmatch([]byte(err.Error()))
if len(submatch) == 2 {
dockerCommand := string(submatch[1])
if mobycli.IsDefaultContextCommand(dockerCommand) {
fmt.Fprintf(os.Stderr, "Command %q not available in current context (%s), you can use the \"default\" context to run this command\n", dockerCommand, currentContext)
metrics.Track(currentContext, os.Args[1:], root.PersistentFlags(), metrics.FailureStatus)
metrics.Track(contextType, os.Args[1:], root.PersistentFlags(), metrics.FailureStatus)
os.Exit(1)
}
}

View File

@ -86,7 +86,7 @@ func Exec(root *cobra.Command) {
err := cmd.Run()
childExit <- true
if err != nil {
metrics.Track(store.DefaultContextName, os.Args[1:], root.PersistentFlags(), metrics.FailureStatus)
metrics.Track(store.DefaultContextType, os.Args[1:], root.PersistentFlags(), metrics.FailureStatus)
if exiterr, ok := err.(*exec.ExitError); ok {
os.Exit(exiterr.ExitCode())
@ -94,7 +94,7 @@ func Exec(root *cobra.Command) {
fmt.Fprintln(os.Stderr, err)
os.Exit(1)
}
metrics.Track(store.DefaultContextName, os.Args[1:], root.PersistentFlags(), metrics.SuccessStatus)
metrics.Track(store.DefaultContextType, os.Args[1:], root.PersistentFlags(), metrics.SuccessStatus)
os.Exit(0)
}