Skip to content

Commit 1307fb1

Browse files
committed
Fix line length for monitor and remove suppressions (#37456)
Relates #34884
1 parent 3d80786 commit 1307fb1

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

buildSrc/src/main/resources/checkstyle_suppressions.xml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@
4848

4949
<!-- Hopefully temporary suppression of LineLength on files that don't pass it. We should remove these when we the
5050
files start to pass. -->
51-
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]monitor[/\\]jvm[/\\]GcNames.java" checks="LineLength" />
52-
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]monitor[/\\]jvm[/\\]HotThreads.java" checks="LineLength" />
5351
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]node[/\\]Node.java" checks="LineLength" />
5452
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]script[/\\]ScriptService.java" checks="LineLength" />
5553
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]MultiValueMode.java" checks="LineLength" />
@@ -95,9 +93,7 @@
9593
<suppress files="server[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]suggest[/\\]phrase[/\\]WordScorer.java" checks="LineLength" />
9694
<suppress files="modules[/\\]tribe[/\\]src[/\\]main[/\\]java[/\\]org[/\\]elasticsearch[/\\]tribe[/\\]TribeService.java" checks="LineLength" />
9795
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]aliases[/\\]IndexAliasesIT.java" checks="LineLength" />
98-
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]monitor[/\\]jvm[/\\]JvmGcMonitorServiceSettingsTests.java" checks="LineLength" />
9996
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]indexing[/\\]IndexActionIT.java" checks="LineLength" />
100-
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]monitor[/\\]jvm[/\\]JvmGcMonitorServiceSettingsTests.java" checks="LineLength" />
10197
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]MultiValueModeTests.java" checks="LineLength" />
10298
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]SearchWithRejectionsIT.java" checks="LineLength" />
10399
<suppress files="server[/\\]src[/\\]test[/\\]java[/\\]org[/\\]elasticsearch[/\\]search[/\\]aggregations[/\\]MissingValueIT.java" checks="LineLength" />

