diagnostics icon indicating copy to clipboard operation
diagnostics copied to clipboard

Abnormal dotnet-counters output UI with alpine container

Open WeihanLi opened this issue 5 years ago • 14 comments

Description

image

Configuration

  • dotnet-counters (5.0.236902+5366510b270d0f0ebffc9e36e9496688b20b96c2)
  • Alpine docker container

dotnet --info output:

image

WeihanLi avatar Aug 30 '21 03:08 WeihanLi

@mikelle-rogers @josalem

tommcdon avatar Aug 30 '21 04:08 tommcdon

Based on the output, it looks like the console line rewriting failed, so it continuously printed on the same line.

What shell and terminal/console were you using?

Do you have a specific base container you were using or was it just a generic Alpine image?

@mikelle-rogers can you see if you can repro this behavior?

josalem avatar Aug 30 '21 17:08 josalem

Just a generic docker alpine image, I use the docker image with tag mcr.microsoft.com/dotnet/core/aspnet:3.1-alpine, used with the original shell with sh command

WeihanLi avatar Aug 31 '21 01:08 WeihanLi

used with the original shell

Was this the console on Windows, Linux, or Mac? And specifically, was it a special console like iTerm2 on macOS or the new Windows Terminal on Windows?

josalem avatar Aug 31 '21 16:08 josalem

I used ubuntu terminal on wsl2 and powershell 7 both on windows terminal. And also on our rancher temp container terminal(not sure what it is)

WeihanLi avatar Aug 31 '21 23:08 WeihanLi

I tried to repro this behavior on a Windows computer, using an ubuntu terminal on wsl2, but line rewriting worked great. What version of ubuntu were you using?

mikelle-rogers avatar Sep 01 '21 00:09 mikelle-rogers

I'm using Ubuntu 20.04 image image

WeihanLi avatar Sep 01 '21 01:09 WeihanLi

Out of curiosity, is the container running locally on your machine or are you connecting to a container on a remote machine?

josalem avatar Sep 01 '21 17:09 josalem

The container is running on remote machine, it's running in a kubernetes cluster on aws

WeihanLi avatar Sep 02 '21 00:09 WeihanLi

Does running dotnet-trace, in the same environment as dotnet-counters was running in, exhibit similar behavior?

mikelle-rogers avatar Sep 02 '21 16:09 mikelle-rogers

@mikelle-rogers sorry for my late response, no, dotnet-trace collect works as expected, and dotnet-counters collect also works, dotnet-counters monitor is the only thing I meet that does not work. And besides, I can reproduce it on my Windows 10 with PowerShell Core 7.1.4 and Powershell 5.

WeihanLi avatar Sep 17 '21 02:09 WeihanLi

I'm having the same problem, with that same image, when i connect to the container using Portainer. Other tools like top or htop work just fine.

janek-lopez avatar Sep 28 '21 16:09 janek-lopez

After some investigation, it seems in alpine Console.SetCursorPosition and Console.Clear are not working properly but ANSI escape codes are.

I did some quick and dirty changes to dotnet-counters/Exporters/ConsoleWriter.cs

I added this two methods and replace all references to Console.SetCursorPosition and Console.Clear and re-tested on alpine and it seems to be working fine.

private void SetCursorPosition(int col, int row)
{
    Console.Write($"\u001B[{row + 1};{col + 1}H");
}

private static void Clear()
{
    Console.WriteLine($"\u001b[H\u001B[J");
}

janek-lopez avatar Sep 30 '21 20:09 janek-lopez

That was my hunch of what was wrong. dotnet-trace uses this code to handle this kind of issue: https://github.com/dotnet/diagnostics/blob/e7976ae7bbcf55242d5b1b174c44f1e6991161ed/src/Tools/Common/Commands/Utils.cs#L130-L163

The fix is to have dotnet-counters attempt to use ANSI escape codes if the following attempt to enable vterm passes: https://github.com/dotnet/diagnostics/blob/e7976ae7bbcf55242d5b1b174c44f1e6991161ed/src/Tools/dotnet-trace/CommandLine/Commands/CollectCommand.cs#L217

josalem avatar Sep 30 '21 20:09 josalem