Skip to content

Improve tsh debug messages with client version output#60297

Merged
kshi36 merged 5 commits intomasterfrom
kevin/tsh-debug-output-version
Oct 18, 2025
Merged

Improve tsh debug messages with client version output#60297
kshi36 merged 5 commits intomasterfrom
kevin/tsh-debug-output-version

Conversation

@kshi36
Copy link
Copy Markdown
Contributor

@kshi36 kshi36 commented Oct 15, 2025

Fixes #55738.
Added tsh client version to improve tsh command debugging, eg. client version mismatch.

Changelog: Updated tsh debug output to include tsh client version when --debug flag is set.

@github-actions github-actions bot added size/sm tsh tsh - Teleport's command line tool for logging into nodes running Teleport. labels Oct 15, 2025
@github-actions github-actions bot requested review from klizhentas and zmb3 October 15, 2025 23:32
@r0mant r0mant requested review from bernardjkim and r0mant and removed request for klizhentas and zmb3 October 16, 2025 01:58
Comment thread tool/tsh/common/tsh.go Outdated
// print tsh version when --debug flag is set
// to diagnose potential client version mismatch
if cf.Debug && command != ver.FullCommand() {
modules.GetModules().PrintVersion()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This prints to stdout, but on macOS tsh can be configured to log to os_log.

Instead of logging the version to stdout, I think a better approach might be to make sure that initLogger was already called twice (it was at this point in the Run function) and use logger.DebugContext instead of printing to stdout. This will make the logger print to whatever destination it is set, in case we add more destinations in the future.

This would require extending modules with something like GetVersionString. It unfortunately complicates the whole implementation, as adjusting the Modules interface means that you first have to add the relevant method to the enterprise Modules in the other repo, then update the e ref in the OSS repo and only then merge the OSS change which uses the new method. Otherwise merging just the OSS change would end up breaking the enterprise build.

https://github.com/gravitational/teleport.e?tab=readme-ov-file#working-with-submodules

I know it's much more complicated than what you initially wanted to do here. But I think it'll also be a good introduction to the peculiarities of the enterprise repo and how to work with it. :~)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd also be fine to merge this first and then make it use the logger in another PR!

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should log directly instead of using the modules function to print the version here.

That aligns better with what we already do in tbot, see #58033.

Comment thread tool/tsh/common/tsh.go Outdated
// print tsh version when --debug flag is set
// to diagnose potential client version mismatch
if cf.Debug && command != ver.FullCommand() {
modules.GetModules().PrintVersion()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd also be fine to merge this first and then make it use the logger in another PR!

@bernardjkim
Copy link
Copy Markdown
Contributor

Regarding the failed Unit Tests, it looks like it is most likely unrelated to your changes and is the result of a flaky test failure. The error message looks like the same one as seen in #32958.

In this case you can re-run the unit tests to pass the check. If the flaky test wasn't already being tracked, it'd also be helpful to create a GitHub issue to track it.

@bernardjkim
Copy link
Copy Markdown
Contributor

bernardjkim commented Oct 16, 2025

My mistake, after taking a closer look at the error messages, I think the code change may actually be causing this particular test case to fail. So we'll probably need to go with the above suggestions and avoid writing to stdout here.

Messages:   	exit code: 2
        	            	stderr: protocol version mismatch -- is your shell clean?
        	            	(see the rsync manpage for an explanation)
        	            	rsync error: protocol incompatibility (code 2) at compat.c(622) [sender=3.2.7]

The rsync man page documents this under their Diagnostics section:

rsync occasionally produces error messages that may seem a little cryptic. The one that seems to cause the most confusion is lqprotocol version mismatch -- is your shell clean?rq.

This message is usually caused by your startup scripts or remote shell facility producing unwanted garbage on the stream that rsync is using for its transport.

Copy link
Copy Markdown
Contributor

@rosstimothy rosstimothy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good other than one small suggestion. Happy first commit @kshi36 🎉 !

Comment thread tool/tsh/common/tsh.go Outdated
// print tsh version when --debug flag is set
// to diagnose potential client version mismatch
if cf.Debug && command != ver.FullCommand() {
logger.InfoContext(ctx, "Debugging tsh client",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should alter the message to match what tbot uses.

Suggested change
logger.InfoContext(ctx, "Debugging tsh client",
logger.InfoContext(ctx, "Initializing tsh",

Copy link
Copy Markdown
Collaborator

@r0mant r0mant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Congrats on the first commit @kshi36! Looks good to me as well but can you please add test coverage before merging as we discussed yesterday?

@kshi36 kshi36 requested a review from r0mant October 17, 2025 19:13
Copy link
Copy Markdown
Collaborator

@r0mant r0mant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm with one more suggestion


output, err := exec.Command(testExecutable, "logout", "--debug").CombinedOutput()
require.NoError(t, err)
require.Contains(t, string(output), "Initializing tsh version")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Can we check that the output contains versions as well?

@kshi36 kshi36 added this pull request to the merge queue Oct 18, 2025
Merged via the queue into master with commit d90e4ea Oct 18, 2025
41 checks passed
@kshi36 kshi36 deleted the kevin/tsh-debug-output-version branch October 18, 2025 02:50
@backport-bot-workflows
Copy link
Copy Markdown
Contributor

@kshi36 See the table below for backport results.

Branch Result
branch/v18 Create PR

mmcallister pushed a commit that referenced this pull request Nov 6, 2025
* 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
mmcallister pushed a commit that referenced this pull request Nov 19, 2025
* 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
codingllama pushed a commit that referenced this pull request Nov 19, 2025
* 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
github-merge-queue bot pushed a commit that referenced this pull request Nov 19, 2025
* 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

Co-authored-by: Kevin <76608931+kshi36@users.noreply.github.com>
mmcallister pushed a commit that referenced this pull request Nov 20, 2025
* 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/branch/v18 size/sm tsh tsh - Teleport's command line tool for logging into nodes running Teleport.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatically print tsh version when the --debug flag is used

5 participants