Skip to content

Commit

Permalink
Revert "Index stats enhancement: creation date and tier_preference (e…
Browse files Browse the repository at this point in the history
…lastic#116339)" (elastic#116959)

This reverts commit e0af123.
  • Loading branch information
DaveCTurner authored Nov 18, 2024
1 parent c804953 commit c72d5fd
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 100 deletions.
5 changes: 0 additions & 5 deletions docs/changelog/116339.yaml

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ static TransportVersion def(int id) {
public static final TransportVersion SKIP_INNER_HITS_SEARCH_SOURCE = def(8_791_00_0);
public static final TransportVersion QUERY_RULES_LIST_INCLUDES_TYPES = def(8_792_00_0);
public static final TransportVersion INDEX_STATS_ADDITIONAL_FIELDS = def(8_793_00_0);
public static final TransportVersion INDEX_STATS_ADDITIONAL_FIELDS_REVERT = def(8_794_00_0);

/*
* STOP! READ THIS FIRST! No, really,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@

public class IndexStats implements Iterable<IndexShardStats> {

public static final NodeFeature TIER_CREATION_DATE = new NodeFeature("stats.tier_creation_date");
// feature was effectively reverted but we still need to keep this constant around
public static final NodeFeature REVERTED_TIER_CREATION_DATE = new NodeFeature("stats.tier_creation_date");

private final String index;

Expand All @@ -32,27 +33,19 @@ public class IndexStats implements Iterable<IndexShardStats> {

private final IndexMetadata.State state;

private final List<String> tierPreference;

private final Long creationDate;

private final ShardStats shards[];

public IndexStats(
String index,
String uuid,
@Nullable ClusterHealthStatus health,
@Nullable IndexMetadata.State state,
@Nullable List<String> tierPreference,
@Nullable Long creationDate,
ShardStats[] shards
) {
this.index = index;
this.uuid = uuid;
this.health = health;
this.state = state;
this.tierPreference = tierPreference;
this.creationDate = creationDate;
this.shards = shards;
}

Expand All @@ -72,14 +65,6 @@ public IndexMetadata.State getState() {
return state;
}

public List<String> getTierPreference() {
return tierPreference;
}

public Long getCreationDate() {
return creationDate;
}

public ShardStats[] getShards() {
return this.shards;
}
Expand Down Expand Up @@ -148,24 +133,13 @@ public static class IndexStatsBuilder {
private final String uuid;
private final ClusterHealthStatus health;
private final IndexMetadata.State state;
private final List<String> tierPreference;
private final Long creationDate;
private final List<ShardStats> shards = new ArrayList<>();

public IndexStatsBuilder(
String indexName,
String uuid,
@Nullable ClusterHealthStatus health,
@Nullable IndexMetadata.State state,
@Nullable List<String> tierPreference,
@Nullable Long creationDate
) {
public IndexStatsBuilder(String indexName, String uuid, @Nullable ClusterHealthStatus health, @Nullable IndexMetadata.State state) {
this.indexName = indexName;
this.uuid = uuid;
this.health = health;
this.state = state;
this.tierPreference = tierPreference;
this.creationDate = creationDate;
}

public IndexStatsBuilder add(ShardStats shardStats) {
Expand All @@ -174,15 +148,7 @@ public IndexStatsBuilder add(ShardStats shardStats) {
}

public IndexStats build() {
return new IndexStats(
indexName,
uuid,
health,
state,
tierPreference,
creationDate,
shards.toArray(new ShardStats[shards.size()])
);
return new IndexStats(indexName, uuid, health, state, shards.toArray(new ShardStats[shards.size()]));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public class IndicesStatsFeatures implements FeatureSpecification {

@Override
public Set<NodeFeature> getFeatures() {
return Set.of(IndexStats.TIER_CREATION_DATE);
return Set.of(IndexStats.REVERTED_TIER_CREATION_DATE);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,34 +47,29 @@ public class IndicesStatsResponse extends ChunkedBroadcastResponse {

private final Map<String, IndexMetadata.State> indexStateMap;

private final Map<String, List<String>> indexTierPreferenceMap;

private final Map<String, Long> indexCreationDateMap;

private final ShardStats[] shards;

private Map<ShardRouting, ShardStats> shardStatsMap;

IndicesStatsResponse(StreamInput in) throws IOException {
super(in);
shards = in.readArray(ShardStats::new, ShardStats[]::new);
if (in.getTransportVersion().onOrAfter(TransportVersions.INDEX_STATS_ADDITIONAL_FIELDS)) {
if (in.getTransportVersion().onOrAfter(TransportVersions.INDEX_STATS_ADDITIONAL_FIELDS_REVERT)) {
indexHealthMap = in.readMap(ClusterHealthStatus::readFrom);
indexStateMap = in.readMap(IndexMetadata.State::readFrom);
indexTierPreferenceMap = in.readMap(StreamInput::readStringCollectionAsList);
indexCreationDateMap = in.readMap(StreamInput::readLong);
} else if (in.getTransportVersion().onOrAfter(TransportVersions.INDEX_STATS_ADDITIONAL_FIELDS)) {
indexHealthMap = in.readMap(ClusterHealthStatus::readFrom);
indexStateMap = in.readMap(IndexMetadata.State::readFrom);
in.readMap(StreamInput::readStringCollectionAsList); // unused, reverted
in.readMap(StreamInput::readLong); // unused, reverted
} else if (in.getTransportVersion().onOrAfter(TransportVersions.V_8_1_0)) {
// Between 8.1 and INDEX_STATS_ADDITIONAL_FIELDS, we had a different format for the response
// where we only had health and state available.
indexHealthMap = in.readMap(ClusterHealthStatus::readFrom);
indexStateMap = in.readMap(IndexMetadata.State::readFrom);
indexTierPreferenceMap = Map.of();
indexCreationDateMap = Map.of();
} else {
indexHealthMap = Map.of();
indexStateMap = Map.of();
indexTierPreferenceMap = Map.of();
indexCreationDateMap = Map.of();
}
}

Expand All @@ -94,8 +89,6 @@ public class IndicesStatsResponse extends ChunkedBroadcastResponse {
Objects.requireNonNull(shards);
Map<String, ClusterHealthStatus> indexHealthModifiableMap = new HashMap<>();
Map<String, IndexMetadata.State> indexStateModifiableMap = new HashMap<>();
Map<String, List<String>> indexTierPreferenceModifiableMap = new HashMap<>();
Map<String, Long> indexCreationDateModifiableMap = new HashMap<>();
for (ShardStats shard : shards) {
Index index = shard.getShardRouting().index();
IndexMetadata indexMetadata = metadata.index(index);
Expand All @@ -105,14 +98,10 @@ public class IndicesStatsResponse extends ChunkedBroadcastResponse {
ignored -> new ClusterIndexHealth(indexMetadata, routingTable.index(index)).getStatus()
);
indexStateModifiableMap.computeIfAbsent(index.getName(), ignored -> indexMetadata.getState());
indexTierPreferenceModifiableMap.computeIfAbsent(index.getName(), ignored -> indexMetadata.getTierPreference());
indexCreationDateModifiableMap.computeIfAbsent(index.getName(), ignored -> indexMetadata.getCreationDate());
}
}
indexHealthMap = unmodifiableMap(indexHealthModifiableMap);
indexStateMap = unmodifiableMap(indexStateModifiableMap);
indexTierPreferenceMap = unmodifiableMap(indexTierPreferenceModifiableMap);
indexCreationDateMap = unmodifiableMap(indexCreationDateModifiableMap);
}

public Map<ShardRouting, ShardStats> asMap() {
Expand Down Expand Up @@ -150,14 +139,7 @@ public Map<String, IndexStats> getIndices() {
Index index = shard.getShardRouting().index();
IndexStatsBuilder indexStatsBuilder = indexToIndexStatsBuilder.computeIfAbsent(
index.getName(),
k -> new IndexStatsBuilder(
k,
index.getUUID(),
indexHealthMap.get(index.getName()),
indexStateMap.get(index.getName()),
indexTierPreferenceMap.get(index.getName()),
indexCreationDateMap.get(index.getName())
)
k -> new IndexStatsBuilder(k, index.getUUID(), indexHealthMap.get(index.getName()), indexStateMap.get(index.getName()))
);
indexStatsBuilder.add(shard);
}
Expand Down Expand Up @@ -202,12 +184,14 @@ public CommonStats getPrimaries() {
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeArray(shards);
if (out.getTransportVersion().onOrAfter(TransportVersions.INDEX_STATS_ADDITIONAL_FIELDS)) {
if (out.getTransportVersion().onOrAfter(TransportVersions.INDEX_STATS_ADDITIONAL_FIELDS_REVERT)) {
out.writeMap(indexHealthMap, StreamOutput::writeWriteable);
out.writeMap(indexStateMap, StreamOutput::writeWriteable);
out.writeMap(indexTierPreferenceMap, StreamOutput::writeStringCollection);
out.writeMap(indexCreationDateMap, StreamOutput::writeLong);

} else if (out.getTransportVersion().onOrAfter(TransportVersions.INDEX_STATS_ADDITIONAL_FIELDS)) {
out.writeMap(indexHealthMap, StreamOutput::writeWriteable);
out.writeMap(indexStateMap, StreamOutput::writeWriteable);
out.writeMap(Map.of(), StreamOutput::writeStringCollection);
out.writeMap(Map.of(), StreamOutput::writeLong);
} else if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_1_0)) {
out.writeMap(indexHealthMap, StreamOutput::writeWriteable);
out.writeMap(indexStateMap, StreamOutput::writeWriteable);
Expand Down Expand Up @@ -237,12 +221,6 @@ protected Iterator<ToXContent> customXContentChunks(ToXContent.Params params) {
if (indexStats.getState() != null) {
builder.field("status", indexStats.getState().toString().toLowerCase(Locale.ROOT));
}
if (indexStats.getTierPreference() != null) {
builder.field("tier_preference", indexStats.getTierPreference());
}
if (indexStats.getCreationDate() != null) {
builder.field("creation_date", indexStats.getCreationDate());
}
builder.startObject("primaries");
indexStats.getPrimaries().toXContent(builder, p);
builder.endObject();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,10 +189,7 @@ public void testNoShardStats() {
shardStats[0] = sStats;

mockXPackInfo(true, true);
mockIndexStatsCall(
indexName,
new IndexStats(indexName, "uuid", ClusterHealthStatus.GREEN, IndexMetadata.State.OPEN, null, null, shardStats)
);
mockIndexStatsCall(indexName, new IndexStats(indexName, "uuid", ClusterHealthStatus.GREEN, IndexMetadata.State.OPEN, shardStats));

final SetOnce<Boolean> conditionMetHolder = new SetOnce<>();
final SetOnce<ToXContentObject> stepInfoHolder = new SetOnce<>();
Expand Down Expand Up @@ -292,7 +289,7 @@ private IndexStats randomIndexStats(boolean isLeaderIndex, int numOfShards) {
for (int i = 0; i < numOfShards; i++) {
shardStats[i] = randomShardStats(isLeaderIndex);
}
return new IndexStats(randomAlphaOfLength(5), randomAlphaOfLength(10), null, null, null, null, shardStats);
return new IndexStats(randomAlphaOfLength(5), randomAlphaOfLength(10), null, null, shardStats);
}

private ShardStats randomShardStats(boolean isLeaderIndex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public void setUp() throws Exception {
"dcvO5uZATE-EhIKc3tk9Bg",
null,
null,
null,
null,
new ShardStats[] {
// Primaries
new ShardStats(mockShardRouting(true), mockShardPath(), mockCommonStats(), null, null, null, false, 0),
Expand Down

0 comments on commit c72d5fd

Please sign in to comment.