ConsoleLogFilter not working for builds on slaves

22 views
Skip to first unread message

Tim Webster

unread,
Jan 19, 2018, 8:46:52 AM1/19/18
to Jenkins Developers
Hi,

I've written a plugin that forwards console logs to a remote TCP log collector, using a ConsoleLogFilter.  It works perfectly for jobs running on master, but gets ignored for jobs running on slaves.

It's borrowing heavily from the Splunk plugin in that it 'tees' the console logs both to the existing logger output stream and a remote socket output stream.

Can anyone point out what I'm missing?  Plugin source is here: https://github.com/timwebster9/jenkins-tcp-log-fowarder-plugin

thanks :-)

Jesse Glick

unread,
Jan 19, 2018, 9:34:29 AM1/19/18
to Jenkins Dev
On Fri, Jan 19, 2018 at 7:54 AM, Tim Webster <tim.w...@gmail.com> wrote:
> I've written a plugin that forwards console logs to a remote TCP log
> collector, using a ConsoleLogFilter.

I am not sure of your specific problem, but BTW JENKINS-38381 and
related issues propose a more solid foundation foundation for this
class of plugin.

Tim Webster

unread,
Jan 19, 2018, 9:47:11 AM1/19/18
to Jenkins Developers
Basically I just wanted a simple plugin that could forward console logs to a remote collector.  The existing ones around are pretty specific the the collector/indexer (e.g. Splunk, ELK, Logstash, etc).

We're looking at using OK Log, which only requires a host and port to connect to: https://github.com/oklog/oklog

There are other ways to get the console log there, but they are clunky (e.g. downloading it after the job and forwarding it, etc).

The specific problem that I'm seeing is that if the build runs on a remote slave (I'm using Jenkins Swarm plugin agents), my ConsoleLogFilter.decorateLogger() extension/implementation isn't even being called.  If it runs on master it works fine.  Was wondering if I need to use a different extension point or something (e.g. BuildWrapper.decorateLogger() )?

Jesse Glick

unread,
Jan 19, 2018, 10:05:08 AM1/19/18
to Jenkins Dev
On Fri, Jan 19, 2018 at 9:47 AM, Tim Webster <tim.w...@gmail.com> wrote:
> Was wondering if I need to use
> a different extension point or something

Not that I am aware of. Sounds like a bug offhand.

Tim Webster

unread,
Jan 19, 2018, 11:34:19 AM1/19/18
to Jenkins Developers
Just realised I think it's something to do with it being a Pipeline job - a freestyle job seems to work on the remote slave.

So:
- Freestyle job works everywhere
- Pipeline job only on master.

Any ideas?

Tim Webster

unread,
Jan 19, 2018, 11:50:57 AM1/19/18
to Jenkins Developers
apologies - pipeline doesn't work on master either.  I will look at the pipeline support for plugins stuff...

Thanks

Jesse Glick

unread,
Jan 19, 2018, 12:25:05 PM1/19/18
to Jenkins Dev
On Fri, Jan 19, 2018 at 11:50 AM, Tim Webster <tim.w...@gmail.com> wrote:
> pipeline doesn't work on master either.

No, `ConsoleLogFilter` is not supported for Pipeline currently. See
JENKINS-38381, some variant of which would be the preferred API for
adding this kind of functionality.

Markus Winter

unread,
Jan 19, 2018, 12:45:08 PM1/19/18
to jenkin...@googlegroups.com
Why is ConsoleLogFilter not supported in pipeline.
Timestamper plugin is also using a ConsoleLogFilter to add the
timestamps in pipeline
(https://github.com/jenkinsci/timestamper-plugin/blob/master/src/main/java/hudson/plugins/timestamper/pipeline/TimestamperStep.java)
Sure it has the limitation that it will not catch all the output of the
pipeline (some output from the pipeline workflow execution engine is
missed).
BTW, I've opened a PR in the logstash plugin that does a major
refactoring that adds an extension point for indexers. So adding
something to write to oklog would be quite easy.

And I also have implemented (not submitted) a true pipeline BuildWrapper
for it so you can do
logstash {
  node('label')
{
  sh ....

Jesse Glick

unread,
Jan 19, 2018, 1:17:51 PM1/19/18
to Jenkins Dev
On Fri, Jan 19, 2018 at 12:44 PM, Markus Winter <m_wi...@gmx.de> wrote:
> Why is ConsoleLogFilter not supported in pipeline.

Because…it isn’t yet. And JENKINS-38381, the better approach, was
blocked for the moment due to lack of test infrastructure.

> Timestamper plugin is also using a ConsoleLogFilter to add the timestamps in
> pipeline

That is using _contextual_ `ConsoleLogFilter`, which is definitely
supported. Just not `ConsoleLogFilter` as an _extension_.

Tim Webster

unread,
Jan 19, 2018, 2:06:21 PM1/19/18
to Jenkins Developers
Could I use 'contextual' ConsoleLogFilter to do what I need then?  I confess I don't really know what that means though - I'll look at the Timestamper plugin.

Although if JENKINS-38381 is going to be the preferred approach, I can also wait for that - or do both.  This is an internal project at the moment and I'm in no rush to release anything into the wild.

Jesse Glick

unread,
Jan 19, 2018, 3:05:56 PM1/19/18
to Jenkins Dev
On Fri, Jan 19, 2018 at 2:06 PM, Tim Webster <tim.w...@gmail.com> wrote:
> Could I use 'contextual' ConsoleLogFilter to do what I need then?

If what you need is simply to *copy* all log lines somewhere else,
performance be damned, and you do not mind this being configured on a
per-job basis, then yes you could just make a `SimpleBuildWrapper`
defining a `ConsoleLogFilter`, which would work from either freestyle
projects (with a “build environment”) or Pipeline (with a block-scoped
step).

JENKINS-38381 would define a different API allowing the entire build
log to be sent to an external sink as the authoritative record,
meaning

· `$JENKINS_HOME/jobs/*/builds/*/log` need not even exist (except
perhaps as a cache)
· text produced by external processes launched on agents can be
streamed directly from there, never going over the Remoting channel to
the master

Tim Webster

unread,
Jan 19, 2018, 4:25:28 PM1/19/18
to Jenkins Developers
OK - thanks for the info.  JENKINS-38381 definitely sounds like the way forward - keeping an eye on that..
Reply all
Reply to author
Forward
0 new messages