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 console log character encoding #4044

Merged
merged 5 commits into from
Feb 7, 2018

Conversation

ketan
Copy link
Member

@ketan ketan commented Nov 30, 2017

Fixes #3926, #3442

@@ -166,7 +166,8 @@ private void runBuild(BuildSettings buildSettings) {
buildConsole = new ConsoleOutputTransmitter(
new RemoteConsoleAppender(
urlService.prefixPartialUrl(buildSettings.getConsoleUrl()),
httpService)
httpService,
getSystemEnvironment().consoleLogCharsetAsCharset())
Copy link
Contributor

Choose a reason for hiding this comment

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

This would be set at the server side not agent. The charset that was passed along from the server to the agent needs to be passed along to the Console appender

Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be handled for the BuildCompose workflow. We should be able to pass along the encoding from server as a part of BuildSettings instead of using getSystemEnvironment().consoleLogCharsetAsCharset().

@ketan ketan force-pushed the fix/console-log-char-encoding branch 2 times, most recently from f9ea049 to 8ae3f7f Compare December 11, 2017 03:58
Copy link
Contributor

@jyotisingh jyotisingh left a comment

Choose a reason for hiding this comment

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

Did a quick round of testing for this since I wasn't sure if console logs over websocket will work out of the box as far as encoding is concerned. It doesn't. Haven't debugged to see what exactly is the issue with that though.
When I say it doesn't work, I meant the encoding gets screwed up during the transmission. There might be some other issues with transmission of logs over websockets, I wasn't talking about them.

@@ -212,6 +212,6 @@ public void setProperty(JobIdentifier jobIdentifier, Property property) {
public ConsoleOutputTransmitter createConsoleOutputTransmitter(JobIdentifier jobIdentifier,
AgentIdentifier agentIdentifier) {
String consoleUrl = urlService.getUploadUrlOfAgent(jobIdentifier, getConsoleOutputFolderAndFileNameUrl());
return new ConsoleOutputTransmitter(new RemoteConsoleAppender(consoleUrl, httpService));
return new ConsoleOutputTransmitter(new RemoteConsoleAppender(consoleUrl, httpService, new SystemEnvironment().consoleLogCharsetAsCharset()));
Copy link
Contributor

Choose a reason for hiding this comment

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

Since BuildWork already contains the charset from server, we should just be able to pass it here.

@@ -166,7 +166,8 @@ private void runBuild(BuildSettings buildSettings) {
buildConsole = new ConsoleOutputTransmitter(
new RemoteConsoleAppender(
urlService.prefixPartialUrl(buildSettings.getConsoleUrl()),
httpService)
httpService,
getSystemEnvironment().consoleLogCharsetAsCharset())
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs to be handled for the BuildCompose workflow. We should be able to pass along the encoding from server as a part of BuildSettings instead of using getSystemEnvironment().consoleLogCharsetAsCharset().

@ketan ketan force-pushed the fix/console-log-char-encoding branch 4 times, most recently from 4b62934 to 2a43292 Compare December 21, 2017 08:59
@ketan ketan force-pushed the fix/console-log-char-encoding branch from 2a43292 to eb3087d Compare February 6, 2018 05:00
@ketan ketan force-pushed the fix/console-log-char-encoding branch 5 times, most recently from 71cfe71 to 5971481 Compare February 6, 2018 05:34
@@ -83,6 +84,7 @@ private CommandLine createCommandLine(String cmd) {
} else {
commandLine = CommandLine.createCommandLine(cmd);
}
commandLine.withEncoding(new SystemEnvironment().consoleLogCharset());
Copy link
Member Author

Choose a reason for hiding this comment

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

@jyotisingh — we'd likely need to inject the charset to all BuildCommandExecutor impls, or add it to BuildSession to make it available to all executors.

Thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer adding it to the BuildSession. One way would be to pass along the charset with BuildSettings and then use it to construct the BuildSession. That way in future too if any other CommandExecutor needs access to commandline, it could just get hold of the charset from BuildSession

@ketan ketan force-pushed the fix/console-log-char-encoding branch 5 times, most recently from 7ad694a to 6c8a9c8 Compare February 6, 2018 14:37
@ketan ketan added this to the Release 18.2 milestone Feb 6, 2018
@ketan ketan force-pushed the fix/console-log-char-encoding branch from 6c8a9c8 to dab2c7c Compare February 7, 2018 11:00
As part of commit 7fc200b, the
`Content-Type` header was set to `text/plain; charset=utf-8`. However
the `HttpServletResponse`'s `getWriter()` was returning a writer bound
to the system default character encoding. We now force the encoding of
the writer to `utf-8`.

Fixes gocd#3926, gocd#3442
Charset is determined on the server using the system property
`go.console.log.charset`.
@ketan ketan merged commit dab2c7c into gocd:master Feb 7, 2018
@ketan ketan deleted the fix/console-log-char-encoding branch February 7, 2018 11:00
@ketan
Copy link
Member Author

ketan commented Feb 7, 2018

For testing this PR, create a file (/tmp/unicode.txt) with some unicode characters, emojis. I used this file, make sure to click "raw" and download using wget, copy/pasting is not recommended.

Use the following config.xml snippet:

    <pipeline name="up42">
      <materials>
        <git url="test-repo" />
      </materials>
      <stage name="up42_stage">
        <jobs>
          <job name="up42_job">
            <tasks>
              <exec command="bash" args="-c 'while true; do cat /tmp/unicode.txt; sleep 1; done'" />
            </tasks>
          </job>
        </jobs>
      </stage>
    </pipeline>

On 18.1 of GoCD server and agent:

  • set the file.encoding system property to cp1252 (to simulate GoCD running on windows). This needs to be done on both the server and agent.
  • Run the build
  • When viewing the console logs, the non-ascii part the output will appear garbled

On latest (experimental) GoCD

  • set the file.encoding system property to cp1252 (to simulate GoCD running on windows). This needs to be done on both the server and agent.
  • Run the build
  • the console output will not be garbled

On latest (experimental) GoCD

  • set the go.console.log.charset system property to cp1252 (to force console log encoding to be that used by windows). This needs to be done on the server, doing it on the agent has no effect
  • Run the build
  • the console output will be garbled — because the unicode text is being rendered using cp1252 encoding. This is expected behaviour.

@adityasood
Copy link
Contributor

Tested the above steps

  1. On 18.1 of GoCD server and agent:
    The non-ascii part the output appeared garbled after file.encoding is set to cp1252 on both GoCD server and agent

  2. On latest (experimental) GoCD git sha (6029...)
    The console output is not garbled after file.encoding is set to cp1252 on both GoCD server and agent

  3. On latest (experimental) GoCD git sha (6029...)
    The console output is garbled after go.console.log.charset is set to cp1252 on GoCD server

@lobster2012-user
Copy link

It works for me.

wrapper.java.additional.100=-Dgo.console.log.charset=CP866

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: Console logs stop updating when non-ascii characters are encountered
4 participants