command "pmm-admin inventory" returns GO errors
General
Escalation
General
Escalation
Description
How to test
1/ Deploy a docker-based PMM Server
2/ get inside the container with `docker exec -it pmm-server bash`
3/ run `pmm-admin inventory` - you should see a helpful output and not the error trace
Note: running `pmm-admin inventory --help` yields the same effect
How to document
-
Activity
Show:
vasyl.yurkovych August 24, 2023 at 9:26 AM
verified in build:
server docker - perconalab/pmm-server-fb:PR-3358-01eea2a
client docker - perconalab/pmm-client-fb:PR-3358-01eea2a
client - https://s3.us-east-2.amazonaws.com/pmm-build-cache/PR-BUILDS/pmm2-client/pmm2-client-PR-3358-01eea2a.tar.gz
Done
Smart Checklist
Open Smart Checklist
Smart Checklist

Open Smart Checklist
Created July 26, 2023 at 1:45 PM
Updated March 5, 2024 at 10:15 PM
Resolved August 24, 2023 at 10:13 AM
Easy to reproduce
Before:
root@ip-192-168-1-204:~# pmm-admin inventory panic: The command does not implement RunCmd() goroutine 1 [running]: github.com/percona/pmm/admin/cli.run(0x3?, 0x0?) /tmp/go/src/github.com/percona/pmm/admin/cli/cli.go:123 +0x151 github.com/percona/pmm/admin/cli.(*PMMAdminCommands).Run(0x2?, 0xc000668808?, 0x1?) /tmp/go/src/github.com/percona/pmm/admin/cli/cli.go:68 +0x1f reflect.Value.call({0xbda7e0?, 0xc0000bac80?, 0x44ca76?}, {0xce1a68, 0x4}, {0xc00042e990, 0x2, 0x2?}) /usr/local/go/src/reflect/value.go:586 +0xb07 reflect.Value.Call({0xbda7e0?, 0xc0000bac80?, 0xbe0d80?}, {0xc00042e990?, 0xcde080?, 0xc000090400?}) /usr/local/go/src/reflect/value.go:370 +0xbc github.com/alecthomas/kong.callMethod({0xce142b, 0x3}, {0xcb52e0?, 0xc0000bac80?, 0xc48620?}, {0xbda7e0?, 0xc0000bac80?, 0x13616e0?}, 0xc000606490?) /tmp/go/pkg/mod/github.com/alecthomas/kong@v0.7.1/callbacks.go:95 +0x4fa github.com/alecthomas/kong.(*Context).RunNode(0xc0002fc880, 0xc000020ff0, {0xc000606698, 0x1, 0x1}) /tmp/go/pkg/mod/github.com/alecthomas/kong@v0.7.1/context.go:755 +0x60f github.com/alecthomas/kong.(*Context).Run(0xc0000bac80?, {0xc000606698?, 0xc0000bac80?, 0x0?}) /tmp/go/pkg/mod/github.com/alecthomas/kong@v0.7.1/context.go:780 +0x14e github.com/percona/pmm/admin/cmd.Bootstrap({0xcb52e0?, 0xc0000b9300?}) /tmp/go/src/github.com/percona/pmm/admin/cmd/bootstrap.go:72 +0x325 main.main() /tmp/go/src/github.com/percona/pmm/admin/cmd/pmm-admin/main.go:23 +0x5e
After:
[root@pmm-server pmm] # pmm-admin inventory Usage: pmm-admin inventory <command>Inventory commandsFlags: -h, --help Show context-sensitive help. --server-url=SERVER-URL PMM Server URL in https://username:password@pmm-server-host/ format --server-insecure-tls Skip PMM Server TLS certificate validation --debug Enable debug logging --trace Enable trace logging (implies debug) --pmm-agent-listen-port=7777 Set listen port of pmm-agent --json Enable JSON output -v, --version Show application versionCommands: inventory list List inventory commands inventory add Add to inventory commands inventory remove Remove from inventory commands pmm-admin: error: expected one of "list", "add", "remove"
Implementation:
The top-level `pmm-admin inventory` is a "hidden" command, which was done on purpose so that user favor as shorter and therefore the more memorable `pmm-admin add/remove service` commands. However, `pmm-admin inventory list/add/remove` were also hidden, which was contributing to the reported problem, since Kong was unable to execute the `pmm-admin inventory [--help]` command.
The solution was to implement the inventory's `RunCmd()` method and "unhide" `pmm-admin inventory list/add/remove` comands, while keeping `pmm-admin inventory` hidden.