server/src/main/java/org/elasticsearch/monitor/jvm/GcNames.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,16 @@ public class GcNames {
2929
* Resolves the GC type by its memory pool name ({@link java.lang.management.MemoryPoolMXBean#getName()}.
3030
*/
3131
public static String getByMemoryPoolName(String poolName, String defaultName) {
32-
if ("Eden Space".equals(poolName) || "PS Eden Space".equals(poolName) || "Par Eden Space".equals(poolName) || "G1 Eden Space".equals(poolName)) {
32+
if ("Eden Space".equals(poolName) || "PS Eden Space".equals(poolName)
33+
|| "Par Eden Space".equals(poolName) || "G1 Eden Space".equals(poolName)) {
3334
return YOUNG;
3435
}
35-
if ("Survivor Space".equals(poolName) || "PS Survivor Space".equals(poolName) || "Par Survivor Space".equals(poolName) || "G1 Survivor Space".equals(poolName)) {
36+
if ("Survivor Space".equals(poolName) || "PS Survivor Space".equals(poolName)
37+
|| "Par Survivor Space".equals(poolName) || "G1 Survivor Space".equals(poolName)) {
3638
return SURVIVOR;
3739
}
38-
if ("Tenured Gen".equals(poolName) || "PS Old Gen".equals(poolName) || "CMS Old Gen".equals(poolName) || "G1 Old Gen".equals(poolName)) {
40+
if ("Tenured Gen".equals(poolName) || "PS Old Gen".equals(poolName)
41+
|| "CMS Old Gen".equals(poolName) || "G1 Old Gen".equals(poolName)) {
3942
return OLD;
4043
}
4144
return defaultName;
@@ -45,7 +48,8 @@ public static String getByGcName(String gcName, String defaultName) {
4548
if ("Copy".equals(gcName) || "PS Scavenge".equals(gcName) || "ParNew".equals(gcName) || "G1 Young Generation".equals(gcName)) {
4649
return YOUNG;
4750
}
48-
if ("MarkSweepCompact".equals(gcName) || "PS MarkSweep".equals(gcName) || "ConcurrentMarkSweep".equals(gcName) || "G1 Old Generation".equals(gcName)) {
51+
if ("MarkSweepCompact".equals(gcName) || "PS MarkSweep".equals(gcName)
52+
|| "ConcurrentMarkSweep".equals(gcName) || "G1 Old Generation".equals(gcName)) {
4953
return OLD;
5054
}
5155
return defaultName;

server/src/main/java/org/elasticsearch/monitor/jvm/HotThreads.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,8 @@ private String innerDetect() throws Exception {
234234
continue; // thread is not alive yet or died before the first snapshot - ignore it!
235235
}
236236
double percent = (((double) time) / interval.nanos()) * 100;
237-
sb.append(String.format(Locale.ROOT, "%n%4.1f%% (%s out of %s) %s usage by thread '%s'%n", percent, TimeValue.timeValueNanos(time), interval, type, threadName));
237+
sb.append(String.format(Locale.ROOT, "%n%4.1f%% (%s out of %s) %s usage by thread '%s'%n",
238+
percent, TimeValue.timeValueNanos(time), interval, type, threadName));
238239
// for each snapshot (2nd array index) find later snapshot for same thread with max number of
239240
// identical StackTraceElements (starting from end of each)
240241
boolean[] done = new boolean[threadElementsSnapshotCount];
@@ -267,7 +268,8 @@ private String innerDetect() throws Exception {
267268
sb.append(String.format(Locale.ROOT, " %s%n", show[l]));
268269
}
269270
} else {
270-
sb.append(String.format(Locale.ROOT, " %d/%d snapshots sharing following %d elements%n", count, threadElementsSnapshotCount, maxSim));
271+
sb.append(String.format(Locale.ROOT, " %d/%d snapshots sharing following %d elements%n",
272+
count, threadElementsSnapshotCount, maxSim));
271273
for (int l = show.length - maxSim; l < show.length; l++) {
272274
sb.append(String.format(Locale.ROOT, " %s%n", show[l]));
273275
}

server/src/test/java/org/elasticsearch/monitor/jvm/JvmGcMonitorServiceSettingsTests.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public void testNegativeSetting() throws InterruptedException {
6565
Settings settings = Settings.builder().put("monitor.jvm.gc.collector." + collector + ".warn", "-" + randomTimeValue()).build();
6666
execute(settings, (command, interval, name) -> null, e -> {
6767
assertThat(e, instanceOf(IllegalArgumentException.class));
68-
assertThat(e.getMessage(), allOf(containsString("invalid gc_threshold"), containsString("for [monitor.jvm.gc.collector." + collector + ".")));
68+
assertThat(e.getMessage(), allOf(containsString("invalid gc_threshold"),
69+
containsString("for [monitor.jvm.gc.collector." + collector + ".")));
6970
}, true, null);
7071
}
7172

@@ -78,8 +79,9 @@ public void testMissingSetting() throws InterruptedException {
7879
Settings.Builder builder = Settings.builder();
7980

8081
// drop a random setting or two
81-
for (@SuppressWarnings("unchecked") AbstractMap.SimpleEntry<String, String> entry : randomSubsetOf(randomIntBetween(1, 2), entries.toArray(new AbstractMap.SimpleEntry[0]))) {
82-
builder.put(entry.getKey(), entry.getValue());
82+
for (@SuppressWarnings("unchecked") AbstractMap.SimpleEntry<String, String> entry : randomSubsetOf(randomIntBetween(1, 2),
83+
entries.toArray(new AbstractMap.SimpleEntry[0]))) {
84+
builder.put(entry.getKey(), entry.getValue());
8385
}
8486

8587
// we should get an exception that a setting is missing
@@ -115,25 +117,31 @@ public void testIllegalOverheadSettings() throws InterruptedException {
115117
infoWarnOutOfOrderBuilder.put("monitor.jvm.gc.overhead.warn", warn);
116118
execute(infoWarnOutOfOrderBuilder.build(), (command, interval, name) -> null, e -> {
117119
assertThat(e, instanceOf(IllegalArgumentException.class));
118-
assertThat(e.getMessage(), containsString("[monitor.jvm.gc.overhead.warn] must be greater than [monitor.jvm.gc.overhead.info] [" + info + "] but was [" + warn + "]"));
120+
assertThat(e.getMessage(), containsString("[monitor.jvm.gc.overhead.warn] must be greater than "
121+
+ "[monitor.jvm.gc.overhead.info] [" + info + "] but was [" + warn + "]"));
119122
}, true, null);
120123

121124
final Settings.Builder debugInfoOutOfOrderBuilder = Settings.builder();
122125
debugInfoOutOfOrderBuilder.put("monitor.jvm.gc.overhead.info", info);
123126
final int debug = randomIntBetween(info + 1, 99);
124127
debugInfoOutOfOrderBuilder.put("monitor.jvm.gc.overhead.debug", debug);
125-
debugInfoOutOfOrderBuilder.put("monitor.jvm.gc.overhead.warn", randomIntBetween(debug + 1, 100)); // or the test will fail for the wrong reason
128+
debugInfoOutOfOrderBuilder.put("monitor.jvm.gc.overhead.warn",
129+
randomIntBetween(debug + 1, 100)); // or the test will fail for the wrong reason
126130
execute(debugInfoOutOfOrderBuilder.build(), (command, interval, name) -> null, e -> {
127131
assertThat(e, instanceOf(IllegalArgumentException.class));
128-
assertThat(e.getMessage(), containsString("[monitor.jvm.gc.overhead.info] must be greater than [monitor.jvm.gc.overhead.debug] [" + debug + "] but was [" + info + "]"));
132+
assertThat(e.getMessage(), containsString("[monitor.jvm.gc.overhead.info] must be greater than "
133+
+ "[monitor.jvm.gc.overhead.debug] [" + debug + "] but was [" + info + "]"));
129134
}, true, null);
130135
}
131136

132-
private static void execute(Settings settings, TriFunction<Runnable, TimeValue, String, Cancellable> scheduler, Runnable asserts) throws InterruptedException {
137+
private static void execute(Settings settings, TriFunction<Runnable, TimeValue, String, Cancellable> scheduler,
138+
Runnable asserts) throws InterruptedException {
133139
execute(settings, scheduler, null, false, asserts);
134140
}
135141

136-
private static void execute(Settings settings, TriFunction<Runnable, TimeValue, String, Cancellable> scheduler, Consumer<Throwable> consumer, boolean constructionShouldFail, Runnable asserts) throws InterruptedException {
142+
private static void execute(Settings settings, TriFunction<Runnable, TimeValue, String, Cancellable> scheduler,
143+
Consumer<Throwable> consumer, boolean constructionShouldFail,
144+
Runnable asserts) throws InterruptedException {
137145
assert constructionShouldFail == (consumer != null);
138146
assert constructionShouldFail == (asserts == null);
139147
ThreadPool threadPool = null;

0 commit comments

Comments
 (0)