-
-
Notifications
You must be signed in to change notification settings - Fork 141
Write NewNodeConsoleNote to per-step logs instead of overall log #371
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
Write NewNodeConsoleNote to per-step logs instead of overall log #371
Conversation
| */ | ||
| @Restricted(NoExternalUse.class) | ||
| public class NewNodeConsoleNote extends ConsoleNote<WorkflowRun> { | ||
| public class NewNodeConsoleNote extends ConsoleNote { |
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 issue is kind of interesting. I am not sure if it has been reported previously, but any console notes that rely on a Run context totally break the per-step log view in the Pipeline steps view. (The notes aren't just skipped, they cause a ClassCastException here and break all log display!)
Perhaps LogStorage.stepLog should really return a AnnotatedLargeText<WorkflowRun> instead? Not sure if that can be changed compatibly at this point. ConsoleAnnotationOutputStream at least could probably be made more robust though.
There do not seem to be many implementations that would trigger the issue, see here and here.
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.
Hmm, does this have anything to do with jenkinsci/jenkins#3662?
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.
Only tangentially I think, in that the whole API seems wrong. The problem as I see it is that when you create a ConsoleNote, you get to choose an arbitrary type parameter, but when using a ConsoleAnnotationOutputStream, the type parameter is fixed, so code like this is unsound, because the context type of an arbitrary note in the stream is not necessarily T. I think the compiler is only ok with that code because of erasure. If you replace final ConsoleNote a = ... with final ConsoleNote<?> a = ..., then you get the incompatible types: T cannot be converted to CAP#1 error that I would have expected.
Looking at actual usage, I think the context parameters in all associated classes should have just been hard-coded to be Run, and LogStorage.stepLog should have just returned AnnotatedLargeText<WorkflowRun> like overallLog. I guess KK's API design assumption was that you only write notes when you know they will be read with the same context, which doesn't work for Pipeline when we read one log file but return AnnotatedLargeText objects with different contexts.
As far as what we can do compatibly, we could at least catch ClassCastException somewhere in here (I'd have to double-check exactly where the exception gets thrown) so we just skip the note in question. I am not sure if we can get Class<?> witnesses reliably that we could use to pre-check the types instead of just catching exceptions.
| private final class NodePrintListener implements GraphListener.Synchronous { | ||
| @Override public void onNewHead(FlowNode node) { | ||
| NewNodeConsoleNote.print(node, getListener()); | ||
| // TODO: Breaks show/hide links in the console because the line with the show/hide link gets hidden. |
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.
Should be fixable, but I am not going to bother looking into it unless I really want to get this merged.
|
For now we are instead going to filter these out when reading the log file for our visualization. |
This is currently just a prototype I am using to investigate some things. Requires jenkinsci/workflow-api-plugin#296 to fix a test that happens to trigger that bug with this change.
I am working on a (proprietary) Pipeline log viewer that allows users to view logs for an entire stage or branch, by combining the per-step logs for all the steps in the stage/branch. This works fine, but there are a few issues:
[Pipeline] <step>lines fromNewNodeConsoleNotethat give you context about what steps are running, which can be confusing if the stage/branch has a lot of steps.[Pipeline] <step>lines in a row, there is no exact way to mark their context.Emitting the
NewNodeConsoleNotelines to the per-step logs instead allows all of these issues to be addressed using public APIs. I think it could be useful to the classic console view and other Pipeline log visualizations as well.Of course there are some drawbacks:
[Pipeline] <step name>, which is at best useless for these visualizations since they already indicate what step is selected in some other way.Testing done