Skip to content

Commit f91f132

Browse files
ES-10037 Configurable metrics in data stream auto-sharding (#125612)
This adds cluster settings to allow for a choice of write load metrics in the data stream auto-sharding calculations. There are separate settings for the increasing and decreasing calculations. Both default to the existing 'all-time' metric for now. This also refactors `DataStreamAutoShardingServiceTests`. The main two things done are: - Split large test methods which do several independent tests in blank code blocks into more smaller methods. - Fix an unnecessarily complicated pattern where the code would create a `Function` in a local variable and then immediately `apply` it exactly once... rather than just executing the code normally.
1 parent 27ebb14 commit f91f132

File tree

4 files changed

+856
-391
lines changed

4 files changed

+856
-391
lines changed

server/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -278,23 +278,12 @@ protected void masterOperation(
278278
final IndexAbstraction indexAbstraction = projectMetadata.getIndicesLookup().get(resolvedRolloverTarget.resource());
279279
if (indexAbstraction.getType().equals(IndexAbstraction.Type.DATA_STREAM)) {
280280
DataStream dataStream = (DataStream) indexAbstraction;
281-
final Optional<IndexStats> indexStats = Optional.ofNullable(statsResponse)
282-
.map(stats -> stats.getIndex(dataStream.getWriteIndex().getName()));
283-
284-
Double indexWriteLoad = indexStats.map(
285-
stats -> Arrays.stream(stats.getShards())
286-
.filter(shardStats -> shardStats.getStats().indexing != null)
287-
// only take primaries into account as in stateful the replicas also index data
288-
.filter(shardStats -> shardStats.getShardRouting().primary())
289-
.map(shardStats -> shardStats.getStats().indexing.getTotal().getWriteLoad())
290-
.reduce(0.0, Double::sum)
291-
).orElse(null);
292-
293-
rolloverAutoSharding = dataStreamAutoShardingService.calculate(projectState, dataStream, indexWriteLoad);
281+
IndexStats indexStats = statsResponse != null ? statsResponse.getIndex(dataStream.getWriteIndex().getName()) : null;
282+
rolloverAutoSharding = dataStreamAutoShardingService.calculate(projectState, dataStream, indexStats);
294283
logger.debug("auto sharding result for data stream [{}] is [{}]", dataStream.getName(), rolloverAutoSharding);
295284

296285
// if auto sharding recommends increasing the number of shards we want to trigger a rollover even if there are no
297-
// other "regular" conditions matching (we want to aggressively increse the number of shards) so we're adding the
286+
// other "regular" conditions matching (we want to aggressively increase the number of shards) so we're adding the
298287
// automatic {@link OptimalShardCountCondition} to the rollover request conditions so it gets evaluated and triggers
299288
// the rollover operation (having this condition met will also provide a useful paper trail as it'll get stored in
300289
// the {@link org.elasticsearch.action.admin.indices.rollover.RolloverInfo#metConditions} )

0 commit comments

Comments
 (0)