Skip to content

Commit 3a8ac86

Browse files
ES-10037 Periodic logging in autosharding service
This enhances `DataStreamAutoShardingService` so that it periodically logs at `INFO` level the most 'interesting' results it has produced in the last period. In this PR, the most 'interesting' results are considered to be the ones with the highest load, keeping track separately of the top 10 which resulting in an increase decision and the top 10 which did not. In practice, increase recommendations are sufficiently rare that the top 10 will often be 'all of them', and they are all potentially interesting (but we cap it to protect against taking up an unbounded amount of memory). We keep the high load non-increase recommendations as well, since these are likely to be the interesting ones to look at when investigating why some data stream did not get an increase shards recommendation when we might have expected it. The mechanism would be easily extended to add in other categories. The existing `DEBUG` and `TRACE` log lines in the service are replaced with a single `DEBUG` log which pulls together all the data. This is an improvement, since at the moment it is hard to figure out from the logs which lines refer to the same data stream (they are interleaved, and don't all include the data stream name). The write load field in the `AutoShardingResult` was unused, and is removed.
1 parent 483f979 commit 3a8ac86

File tree

5 files changed

+774
-229
lines changed

5 files changed

+774
-229
lines changed

server/src/main/java/org/elasticsearch/action/datastreams/autosharding/AutoShardingResult.java

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
package org.elasticsearch.action.datastreams.autosharding;
1111

12-
import org.elasticsearch.core.Nullable;
12+
import org.elasticsearch.common.Strings;
1313
import org.elasticsearch.core.TimeValue;
1414

1515
import java.util.Arrays;
@@ -25,13 +25,7 @@
2525
* {@link DataStreamAutoShardingService#DATA_STREAMS_AUTO_SHARDING_EXCLUDES_SETTING}) the target number of shards will be -1 and cool down
2626
* remaining {@link TimeValue#MAX_VALUE}.
2727
*/
28-
public record AutoShardingResult(
29-
AutoShardingType type,
30-
int currentNumberOfShards,
31-
int targetNumberOfShards,
32-
TimeValue coolDownRemaining,
33-
@Nullable Double writeLoad
34-
) {
28+
public record AutoShardingResult(AutoShardingType type, int currentNumberOfShards, int targetNumberOfShards, TimeValue coolDownRemaining) {
3529

3630
static final String COOLDOWN_PREVENTING_TYPES = Arrays.toString(
3731
new AutoShardingType[] { COOLDOWN_PREVENTED_DECREASE, COOLDOWN_PREVENTED_INCREASE }
@@ -53,8 +47,36 @@ public record AutoShardingResult(
5347
AutoShardingType.NOT_APPLICABLE,
5448
-1,
5549
-1,
56-
TimeValue.MAX_VALUE,
57-
null
50+
TimeValue.MAX_VALUE
5851
);
5952

53+
@Override
54+
public String toString() {
55+
return switch (type) {
56+
case INCREASE_SHARDS -> Strings.format(
57+
"Recommendation to increase shards from %d to %d",
58+
currentNumberOfShards,
59+
targetNumberOfShards
60+
);
61+
case DECREASE_SHARDS -> Strings.format(
62+
"Recommendation to decrease shards from %d to %d",
63+
currentNumberOfShards,
64+
targetNumberOfShards
65+
);
66+
case COOLDOWN_PREVENTED_INCREASE -> Strings.format(
67+
"Deferred recommendation to increase shards from %d to %d after cooldown period %s",
68+
currentNumberOfShards,
69+
targetNumberOfShards,
70+
coolDownRemaining
71+
);
72+
case COOLDOWN_PREVENTED_DECREASE -> Strings.format(
73+
"Deferred recommendation to decrease shards from %d to %d after cooldown period %s",
74+
currentNumberOfShards,
75+
targetNumberOfShards,
76+
coolDownRemaining
77+
);
78+
case NO_CHANGE_REQUIRED -> Strings.format("Recommendation to leave shards unchanged at %d", currentNumberOfShards);
79+
case NOT_APPLICABLE -> "No recommendation as auto-sharding not enabled";
80+
};
81+
}
6082
}

0 commit comments

Comments
 (0)