From b821810726c9724fe5afbd429b8a47656e71eb33 Mon Sep 17 00:00:00 2001 From: Milas Bowman Date: Thu, 1 Jun 2023 16:22:28 -0400 Subject: [PATCH] metrics: adjust Compose event collection * for per-invocation events, only look at Compose `alpha` commands * for aggregated events, include Compose `alpha` commands Signed-off-by: Milas Bowman --- cli/metrics/commands.go | 2 ++ cli/metrics/docker_command.go | 33 ++++++------------------------ cli/metrics/docker_command_test.go | 19 ++++++++++------- 3 files changed, 20 insertions(+), 34 deletions(-) diff --git a/cli/metrics/commands.go b/cli/metrics/commands.go index f872b36cb..cee87af9b 100644 --- a/cli/metrics/commands.go +++ b/cli/metrics/commands.go @@ -26,6 +26,7 @@ var commandFlags = []string{ // Generated with generatecommands/main.go var managementCommands = []string{ "help", + "alpha", "app", "builder", "buildx", @@ -157,4 +158,5 @@ var commands = []string{ "validate", "version", "wait", + "watch", } diff --git a/cli/metrics/docker_command.go b/cli/metrics/docker_command.go index f756ffc1c..5b46f4267 100644 --- a/cli/metrics/docker_command.go +++ b/cli/metrics/docker_command.go @@ -68,6 +68,11 @@ func NewDockerCLIEvent(cmd CmdResult) *DockerCLIEvent { subcommand = strings.Join(subcommandParts, "-") } + cmdOrPlugin := cmdPath[1] + if cmdOrPlugin.plugin && subcommand == "" { + return nil + } + var usage bool for _, arg := range cmd.Args { // TODO(milas): also support `docker help build` syntax @@ -81,7 +86,7 @@ func NewDockerCLIEvent(cmd CmdResult) *DockerCLIEvent { } event := &DockerCLIEvent{ - Command: cmdPath[1].name, + Command: cmdOrPlugin.name, Subcommand: subcommand, ExitCode: int32(cmd.ExitCode), Usage: usage, @@ -161,32 +166,6 @@ var cmdHierarchy = &cmdNode{ {name: "dryrun"}, }, }, - {name: "build"}, - {name: "config"}, - {name: "convert"}, - {name: "cp"}, - {name: "create"}, - {name: "down"}, - {name: "events"}, - {name: "exec"}, - {name: "images"}, - {name: "kill"}, - {name: "logs"}, - {name: "ls"}, - {name: "pause"}, - {name: "port"}, - {name: "ps"}, - {name: "pull"}, - {name: "push"}, - {name: "restart"}, - {name: "rm"}, - {name: "run"}, - {name: "start"}, - {name: "stop"}, - {name: "top"}, - {name: "unpause"}, - {name: "up"}, - {name: "version"}, }, }, }, diff --git a/cli/metrics/docker_command_test.go b/cli/metrics/docker_command_test.go index 233ef2aac..73b8f3434 100644 --- a/cli/metrics/docker_command_test.go +++ b/cli/metrics/docker_command_test.go @@ -43,30 +43,35 @@ func TestCmdCompose(t *testing.T) { { name: "Compose - Base", input: "docker compose", - expected: &DockerCLIEvent{Command: "compose"}, + expected: nil, + }, + { + name: "Compose - Ignored", + input: "docker compose up", + expected: nil, }, { name: "Compose - Root Args", - input: "docker --host 127.0.0.1 --debug=true compose ls", + input: "docker --host 127.0.0.1 --debug=true compose alpha watch", expected: &DockerCLIEvent{ Command: "compose", - Subcommand: "ls", + Subcommand: "alpha-watch", }, }, { name: "Compose - Base Args", - input: "docker compose -p myproject build myservice", + input: "docker compose -p myproject alpha watch myservice", expected: &DockerCLIEvent{ Command: "compose", - Subcommand: "build", + Subcommand: "alpha-watch", }, }, { name: "Compose - Usage", - input: "docker compose --file=mycompose.yaml up --help myservice", + input: "docker compose --file=mycompose.yaml alpha watch --help myservice", expected: &DockerCLIEvent{ Command: "compose", - Subcommand: "up", + Subcommand: "alpha-watch", Usage: true, }, },