Skip to content

Commit

Permalink
General code cleanup (#1083)
Browse files Browse the repository at this point in the history
Signed-off-by: dhoard <[email protected]>
  • Loading branch information
dhoard authored Dec 4, 2024
1 parent 4e25f23 commit 3822110
Show file tree
Hide file tree
Showing 24 changed files with 49 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/github-pages.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 2 additions & 5 deletions collector/src/main/java/io/prometheus/jmx/JmxCollector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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());
}
Expand Down
4 changes: 2 additions & 2 deletions collector/src/main/java/io/prometheus/jmx/JmxScraper.java
Original file line number Diff line number Diff line change
Expand Up @@ -135,9 +135,9 @@ public void doScrape() throws Exception {
} else {
Map<String, Object> 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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import javax.management.ObjectName;

public interface BeanWithEnumMBean {
public State getState();

State getState();
}

class BeanWithEnum implements BeanWithEnumMBean {
Expand Down
5 changes: 3 additions & 2 deletions collector/src/test/java/io/prometheus/jmx/BoolMBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import javax.management.ObjectName;

public interface CassandraMBean {
public int getActiveCount();

int getActiveCount();
}

class Cassandra implements CassandraMBean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
import javax.management.ObjectName;

public interface HadoopDataNodeMXBean {
public Map<String, Map<String, Long>> getDatanodeNetworkCounts();

Map<String, Map<String, Long>> getDatanodeNetworkCounts();
}

class HadoopDataNode implements HadoopDataNodeMXBean {
Expand Down
3 changes: 2 additions & 1 deletion collector/src/test/java/io/prometheus/jmx/HadoopMBean.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import javax.management.ObjectName;

public interface HadoopMBean {
public int getreplaceBlockOpMinTime();

int getreplaceBlockOpMinTime();
}

class Hadoop implements HadoopMBean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,16 @@ 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
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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 2 additions & 3 deletions collector/src/test/java/io/prometheus/jmx/State.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@
*
* See <a
* href="http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html">http://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html</a>
* } or
*
* <p>or
*
* <p><a
* href="http://stackoverflow.com/questions/163360/regular-expresion-to-match-urls-in-java">http://stackoverflow.com/questions/163360/regular-expresion-to-match-urls-in-java</a>
Expand All @@ -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 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
import javax.management.ObjectName;

public interface TomcatServletMBean {
public int getRequestCount();

int getRequestCount();
}

class TomcatServlet implements TomcatServletMBean {
Expand Down
8 changes: 4 additions & 4 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -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
-----------
Expand All @@ -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
-----
Expand Down
2 changes: 1 addition & 1 deletion docs/data/menu/more.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public class RMIRegistrySSLDisabledTest {

@Verifyica.ArgumentSupplier(parallelism = Integer.MAX_VALUE)
public static Stream<ExporterTestEnvironment> 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ public OpenTelemetryExporter createOpenTelemetryExporter(
throw new IllegalArgumentException("exporterYamlFile is null");
}

OpenTelemetryExporter openTelemetryExporter = null;

try {
try (Reader reader = new FileReader(exporterYamlFile)) {
Map<Object, Object> yamlMap = new Yaml().load(reader);
Expand Down Expand Up @@ -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;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public void testEmpty() {
assertTrue(optional.get() instanceof Map);
map = (Map<Object, Object>) optional.get();
assertTrue(map.get("value") instanceof Integer);
assertTrue(((Integer) map.get("value")) == 1);
assertEquals(1, (int) ((Integer) map.get("value")));
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion jmx_prometheus_standalone/src/deb/bin/jmx_exporter
Original file line number Diff line number Diff line change
@@ -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 "$@"
6 changes: 3 additions & 3 deletions stress-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
(
while true;
do
DATE=`date`
DATE=$(date)
echo "STRESS-TEST-START ${DATE}"

export JAVA_DOCKER_IMAGES=all
Expand 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

0 comments on commit 3822110

Please sign in to comment.