Skip to content

Commit 8d4073d

Browse files
authored
Fix logging of cluster state update descriptions (#34243)
In #28941 we changed the computation of cluster state task descriptions but this introduced a bug in which we only log the empty descriptions (rather than the non-empty ones). This change fixes that. Backport of #34182.
1 parent 0c16a79 commit 8d4073d

File tree

2 files changed

+63
-1
lines changed

2 files changed

+63
-1
lines changed

core/src/main/java/org/elasticsearch/cluster/ClusterStateTaskExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ default void clusterStatePublished(ClusterChangedEvent clusterChangedEvent) {
5555
* This allows groupd task description but the submitting source.
5656
*/
5757
default String describeTasks(List<T> tasks) {
58-
return String.join(", ", tasks.stream().map(t -> (CharSequence)t.toString()).filter(t -> t.length() == 0)::iterator);
58+
return String.join(", ", tasks.stream().map(t -> (CharSequence)t.toString()).filter(t -> t.length() > 0)::iterator);
5959
}
6060

6161
/**
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Licensed to Elasticsearch under one or more contributor
3+
* license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright
5+
* ownership. Elasticsearch licenses this file to you under
6+
* the Apache License, Version 2.0 (the "License"); you may
7+
* not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.elasticsearch.cluster;
20+
21+
import org.elasticsearch.test.ESTestCase;
22+
23+
import java.util.Arrays;
24+
import java.util.Collections;
25+
26+
import static org.hamcrest.Matchers.equalTo;
27+
28+
public class ClusterStateTaskExecutorTests extends ESTestCase {
29+
30+
private class TestTask {
31+
private final String description;
32+
33+
TestTask(String description) {
34+
this.description = description;
35+
}
36+
37+
@Override
38+
public String toString() {
39+
return description == null ? "" : "Task{" + description + "}";
40+
}
41+
}
42+
43+
public void testDescribeTasks() {
44+
final ClusterStateTaskExecutor<TestTask> executor = (currentState, tasks) -> {
45+
throw new AssertionError("should not be called");
46+
};
47+
48+
assertThat("describes an empty list", executor.describeTasks(Collections.emptyList()), equalTo(""));
49+
assertThat("describes a singleton list", executor.describeTasks(Collections.singletonList(new TestTask("a task"))),
50+
equalTo("Task{a task}"));
51+
assertThat("describes a list of two tasks",
52+
executor.describeTasks(Arrays.asList(new TestTask("a task"), new TestTask("another task"))),
53+
equalTo("Task{a task}, Task{another task}"));
54+
55+
assertThat("skips the only item if it has no description", executor.describeTasks(Collections.singletonList(new TestTask(null))),
56+
equalTo(""));
57+
assertThat("skips an item if it has no description",
58+
executor.describeTasks(Arrays.asList(
59+
new TestTask("a task"), new TestTask(null), new TestTask("another task"), new TestTask(null))),
60+
equalTo("Task{a task}, Task{another task}"));
61+
}
62+
}

0 commit comments

Comments
 (0)