-
Notifications
You must be signed in to change notification settings - Fork 65
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
[JEP-210] Log handling rewrite #15
Merged
Merged
Changes from 45 commits
Commits
Show all changes
55 commits
Select commit
Hold shift + click to select a range
3e85272
[JENKINS-38381] Prototype of log handling rewrite.
jglick ffac76d
Pick up https://github.com/jenkinsci/maven-hpi-plugin/pull/25.
jglick b70ada1
Merge branch 'master' into logs-JENKINS-38381
jglick 87bba53
In practice it seems the type parameter of ConsoleNote must be Object…
jglick fed6abd
If we are using an old WorkflowRun with copyLogs, fall back to origin…
jglick aef8545
Lighter-weight way of marking which node printed a line.
jglick 710bb87
Some Javadoc, and tightening up access control.
jglick a8b1f2d
Rewrote AnnotatedLogAction.decorate to handle remotable listeners.
jglick 596c2f8
FindBugs
jglick f7a1743
2.16 parent
jglick dfd971d
Seems cleaner to move LogActionImpl compatibility code from DefaultSt…
jglick 97d30f9
LessAbstractTaskListener
jglick 158619f
API to expose the origin of node text in the HTML log.
jglick 3a03cf9
Working around a bug in ConsoleLogFilter.
jglick 5a86013
LessAbstractTaskListener is likely needed by PipelineLogFile implemen…
jglick a348381
Should also offer a Closeable implementation.
jglick 549b446
Merge branch 'master' into logs-JENKINS-38381
jglick 32acc6f
Merge branch 'master' into logs-JENKINS-38381
jglick cf6f11f
Simpler configuration; no need to use pluginRepository just to pick u…
jglick 2138c6b
Added TODO comment.
jglick 30b52c3
hpi-plugin.version=1.121
jglick 284f0dc
getLog should take a long start argument.
jglick afa644c
Giving up on jitpack for now.
jglick ef682b8
Copied isRunning from LogActionImpl, to ensure that the completed fla…
jglick 7917486
Somewhat better performance for running the build: down to 2569ms.
jglick 5666458
Speeding up strip and getLogText a bit by using ByteArrayOutputStream…
jglick 4ebbf8d
Making annotateHtml coalesce lines coming from the same step, for mor…
jglick 2c2cfef
Merge branch 'master' into logs-JENKINS-38381
jglick d1029ea
Merge branch 'master' into logs-JENKINS-38381
jglick 9b147a4
Merge branch 'UTF-8-JENKINS-31096' into logs-JENKINS-38381
jglick 32e4129
Merge branch 'UTF-8-JENKINS-31096' into logs-JENKINS-38381
jglick 98b83d2
Windows test fix.
jglick 54f2094
Deleting LessAbstractTaskListener as it is superseded by https://gith…
jglick 8fee826
requireUpperBoundDeps
jglick cd70bcc
Saw an IllegalArgumentException from Arrays.copyOfRange but cannot re…
jglick 3a31b4c
Noting apparent cause of ISE; needs to be reproduced in a test however.
jglick 1b22cbc
Updating dep, and refining restrictions on AnnotatedLogAction.
jglick 842ee5a
Tracked down the proximate cause of an ISE.
jglick 0ecaa7a
Updated comment.
jglick 063ea96
Passing complete flag to getLog.
jglick 468f91d
Refactored to LogStorage.
jglick a917f4a
Bump.
jglick 3e5e4ae
FindBugs
jglick 7a6c94f
Merge branch 'UTF-8-JENKINS-31096' into logs-JENKINS-38381
jglick 27a34dc
Merge branch 'master' into logs-JENKINS-38381
jglick 628846b
Bump.
jglick 338afdd
Renamed AnnotatedLogAction to LogStorageAction.
jglick 8f47806
Forgot to rename Stapler view of AnnotatedLogAction → LogStorageAction.
jglick a3d0646
If during an upgrade we are resuming a build with a running step that…
jglick b589b8f
Centralizing support for closing step logs in DefaultStepContext, to …
jglick 07c85e5
Merge branch 'master' into logs-JENKINS-38381
jglick b249afd
Bump.
jglick d5d1f46
If there is any output from Run.getEnvironment(TaskListener), and non…
jglick 95f4df4
If there is any output from Run.getEnvironment(TaskListener), and non…
jglick 93b9b13
Merge branch 'DefaultStepContext+Run.getEnvironment' into logs-JENKIN…
jglick File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
159 changes: 159 additions & 0 deletions
159
src/main/java/org/jenkinsci/plugins/workflow/support/actions/AnnotatedLogAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright (c) 2016, CloudBees, Inc. | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
*/ | ||
|
||
package org.jenkinsci.plugins.workflow.support.actions; | ||
|
||
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; | ||
import hudson.Util; | ||
import hudson.console.AnnotatedLargeText; | ||
import hudson.console.ConsoleLogFilter; | ||
import hudson.model.AbstractBuild; | ||
import hudson.model.Run; | ||
import hudson.model.TaskListener; | ||
import java.io.BufferedOutputStream; | ||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.io.PrintStream; | ||
import java.io.Serializable; | ||
import java.io.UnsupportedEncodingException; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import javax.annotation.CheckForNull; | ||
import javax.annotation.Nonnull; | ||
import org.apache.commons.jelly.XMLOutput; | ||
import org.jenkinsci.plugins.workflow.actions.FlowNodeAction; | ||
import org.jenkinsci.plugins.workflow.actions.LogAction; | ||
import org.jenkinsci.plugins.workflow.actions.PersistentAction; | ||
import org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner; | ||
import org.jenkinsci.plugins.workflow.graph.FlowNode; | ||
import org.jenkinsci.plugins.workflow.log.LogStorage; | ||
import org.kohsuke.accmod.Restricted; | ||
import org.kohsuke.accmod.restrictions.DoNotUse; | ||
import org.kohsuke.accmod.restrictions.NoExternalUse; | ||
|
||
/** | ||
* A marker for a node which had some log text. | ||
*/ | ||
@Restricted(NoExternalUse.class) // for use from DefaultStepContext only | ||
public class AnnotatedLogAction extends LogAction implements FlowNodeAction, PersistentAction { | ||
|
||
private static final Logger LOGGER = Logger.getLogger(AnnotatedLogAction.class.getName()); | ||
|
||
public transient FlowNode node; | ||
|
||
private AnnotatedLogAction(FlowNode node) { | ||
if (!node.isActive()) { | ||
throw new IllegalStateException("cannot start writing logs to a finished node " + node); | ||
} | ||
this.node = node; | ||
} | ||
|
||
@Override public void onLoad(FlowNode node) { | ||
this.node = node; | ||
} | ||
|
||
@Override public AnnotatedLargeText<? extends FlowNode> getLogText() { | ||
FlowExecutionOwner owner = node.getExecution().getOwner(); | ||
return LogStorage.of(owner).stepLog(node, !node.isActive()); | ||
} | ||
|
||
/** | ||
* Used from <tt>console.jelly</tt> to write annotated log to the given output. | ||
*/ | ||
@Restricted(DoNotUse.class) // Jelly | ||
public void writeLogTo(long offset, XMLOutput out) throws IOException { | ||
getLogText().writeHtmlTo(offset, out.asWriter()); | ||
} | ||
|
||
/** | ||
* Creates a sink to print output from a step. | ||
* Will use {@link LogActionImpl} if necessary. | ||
* @param node a node which wishes to print output | ||
* @param filter an optional log filter (must be {@link Serializable}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As in jenkinsci/workflow-job-plugin#27 and jenkinsci/workflow-api-plugin#17 and jenkinsci/workflow-basic-steps-plugin#62 (comment) we should probably introduce into public interface Remotable extends Serializable {
default Channel getChannelForSerialization() throws NotSerializableException {/*…*/}
}
public interface SerializableOnlyOverRemoting extends Remotable {
// empty
} |
||
* @return a stream | ||
*/ | ||
@SuppressWarnings("deprecation") // LogActionImpl here for backward compatibility | ||
public static @Nonnull TaskListener listenerFor(@Nonnull FlowNode node, @CheckForNull ConsoleLogFilter filter) throws IOException, InterruptedException { | ||
FlowExecutionOwner owner = node.getExecution().getOwner(); | ||
if (LogActionImpl.isOld(owner)) { | ||
return LogActionImpl.stream(node, filter); | ||
} else { | ||
if (node.getAction(AnnotatedLogAction.class) == null) { | ||
node.addAction(new AnnotatedLogAction(node)); | ||
} | ||
TaskListener listener = LogStorage.of(owner).nodeListener(node); | ||
if (filter != null) { | ||
if (filter instanceof Serializable) { | ||
return new FilteringTaskListener(listener, filter); | ||
} else { | ||
LOGGER.log(Level.WARNING, "{0} must implement Serializable to be used with Pipeline", filter.getClass()); | ||
} | ||
} | ||
return listener; | ||
} | ||
} | ||
|
||
private static class FilteringTaskListener implements TaskListener { | ||
private static final long serialVersionUID = 1; | ||
/** | ||
* The listener we are delegating to, which was expected to be remotable. | ||
* Note that we ignore all of its methods other than {@link TaskListener#getLogger}. | ||
*/ | ||
private final @Nonnull TaskListener delegate; | ||
/** | ||
* A filter. | ||
* Note that null is passed for the {@code build} parameter, since that would not be available on an agent. | ||
*/ | ||
@SuppressFBWarnings(value="SE_BAD_FIELD", justification="The filter is expected to be serializable.") | ||
private final @Nonnull ConsoleLogFilter filter; | ||
private transient PrintStream logger; | ||
FilteringTaskListener(@Nonnull TaskListener delegate, @Nonnull ConsoleLogFilter filter) { | ||
this.delegate = delegate; | ||
this.filter = filter; | ||
} | ||
@SuppressWarnings("deprecation") | ||
@Override public PrintStream getLogger() { | ||
if (logger == null) { | ||
OutputStream base = delegate.getLogger(); | ||
try { | ||
// TODO the compatibility code in ConsoleLogFilter fails to delegate to the old overload when given a null argument | ||
if (Util.isOverridden(ConsoleLogFilter.class, filter.getClass(), "decorateLogger", Run.class, OutputStream.class)) { | ||
base = filter.decorateLogger((Run) null, base); | ||
} else { | ||
base = filter.decorateLogger((AbstractBuild) null, base); | ||
} | ||
} catch (Exception x) { | ||
LOGGER.log(Level.WARNING, null, x); | ||
} | ||
try { | ||
logger = new PrintStream(base, false, "UTF-8"); | ||
} catch (UnsupportedEncodingException x) { | ||
throw new AssertionError(x); | ||
} | ||
} | ||
return logger; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
...n/resources/org/jenkinsci/plugins/workflow/support/actions/AnnotatedLogAction/index.jelly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<!-- | ||
The MIT License | ||
|
||
Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi | ||
|
||
Copyright (c) 2012, Martin Schroeder, Intel Mobile Communications GmbH | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in | ||
all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
THE SOFTWARE. | ||
--> | ||
|
||
<!-- | ||
Displays the console output | ||
--> | ||
<?jelly escape-by-default='true'?> | ||
<st:compress xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt" xmlns:flow="/lib/flow"> | ||
<l:layout title="${it.node.displayName} Console" norefresh="true"> | ||
<st:include it="${it.node}" page="sidepanel.jelly" /> | ||
<l:main-panel> | ||
<flow:nodeCaption node="${it.node}"> | ||
${%Console Output} | ||
</flow:nodeCaption> | ||
|
||
<j:set var="threshold" value="${h.getSystemProperty('hudson.consoleTailKB')?:'150'}" /> | ||
<!-- Show at most last 150KB (can override with system property) unless consoleFull is set --> | ||
<j:set var="offset" value="${request.hasParameter('consoleFull') ? 0 : it.logText.length()-threshold*1024}" /> | ||
<j:choose> | ||
<j:when test="${offset > 0}"> | ||
${%skipSome(offset/1024,"?consoleFull")} | ||
</j:when> | ||
<j:otherwise> | ||
<j:set var="offset" value="${0}" /> | ||
</j:otherwise> | ||
</j:choose> | ||
|
||
<j:out value="${h.generateConsoleAnnotationScriptAndStylesheet()}"/> | ||
|
||
<j:choose> | ||
<!-- Do progressive console output --> | ||
<j:when test="${it.node.running}"> | ||
<pre id="out" /> | ||
<div id="spinner"> | ||
<img src="${imagesURL}/spinner.gif" alt="" /> | ||
</div> | ||
<t:progressiveText href="logText/progressiveHtml" idref="out" spinner="spinner" startOffset="${offset}" /> | ||
</j:when> | ||
<!-- output is completed now. --> | ||
<j:otherwise> | ||
<pre class="console-output"> | ||
<st:getOutput var="output" /> | ||
<j:whitespace>${it.writeLogTo(offset,output)}</j:whitespace> | ||
</pre> | ||
</j:otherwise> | ||
</j:choose> | ||
</l:main-panel> | ||
</l:layout> | ||
</st:compress> |
2 changes: 2 additions & 0 deletions
2
...ources/org/jenkinsci/plugins/workflow/support/actions/AnnotatedLogAction/index.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
skipSome=Skipping {0,number,integer} KB.. <a href="{1}">Full Log</a> | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be renamed.