Skip to content
This repository has been archived by the owner on Nov 27, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2249 from milas/adjust-compose-events
Browse files Browse the repository at this point in the history
metrics: adjust Compose event collection
  • Loading branch information
glours authored Jun 2, 2023
2 parents e099b83 + b821810 commit a0eabb3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 34 deletions.
2 changes: 2 additions & 0 deletions cli/metrics/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var commandFlags = []string{
// Generated with generatecommands/main.go
var managementCommands = []string{
"help",
"alpha",
"app",
"builder",
"buildx",
Expand Down Expand Up @@ -160,4 +161,5 @@ var commands = []string{
"validate",
"version",
"wait",
"watch",
}
33 changes: 6 additions & 27 deletions cli/metrics/docker_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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"},
},
},
},
Expand Down
19 changes: 12 additions & 7 deletions cli/metrics/docker_command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
Expand Down

0 comments on commit a0eabb3

Please sign in to comment.