Skip to content

Commit

Permalink
Merge pull request #716 from jenkinsci/maintenance/update-parent
Browse files Browse the repository at this point in the history
Updating parent pom version to 5.3. Removing deprecated classes usage
  • Loading branch information
Waschndolos authored Nov 30, 2024
2 parents 9957621 + d0e78ba commit a72036c
Show file tree
Hide file tree
Showing 26 changed files with 97 additions and 115 deletions.
62 changes: 0 additions & 62 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

1 change: 0 additions & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@ buildPlugin(
[platform: 'linux', jdk: 21],
[platform: 'windows', jdk: 21],
[platform: 'linux', jdk: 17],
[platform: 'linux', jdk: 11],
])
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>4.88</version>
<version>5.3</version>
<relativePath />
</parent>

Expand All @@ -20,7 +20,7 @@
<changelist>999999-SNAPSHOT</changelist>
<gitHubRepo>jenkinsci/prometheus-plugin</gitHubRepo>
<!-- when updated the io.jenkins.tools.bom:bom-X.Y.Z must be updated too -->
<jenkins.version>2.387.3</jenkins.version>
<jenkins.version>2.479</jenkins.version>

<prometheus.simpleclient.version>0.16.0</prometheus.simpleclient.version>
<slf4j.version>2.0.16</slf4j.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@
import java.io.IOException;
import java.nio.file.FileStore;
import java.nio.file.Files;
import java.util.*;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.util.List;

import static org.jenkinsci.plugins.prometheus.util.FlowNodes.getSortedStageNodes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import java.nio.file.FileStore;
import java.util.Objects;

import static org.jenkinsci.plugins.prometheus.collectors.CollectorType.*;
import static org.jenkinsci.plugins.prometheus.collectors.CollectorType.DISK_USAGE_BYTES_GAUGE;
import static org.jenkinsci.plugins.prometheus.collectors.CollectorType.DISK_USAGE_FILE_COUNT_GAUGE;
import static org.jenkinsci.plugins.prometheus.collectors.CollectorType.JOB_USAGE_BYTES_GAUGE;

