Skip to content

Commit

Permalink
Fixing Disk Usage Collector handling
Browse files Browse the repository at this point in the history
  • Loading branch information
waschndolos committed Nov 26, 2023
1 parent 4f5e028 commit 09df7db
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public List<MetricFamilySamples> collect() {
return Collections.emptyList();
} catch (final java.lang.NoClassDefFoundError e) {
LOGGER.warn("Cannot collect disk usage data because plugin CloudBees Disk Usage Simple is not installed: {}", e.toString());
LOGGER.info("You can remove this warning if you disable Collect Disk Usage in Prometheus Configuration.");

Check warning on line 42 in src/main/java/org/jenkinsci/plugins/prometheus/DiskUsageCollector.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 42 is not covered by tests
return Collections.emptyList();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ public class PrometheusConfiguration extends GlobalConfiguration {
private boolean appendStatusLabel = false;
private boolean perBuildMetrics = false;


private transient boolean collectDiskUsageEnvironmentVariableSet = false;

private String labeledBuildParameterNames = "";

private boolean collectDiskUsage = true;
Expand Down Expand Up @@ -115,21 +118,26 @@ public void setDefaultNamespace(String path) {
}

@DataBoundSetter
public void setCollectDiskUsage(Boolean collectDiskUsage) {
public void setCollectDiskUsage(boolean collectDiskUsage) {
this.collectDiskUsage = collectDiskUsage;
}

public void setCollectDiskUsageBasedOnEnvironmentVariableIfDefined() {
try {
final String envValue = System.getenv(COLLECT_DISK_USAGE);
if (envValue != null) {
this.collectDiskUsage = getValidBooleanValueOrThrowException(envValue);
setCollectDiskUsage(getValidBooleanValueOrThrowException(envValue));
collectDiskUsageEnvironmentVariableSet = true;
}
} catch (IllegalArgumentException e) {
logger.warn("Unable to parse environment variable '{}'. Must either be 'true' or 'false'. Ignoring...", COLLECT_DISK_USAGE);
}
}

public boolean isCollectDiskUsageEnvironmentVariableSet() {
return collectDiskUsageEnvironmentVariableSet;

Check warning on line 138 in src/main/java/org/jenkinsci/plugins/prometheus/config/PrometheusConfiguration.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered line

Line 138 is not covered by tests
}

private boolean getValidBooleanValueOrThrowException(String value) throws IllegalArgumentException {
if ("true".equalsIgnoreCase(value) || "false".equalsIgnoreCase(value)) {
return Boolean.parseBoolean(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
<f:textbox />
</f:entry>
<f:entry title="${%Collect disk usage}" field="collectDiskUsage">
<j:set var="readOnlyMode" value="${instance.isEnvironmentVariableSet()}"/>
<j:set var="readOnlyMode" value="${instance.isCollectDiskUsageEnvironmentVariableSet()}"/>
<f:checkbox />
</f:entry>
<f:entry title="${%Collect node status}" field="collectNodeStatus">
Expand Down

0 comments on commit 09df7db

Please sign in to comment.