Repository navigation
Expose Debug API through the CLI - #7133
Conversation
Signed-off-by: Sorin Dumitru <[email protected]>
Signed-off-by: Sorin Dumitru <[email protected]>
Signed-off-by: Sorin Dumitru <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR exposes the existing Agent and Server Debug APIs via new CLI subcommands (debug getinfo), making it easier for operators to retrieve runtime debug information (uptime, counts, and SVID chain) without writing custom clients.
Changes:
- Add
spire-server debug getinfobacked by the server Debug gRPC API, including CLI wiring and tests. - Add
spire-agent debug getinfobacked by the agent Debug gRPC API, including OS-specific socket/named-pipe handling and tests. - Update CLI documentation and the agent sample config to surface the new debug functionality.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| doc/spire_server.md | Documents new spire-server debug getinfo command and flags |
| doc/spire_agent.md | Documents new spire-agent debug getinfo command and flags |
| conf/agent/agent.conf | Updates sample agent config to include an Admin API socket path |
| cmd/spire-server/util/util.go | Adds NewDebugClient() to the server CLI client interface |
| cmd/spire-server/cli/debug/debug.go | Implements spire-server debug getinfo command and pretty output |
| cmd/spire-server/cli/debug/debug_posix_test.go | POSIX usage string expectations for server debug command |
| cmd/spire-server/cli/debug/debug_windows_test.go | Windows usage string expectations for server debug command |
| cmd/spire-server/cli/debug/debug_test.go | Unit tests for server debug command behavior/output |
| cmd/spire-server/cli/cli.go | Registers debug getinfo in the server CLI command map |
| cmd/spire-agent/cli/debug/debug.go | Implements spire-agent debug getinfo command and pretty output |
| cmd/spire-agent/cli/debug/debug_posix.go | POSIX socket flag/address handling for agent debug command |
| cmd/spire-agent/cli/debug/debug_windows.go | Windows named-pipe flag/address handling for agent debug command |
| cmd/spire-agent/cli/debug/debug_posix_test.go | POSIX usage + helper setup for agent debug tests |
| cmd/spire-agent/cli/debug/debug_windows_test.go | Windows usage + helper setup for agent debug tests |
| cmd/spire-agent/cli/debug/debug_test.go | Unit tests for agent debug command behavior/output |
| cmd/spire-agent/cli/cli.go | Registers debug getinfo in the agent CLI command map |
| server_address = "127.0.0.1" | ||
| server_port = "8081" | ||
| socket_path ="/tmp/spire-agent/public/api.sock" | ||
| admin_socket_path ="/tmp/spire-agent/private/admin.sock" |
There was a problem hiding this comment.
makes sense to me, or do you plan to make it enabled as default?
There was a problem hiding this comment.
Yeah, that's probably best
| Prints debug information about the agent, including uptime, last successful | ||
| sync time, cached SVID counts, and the agent's own SVID chain. | ||
|
|
| env.Printf("Agent Debug Info:\n") | ||
| env.Printf(" Uptime: %s\n", (time.Duration(resp.Uptime) * time.Second).String()) | ||
| env.Printf(" Last Sync Success: %s\n", time.Unix(resp.LastSyncSuccess, 0).UTC().Format(time.RFC3339)) | ||
| env.Printf(" Cached X.509 SVIDs: %d\n", resp.CachedX509SvidsCount) |
| server_address = "127.0.0.1" | ||
| server_port = "8081" | ||
| socket_path ="/tmp/spire-agent/public/api.sock" | ||
| admin_socket_path ="/tmp/spire-agent/private/admin.sock" |
There was a problem hiding this comment.
makes sense to me, or do you plan to make it enabled as default?
| return newGetInfoCommand(commoncli.DefaultEnv) | ||
| } | ||
|
|
||
| func newGetInfoCommand(env *commoncli.Env) *getInfoCommand { |
There was a problem hiding this comment.
can you reuse https://github.com/spiffe/spire/blob/main/cmd/spire-agent/util/util.go#L66? I think this is going to reduce this code a lot and add windows/linux support for free
| |---------------|------------------------------------|----------------------------------| | ||
| | `-socketPath` | Path to the SPIRE Agent API socket | /tmp/spire-agent/public/api.sock | | ||
|
|
||
| ### `spire-agent debug getinfo` |
There was a problem hiding this comment.
for both can you mention than the debugAPI must be enabled to use this?
|
|
||
| env.Printf("Agent Debug Info:\n") | ||
| env.Printf(" Uptime: %s\n", (time.Duration(resp.Uptime) * time.Second).String()) | ||
| env.Printf(" Last Sync Success: %s\n", time.Unix(resp.LastSyncSuccess, 0).UTC().Format(time.RFC3339)) |
There was a problem hiding this comment.
if it never sync it is ngoing to be 0 that is translated to 1970-01-01 right? can you verify no empty before printing this?
There was a problem hiding this comment.
I made it print (never) here.
| func prettyPrintGetInfo(env *commoncli.Env, results ...any) error { | ||
| resp, ok := results[0].(*debugv1.GetInfoResponse) | ||
| if !ok { | ||
| return errors.New("internal error: cli printer; please report this bug") |
There was a problem hiding this comment.
can you reuse ErrInternalCustomPrettyFunc as all another cmds? (same for all places like this)
Signed-off-by: Sorin Dumitru <[email protected]>
Signed-off-by: Sorin Dumitru <[email protected]>
Pull Request check list
Affected functionality
Agent and server CLIs
Description of change
The debug API is now exposed through the CLI, making it easier to use.