Skip to content

Commit d90e4ea

Browse files
authored
Improve tsh debug messages with client version output (#60297)
* Added client version output when --debug flag is added to tsh commands * Moved client version output to logger * Altered tsh client version output to match tbot's, added test coverage * Updated test to check versions in output
1 parent 0218493 commit d90e4ea

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

tool/tsh/common/tsh.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1632,6 +1632,18 @@ func Run(ctx context.Context, args []string, opts ...CliOption) error {
16321632
defer runtimetrace.Stop()
16331633
}
16341634

1635+
// print tsh version when --debug flag is set
1636+
// to diagnose potential client version mismatch
1637+
if cf.Debug && command != ver.FullCommand() {
1638+
logger.InfoContext(ctx, "Initializing tsh",
1639+
"version", slog.GroupValue(
1640+
slog.String("teleport", teleport.Version),
1641+
slog.String("teleport_git", teleport.Gitref),
1642+
slog.String("go", runtime.Version()),
1643+
),
1644+
)
1645+
}
1646+
16351647
switch command {
16361648
case ver.FullCommand():
16371649
err = onVersion(&cf)

tool/tsh/common/tsh_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7747,3 +7747,23 @@ func Test_humanFriendlyValidUntilDuration(t *testing.T) {
77477747
})
77487748
}
77497749
}
7750+
7751+
func TestDebugVersionOutput(t *testing.T) {
7752+
t.Setenv(tshBinMainTestEnv, "1")
7753+
testExecutable, err := os.Executable()
7754+
require.NoError(t, err)
7755+
7756+
output, err := exec.Command(testExecutable, "logout", "--debug").CombinedOutput()
7757+
require.NoError(t, err)
7758+
7759+
vers := []string{
7760+
teleport.Version,
7761+
teleport.Gitref,
7762+
runtime.Version(),
7763+
}
7764+
7765+
require.Contains(t, string(output), "Initializing tsh version")
7766+
for _, v := range vers {
7767+
require.Contains(t, string(output), v)
7768+
}
7769+
}

0 commit comments

Comments
 (0)