diff --git a/.github/workflows/github-pages.yaml b/.github/workflows/github-pages.yaml index f9cf8d8e..eb4cfe84 100644 --- a/.github/workflows/github-pages.yaml +++ b/.github/workflows/github-pages.yaml @@ -1,4 +1,4 @@ -name: Deploy Documentation to Github Pages +name: Deploy Documentation to GitHub Pages on: # Runs on pushes targeting the 1.0.x branch diff --git a/collector/src/main/java/io/prometheus/jmx/JmxCollector.java b/collector/src/main/java/io/prometheus/jmx/JmxCollector.java index f1a3f989..9123a364 100644 --- a/collector/src/main/java/io/prometheus/jmx/JmxCollector.java +++ b/collector/src/main/java/io/prometheus/jmx/JmxCollector.java @@ -94,10 +94,9 @@ private static class Config { MatchedRulesCache rulesCache; } - private PrometheusRegistry prometheusRegistry; private Config config; private File configFile; - private long createTimeNanoSecs = System.nanoTime(); + private final long createTimeNanoSecs = System.nanoTime(); private Counter configReloadSuccess; private Counter configReloadFailure; @@ -172,8 +171,6 @@ public JmxCollector register() { * @return the JmxCollector */ public JmxCollector register(PrometheusRegistry prometheusRegistry) { - this.prometheusRegistry = prometheusRegistry; - configReloadSuccess = Counter.builder() .name("jmx_config_reload_success_total") @@ -514,7 +511,7 @@ private MatchedRule defaultExport( String type) { StringBuilder name = new StringBuilder(); name.append(domain); - if (beanProperties.size() > 0) { + if (!beanProperties.isEmpty()) { name.append(SEP); name.append(beanProperties.values().iterator().next()); } diff --git a/collector/src/main/java/io/prometheus/jmx/JmxScraper.java b/collector/src/main/java/io/prometheus/jmx/JmxScraper.java index 16f00b82..54e40af6 100644 --- a/collector/src/main/java/io/prometheus/jmx/JmxScraper.java +++ b/collector/src/main/java/io/prometheus/jmx/JmxScraper.java @@ -135,9 +135,9 @@ public void doScrape() throws Exception { } else { Map environment = new HashMap<>(); if (username != null - && username.length() != 0 + && !username.isEmpty() && password != null - && password.length() != 0) { + && !password.isEmpty()) { String[] credent = new String[] {username, password}; environment.put(javax.management.remote.JMXConnector.CREDENTIALS, credent); } diff --git a/collector/src/test/java/io/prometheus/jmx/BeanWithEnumMBean.java b/collector/src/test/java/io/prometheus/jmx/BeanWithEnumMBean.java index c13ea68b..e2913677 100644 --- a/collector/src/test/java/io/prometheus/jmx/BeanWithEnumMBean.java +++ b/collector/src/test/java/io/prometheus/jmx/BeanWithEnumMBean.java @@ -20,7 +20,8 @@ import javax.management.ObjectName; public interface BeanWithEnumMBean { - public State getState(); + + State getState(); } class BeanWithEnum implements BeanWithEnumMBean { diff --git a/collector/src/test/java/io/prometheus/jmx/BoolMBean.java b/collector/src/test/java/io/prometheus/jmx/BoolMBean.java index f277181f..01f2b818 100644 --- a/collector/src/test/java/io/prometheus/jmx/BoolMBean.java +++ b/collector/src/test/java/io/prometheus/jmx/BoolMBean.java @@ -20,9 +20,10 @@ import javax.management.ObjectName; public interface BoolMBean { - public boolean getTrue(); - public boolean getFalse(); + boolean getTrue(); + + boolean getFalse(); } class Bool implements BoolMBean { diff --git a/collector/src/test/java/io/prometheus/jmx/CassandraMBean.java b/collector/src/test/java/io/prometheus/jmx/CassandraMBean.java index 561abd11..ab07903c 100644 --- a/collector/src/test/java/io/prometheus/jmx/CassandraMBean.java +++ b/collector/src/test/java/io/prometheus/jmx/CassandraMBean.java @@ -20,7 +20,8 @@ import javax.management.ObjectName; public interface CassandraMBean { - public int getActiveCount(); + + int getActiveCount(); } class Cassandra implements CassandraMBean { diff --git a/collector/src/test/java/io/prometheus/jmx/CassandraMetricsMBean.java b/collector/src/test/java/io/prometheus/jmx/CassandraMetricsMBean.java index 5a017ec4..e98c9ee4 100644 --- a/collector/src/test/java/io/prometheus/jmx/CassandraMetricsMBean.java +++ b/collector/src/test/java/io/prometheus/jmx/CassandraMetricsMBean.java @@ -23,7 +23,8 @@ public interface CassandraMetricsMBean { // This how yammer's metrics // http://www.javacodegeeks.com/2012/12/yammer-metrics-a-new-way-to-monitor-your-application.html // look through JMX. - public float getValue(); + + float getValue(); } class CassandraMetrics implements CassandraMetricsMBean { diff --git a/collector/src/test/java/io/prometheus/jmx/HadoopDataNodeMXBean.java b/collector/src/test/java/io/prometheus/jmx/HadoopDataNodeMXBean.java index c61f3c5a..84bd7772 100644 --- a/collector/src/test/java/io/prometheus/jmx/HadoopDataNodeMXBean.java +++ b/collector/src/test/java/io/prometheus/jmx/HadoopDataNodeMXBean.java @@ -22,7 +22,8 @@ import javax.management.ObjectName; public interface HadoopDataNodeMXBean { - public Map> getDatanodeNetworkCounts(); + + Map> getDatanodeNetworkCounts(); } class HadoopDataNode implements HadoopDataNodeMXBean { diff --git a/collector/src/test/java/io/prometheus/jmx/HadoopMBean.java b/collector/src/test/java/io/prometheus/jmx/HadoopMBean.java index 3db89e45..41ba3200 100644 --- a/collector/src/test/java/io/prometheus/jmx/HadoopMBean.java +++ b/collector/src/test/java/io/prometheus/jmx/HadoopMBean.java @@ -20,7 +20,8 @@ import javax.management.ObjectName; public interface HadoopMBean { - public int getreplaceBlockOpMinTime(); + + int getreplaceBlockOpMinTime(); } class Hadoop implements HadoopMBean { diff --git a/collector/src/test/java/io/prometheus/jmx/JmxMBeanPropertyCacheTest.java b/collector/src/test/java/io/prometheus/jmx/JmxMBeanPropertyCacheTest.java index e8f95c00..68c21b39 100644 --- a/collector/src/test/java/io/prometheus/jmx/JmxMBeanPropertyCacheTest.java +++ b/collector/src/test/java/io/prometheus/jmx/JmxMBeanPropertyCacheTest.java @@ -165,8 +165,8 @@ public void testRemoveOneOfMultipleObjects() throws Throwable { keepSet.add(mBean3); testCache.onlyKeepMBeans(keepSet); assertEquals(2, testCache.getKeyPropertiesPerBean().size()); - assertTrue(testCache.getKeyPropertiesPerBean().keySet().contains(mBean2)); - assertTrue(testCache.getKeyPropertiesPerBean().keySet().contains(mBean3)); + assertTrue(testCache.getKeyPropertiesPerBean().containsKey(mBean2)); + assertTrue(testCache.getKeyPropertiesPerBean().containsKey(mBean3)); } @Test @@ -174,7 +174,7 @@ public void testRemoveEmptyIdempotent() throws Throwable { JmxMBeanPropertyCache testCache = new JmxMBeanPropertyCache(); testCache.onlyKeepMBeans(Collections.emptySet()); testCache.onlyKeepMBeans(Collections.emptySet()); - assertEquals(testCache.getKeyPropertiesPerBean().size(), 0); + assertEquals(0, testCache.getKeyPropertiesPerBean().size()); } private void assertSameElementsAndOrder(LinkedHashMap actual, Object... expected) { diff --git a/collector/src/test/java/io/prometheus/jmx/PrometheusRegistryUtils.java b/collector/src/test/java/io/prometheus/jmx/PrometheusRegistryUtils.java index 6f26aa70..1079b7bc 100644 --- a/collector/src/test/java/io/prometheus/jmx/PrometheusRegistryUtils.java +++ b/collector/src/test/java/io/prometheus/jmx/PrometheusRegistryUtils.java @@ -27,8 +27,7 @@ import java.util.function.Consumer; import java.util.function.Predicate; -/** Class to get a sample value from a PrometheusRegistery */ -@SuppressWarnings("unchecked") +/** Class to get a sample value from a PrometheusRegistry */ public class PrometheusRegistryUtils { private final PrometheusRegistry prometheusRegistry; diff --git a/collector/src/test/java/io/prometheus/jmx/State.java b/collector/src/test/java/io/prometheus/jmx/State.java index 375d8d25..72204458 100644 --- a/collector/src/test/java/io/prometheus/jmx/State.java +++ b/collector/src/test/java/io/prometheus/jmx/State.java @@ -20,9 +20,8 @@ public enum State { RUNNING(1, 2), TERMINATED(2, 3); - private int valueOne; - - private int valueTwo; + private final int valueOne; + private final int valueTwo; State(int valueOne, int valueTwo) { this.valueOne = valueOne; diff --git a/collector/src/test/java/io/prometheus/jmx/TomcatPatternCheckTest.java b/collector/src/test/java/io/prometheus/jmx/TomcatPatternCheckTest.java index ddf332d5..c38bf670 100644 --- a/collector/src/test/java/io/prometheus/jmx/TomcatPatternCheckTest.java +++ b/collector/src/test/java/io/prometheus/jmx/TomcatPatternCheckTest.java @@ -31,7 +31,8 @@ * * See http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html - * } or + * + *

