Fix global instance singleton resolver#138
Conversation
According to the [doc][1] to get an instance of a config we should use `ExtensionList.lookupSingleton(<your GlobalConfiguration subclass>.class)` Added additional test to handle a remote logging from workflow pipeline job. Initially started to check the code because we got exceptions on agents when using Git checkout: ``` java.lang.IllegalStateException: Jenkins.instance is missing. Read the documentation of Jenkins.getInstanceOrNull to see what you are doing wrong. at jenkins.model.Jenkins.get(Jenkins.java:816) at jenkins.model.GlobalConfiguration.all(GlobalConfiguration.java:75) at jenkins.plugins.logstash.LogstashConfiguration.getInstance(LogstashConfiguration.java:289) at jenkins.plugins.logstash.LogstashWriter.getIndexerDao(LogstashWriter.java:162) at jenkins.plugins.logstash.LogstashWriter.getDaoOrNull(LogstashWriter.java:201) at jenkins.plugins.logstash.LogstashWriter.<init>(LogstashWriter.java:82) at jenkins.plugins.logstash.pipeline.GlobalDecorator.decorate(GlobalDecorator.java:41) at org.jenkinsci.plugins.workflow.log.TaskListenerDecorator.decorateAll(TaskListenerDecorator.java:230) at org.jenkinsci.plugins.workflow.log.TaskListenerDecorator$DecoratedTaskListener.getOutputStream(TaskListenerDecorator.java:267) at org.jenkinsci.plugins.workflow.log.OutputStreamTaskListener$Default.getLogger(OutputStreamTaskListener.java:116) at org.jenkinsci.plugins.workflow.log.TaskListenerDecorator$CloseableTaskListener.getLogger(TaskListenerDecorator.java:307) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2801) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2762) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2757) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:2051) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:2063) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.revParse(CliGitAPIImpl.java:1115) at hudson.plugins.git.GitAPI.revParse(GitAPI.java:419) ``` [1]: https://javadoc.jenkins-ci.org/jenkins/model/GlobalConfiguration.html
|
BTW I think it was already reported on jira |
I didn't tested this yet on real Jenkins instance. Will post an update here. |
|
Nope, different error, but still an exception: Seems need to add a filter or a handler for that case... |
According to the [doc][1] to get an instance of a config we should use `ExtensionList.lookupSingleton(<your GlobalConfiguration subclass>.class)` Added additional test to handle a remote logging from workflow pipeline job. Initially started to check the code because we got exceptions on agents when using Git checkout: ``` java.lang.IllegalStateException: Jenkins.instance is missing. Read the documentation of Jenkins.getInstanceOrNull to see what you are doing wrong. at jenkins.model.Jenkins.get(Jenkins.java:816) at jenkins.model.GlobalConfiguration.all(GlobalConfiguration.java:75) at jenkins.plugins.logstash.LogstashConfiguration.getInstance(LogstashConfiguration.java:289) at jenkins.plugins.logstash.LogstashWriter.getIndexerDao(LogstashWriter.java:162) at jenkins.plugins.logstash.LogstashWriter.getDaoOrNull(LogstashWriter.java:201) at jenkins.plugins.logstash.LogstashWriter.<init>(LogstashWriter.java:82) at jenkins.plugins.logstash.pipeline.GlobalDecorator.decorate(GlobalDecorator.java:41) at org.jenkinsci.plugins.workflow.log.TaskListenerDecorator.decorateAll(TaskListenerDecorator.java:230) at org.jenkinsci.plugins.workflow.log.TaskListenerDecorator$DecoratedTaskListener.getOutputStream(TaskListenerDecorator.java:267) at org.jenkinsci.plugins.workflow.log.OutputStreamTaskListener$Default.getLogger(OutputStreamTaskListener.java:116) at org.jenkinsci.plugins.workflow.log.TaskListenerDecorator$CloseableTaskListener.getLogger(TaskListenerDecorator.java:307) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2801) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2762) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommandIn(CliGitAPIImpl.java:2757) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:2051) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.launchCommand(CliGitAPIImpl.java:2063) at org.jenkinsci.plugins.gitclient.CliGitAPIImpl.revParse(CliGitAPIImpl.java:1115) at hudson.plugins.git.GitAPI.revParse(GitAPI.java:419) ``` `getIndexerDao` should return `null` if configuration isn't yet available. In that case `getDaoOrNull` will return `null` as it is expected. [1]: https://javadoc.jenkins-ci.org/jenkins/model/GlobalConfiguration.html
|
After latest fix issue got fixed. I tested it in Jenkins and issue seems to be resolved. Now it is reporting only |
that doesn't look good, LogstashIndexerDao is the interface used to actually push the log data out are you getting the job logs still? |
|
@kuzaxak Is is working even if you receive this error message? |
|
Hi, we are also suffering from this issue. Is there a plan to fix it? |
I am guessing most of the logs will still be sent. Only the Git Checkout will be missed since Git Client plugin is a bit special, see https://issues.jenkins.io/browse/JENKINS-30600. Can this be merged to at least stop the stack traces? |
|
Would be nice to hear from OP @kuzaxak ? |
Yes, the plugin works, but it is printing an error every time Jenkins starts the k8s agent And as mentioned Git Checkout too. So, we are using it in our Jenkins. |
|
Any updates on this one? :D |
Sorry, I went on vacation after I wrote the last message and missed the reply. The error message still worries me, but I don't have time to investigate this. I believe this MR should be available as an incremental release already. |
|
Hello and thanks for the fix @kuzaxak @jakub-bochenski |
|
I don't think it will make the warning go away Yet per the Javadoc description you quoted:
I think we should be using JenkinsJVM here instead of the current call |
|
@jakub-bochenski Agreed. Is it possible to change the code and test? I do not have intimate knowledge of the inner workings of this filter, and as such would prefer not to mess things up. |
|
If I'm not mistaken we just need to swap this line https://github.com/jenkinsci/logstash-plugin/pull/138/files#diff-788d74b65c8f1ef69c0b62956c4fa34d8d61dd1e572b388af767de1376e01a45R162 We should probably include this before merging to master. |
|
I have created this PR. If we are happy with the change, we can merge it into existing fork, which should update the old PR salemove#1 |
@kuzaxak can you take a look? |
|
@jakub-bochenski @kuzaxak Any update on this please? Would like to get it merged and try it out. Worst case we rollback to previous version of the plugin.. |
|
@tranceporter I can't merge that PR because it's targeting another repository. Feel free to submit you changes here directly |
|
@jakub-bochenski Do you want just my change in the fork PR or do you want me to include @kuzaxak changes as well? EDIT: I have created a PR with just my code fix. #147 |
235a64b to
dbe90c1
Compare
|
Superseded by #149 |

According to the doc to get an instance of a config we should use
ExtensionList.lookupSingleton(<your GlobalConfiguration subclass>.class)Initially started to check the code because we got exceptions on agents when using Git checkout:
Testing done
Added additional test to handle a remote logging from workflow pipeline job executed on agent.
Don't know how to test Git plugin within tests of this plugin.
https://issues.jenkins.io/browse/JENKINS-71693