Skip to content

[JENKINS-38381] Pipeline remote build logging #18

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

Closed
wants to merge 53 commits into from
Closed
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
664bd6b
Upgrade the plugin to the latest Parent POM and to 1.625.3 baseline.
oleg-nenashev Sep 16, 2016
3aa94a1
Fix incorrect Javadoc
oleg-nenashev Sep 16, 2016
68a2d1e
Restore injected tests and escape forms by default
oleg-nenashev Sep 16, 2016
8ccd669
Very first prototype of Remote logging from slaves
oleg-nenashev Sep 16, 2016
849c9cd
Workaround JENKINS-38291 - Do not report vars with dots to Elasticsearch
oleg-nenashev Sep 16, 2016
bbf3310
Attach unique Job IDs to the reports
oleg-nenashev Sep 16, 2016
679d53e
Hide secret in Logstash.
Sep 17, 2016
a7ee24a
Merge branch 'jw-hackaton-remote-logging' of https://github.com/oleg-…
Sep 17, 2016
73fed23
Save the progress.
oleg-nenashev Sep 17, 2016
969a7ae
Fix duplicated log messages.
Sep 17, 2016
8b23ae2
Pipeline support - Adapt BuildData and LogstashBuildWrapper
oleg-nenashev Sep 17, 2016
c0db1ca
KibanaEmbeddedLogAction: Fix symbols in the search query
oleg-nenashev Sep 17, 2016
7511154
Update the core to a Pipeline-compatible version
oleg-nenashev Sep 17, 2016
fe66fec
Semi-working Elastic-search based propagation
oleg-nenashev Sep 17, 2016
32db954
Fix the glitch with ArrayOutOfBounds in output
oleg-nenashev Sep 17, 2016
abbaadf
Remove debug output
oleg-nenashev Sep 17, 2016
2659d46
Merge branch 'pipeline-support' into jw-hackaton-remote-logging
oleg-nenashev Sep 17, 2016
2168eb0
Merge branch 'web-ui-log-viewer' into jw-hackaton-remote-logging
oleg-nenashev Sep 17, 2016
577d137
BuildData constructor should not fail with NPE when Jenkins instance …
oleg-nenashev Sep 17, 2016
b489e23
Ignore BuildData tests broken by Pipeline integration
oleg-nenashev Sep 17, 2016
f455aff
Add skeleton implementation for the External logging extension point
oleg-nenashev Sep 17, 2016
c301636
Basic support of Console log reporting for Pipeline
oleg-nenashev Sep 17, 2016
fe18d32
Fix printing of logs in Elasicsearch-based console
oleg-nenashev Sep 17, 2016
a61a7be
Elasticsearch-based console: Also display timestamp
oleg-nenashev Sep 17, 2016
8529515
Elasticsearch-based log: Report real data from the job (via query par…
oleg-nenashev Sep 17, 2016
8b75c99
Restore ConsoleAnnotator code
oleg-nenashev Sep 17, 2016
13bbfab
Add runtime build status balls to External Console Log actions.
oleg-nenashev Sep 18, 2016
2a5f92a
Allow posting logs at same second as the build start
oleg-nenashev Sep 18, 2016
0e502ed
Some fixes for progressive logs in Elasticsearch browser
oleg-nenashev Sep 18, 2016
4bcbe7b
use new LoggingMethod extension point.
Sep 19, 2016
2541097
Merge pull request #1 from xyan0607/jw-hackaton-remote-logging
oleg-nenashev Oct 4, 2016
7d92624
[JENKINS-38381] Prototype of using Logstash for a complete Pipeline b…
jglick Oct 14, 2016
bd5c9a2
Going back to 2.24 baseline. 2.19.2 would be fine when it comes out.
jglick Oct 14, 2016
fcb709f
jitpack, and linking to https://github.com/jenkinsci/maven-hpi-plugin…
jglick Dec 7, 2016
e886ea2
Demo sort of working.
jglick Dec 8, 2016
4a089e2
Work even in UTC.
jglick Dec 8, 2016
4d6b55e
Using millisecond granularity in messages, and sorting.
jglick Dec 8, 2016
9b8212f
Make sure source_host is sent.
jglick Dec 8, 2016
977bf05
TODO comment.
jglick Dec 8, 2016
7feaf75
Record the host sending each message, so it is clear which are logged…
jglick Dec 8, 2016
e168c03
Finally tracked down the missing-record bug.
jglick Dec 8, 2016
3f66386
Demonstrating password masking.
jglick Dec 8, 2016
b5fa447
Showing parallel work.
jglick Dec 8, 2016
9619531
hpi-plugin.version=1.121
jglick Dec 16, 2016
74e4379
Recording demo protocol.
jglick Dec 21, 2016
4f22bd3
getLog should take a long start argument.
jglick Dec 21, 2016
5c4d441
Refresh demo plugins.
jglick Dec 21, 2016
5888222
Giving up on jitpack for now.
jglick Jan 3, 2017
d00e7f5
Merge branch 'master' into logs-JENKINS-38381
jglick Feb 6, 2018
40008c9
Updated demo.
jglick Feb 6, 2018
5bb3486
Using updated dependencies, without merging _this_ with master.
jglick Jun 11, 2018
b75f573
Updated.
jglick Jun 11, 2018
3b11233
Updating Pipeline deps.
jglick Jun 11, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 37 additions & 21 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>1.599</version>
<version>2.17</version>
</parent>

<properties>
<jenkins.version>2.26-SNAPSHOT</jenkins.version>
Copy link
Member Author

Choose a reason for hiding this comment

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

Did not care to use a patched core in my case. But, 2.19.1 suffered from JENKINS-35184, making it impossible to connect an agent. Was fixed as of 2.24, I just happened to have 2.26-SNAPSHOT locally.

</properties>

<repositories>
<repository>
Expand Down Expand Up @@ -108,6 +112,38 @@
<artifactId>junit</artifactId>
<version>1.10</version>
</dependency>

<!-- For indexing of jobs in Elasticsearch -->
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>unique-id</artifactId>
<version>2.1.1</version>
</dependency>

<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-job</artifactId>
<version>2.8-SNAPSHOT</version>
</dependency>
<!-- For testing of Log wrapping in Pipeline -->
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-durable-task-step</artifactId>
<version>2.6-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-cps</artifactId>
<version>2.19</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins.workflow</groupId>
<artifactId>workflow-basic-steps</artifactId>
<version>2.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand All @@ -127,15 +163,6 @@
</dependencies>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>

<!-- http://jira.codehaus.org/browse/MRELEASE-812 -->
<plugin>
<artifactId>maven-release-plugin</artifactId>
Expand All @@ -152,17 +179,6 @@
</dependency>
</dependencies>
</plugin>

<!-- https://issues.jenkins-ci.org/browse/JENKINS-21977 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<excludes>
<exclude>InjectedTest.java</exclude>
</excludes>
</configuration>
</plugin>
</plugins>
</build>

Expand Down
81 changes: 30 additions & 51 deletions src/main/java/jenkins/plugins/logstash/LogstashBuildWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

package jenkins.plugins.logstash;

import jenkins.plugins.logstash.remoteLogging.RemoteLogstashWriter;
import jenkins.plugins.logstash.remoteLogging.RemoteLogstashOutputStream;
import hudson.Extension;
import hudson.Launcher;
import hudson.model.BuildListener;
Expand All @@ -43,74 +45,51 @@
import com.michelin.cio.hudson.plugins.maskpasswords.MaskPasswordsBuildWrapper;
import com.michelin.cio.hudson.plugins.maskpasswords.MaskPasswordsBuildWrapper.VarPasswordPair;
import com.michelin.cio.hudson.plugins.maskpasswords.MaskPasswordsConfig;
import hudson.CloseProofOutputStream;
import hudson.EnvVars;
import hudson.FilePath;
import hudson.Proc;
import hudson.console.ConsoleLogFilter;
import hudson.model.Job;
import hudson.model.Run;
import hudson.model.TaskListener;
import hudson.remoting.Channel;
import hudson.remoting.RemoteInputStream;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.io.Serializable;
import jenkins.model.Jenkins;
import jenkins.security.MasterToSlaveCallable;
import jenkins.tasks.SimpleBuildWrapper;
import org.apache.commons.io.input.NullInputStream;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

/**
* Build wrapper that decorates the build's logger to insert a
* {@link LogstashNote} on each output line.
* {@code LogstashNote} on each output line.
*
* @author K Jonathan Harker
*/
public class LogstashBuildWrapper extends BuildWrapper {
public class LogstashBuildWrapper extends SimpleBuildWrapper {

/**
* Create a new {@link LogstashBuildWrapper}.
*/
@DataBoundConstructor
public LogstashBuildWrapper() {}

/**
* {@inheritDoc}
*/
@Override
public Environment setUp(AbstractBuild build, Launcher launcher, BuildListener listener) throws IOException, InterruptedException {

return new Environment() {};
}

/**
* {@inheritDoc}
*/
@Override
public OutputStream decorateLogger(AbstractBuild build, OutputStream logger) {
LogstashWriter logstash = getLogStashWriter(build, logger);

LogstashOutputStream los = new LogstashOutputStream(logger, logstash);

if (build.getProject() instanceof BuildableItemWithBuildWrappers) {
BuildableItemWithBuildWrappers project = (BuildableItemWithBuildWrappers) build.getProject();
for (BuildWrapper wrapper: project.getBuildWrappersList()) {
if (wrapper instanceof MaskPasswordsBuildWrapper) {
List<VarPasswordPair> allPasswordPairs = new ArrayList<VarPasswordPair>();

MaskPasswordsBuildWrapper maskPasswordsWrapper = (MaskPasswordsBuildWrapper) wrapper;
List<VarPasswordPair> jobPasswordPairs = maskPasswordsWrapper.getVarPasswordPairs();
if (jobPasswordPairs != null) {
allPasswordPairs.addAll(jobPasswordPairs);
}

MaskPasswordsConfig config = MaskPasswordsConfig.getInstance();
List<VarPasswordPair> globalPasswordPairs = config.getGlobalVarPasswordPairs();
if (globalPasswordPairs != null) {
allPasswordPairs.addAll(globalPasswordPairs);
}

return los.maskPasswords(allPasswordPairs);
}
}
@Override
public void setUp(Context context, Run<?, ?> build, FilePath workspace,
Launcher launcher, TaskListener listener, EnvVars initialEnvironment)
throws IOException, InterruptedException {
// Do nothing
}

return los;
}


public DescriptorImpl getDescriptor() {
return (DescriptorImpl) super.getDescriptor();
}

// Method to encapsulate calls for unit-testing
LogstashWriter getLogStashWriter(AbstractBuild<?, ?> build, OutputStream errorStream) {
return new LogstashWriter(build, errorStream);
}

/**
* Registers {@link LogstashBuildWrapper} as a {@link BuildWrapper}.
*/
Expand All @@ -129,7 +108,7 @@ public DescriptorImpl() {
public String getDisplayName() {
return Messages.DisplayName();
}

/**
* {@inheritDoc}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
* @author Rusty Gerard
* @since 1.0.0
*/
// TODO this should be GlobalConfiguration, not ToolInstallation!
public class LogstashInstallation extends ToolInstallation {
private static final long serialVersionUID = -5730780734005293851L;

Expand Down
9 changes: 4 additions & 5 deletions src/main/java/jenkins/plugins/logstash/LogstashWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@

package jenkins.plugins.logstash;


import hudson.model.AbstractBuild;
import hudson.model.Run;
import jenkins.model.Jenkins;
import jenkins.plugins.logstash.persistence.BuildData;
import jenkins.plugins.logstash.persistence.IndexerDaoFactory;
Expand All @@ -52,15 +51,15 @@
public class LogstashWriter {

final OutputStream errorStream;
final AbstractBuild<?, ?> build;
final Run<?, ?> build;
final BuildData buildData;
final String jenkinsUrl;
final LogstashIndexerDao dao;
private boolean connectionBroken;

public LogstashWriter(AbstractBuild<?, ?> build, OutputStream error) {
public LogstashWriter(Run<?, ?> run, OutputStream error) {
this.errorStream = error != null ? error : System.err;
this.build = build;
this.build = run;
this.dao = this.getDaoOrNull();
if (this.dao == null) {
this.jenkinsUrl = "";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package jenkins.plugins.logstash.kibana;

import hudson.model.Action;
import hudson.model.Run;
import jenkins.plugins.logstash.util.UniqueIdHelper;

/**
* Wrapper base, which is required to nest {@code buildCaption.jelly}.
* @author Oleg Nenashev
*/
public abstract class AbstractConsoleAction implements Action {
private final String jobId;
private final Run run;

public AbstractConsoleAction(Run run) {
this.run = run;
this.jobId = UniqueIdHelper.getOrCreateId(run);
}

@Override
public String getDisplayName() {
return "External log (" + getDataSourceDisplayName() + ")";
}

public Run getRun() {
return run;
}

public String getJobId() {
return jobId;
}

public boolean isLogUpdated() {
return run.isLogUpdated();
}

public abstract String getDataSourceDisplayName();
}
Loading