or * *

http://stackoverflow.com/questions/163360/regular-expresion-to-match-urls-in-java @@ -40,6 +41,7 @@ public class TomcatPatternCheckTest { private static final Pattern VALID_TOMCAT_PATH = Pattern.compile("//([-a-zA-Z0-9+&@#/%?=~_|!:,.;]*[-a-zA-Z0-9+&@#/%=~_|])"); + private static final Pattern VALID_SERVLET_NAME = Pattern.compile("([-a-zA-Z0-9+/$%~_-|!.]*)"); private static final Pattern VALID_WEBMODULE = diff --git a/collector/src/test/java/io/prometheus/jmx/TomcatServletMBean.java b/collector/src/test/java/io/prometheus/jmx/TomcatServletMBean.java index 00fe46ec..bd794e6a 100644 --- a/collector/src/test/java/io/prometheus/jmx/TomcatServletMBean.java +++ b/collector/src/test/java/io/prometheus/jmx/TomcatServletMBean.java @@ -20,7 +20,8 @@ import javax.management.ObjectName; public interface TomcatServletMBean { - public int getRequestCount(); + + int getRequestCount(); } class TomcatServlet implements TomcatServletMBean { diff --git a/docs/README.md b/docs/README.md index db305e94..da12853b 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,7 +1,7 @@ Docs ---- -This directory contains [hugo](https://gohugo.io) documentation to be published in Github pages. +This directory contains [hugo](https://gohugo.io) documentation to be published in GitHub pages. Run Locally ----------- @@ -12,15 +12,15 @@ hugo server -D This will serve the docs on [http://localhost:1313](http://localhost:1313). -Deploy to Github Pages +Deploy to GitHub Pages ---------------------- -Changes to the `main` branch will be deployed automatically with Github actions. +Changes to the `main` branch will be deployed automatically with GitHub actions. Update Geekdocs --------------- -The docs use the [Geekdocs](https://geekdocs.de/) theme. The theme is checked in to Github in the `./docs/themes/hugo-geekdoc/` folder. To update [Geekdocs](https://geekdocs.de/), remove the current folder and create a new one with the latest [release](https://github.com/thegeeklab/hugo-geekdoc/releases). There are no local modifications in `./docs/themes/hugo-geekdoc/`. +The docs use the [Geekdocs](https://geekdocs.de/) theme. The theme is checked in to GitHub in the `./docs/themes/hugo-geekdoc/` folder. To update [Geekdocs](https://geekdocs.de/), remove the current folder and create a new one with the latest [release](https://github.com/thegeeklab/hugo-geekdoc/releases). There are no local modifications in `./docs/themes/hugo-geekdoc/`. Notes ----- diff --git a/docs/data/menu/more.yaml b/docs/data/menu/more.yaml index cb3ece7f..558e0529 100644 --- a/docs/data/menu/more.yaml +++ b/docs/data/menu/more.yaml @@ -4,7 +4,7 @@ more: ref: "https://github.com/prometheus/jmx_exporter/releases" external: true icon: "gdoc_download" - - name: Github + - name: GitHub ref: "https://github.com/prometheus/jmx_exporter" external: true icon: "gdoc_github" diff --git a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/metrics/MetricsParser.java b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/metrics/MetricsParser.java index cc01a917..15844c8c 100644 --- a/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/metrics/MetricsParser.java +++ b/integration_test_suite/integration_tests/src/main/java/io/prometheus/jmx/test/support/metrics/MetricsParser.java @@ -235,7 +235,7 @@ private static String readMetricLine(LineReader lineReader) throws IOException { * @param typeLine typeLine * @param help help * @param metricLine metricLine - * @return + * @return a Metric */ private static Metric createMetric(String typeLine, String help, String metricLine) { String name; diff --git a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/rmi/ssl/RMIRegistrySSLDisabledTest.java b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/rmi/ssl/RMIRegistrySSLDisabledTest.java index 0adc22cf..31e66654 100644 --- a/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/rmi/ssl/RMIRegistrySSLDisabledTest.java +++ b/integration_test_suite/integration_tests/src/test/java/io/prometheus/jmx/test/rmi/ssl/RMIRegistrySSLDisabledTest.java @@ -45,7 +45,7 @@ public class RMIRegistrySSLDisabledTest { @Verifyica.ArgumentSupplier(parallelism = Integer.MAX_VALUE) public static Stream arguments() { - // Filter the arguments.. + // Filter the arguments ... // // 1. only run the Standalone exporter // 2. filter out the GraalVM 1.8 JVM - exception is that SunJSSE is not found diff --git a/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/opentelemetry/OpenTelemetryExporterFactory.java b/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/opentelemetry/OpenTelemetryExporterFactory.java index 78ca3bf3..7b86cb47 100644 --- a/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/opentelemetry/OpenTelemetryExporterFactory.java +++ b/jmx_prometheus_common/src/main/java/io/prometheus/jmx/common/opentelemetry/OpenTelemetryExporterFactory.java @@ -45,8 +45,6 @@ public OpenTelemetryExporter createOpenTelemetryExporter( throw new IllegalArgumentException("exporterYamlFile is null"); } - OpenTelemetryExporter openTelemetryExporter = null; - try { try (Reader reader = new FileReader(exporterYamlFile)) { Map yamlMap = new Yaml().load(reader); @@ -161,14 +159,12 @@ public OpenTelemetryExporter createOpenTelemetryExporter( }); } - openTelemetryExporter = openTelemetryExporterBuilder.buildAndStart(); + return openTelemetryExporterBuilder.buildAndStart(); } } catch (IOException e) { throw new ConfigurationException( format("Exception loading file [%s]", exporterYamlFile), e); } - - return openTelemetryExporter; } /** diff --git a/jmx_prometheus_common/src/test/java/io/prometheus/jmx/common/http/authenticator/CredentialsTest.java b/jmx_prometheus_common/src/test/java/io/prometheus/jmx/common/http/authenticator/CredentialsTest.java index 574464b1..f5f9ebcf 100644 --- a/jmx_prometheus_common/src/test/java/io/prometheus/jmx/common/http/authenticator/CredentialsTest.java +++ b/jmx_prometheus_common/src/test/java/io/prometheus/jmx/common/http/authenticator/CredentialsTest.java @@ -16,8 +16,8 @@ package io.prometheus.jmx.common.http.authenticator; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; import org.junit.Test; @@ -31,7 +31,7 @@ public void testEquals() { Credentials credentials1 = new Credentials(username, password); Credentials credentials2 = new Credentials(username, password); - assertTrue(credentials1.equals(credentials2)); + assertEquals(credentials1, credentials2); } @Test @@ -42,6 +42,6 @@ public void testList() { Credentials credentials1 = new Credentials(username, password); Credentials credentials2 = new Credentials(username, password + "X"); - assertFalse(credentials1.equals(credentials2)); + assertNotEquals(credentials1, credentials2); } } diff --git a/jmx_prometheus_common/src/test/java/io/prometheus/jmx/common/http/authenticator/MessageDigestAuthenticatorTest.java b/jmx_prometheus_common/src/test/java/io/prometheus/jmx/common/http/authenticator/MessageDigestAuthenticatorTest.java index 41ca5ed7..58c21e3f 100644 --- a/jmx_prometheus_common/src/test/java/io/prometheus/jmx/common/http/authenticator/MessageDigestAuthenticatorTest.java +++ b/jmx_prometheus_common/src/test/java/io/prometheus/jmx/common/http/authenticator/MessageDigestAuthenticatorTest.java @@ -18,8 +18,8 @@ import static org.junit.Assert.assertEquals; -import java.io.UnsupportedEncodingException; import java.math.BigInteger; +import java.nio.charset.StandardCharsets; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import org.junit.Test; @@ -71,9 +71,9 @@ public void test_upperCase() throws Exception { } private static String hash(String algorithm, String value, String salt) - throws NoSuchAlgorithmException, UnsupportedEncodingException { + throws NoSuchAlgorithmException { MessageDigest digest = MessageDigest.getInstance(algorithm); - byte[] hashedBytes = digest.digest((salt + ":" + value).getBytes("UTF-8")); + byte[] hashedBytes = digest.digest((salt + ":" + value).getBytes(StandardCharsets.UTF_8)); BigInteger number = new BigInteger(1, hashedBytes); return number.toString(16).toLowerCase(); } diff --git a/jmx_prometheus_common/src/test/java/io/prometheus/jmx/common/yaml/YamlMapAccessorTest.java b/jmx_prometheus_common/src/test/java/io/prometheus/jmx/common/yaml/YamlMapAccessorTest.java index f8956fc0..7b8c7179 100644 --- a/jmx_prometheus_common/src/test/java/io/prometheus/jmx/common/yaml/YamlMapAccessorTest.java +++ b/jmx_prometheus_common/src/test/java/io/prometheus/jmx/common/yaml/YamlMapAccessorTest.java @@ -230,7 +230,7 @@ public void testEmpty() { assertTrue(optional.get() instanceof Map); map = (Map) optional.get(); assertTrue(map.get("value") instanceof Integer); - assertTrue(((Integer) map.get("value")) == 1); + assertEquals(1, (int) ((Integer) map.get("value"))); } @Test diff --git a/jmx_prometheus_standalone/src/deb/bin/jmx_exporter b/jmx_prometheus_standalone/src/deb/bin/jmx_exporter index 906808e2..32ee8494 100755 --- a/jmx_prometheus_standalone/src/deb/bin/jmx_exporter +++ b/jmx_prometheus_standalone/src/deb/bin/jmx_exporter @@ -1,3 +1,3 @@ #!/bin/sh -exec java -jar /usr/share/jmx_exporter/jmx_prometheus_standalone-*.jar $@ +exec java -jar /usr/share/jmx_exporter/jmx_prometheus_standalone-*.jar "$@" diff --git a/stress-test.sh b/stress-test.sh index b4936a45..83f82032 100755 --- a/stress-test.sh +++ b/stress-test.sh @@ -24,7 +24,7 @@ ( while true; do - DATE=`date` + DATE=$(date) echo "STRESS-TEST-START ${DATE}" export JAVA_DOCKER_IMAGES=all @@ -33,12 +33,12 @@ ./mvnw clean verify if [[ "$?" -ne 0 ]]; then - DATE=`date` + DATE=$(date) echo "STRESS-TEST-FAILED ${DATE}" break fi - DATE=`date` + DATE=$(date) echo "STRESS-TEST-FINISHED ${DATE}" done ) 2>&1 | tee stress-test.log