Skip to content

Commit

Permalink
Removed some codacy issues (#656)
Browse files Browse the repository at this point in the history
* Removed some codacy issues

* Update slf4j version
  • Loading branch information
Waschndolos authored Apr 21, 2024
1 parent f216ace commit f8c26ba
Show file tree
Hide file tree
Showing 12 changed files with 23 additions and 48 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<jenkins.version>2.387.3</jenkins.version>

<prometheus.simpleclient.version>0.16.0</prometheus.simpleclient.version>
<slf4j.version>2.0.12</slf4j.version>
<slf4j.version>2.0.13</slf4j.version>

<cloudbees-disk-usage-simple.version>203.v3f46a_7462b_1a_</cloudbees-disk-usage-simple.version>
<coverage.version>1.10.0</coverage.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public List<MetricFamilySamples> collect() {
} catch (final IOException | RuntimeException e) {
LOGGER.warn("Failed to get disk usage data due to an unexpected error.", e);
return Collections.emptyList();
} catch (final java.lang.NoClassDefFoundError e) {
} catch (final NoClassDefFoundError e) {

Check warning on line 40 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 40 is not covered by tests
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.");
return Collections.emptyList();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ public class ExecutorCollector extends Collector {

private static final Logger LOGGER = LoggerFactory.getLogger(ExecutorCollector.class);

public ExecutorCollector() {
}

@Override
public List<MetricFamilySamples> collect() {
LOGGER.debug("Collecting executor metrics for prometheus");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ public class JobCollector extends Collector {

private static final Logger LOGGER = LoggerFactory.getLogger(JobCollector.class);

private final BuildMetrics lastBuildMetrics = new BuildMetrics("last");
private final BuildMetrics perBuildMetrics = new BuildMetrics("");

private MetricCollector<Run<?, ?>, ? extends Collector> summary;
private MetricCollector<Job<?, ?>, ? extends Collector> jobHealthScoreGauge;
private MetricCollector<Job<?, ?>, ? extends Collector> nbBuildsGauge;
Expand Down Expand Up @@ -65,11 +68,6 @@ public void initCollectors(String[] labelNameArray) {
}
}

private final BuildMetrics lastBuildMetrics = new BuildMetrics("last");
private final BuildMetrics perBuildMetrics = new BuildMetrics("");

public JobCollector() {}

@Override
public List<MetricFamilySamples> collect() {
LOGGER.debug("Collecting metrics for prometheus");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@

public class BuildCollectorFactory extends BaseCollectorFactory {

public BuildCollectorFactory() {
super();
}

public MetricCollector<Run<?, ?>, ? extends Collector> createCollector(CollectorType type, String[] labelNames, String prefix) {
switch (type) {
case BUILD_DURATION_GAUGE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@

public class DiskCollectorFactory extends BaseCollectorFactory {

public DiskCollectorFactory() {
super();
}

public MetricCollector<DiskItem, ? extends Collector> createDiskItemCollector(CollectorType type, String[] labelNames) {
if (Objects.requireNonNull(type) == DISK_USAGE_BYTES_GAUGE) {
return saveBuildCollector(new DiskUsageBytesGauge(labelNames, namespace, subsystem));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@

public class ExecutorCollectorFactory extends BaseCollectorFactory {

public ExecutorCollectorFactory() {
super();
}

public MetricCollector<LoadStatistics.LoadStatisticsSnapshot, ? extends Collector> createCollector(CollectorType type, String[] labelNames, String prefix) {
switch (type) {
case EXECUTORS_AVAILABLE_GAUGE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
*/
public class JenkinsCollectorFactory extends BaseCollectorFactory {

public JenkinsCollectorFactory() {
super();
}

public MetricCollector<Jenkins, ? extends Collector> createCollector(CollectorType type, String[] labelNames) {
switch (type) {
case JENKINS_UP_GAUGE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@

public class JobCollectorFactory extends BaseCollectorFactory {

public JobCollectorFactory() {
super();
}

public MetricCollector<Job<?, ?>, ? extends Collector> createCollector(CollectorType type, String[] labelNames) {
switch (type) {
case HEALTH_SCORE_GAUGE:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void testNothingCalculatedWhenRunIsNull() {

@Test
public void testNothingCalculatedWhenJobIsNotBuilding() {
Mockito.when(mock.isBuilding()).thenReturn(false);
when(mock.isBuilding()).thenReturn(false);

BuildLikelyStuckGauge sut = new BuildLikelyStuckGauge(getLabelNames(), getNamespace(), getSubSystem(), "");

Expand All @@ -46,8 +46,8 @@ public void testNothingCalculatedWhenJobIsNotBuilding() {

@Test
public void testNothingCalculatedWhenNoExecutorFound() {
Mockito.when(mock.isBuilding()).thenReturn(true);
Mockito.when(mock.getExecutor()).thenReturn(null);
when(mock.isBuilding()).thenReturn(true);
when(mock.getExecutor()).thenReturn(null);

BuildLikelyStuckGauge sut = new BuildLikelyStuckGauge(getLabelNames(), getNamespace(), getSubSystem(), "");

Expand All @@ -61,10 +61,10 @@ public void testNothingCalculatedWhenNoExecutorFound() {

@Test
public void testBuildIsLikelyStuck() {
Mockito.when(mock.isBuilding()).thenReturn(true);
when(mock.isBuilding()).thenReturn(true);
Executor mockedExecutor = mock(Executor.class);
when(mockedExecutor.isLikelyStuck()).thenReturn(true);
Mockito.when(mock.getExecutor()).thenReturn(mockedExecutor);
when(mock.getExecutor()).thenReturn(mockedExecutor);

BuildLikelyStuckGauge sut = new BuildLikelyStuckGauge(getLabelNames(), getNamespace(), getSubSystem(), "");

Expand All @@ -79,10 +79,10 @@ public void testBuildIsLikelyStuck() {

@Test
public void testBuildIsNotLikelyStuck() {
Mockito.when(mock.isBuilding()).thenReturn(true);
when(mock.isBuilding()).thenReturn(true);
Executor mockedExecutor = mock(Executor.class);
when(mockedExecutor.isLikelyStuck()).thenReturn(false);
Mockito.when(mock.getExecutor()).thenReturn(mockedExecutor);
when(mock.getExecutor()).thenReturn(mockedExecutor);

BuildLikelyStuckGauge sut = new BuildLikelyStuckGauge(getLabelNames(), getNamespace(), getSubSystem(), "");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import org.jenkinsci.plugins.prometheus.collectors.CollectorType;
import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedRunCollectorTest;
import org.jenkinsci.plugins.prometheus.config.PrometheusConfiguration;
import org.junit.Assert;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;

import java.util.Arrays;

import static org.mockito.Mockito.*;

public class CounterManagerTest extends MockedRunCollectorTest {
private CounterManager manager;
private final CounterManager manager;

public CounterManagerTest() {
manager = CounterManager.getManager();
Expand All @@ -31,7 +31,7 @@ public void TestEquivalentEntryReturnsCounter() {

// Should be a value reference comparison. They should be the exact same
// MetricCollector.
Assert.assertEquals(retrievedCounter, retrievedCounter2);
Assertions.assertEquals(retrievedCounter, retrievedCounter2);
}
}

Expand All @@ -52,7 +52,7 @@ public void TestNamespaceChangeReturnsNewCounter() {
var retrievedCounter2 = manager.getCounter(CollectorType.BUILD_SUCCESSFUL_COUNTER, labels, null);

// Should be a value reference comparison. They should not be the same metric since the namespace has changed.
Assert.assertNotEquals(retrievedCounter, retrievedCounter2);
Assertions.assertNotEquals(retrievedCounter, retrievedCounter2);
}
}

Expand All @@ -68,7 +68,7 @@ public void TestLabelChangeReturnsNewCounter(){
var retrievedCounter2 = manager.getCounter(CollectorType.BUILD_SUCCESSFUL_COUNTER, label2, null);

// Should be a value reference comparison. They should be different since labels differ.
Assert.assertNotEquals(retrievedCounter, retrievedCounter2);
Assertions.assertNotEquals(retrievedCounter, retrievedCounter2);
}
}

Expand All @@ -83,7 +83,7 @@ public void TestPrefixChangeReturnsNewCounter(){
var retrievedCounter2 = manager.getCounter(CollectorType.BUILD_SUCCESSFUL_COUNTER, label1, null);

// Should be a value reference comparison. They should not be the same since prefix changed
Assert.assertNotEquals(retrievedCounter, retrievedCounter2);
Assertions.assertNotEquals(retrievedCounter, retrievedCounter2);
}
}

Expand All @@ -98,7 +98,7 @@ public void TestDifferentCounterReturnsUniqueCounter(){
var retrievedCounter2 = manager.getCounter(CollectorType.BUILD_SUCCESSFUL_COUNTER, label1, null);

// Should be a value reference comparison. They should not be the same since the collector type differs.
Assert.assertNotEquals(retrievedCounter, retrievedCounter2);
Assertions.assertNotEquals(retrievedCounter, retrievedCounter2);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

public class JenkinsNodeBuildsSampleBuilderTest {
@Test
public void master_node_count_format() {
public void masterNodeCountFormat() {
assertEquals(
new Collector.MetricFamilySamples.Sample(
"jenkins_node_builds_count",
Expand All @@ -29,7 +29,7 @@ public void master_node_count_format() {
}

@Test
public void master_node_histogram_format() {
public void masterNodeHistogramFormat() {
assertEquals(
new Collector.MetricFamilySamples.Sample(
"jenkins_node_builds",
Expand All @@ -48,7 +48,7 @@ public void master_node_histogram_format() {
}

@Test
public void named_node_count_format() {
public void namedNodeCountFormat() {
assertEquals(
new Collector.MetricFamilySamples.Sample(
"jenkins_node_builds_count",
Expand Down

0 comments on commit f8c26ba

Please sign in to comment.