Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix TTY color support #1805

Closed
na-- opened this issue Jan 18, 2021 · 4 comments · Fixed by #1975
Closed

Fix TTY color support #1805

na-- opened this issue Jan 18, 2021 · 4 comments · Fixed by #1975

Comments

@na--
Copy link
Member

na-- commented Jan 18, 2021

This used to be considered a minor issue and lived as this code TODO: https://github.com/loadimpact/k6/blob/c00a85bfea21d748f0f9d11fdbc326087f34c411/cmd/root.go#L139-L154

But it turns out that the problem is a bit bigger than that, evidenced by my troubles with the recent summary work (After #1788, #1768, #1803). I noticed that in the above code, we don't even check for stdoutTTY or stderrTTY. Instead, we actually somewhat implement the TODO above, but in a nasty way that doesn't use dependency injection and is completely untestable...

The color library directly uses Go's os package to check things for itself: https://github.com/loadimpact/k6/blob/c00a85bfea21d748f0f9d11fdbc326087f34c411/vendor/github.com/fatih/color/color.go#L20-L21

And we also directly use stderrTTY in our logger constructor: https://github.com/loadimpact/k6/blob/c00a85bfea21d748f0f9d11fdbc326087f34c411/cmd/root.go#L309

And for a taste of #883, nocolor, stdoutTTY, and stderrTTY are all global variables... 😭 So yeah, all of these things get in the way of handling colors in the JS-based summary handlers properly...

@na--
Copy link
Member Author

na-- commented Jan 19, 2021

Somewhat connected issue: #1748

@mstoykov
Copy link
Collaborator

I am sometimes (rarely) getting

--- FAIL: TestExceptionInHandleSummaryFallsBackToTextSummary (0.00s)
        Error Trace:    summary_test.go:470
        Error:          "
                             █ child

                               ✓ check1
                               ✗ check3
                                ↳  66% — ✓ 10 / ✗ 5
                               ✗ check2
                                ↳  33% — ✓ 5 / ✗ 10

                           ✓ checks......: 75.00% ✓ 45  ✗ 15
                           ✗ http_reqs...: 3      3/s
                           ✗ my_trend....:
                             vus.........: 1      min=1 max=1

                        " does not contain "     █ child

                               ✓ check1
                               ✗ check3
                                ↳  66% — ✓ 10 / ✗ 5
                               ✗ check2
                                ↳  33% — ✓ 5 / ✗ 10

                           ✓ checks......: 75.00% ✓ 45  ✗ 15
                           ✗ http_reqs...: 3      3/s
                        "
        Test:           TestExceptionInHandleSummaryFallsBackToTextSummary
--- FAIL: TestTextSummary (0.00s)
    --- FAIL: TestTextSummary/0_[avg_min_med_max_p(90)_p(95)_p(99.9)] (0.00s)
        Error Trace:    summary_test.go:93
        Error:          Not equal:
                        expected: "\n     █ child\n\n       ✓ check1\n       ✗ check3\n        ↳  66% — ✓ 10 / ✗ 5\n       ✗ check2\n        ↳  33% — ✓ 5 / ✗ 10\n\n   ✓ checks......: 75.00% ✓ 45  ✗ 15 \n   ✗ http_reqs...: 3      3/s\n   ✗ my_trend....: avg=15ms min=10ms med=15ms max=20ms p(90)=19ms p(95)=19.5ms p(99.9)=19.99ms\n     vus.........: 1      min=1 max=1\n\n"
                        actual  : "\n     █ child\n\n\x1b[32m       ✓ check1\n\x1b[0m\x1b[31m       ✗ check3\n\x1b[0m\x1b[31m        ↳  66% — ✓ 10 / ✗ 5\n\x1b[0m\x1b[31m       ✗ check2\n\x1b[0m\x1b[31m        ↳  33% — ✓ 5 / ✗ 10\n\x1b[0m\n   \x1b[32m✓\x1b[0m checks\x1b[2m......:\x1b[0m \x1b[36m75.00%\x1b[0m \x1b[36;2m\x1b[36;2m✓ 45\x1b[0m  \x1b[36;2m✗ 15\x1b[0m \x1b[0m\n   \x1b[31m✗\x1b[0m http_reqs\x1b[2m...:\x1b[0m \x1b[36m3\x1b[0m      \x1b[36;2m3/s\x1b[0m\n   \x1b[31m✗\x1b[0m my_trend\x1b[2m....:\x1b[0m avg=\x1b[36m15ms\x1b[0m min=\x1b[36m10ms\x1b[0m med=\x1b[36m15ms\x1b[0m max=\x1b[36m20ms\x1b[0m p(90)=\x1b[36m19ms\x1b[0m p(95)=\x1b[36m19.5ms\x1b[0m p(99.9)=\x1b[36m19.99ms\x1b[0m\n   \x1b[m \x1b[0m vus\x1b[2m.........:\x1b[0m \x1b[36m1\x1b[0m      \x1b[36;2m\x1b[36;2mmin=1\x1b[0m \x1b[36;2mmax=1\x1b[0m\x1b[0m\n\n"
        Test:           TestTextSummary/0_[avg_min_med_max_p(90)_p(95)_p(99.9)]
    --- FAIL: TestTextSummary/2_[avg_count] (0.00s)
        Error Trace:    summary_test.go:93
        Error:          Not equal:
                        expected: "\n     █ child\n\n       ✓ check1\n       ✗ check3\n        ↳  66% — ✓ 10 / ✗ 5\n       ✗ check2\n        ↳  33% — ✓ 5 / ✗ 10\n\n   ✓ checks......: 75.00% ✓ 45  ✗ 15 \n   ✗ http_reqs...: 3      3/s\n   ✗ my_trend....: avg=15ms count=3\n     vus.........: 1      min=1 max=1\n\n"
                        actual  : "\n     █ child\n\n\x1b[32m       ✓ check1\n\x1b[0m\x1b[31m       ✗ check3\n\x1b[0m\x1b[31m        ↳  66% — ✓ 10 / ✗ 5\n\x1b[0m\x1b[31m       ✗ check2\n\x1b[0m\x1b[31m        ↳  33% — ✓ 5 / ✗ 10\n\x1b[0m\n   \x1b[32m✓\x1b[0m checks\x1b[2m......:\x1b[0m \x1b[36m75.00%\x1b[0m \x1b[36;2m\x1b[36;2m✓ 45\x1b[0m  \x1b[36;2m✗ 15\x1b[0m \x1b[0m\n   \x1b[31m✗\x1b[0m http_reqs\x1b[2m...:\x1b[0m \x1b[36m3\x1b[0m      \x1b[36;2m3/s\x1b[0m\n   \x1b[31m✗\x1b[0m my_trend\x1b[2m....:\x1b[0m avg=\x1b[36m15ms\x1b[0m count=\x1b[36m3\x1b[0m\n   \x1b[m \x1b[0m vus\x1b[2m.........:\x1b[0m \x1b[36m1\x1b[0m      \x1b[36;2m\x1b[36;2mmin=1\x1b[0m \x1b[36;2mmax=1\x1b[0m\x1b[0m\n\n"
        Test:           TestTextSummary/2_[avg_count]
    --- FAIL: TestTextSummary/1_[count] (0.00s)
        Error Trace:    summary_test.go:93
        Error:          Not equal:
                        expected: "\n     █ child\n\n       ✓ check1\n       ✗ check3\n        ↳  66% — ✓ 10 / ✗ 5\n       ✗ check2\n        ↳  33% — ✓ 5 / ✗ 10\n\n   ✓ checks......: 75.00% ✓ 45  ✗ 15 \n   ✗ http_reqs...: 3      3/s\n   ✗ my_trend....: count=3\n     vus.........: 1      min=1 max=1\n\n"
                        actual  : "\n     █ child\n\n\x1b[32m       ✓ check1\n\x1b[0m\x1b[31m       ✗ check3\n\x1b[0m\x1b[31m        ↳  66% — ✓ 10 / ✗ 5\n\x1b[0m\x1b[31m       ✗ check2\n\x1b[0m\x1b[31m        ↳  33% — ✓ 5 / ✗ 10\n\x1b[0m\n   \x1b[32m✓\x1b[0m checks\x1b[2m......:\x1b[0m \x1b[36m75.00%\x1b[0m \x1b[36;2m\x1b[36;2m✓ 45\x1b[0m  \x1b[36;2m✗ 15\x1b[0m \x1b[0m\n   \x1b[31m✗\x1b[0m http_reqs\x1b[2m...:\x1b[0m \x1b[36m3\x1b[0m      \x1b[36;2m3/s\x1b[0m\n   \x1b[31m✗\x1b[0m my_trend\x1b[2m....:\x1b[0m count=\x1b[36m3\x1b[0m\n   \x1b[m \x1b[0m vus\x1b[2m.........:\x1b[0m \x1b[36m1\x1b[0m      \x1b[36;2m\x1b[36;2mmin=1\x1b[0m \x1b[36;2mmax=1\x1b[0m\x1b[0m\n\n"
        Test:           TestTextSummary/1_[count]
FAIL
exit status 1

Where there is actually colors in the first part of the first error, but not the second. This seems to be confirmed by the lack of the coloring "characters" in the other errors. So it seems to me like something disables to colors? probably another test ... no idea 🤷

Also a picture of what I mean by "there is actually colors":
image

@na--
Copy link
Member Author

na-- commented Feb 3, 2021

Found something that might be useful on HN: https://notes.burke.libbey.me/ansi-escape-codes/ (https://news.ycombinator.com/item?id=26011198)

@na--
Copy link
Member Author

na-- commented May 18, 2021

Closed by #1975

@na-- na-- closed this as completed May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants