forked from lsjostro/prometheus-plugin
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code coverage will not show job full name. Provide a default value of…
… -1 if a specific coverage is not available in the coverage report (#612) * Returning job full name * Coverage will return a -1 if a specific coverage is not available now to make it clear that nothing has been found. * Adding line coverage metrics and a percentage gauge for all current coverage metrics
- Loading branch information
Waschndolos
authored
Jan 9, 2024
1 parent
f0e2864
commit d64bcde
Showing
45 changed files
with
1,081 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageBranchPercentGauge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.jenkinsci.plugins.prometheus.collectors.coverage; | ||
|
||
import edu.hm.hafner.coverage.Coverage; | ||
import edu.hm.hafner.coverage.Metric; | ||
import hudson.model.Run; | ||
import io.jenkins.plugins.coverage.metrics.model.Baseline; | ||
import io.prometheus.client.Gauge; | ||
import io.prometheus.client.SimpleCollector; | ||
import org.jenkinsci.plugins.prometheus.collectors.CollectorType; | ||
|
||
import java.util.Optional; | ||
|
||
public class CoverageBranchPercentGauge extends CoverageMetricsCollector<Run<?, ?>, Gauge> { | ||
|
||
protected CoverageBranchPercentGauge(String[] labelNames, String namespace, String subsystem) { | ||
super(labelNames, namespace, subsystem); | ||
} | ||
|
||
@Override | ||
protected CollectorType getCollectorType() { | ||
return CollectorType.COVERAGE_BRANCH_PERCENT; | ||
} | ||
|
||
@Override | ||
protected String getHelpText() { | ||
return "Returns the coverage of branches in percent"; | ||
} | ||
|
||
@Override | ||
protected SimpleCollector.Builder<?, Gauge> getCollectorBuilder() { | ||
return Gauge.build(); | ||
} | ||
|
||
@Override | ||
public void calculateMetric(Run<?, ?> jenkinsObject, String[] labelValues) { | ||
|
||
Optional<Coverage> optional = getCoverage(jenkinsObject, Metric.BRANCH, Baseline.PROJECT); | ||
if (optional.isEmpty()) { | ||
collector.labels(labelValues).set(-1); | ||
return; | ||
} | ||
|
||
Coverage coverage = optional.get(); | ||
collector.labels(labelValues).set(calculatePercentage(coverage)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
.../java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageClassPercentGauge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.jenkinsci.plugins.prometheus.collectors.coverage; | ||
|
||
import edu.hm.hafner.coverage.Coverage; | ||
import edu.hm.hafner.coverage.Metric; | ||
import hudson.model.Run; | ||
import io.jenkins.plugins.coverage.metrics.model.Baseline; | ||
import io.prometheus.client.Gauge; | ||
import io.prometheus.client.SimpleCollector; | ||
import org.jenkinsci.plugins.prometheus.collectors.CollectorType; | ||
|
||
import java.util.Optional; | ||
|
||
public class CoverageClassPercentGauge extends CoverageMetricsCollector<Run<?, ?>, Gauge> { | ||
|
||
protected CoverageClassPercentGauge(String[] labelNames, String namespace, String subsystem) { | ||
super(labelNames, namespace, subsystem); | ||
} | ||
|
||
@Override | ||
protected CollectorType getCollectorType() { | ||
return CollectorType.COVERAGE_CLASS_PERCENT; | ||
} | ||
|
||
@Override | ||
protected String getHelpText() { | ||
return "Returns the coverage of classes in percent"; | ||
} | ||
|
||
@Override | ||
protected SimpleCollector.Builder<?, Gauge> getCollectorBuilder() { | ||
return Gauge.build(); | ||
} | ||
|
||
@Override | ||
public void calculateMetric(Run<?, ?> jenkinsObject, String[] labelValues) { | ||
|
||
Optional<Coverage> optional = getCoverage(jenkinsObject, Metric.CLASS, Baseline.PROJECT); | ||
if (optional.isEmpty()) { | ||
collector.labels(labelValues).set(-1); | ||
return; | ||
} | ||
|
||
Coverage coverage = optional.get(); | ||
collector.labels(labelValues).set(calculatePercentage(coverage)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...n/java/org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageFilePercentGauge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.jenkinsci.plugins.prometheus.collectors.coverage; | ||
|
||
import edu.hm.hafner.coverage.Coverage; | ||
import edu.hm.hafner.coverage.Metric; | ||
import hudson.model.Run; | ||
import io.jenkins.plugins.coverage.metrics.model.Baseline; | ||
import io.prometheus.client.Gauge; | ||
import io.prometheus.client.SimpleCollector; | ||
import org.jenkinsci.plugins.prometheus.collectors.CollectorType; | ||
|
||
import java.util.Optional; | ||
|
||
public class CoverageFilePercentGauge extends CoverageMetricsCollector<Run<?, ?>, Gauge> { | ||
|
||
protected CoverageFilePercentGauge(String[] labelNames, String namespace, String subsystem) { | ||
super(labelNames, namespace, subsystem); | ||
} | ||
|
||
@Override | ||
protected CollectorType getCollectorType() { | ||
return CollectorType.COVERAGE_FILE_PERCENT; | ||
} | ||
|
||
@Override | ||
protected String getHelpText() { | ||
return "Returns the coverage of files in percent"; | ||
} | ||
|
||
@Override | ||
protected SimpleCollector.Builder<?, Gauge> getCollectorBuilder() { | ||
return Gauge.build(); | ||
} | ||
|
||
@Override | ||
public void calculateMetric(Run<?, ?> jenkinsObject, String[] labelValues) { | ||
|
||
Optional<Coverage> optional = getCoverage(jenkinsObject, Metric.FILE, Baseline.PROJECT); | ||
if (optional.isEmpty()) { | ||
collector.labels(labelValues).set(-1); | ||
return; | ||
} | ||
|
||
Coverage coverage = optional.get(); | ||
collector.labels(labelValues).set(calculatePercentage(coverage)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...org/jenkinsci/plugins/prometheus/collectors/coverage/CoverageInstructionPercentGauge.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.jenkinsci.plugins.prometheus.collectors.coverage; | ||
|
||
import edu.hm.hafner.coverage.Coverage; | ||
import edu.hm.hafner.coverage.Metric; | ||
import hudson.model.Run; | ||
import io.jenkins.plugins.coverage.metrics.model.Baseline; | ||
import io.prometheus.client.Gauge; | ||
import io.prometheus.client.SimpleCollector; | ||
import org.jenkinsci.plugins.prometheus.collectors.CollectorType; | ||
|
||
import java.util.Optional; | ||
|
||
public class CoverageInstructionPercentGauge extends CoverageMetricsCollector<Run<?, ?>, Gauge> { | ||
|
||
protected CoverageInstructionPercentGauge(String[] labelNames, String namespace, String subsystem) { | ||
super(labelNames, namespace, subsystem); | ||
} | ||
|
||
@Override | ||
protected CollectorType getCollectorType() { | ||
return CollectorType.COVERAGE_INSTRUCTION_PERCENT; | ||
} | ||
|
||
@Override | ||
protected String getHelpText() { | ||
return "Returns the coverage of instructions in percent"; | ||
} | ||
|
||
@Override | ||
protected SimpleCollector.Builder<?, Gauge> getCollectorBuilder() { | ||
return Gauge.build(); | ||
} | ||
|
||
@Override | ||
public void calculateMetric(Run<?, ?> jenkinsObject, String[] labelValues) { | ||
|
||
Optional<Coverage> optional = getCoverage(jenkinsObject, Metric.INSTRUCTION, Baseline.PROJECT); | ||
if (optional.isEmpty()) { | ||
collector.labels(labelValues).set(-1); | ||
return; | ||
} | ||
|
||
Coverage coverage = optional.get(); | ||
collector.labels(labelValues).set(calculatePercentage(coverage)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.