-
Notifications
You must be signed in to change notification settings - Fork 41
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
fix(pruneOrphan): convert nomad expirtyTime from ns to ms #170
base: master
Are you sure you want to change the base?
Conversation
@@ -177,8 +177,8 @@ private void pruneOrphanedWorkers(NomadWorkerTemplate template) { | |||
String jobNamespace = worker.getJobSummary().getNamespace(); | |||
JSONObject job = this.nomad.getRunningWorker(jobSummary.getJobID(), jobNamespace); | |||
String jobRegion = job.getString("Region"); | |||
Instant expiryTime = Instant.ofEpochMilli(job.getLong("SubmitTime")); | |||
expiryTime.plusSeconds(this.workerTimeout * 60); | |||
Instant expiryTime = Instant.ofEpochMilli(Math.round(job.getLong("SubmitTime")/1000000)); |
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.
Thanks for the fix!
You have to fix the "SpotBugs-finding" first in order to get the build green. Suggestion, just remove Math.round like below:
Instant expiryTime = Instant.ofEpochMilli(job.getLong("SubmitTime") / 1000000);
expiryTime = expiryTime.plusSeconds(this.workerTimeout * 60L);
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.
I used math.Float because ofEpochMilli is expececting a long and the divide to convert to ns generate a number with decimals result of a BigDecimal type. The Math.Round solved both issues (remove the decimals + return a long).
I pushed a different way to do it (and tested it), hope it's a better way ! :D
groovy.lang.MissingMethodException: No signature of method: static java.time.Instant.toEpochMilli() is applicable for argument types: (java.math.BigDecimal) values: [1671487054166.230409]
Possible solutions: toEpochMilli(), ofEpochMilli(long)
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.
I adjusted the expiry time calculation so that it is more clear. Could you please check whether this is working for you?
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.
It's working :D !
33b20e2
to
7ef8ac8
Compare
Also, I think this fix should come with a warning.. As this feature wasn't working before. |
7ef8ac8
to
79a6c7d
Compare
Makes sense, we could add something like this to the release notes I guess.
tbh, I'm not familiar with the prune feature but I guess you are right, that could be the case. We should add a warning which is displayed right to the prune option so that the user is at least aware of the risk. Maybe we could also migrate the cloud configurations so that the prune feature is deactivated for all existing configurations and must be activated actively. |
Hi, |
I tested and running this patch in our environment its work well |
79a6c7d
to
cc0811d
Compare
We are using Nomad 1.4.3 and jenkins 2.361.4.
I noticed that the pruneOrphan feature wasn't working on our side.
After digging, I noticed two anomalies:
I address the previous anomalies by converting the parsed values to milliseconds and update the expirtyTime variable with the added timeout.
I did a small fix that seems to work on our side based on my first tests:
I am far away of being an expert with Java. If this PR need some "touch up", please help! :)
Thanks !