public class DiskCollectorFactory extends BaseCollectorFactory {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jenkinsci.plugins.prometheus.config;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import hudson.Extension;
import hudson.util.FormValidation;
import jenkins.YesNoMaybe;
Expand All @@ -10,11 +11,10 @@
import org.jenkinsci.plugins.prometheus.config.disabledmetrics.DisabledMetricConfig;
import org.kohsuke.stapler.DataBoundSetter;
import org.kohsuke.stapler.QueryParameter;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import edu.umd.cs.findbugs.annotations.CheckForNull;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -80,7 +80,7 @@ public static PrometheusConfiguration get() {
}

@Override
public boolean configure(StaplerRequest req, JSONObject json) {
public boolean configure(StaplerRequest2 req, JSONObject json) {
disabledMetricConfig = null;
req.bindJSON(this, json);
save();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
import org.jenkinsci.plugins.prometheus.service.DefaultPrometheusMetrics;
import org.jenkinsci.plugins.prometheus.service.PrometheusMetrics;
import org.kohsuke.stapler.HttpResponse;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerResponse;
import org.kohsuke.stapler.StaplerRequest2;
import org.kohsuke.stapler.StaplerResponse2;

import java.io.IOException;

@Extension
public class PrometheusAction implements UnprotectedRootAction {
Expand All @@ -33,7 +35,7 @@ public String getUrlName() {
return PrometheusConfiguration.get().getUrlName();
}

public HttpResponse doDynamic(StaplerRequest request) {
public HttpResponse doDynamic(StaplerRequest2 request) {
if (request.getRestOfPath().equals(PrometheusConfiguration.get().getAdditionalPath())) {
if (hasAccess()) {
return prometheusResponse();
Expand All @@ -50,12 +52,16 @@ private boolean hasAccess() {
return true;
}


private HttpResponse prometheusResponse() {
return (request, response, node) -> {
response.setStatus(StaplerResponse.SC_OK);
response.setContentType(TextFormat.CONTENT_TYPE_004);
response.addHeader("Cache-Control", "must-revalidate,no-cache,no-store");
response.getWriter().write(prometheusMetrics.getMetrics());
return new HttpResponse() {
@Override
public void generateResponse(StaplerRequest2 request, StaplerResponse2 response, Object node) throws IOException {
response.setStatus(StaplerResponse2.SC_OK);
response.setContentType(TextFormat.CONTENT_TYPE_004);
response.addHeader("Cache-Control", "must-revalidate,no-cache,no-store");
response.getWriter().write(prometheusMetrics.getMetrics());
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;


@ExtendWith(MockitoExtension.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,16 @@

import static java.util.Objects.requireNonNull;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.empty;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.withSettings;

@ExtendWith(MockitoExtension.class)
public class DiskUsageCollectorTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
public class JenkinsStatusCollectorTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import org.junit.jupiter.api.Test;
import org.mockito.MockedStatic;

import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;

public class TestBasedMetricCollectorTest extends MockedRunCollectorTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedRunCollectorTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@
import hudson.console.AnnotatedLargeText;
import io.prometheus.client.Collector;
import org.jenkinsci.plugins.prometheus.collectors.testutils.MockedRunCollectorTest;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@

import java.util.Arrays;

import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;

public class CounterManagerTest extends MockedRunCollectorTest {
private final CounterManager manager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;

@SuppressWarnings("rawtypes")
public class FailedTestsGaugeTest extends MockedRunCollectorTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;

@SuppressWarnings("rawtypes")
public class SkippedTestsGaugeTest extends MockedRunCollectorTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;

@SuppressWarnings("rawtypes")
public class TotalTestsGaugeTest extends MockedRunCollectorTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import java.util.List;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.jenkinsci.plugins.prometheus.collectors.disk;

import com.cloudbees.simplediskusage.DiskItem;
import com.cloudbees.simplediskusage.JobDiskItem;
import io.prometheus.client.Collector;
import org.jenkinsci.plugins.prometheus.collectors.testutils.CollectorTest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.kohsuke.stapler.StaplerRequest;
import org.kohsuke.stapler.StaplerRequest2;
import org.mockito.Mockito;

import java.util.Arrays;
import java.util.List;

import static com.github.stefanbirkner.systemlambda.SystemLambda.withEnvironmentVariable;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
import static org.mockito.ArgumentMatchers.anyLong;

@SuppressWarnings("rawtypes")
public class PrometheusConfigurationTest {
Expand All @@ -34,7 +38,7 @@ private static List<String> wrongMetricCollectorPeriodsProvider() {
@MethodSource("wrongMetricCollectorPeriodsProvider")
public void shouldGetErrorWhenNotPositiveNumber(String metricCollectorPeriod) throws Descriptor.FormException {
//given
Mockito.when(configuration.configure(any(), any())).thenCallRealMethod();
Mockito.when(configuration.configure(any(StaplerRequest2.class), any())).thenCallRealMethod();
Mockito.when(configuration.doCheckCollectingMetricsPeriodInSeconds(any())).thenCallRealMethod();
JSONObject config = getDefaultConfig();
config.accumulate("collectingMetricsPeriodInSeconds", metricCollectorPeriod);
Expand All @@ -55,9 +59,10 @@ private static List<String> correctMetricCollectorPeriodsProvider() {
@MethodSource("correctMetricCollectorPeriodsProvider")
public void shouldReturnOk(String metricCollectorPeriod) throws Descriptor.FormException {
//given
Mockito.when(configuration.configure(any(), any())).thenCallRealMethod();
Mockito.when(configuration.configure(any(StaplerRequest2.class), any())).thenCallRealMethod();
Mockito.when(configuration.doCheckCollectingMetricsPeriodInSeconds(any())).thenCallRealMethod();
JSONObject config = getDefaultConfig();
StaplerRequest request = Mockito.mock(StaplerRequest.class);
StaplerRequest2 request = Mockito.mock(StaplerRequest2.class);
Mockito.doNothing().when(request).bindJSON(any(Object.class), any(JSONObject.class));
config.accumulate("collectingMetricsPeriodInSeconds", metricCollectorPeriod);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
import java.util.List;
import java.util.Set;

import static org.mockito.Mockito.*;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.when;

public class MetricStatusCheckerTest {

Expand Down
Loading

0 comments on commit a72036c

Please sign in to comment.