Skip to content

Commit

Permalink
prevent spam when setting size to -1 (#1529)
Browse files Browse the repository at this point in the history
prevent spam when setting size to -1

the size for every plugin is set to `-1` which creates excessive spam when running.
log these at FINE level, log all other updates and INFO level

We use instance equality here as the string is a literal and this is a
private method, so we rely on the actual literal to be identical (which
it will be).

Could break in the future - but this is just logspam so the quick check
is better.
  • Loading branch information
jtnord committed Apr 15, 2024
1 parent 9d11377 commit fed75e3
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
public class MockUpdateCenter implements AutoCleaned {

private static final Logger LOGGER = Logger.getLogger(MockUpdateCenter.class.getName());
private static final String MINUS_ONE_STRING = "-1";

@Inject
public Injector injector;
Expand Down Expand Up @@ -129,7 +130,7 @@ public void ensureRunning(Jenkins jenkins) {
plugin.put("url", name + ".hpi");
updating(plugin, "version", version);
// "Avoid IOException: Inconsistent file length" from hudson.model.UpdateCenter
updating(plugin, "size", "-1");
updating(plugin, "size", MINUS_ONE_STRING);
updating(plugin, "gav", meta.gav);
updating(plugin, "requiredCore", meta.requiredCore().toString());
updating(plugin, "dependencies", new JSONArray(meta.getDependencies().stream().map(d -> {
Expand Down Expand Up @@ -227,7 +228,13 @@ private void updating(JSONObject plugin, String key, Object val) throws JSONExce
Object old = plugin.opt(key);
plugin.put(key, val);
if (!String.valueOf(val).equals(String.valueOf(old))) {
LOGGER.log(Level.INFO, "for {0} updating {1} from {2} to {3}", new Object[] {plugin.getString("name"), key, old, val});
// "-1" and "size" are both string literals in the caller,
// so only check their identity to prevent a fallback to checking characters which is unneeded.
if (MINUS_ONE_STRING == val && "size" == key) {
LOGGER.log(Level.FINE, "for {0} updating {1} from {2} to {3}", new Object[] {plugin.getString("name"), key, old, val});
} else {
LOGGER.log(Level.INFO, "for {0} updating {1} from {2} to {3}", new Object[] {plugin.getString("name"), key, old, val});
}
}
}

Expand Down

0 comments on commit fed75e3

Please sign in to comment.