Skip to content
This repository was archived by the owner on Jan 23, 2020. It is now read-only.

Catch NPE when item.getInQueueSince() is unavailable#127

Merged
sjenriquez merged 2 commits into
masterfrom
scott/waiting-null
Nov 6, 2018
Merged

Catch NPE when item.getInQueueSince() is unavailable#127
sjenriquez merged 2 commits into
masterfrom
scott/waiting-null

Conversation

@sjenriquez

Copy link
Copy Markdown
Contributor

When computing the jenkins.job.waiting metric we call item.getInQueueSince(). This may raise a NullPointerException, as seen with the ec2-spot-jenkins-plugin. This PR catches the NPE and skips sending the gauge metric.

@sjenriquez
sjenriquez requested a review from truthbk November 2, 2018 21:25

@truthbk truthbk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a generic question and a note regarding the log level.


// Send waiting metric if item.getInQueueSince() is available
try {
builddata.put("waiting", (System.currentTimeMillis() - item.getInQueueSince()) / DatadogBuildListener.THOUSAND_LONG);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Man, the docs are pretty poor.... Do we know if the NPE comes from item being NULL (I would presume so) or is it being thrown by getInQueueSince()?

@sjenriquez sjenriquez Nov 5, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me, I have a stack track showing the error thrown when calling item.getInQueueSince(), but not totally sure (the plugin version used in this stack trace corresponds to the line computing the waiting metric).

WARNING hudson.model.listeners.RunListener report 
RunListener failed 
java.lang.NullPointerException 
at org.datadog.jenkins.plugins.datadog.DatadogBuildListener.onStarted(DatadogBuildListener.java:113) 
at hudson.model.listeners.RunListener.fireStarted(RunListener.java:240) 
at hudson.maven.MavenBuild$ProxyImpl2.start(MavenBuild.java:609) 
at sun.reflect.GeneratedMethodAccessor981.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:498) 
at hudson.model.Executor$2.call(Executor.java:912) 
at hudson.util.InterceptingProxy$1.invoke(InterceptingProxy.java:23) 
at com.sun.proxy.$Proxy89.start(Unknown Source) 
at sun.reflect.GeneratedMethodAccessor981.invoke(Unknown Source) 
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) 
at java.lang.reflect.Method.invoke(Method.java:498) 
at hudson.remoting.RemoteInvocationHandler$RPCRequest.perform(RemoteInvocationHandler.java:929) 
at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:903) 
at hudson.remoting.RemoteInvocationHandler$RPCRequest.call(RemoteInvocationHandler.java:855) 
at hudson.remoting.UserRequest.perform(UserRequest.java:212) 
at hudson.remoting.UserRequest.perform(UserRequest.java:54) 
at hudson.remoting.Request$2.run(Request.java:369) 
at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72) 
at org.jenkinsci.remoting.CallableDecorator.call(CallableDecorator.java:19) 
at hudson.remoting.CallableDecoratorList$1.call(CallableDecoratorList.java:21) 
at jenkins.util.ContextResettingExecutorService$2.call(ContextResettingExecutorService.java:46) 
at jenkins.security.ImpersonatingExecutorService$2.call(ImpersonatingExecutorService.java:71) 
at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) 
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) 
at java.lang.Thread.run(Thread.java:748)

Comment thread src/main/java/org/datadog/jenkins/plugins/datadog/DatadogBuildListener.java Outdated

@truthbk truthbk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

go for it! :shipit:

@sjenriquez
sjenriquez merged commit 4f12a7d into master Nov 6, 2018
@sjenriquez
sjenriquez deleted the scott/waiting-null branch November 6, 2018 19:16
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants