diff --git a/src/main/java/org/jenkinsci/plugins/prometheus/config/PrometheusConfiguration.java b/src/main/java/org/jenkinsci/plugins/prometheus/config/PrometheusConfiguration.java index 8a72a0daa..0bdbad596 100644 --- a/src/main/java/org/jenkinsci/plugins/prometheus/config/PrometheusConfiguration.java +++ b/src/main/java/org/jenkinsci/plugins/prometheus/config/PrometheusConfiguration.java @@ -52,8 +52,6 @@ public class PrometheusConfiguration extends GlobalConfiguration { private boolean appendStatusLabel = false; private boolean perBuildMetrics = false; - private boolean environmentVariableSet; - private String labeledBuildParameterNames = ""; private boolean collectDiskUsage = true; @@ -69,7 +67,6 @@ public PrometheusConfiguration() { setPath(getPath()); setCollectingMetricsPeriodInSeconds(collectingMetricsPeriodInSeconds); setCollectDiskUsageBasedOnEnvironmentVariableIfDefined(); - environmentVariableSet = isValidBooleanEnv(COLLECT_DISK_USAGE); } public static PrometheusConfiguration get() { @@ -124,27 +121,22 @@ public void setCollectDiskUsage(Boolean collectDiskUsage) { public void setCollectDiskUsageBasedOnEnvironmentVariableIfDefined() { try { - this.collectDiskUsage = getBooleanEnvironmentVariableOrThrowException(COLLECT_DISK_USAGE); + final String envValue = System.getenv(COLLECT_DISK_USAGE); + if (envValue != null) { + this.collectDiskUsage = getValidBooleanValueOrThrowException(envValue); + } } catch (IllegalArgumentException e) { logger.warn("Unable to parse environment variable '{}'. Must either be 'true' or 'false'. Ignoring...", COLLECT_DISK_USAGE); } } - private boolean getBooleanEnvironmentVariableOrThrowException(String key) throws IllegalArgumentException { - if (isValidBooleanEnv(key)) { - return Boolean.parseBoolean(System.getenv(key)); + private boolean getValidBooleanValueOrThrowException(String value) throws IllegalArgumentException { + if ("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value)) { + return Boolean.parseBoolean(value); } throw new IllegalArgumentException(); } - private boolean isValidBooleanEnv(String key) { - String value = System.getenv(key); - if (value != null) { - return ("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value)); - } - return false; - } - public boolean getCollectDiskUsage() { return collectDiskUsage; } @@ -357,8 +349,4 @@ private String[] parseParameterNamesFromStringSeparatedByComma(String stringValu } return stringValue.split("\\s*,\\s*"); } - - public boolean isEnvironmentVariableSet() { - return environmentVariableSet; - } }