-
Notifications
You must be signed in to change notification settings - Fork 68
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
[JENKINS-48344] Lightweight timestamp annotations #25
Merged
jglick
merged 16 commits into
jenkinsci:master
from
jglick:lightweight-annotator-JENKINS-48344
Feb 7, 2019
Merged
Changes from 13 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
077e56b
[JENKINS-48344] Lightweight timestamp annotations.
jglick 04b31fc
Updates to released versions.
jglick cad91e5
NPE when encountering some other formats.
jglick 8d45f11
Updates to official releases.
jglick 1afb7d4
[JENKINS-54081] Fixing interaction with timestamps step.
jglick ce79838
Allow test to pass even after SECURITY-382 fix.
jglick d5abfa2
Fixing TimestamperConfigTest to not use mocks.
jglick ec44eab
Amended fix of LogFileReaderTest to work even when sharing the JVM wi…
jglick 2181e53
Made per-step annotation work on Jenkins 2.145+.
jglick 9b19c6e
Merge branch 'master' into lightweight-annotator-JENKINS-48344
jglick bf1e61c
Properly synchronize access so we do not risk having a timestamp in t…
jglick dc6e9a5
Forgot to implement flush & close as in https://github.com/jenkinsci/…
jglick c45d6cd
Better to use java.time as sketched by @dwnusbaum.
jglick 73d4051
Noting where a couple of fixes should be made for JENKINS-54128.
jglick 37f52eb
Write timestamps as a single byte[] to avoid interleaving
dwnusbaum b204114
Merge pull request #1 from dwnusbaum/JENKINS-48344
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<extensions xmlns="http://maven.apache.org/EXTENSIONS/1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/EXTENSIONS/1.0.0 http://maven.apache.org/xsd/core-extensions-1.0.0.xsd"> | ||
<extension> | ||
<groupId>io.jenkins.tools.incrementals</groupId> | ||
<artifactId>git-changelist-maven-extension</artifactId> | ||
<version>1.0-beta-7</version> | ||
</extension> | ||
</extensions> |
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 @@ | ||
-Pconsume-incrementals | ||
-Pmight-produce-incrementals |
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
119 changes: 119 additions & 0 deletions
119
src/main/java/hudson/plugins/timestamper/pipeline/GlobalAnnotator.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,119 @@ | ||
/* | ||
* The MIT License | ||
* | ||
* Copyright 2018 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 hudson.plugins.timestamper.pipeline; | ||
|
||
import hudson.Extension; | ||
import hudson.MarkupText; | ||
import hudson.console.ConsoleAnnotator; | ||
import hudson.console.ConsoleAnnotatorFactory; | ||
import hudson.model.Queue; | ||
import hudson.model.Run; | ||
import hudson.plugins.timestamper.Timestamp; | ||
import hudson.plugins.timestamper.format.TimestampFormat; | ||
import hudson.plugins.timestamper.format.TimestampFormatProvider; | ||
import java.io.IOException; | ||
import java.time.ZonedDateTime; | ||
import java.time.format.DateTimeParseException; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
import org.jenkinsci.plugins.workflow.flow.FlowExecutionOwner; | ||
import org.jenkinsci.plugins.workflow.graph.FlowNode; | ||
|
||
/** | ||
* Interprets marks added by {@link GlobalDecorator}. | ||
*/ | ||
public final class GlobalAnnotator extends ConsoleAnnotator<Object> { | ||
|
||
private static final long serialVersionUID = 1; | ||
|
||
private static final Logger LOGGER = Logger.getLogger(GlobalAnnotator.class.getName()); | ||
|
||
@Override | ||
public ConsoleAnnotator<Object> annotate(Object context, MarkupText text) { | ||
Run<?, ?> build; | ||
if (context instanceof Run) { | ||
build = (Run<?, ?>) context; | ||
} else if (context instanceof FlowNode) { | ||
FlowExecutionOwner owner = ((FlowNode) context).getExecution().getOwner(); | ||
if (owner == null) { | ||
return null; | ||
} | ||
Queue.Executable executable; | ||
try { | ||
executable = owner.getExecutable(); | ||
} catch (IOException x) { | ||
LOGGER.log(Level.FINE, null, x); | ||
return null; | ||
} | ||
if (executable instanceof Run) { | ||
build = (Run) executable; | ||
} else { | ||
return null; | ||
} | ||
} else { | ||
return null; | ||
} | ||
long buildStartTime = build.getStartTimeInMillis(); | ||
String html = text.toString(true); | ||
int start; | ||
if (html.startsWith("<span class=\"pipeline-new-node\" ")) { // cf. LogStorage.startStep | ||
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. Unpleasant that this is necessary. Not sure if it is solvable upstream. You would probably expect that the |
||
start = html.indexOf('>') + 1; | ||
} else { | ||
start = 0; | ||
} | ||
if (html.startsWith("[", start)) { | ||
int end = html.indexOf(']', start); | ||
if (end != -1) { | ||
try { | ||
long millisSinceEpoch = ZonedDateTime.parse(html.substring(start + 1, end), GlobalDecorator.UTC_MILLIS).toInstant().toEpochMilli(); | ||
// Alternately: Instant.parse(html.substring(start + 1, end)).toEpochMilli() | ||
Timestamp timestamp = new Timestamp(millisSinceEpoch - buildStartTime, millisSinceEpoch); | ||
TimestampFormat format = TimestampFormatProvider.get(); | ||
format.markup(text, timestamp); | ||
text.addMarkup(0, 26, "<span style=\"display: none\">", "</span>"); | ||
} catch (DateTimeParseException x) { | ||
// something else, ignore | ||
} | ||
} | ||
} | ||
return this; | ||
} | ||
|
||
@Extension | ||
public static final class Factory extends ConsoleAnnotatorFactory<Object> { | ||
|
||
@Override | ||
public ConsoleAnnotator<Object> newInstance(Object context) { | ||
if (context instanceof Run && context instanceof FlowExecutionOwner.Executable) { | ||
return new GlobalAnnotator(); | ||
} else if (context instanceof FlowNode) { | ||
return new GlobalAnnotator(); | ||
} | ||
// Note that prior to 2.145, we actually get FlowNode.class here rather than a FlowNode, so there is no per-step annotation. | ||
return null; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.
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.
Quite a jump, although required for the JEP-210 updates. Here are stats for the plugin's usage by Jenkins core version: http://stats.jenkins.io/pluginversions/timestamper.html. According to those stats, 89.63% of users of timestamper-1.8.10 are on Jenkins 2.121.1 or newer, so this looks reasonable to me.