From 302e6ac2d1b64ea9035b00ab9fe79685dbf0aa68 Mon Sep 17 00:00:00 2001 From: Vincent Latombe Date: Thu, 14 Dec 2023 21:35:18 +0100 Subject: [PATCH] Logging improvements to `Run` related classes (#8777) Logging improvements to Run related classes --- core/src/main/java/hudson/model/Run.java | 2 ++ core/src/main/java/hudson/model/RunMap.java | 1 + .../model/lazy/AbstractLazyLoadRunMap.java | 15 ++++++++++++--- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/hudson/model/Run.java b/core/src/main/java/hudson/model/Run.java index 23358ade11f4..103d0c41ee98 100644 --- a/core/src/main/java/hudson/model/Run.java +++ b/core/src/main/java/hudson/model/Run.java @@ -2480,10 +2480,12 @@ public EnvVars getEnvironment() throws IOException, InterruptedException { } Jenkins j = Jenkins.getInstanceOrNull(); if (j == null) { + LOGGER.fine(() -> "Jenkins not running"); return null; } Job job = j.getItemByFullName(jobName, Job.class); if (job == null) { + LOGGER.fine(() -> "no such job " + jobName + " when running as " + Jenkins.getAuthentication2().getName()); return null; } return job.getBuildByNumber(number); diff --git a/core/src/main/java/hudson/model/RunMap.java b/core/src/main/java/hudson/model/RunMap.java index ca16fee660d2..b7bb97037940 100644 --- a/core/src/main/java/hudson/model/RunMap.java +++ b/core/src/main/java/hudson/model/RunMap.java @@ -239,6 +239,7 @@ protected R retrieve(File d) throws IOException { LOGGER.log(Level.WARNING, "could not load " + d, e); } } + LOGGER.fine(() -> "no config.xml in " + d); return null; } diff --git a/core/src/main/java/jenkins/model/lazy/AbstractLazyLoadRunMap.java b/core/src/main/java/jenkins/model/lazy/AbstractLazyLoadRunMap.java index 4d2710282ade..95e647cfdfdc 100644 --- a/core/src/main/java/jenkins/model/lazy/AbstractLazyLoadRunMap.java +++ b/core/src/main/java/jenkins/model/lazy/AbstractLazyLoadRunMap.java @@ -518,15 +518,21 @@ public R getByNumber(int n) { Index snapshot = index; if (snapshot.byNumber.containsKey(n)) { BuildReference ref = snapshot.byNumber.get(n); - if (ref == null) return null; // known failure + if (ref == null) { + LOGGER.fine(() -> "known failure of #" + n + " in " + dir); + return null; + } R v = unwrap(ref); - if (v != null) return v; // already in memory + if (v != null) { + return v; // already in memory + } // otherwise fall through to load } synchronized (this) { if (index.byNumber.containsKey(n)) { // JENKINS-22767: recheck inside lock BuildReference ref = index.byNumber.get(n); if (ref == null) { + LOGGER.fine(() -> "known failure of #" + n + " in " + dir); return null; } R v = unwrap(ref); @@ -655,7 +661,10 @@ private R load(File dataDir, Index editInPlace) { assert Thread.holdsLock(this); try { R r = retrieve(dataDir); - if (r == null) return null; + if (r == null) { + LOGGER.fine(() -> "nothing in " + dataDir); + return null; + } Index copy = editInPlace != null ? editInPlace : new Index(index);