Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ pipeline {
}
```

## Disable fingerprinting

Recording fingerprints are great, but for large Jenkins instances it can become a scalability and performance issue.
It is possible to disable recording of fingerprints by setting the system property
<code>org.jenkinsci.plugins.docker.commons.fingerprint.DockerFingerprints.DISABLE</code> equal to true. This will
not remove old fingerprints but will prevent new fingerprints from being recorded.

## License

[MIT License](http://opensource.org/licenses/MIT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package org.jenkinsci.plugins.docker.commons.fingerprint;

import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import hudson.BulkChange;
import hudson.model.Fingerprint;
import hudson.model.Run;
Expand All @@ -39,6 +40,8 @@
import javax.annotation.Nonnull;
import jenkins.model.FingerprintFacet;
import org.apache.commons.lang.StringUtils;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

/**
* Entry point into fingerprint related functionalities in Docker.
Expand All @@ -47,7 +50,15 @@
public class DockerFingerprints {

private static final Logger LOGGER = Logger.getLogger(DockerFingerprints.class.getName());


/**
* System property, which, when set to true (default false), disables
* recording of new fingerprints.
*/
@SuppressFBWarnings(value="MS_SHOULD_BE_FINAL", justification="mutable for scripts")
@Restricted(NoExternalUse.class)
public static boolean DISABLE = Boolean.getBoolean(DockerFingerprints.class.getName() + ".DISABLE");

private DockerFingerprints() {} // no instantiation

/**
Expand Down Expand Up @@ -221,6 +232,10 @@ private DockerFingerprints() {} // no instantiation
* Adds a new {@link ContainerRecord} for the specified image, creating necessary intermediate objects as it goes.
*/
public static void addRunFacet(@Nonnull ContainerRecord record, @Nonnull Run<?,?> run) throws IOException {
if (DISABLE) {
LOGGER.info("Recording of fingerprints is disabled, no RUN fingerprint record will be made.");
return;
}
Copy link
Member

Choose a reason for hiding this comment

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

Would it also make sense to add logging on the FINE or INFO levels?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not the expert here, after all, I'm the one making a change to disable all of this, so I have a hard time finding a point where it would be useful. But if you can see a reason for adding it, I'll happily add it :) Besides, at level FINE/INFO it would require the user to actively set the log level in order to get it to the system logs etc (have it on by default would be way to chatty IMHO).

String imageId = record.getImageId();
Fingerprint f = forImage(run, imageId);
synchronized (f) {
Expand Down Expand Up @@ -256,6 +271,10 @@ public static void addRunFacet(@Nonnull ContainerRecord record, @Nonnull Run<?,?
* @param run the build in which the image building occurred
*/
public static void addFromFacet(@CheckForNull String ancestorImageId, @Nonnull String descendantImageId, @Nonnull Run<?,?> run) throws IOException {
if (DISABLE) {
LOGGER.info("Recording of fingerprints is disabled, no FROM fingerprint record will be made.");
return;
}
long timestamp = System.currentTimeMillis();
if (ancestorImageId != null) {
Fingerprint f = forImage(run, ancestorImageId);
Expand Down Expand Up @@ -311,4 +330,13 @@ public static void addFromFacet(@CheckForNull String ancestorImageId, @Nonnull S
}
}

/**
* Indicates whether recording of new fingerprints are disabled.
*
* @return true if fingerprint recording is disabled, otherwise false.
*/
public static boolean isFingerprintsDisabled() {
return DISABLE;
}

}