Skip to content
Permalink
Browse files

[JENKINS-42536] fix ansi console note (#62)

* [JENKINS-42536] fix ansi console note

When a line starts with a console note we trimmed the leading escape
character before passing it to the removeNotes method. This makes it not
recognize as a console note. So trim after removing the notes.
  • Loading branch information
mwinter69 authored and jakub-bochenski committed May 28, 2018
1 parent 3299837 commit 188ea2b05f0c7ed3398caf63012b075ae7bb177f
@@ -157,6 +157,12 @@
<version>2.0.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>ansicolor</artifactId>
<version>0.5.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
@@ -59,8 +59,8 @@ protected void eol(byte[] b, int len) throws IOException {
this.flush();

if(!logstash.isConnectionBroken()) {
String line = new String(b, 0, len, logstash.getCharset()).trim();
line = ConsoleNote.removeNotes(line);
String line = new String(b, 0, len, logstash.getCharset());
line = ConsoleNote.removeNotes(line).trim();

This comment has been minimized.

Copy link
@akostadinov

akostadinov Jun 18, 2018

hmm, removing color data is IMO bad, reading bare colors log is a pain

This comment has been minimized.

Copy link
@akostadinov
logstash.write(line);
}
}
@@ -5,6 +5,7 @@
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertThat;
import static org.powermock.api.mockito.PowerMockito.when;
import static org.mockito.ArgumentMatchers.any;
@@ -29,11 +30,13 @@
import com.michelin.cio.hudson.plugins.maskpasswords.MaskPasswordsConfig;
import com.michelin.cio.hudson.plugins.maskpasswords.MaskPasswordsBuildWrapper.VarPasswordPair;

import hudson.model.Cause;
import hudson.model.FreeStyleBuild;
import hudson.model.FreeStyleProject;
import hudson.model.Result;
import hudson.model.Slave;
import hudson.model.queue.QueueTaskFuture;
import hudson.plugins.ansicolor.AnsiColorBuildWrapper;
import net.sf.json.JSONArray;
import jenkins.plugins.logstash.persistence.MemoryDao;
import net.sf.json.JSONObject;
@@ -241,4 +244,20 @@ public void secondTimestamps() throws Exception
assertThat(timestamp,matchesPattern("^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}[+-]\\d{4}$"));
}
}

@Test
public void ansiColorAnnotationsAreNotIncluded() throws Exception
{
AnsiColorBuildWrapper ansi = new AnsiColorBuildWrapper("vga");
project.addProperty(new LogstashJobProperty());
project.getBuildWrappersList().add(ansi);
Cause cause = new Cause.UserIdCause();
QueueTaskFuture<FreeStyleBuild> f = project.scheduleBuild2(0, cause);

FreeStyleBuild build = f.get();
assertThat(build.getResult(), equalTo(Result.SUCCESS));
List<JSONObject> dataLines = memoryDao.getOutput();
JSONObject firstLine = dataLines.get(0);
assertThat(firstLine.getJSONArray("message").get(0).toString(),not(startsWith("[8mha")));
}
}

0 comments on commit 188ea2b

Please sign in to comment.