Skip to content

Commit 182f3b6

Browse files
committed
update after review
1 parent 062fb9f commit 182f3b6

File tree

9 files changed

+39
-46
lines changed

9 files changed

+39
-46
lines changed

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ static TransportVersion def(int id) {
273273
public static final TransportVersion INFERENCE_CUSTOM_SERVICE_ADDED = def(9_084_0_00);
274274
public static final TransportVersion ESQL_LIMIT_ROW_SIZE = def(9_085_0_00);
275275
public static final TransportVersion ESQL_REGEX_MATCH_WITH_CASE_INSENSITIVITY = def(9_086_0_00);
276-
public static final TransportVersion EWMR_STATS = def(9_087_0_00);
276+
public static final TransportVersion SEARCH_LOAD_PER_INDEX_STATS = def(9_087_0_00);
277277

278278
/*
279279
* STOP! READ THIS FIRST! No, really,

server/src/main/java/org/elasticsearch/action/search/load/ShardSearchLoadStats.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import java.util.Objects;
1919

2020
/**
21-
* ShardStats class represents the statistics of a shard in an index.
21+
* ShardSearchLoadStats class represents the statistics of a shard in an index.
2222
* It contains information such as the index name, shard ID, allocation ID, and EWMA rate.
2323
*/
2424
public class ShardSearchLoadStats implements Writeable {
@@ -29,7 +29,7 @@ public class ShardSearchLoadStats implements Writeable {
2929

3030
private final String allocationId;
3131

32-
private final Double emwRate;
32+
private final Double searchLoad;
3333

3434
/**
3535
* Constructor to create a ShardStats object from a StreamInput.
@@ -42,7 +42,7 @@ public ShardSearchLoadStats(StreamInput in) throws IOException {
4242
this.indexName = in.readString();
4343
this.shardId = in.readVInt();
4444
this.allocationId = in.readString();
45-
this.emwRate = in.readDouble();
45+
this.searchLoad = in.readDouble();
4646
}
4747

4848
/**
@@ -51,13 +51,13 @@ public ShardSearchLoadStats(StreamInput in) throws IOException {
5151
* @param indexName the name of the index
5252
* @param shardId the ID of the shard
5353
* @param allocationId the allocation ID of the shard
54-
* @param ewma the EWMA rate of the shard
54+
* @param searchLoad the search load of the shard
5555
*/
56-
public ShardSearchLoadStats(String indexName, Integer shardId, String allocationId, Double ewma) {
56+
public ShardSearchLoadStats(String indexName, Integer shardId, String allocationId, Double searchLoad) {
5757
this.indexName = indexName;
5858
this.shardId = shardId;
5959
this.allocationId = allocationId;
60-
this.emwRate = ewma;
60+
this.searchLoad = searchLoad;
6161
}
6262

6363
@Override
@@ -68,12 +68,12 @@ public boolean equals(Object o) {
6868
return Objects.equals(indexName, that.indexName)
6969
&& Objects.equals(shardId, that.shardId)
7070
&& Objects.equals(allocationId, that.allocationId)
71-
&& Objects.equals(emwRate, that.emwRate);
71+
&& Objects.equals(searchLoad, that.searchLoad);
7272
}
7373

7474
@Override
7575
public int hashCode() {
76-
return Objects.hash(indexName, shardId, allocationId, emwRate);
76+
return Objects.hash(indexName, shardId, allocationId, searchLoad);
7777
}
7878

7979
/**
@@ -104,19 +104,19 @@ public String getAllocationId() {
104104
}
105105

106106
/**
107-
* Returns the EWMA rate of the shard.
107+
* Returns the search load of the shard.
108108
*
109-
* @return the EWMA rate
109+
* @return the search load as a Double
110110
*/
111-
public Double getEwmRate() {
112-
return this.emwRate;
111+
public Double getSearchLoad() {
112+
return this.searchLoad;
113113
}
114114

115115
@Override
116116
public void writeTo(StreamOutput out) throws IOException {
117117
out.writeString(indexName);
118118
out.writeVInt(shardId);
119119
out.writeString(allocationId);
120-
out.writeDouble(emwRate);
120+
out.writeDouble(searchLoad);
121121
}
122122
}

server/src/main/java/org/elasticsearch/action/search/load/ShardSearchLoadStatsAction.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@
1616
* Action definition for retrieving shard-level search load statistics.
1717
* <p>
1818
* This action serves as a marker for executing {@link TransportShardSearchLoadStatsAction}
19+
*
1920
* </p>
2021
*/
2122
public class ShardSearchLoadStatsAction extends ActionType<ShardSearchLoadStatsResponse> {
2223

23-
/**
24-
* Singleton instance of the action type.
25-
*/
2624
public static final ShardSearchLoadStatsAction INSTANCE = new ShardSearchLoadStatsAction();
27-
public static final String NAME = "internal:search/stats";
25+
public static final String NAME = "internal:search/load";
2826
public static final RemoteClusterActionType<ShardSearchLoadStatsResponse> REMOTE_TYPE = new RemoteClusterActionType<>(
2927
NAME,
3028
ShardSearchLoadStatsResponse::new

server/src/main/java/org/elasticsearch/action/search/load/TransportShardSearchLoadStatsAction.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,15 +105,10 @@ public TransportShardSearchLoadStatsAction(
105105
*/
106106
@Override
107107
protected ShardsIterator shards(ClusterState clusterState, Request request, String[] concreteIndices) {
108-
// Create a modifiable list of shard routings for the given indices
109108
List<ShardRouting> shardRoutingList = new ArrayList<>(
110109
clusterState.routingTable(projectResolver.getProjectId()).allShards(concreteIndices).getShardRoutings()
111110
);
112-
113-
// Remove all primary shard routings from the list
114111
shardRoutingList.removeIf(ShardRouting::primary);
115-
116-
// Return an iterator over the remaining (replica) shards
117112
return new PlainShardsIterator(shardRoutingList);
118113
}
119114

server/src/main/java/org/elasticsearch/index/search/stats/SearchStats.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public static class Stats implements Writeable, ToXContentFragment {
4949
private long queryFailure;
5050
private long fetchFailure;
5151

52-
private double exponentiallyWeightedMovingRate;
52+
private double recentSearchLoad;
5353

5454
private Stats() {
5555
// for internal use, initializes all counts to 0
@@ -70,7 +70,7 @@ public Stats(
7070
long suggestCount,
7171
long suggestTimeInMillis,
7272
long suggestCurrent,
73-
double exponentiallyWeightedMovingRate
73+
double recentSearchLoad
7474
) {
7575
this.queryCount = queryCount;
7676
this.queryTimeInMillis = queryTimeInMillis;
@@ -90,7 +90,7 @@ public Stats(
9090
this.suggestTimeInMillis = suggestTimeInMillis;
9191
this.suggestCurrent = suggestCurrent;
9292

93-
this.exponentiallyWeightedMovingRate = exponentiallyWeightedMovingRate;
93+
this.recentSearchLoad = recentSearchLoad;
9494

9595
}
9696

@@ -116,8 +116,8 @@ private Stats(StreamInput in) throws IOException {
116116
fetchFailure = in.readVLong();
117117
}
118118

119-
if (in.getTransportVersion().onOrAfter(TransportVersions.EWMR_STATS)) {
120-
exponentiallyWeightedMovingRate = in.readDouble();
119+
if (in.getTransportVersion().onOrAfter(TransportVersions.SEARCH_LOAD_PER_INDEX_STATS)) {
120+
recentSearchLoad = in.readDouble();
121121
}
122122
}
123123

@@ -144,8 +144,8 @@ public void writeTo(StreamOutput out) throws IOException {
144144
out.writeVLong(fetchFailure);
145145
}
146146

147-
if (out.getTransportVersion().onOrAfter(TransportVersions.EWMR_STATS)) {
148-
out.writeDouble(exponentiallyWeightedMovingRate);
147+
if (out.getTransportVersion().onOrAfter(TransportVersions.SEARCH_LOAD_PER_INDEX_STATS)) {
148+
out.writeDouble(recentSearchLoad);
149149
}
150150
}
151151

@@ -168,7 +168,7 @@ public void add(Stats stats) {
168168
suggestTimeInMillis += stats.suggestTimeInMillis;
169169
suggestCurrent += stats.suggestCurrent;
170170

171-
exponentiallyWeightedMovingRate += stats.exponentiallyWeightedMovingRate;
171+
recentSearchLoad += stats.recentSearchLoad;
172172
}
173173

174174
public void addForClosingShard(Stats stats) {
@@ -188,7 +188,7 @@ public void addForClosingShard(Stats stats) {
188188
suggestCount += stats.suggestCount;
189189
suggestTimeInMillis += stats.suggestTimeInMillis;
190190

191-
exponentiallyWeightedMovingRate += stats.exponentiallyWeightedMovingRate;
191+
recentSearchLoad += stats.recentSearchLoad;
192192
}
193193

194194
public long getQueryCount() {
@@ -263,8 +263,8 @@ public long getSuggestCurrent() {
263263
return suggestCurrent;
264264
}
265265

266-
public double getExponentiallyWeightedMovingRate() {
267-
return exponentiallyWeightedMovingRate;
266+
public double getSearchLoadRate() {
267+
return recentSearchLoad;
268268
}
269269

270270
public static Stats readStats(StreamInput in) throws IOException {
@@ -291,7 +291,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
291291
builder.humanReadableField(Fields.SUGGEST_TIME_IN_MILLIS, Fields.SUGGEST_TIME, getSuggestTime());
292292
builder.field(Fields.SUGGEST_CURRENT, suggestCurrent);
293293

294-
builder.field(Fields.EMW_RATE, exponentiallyWeightedMovingRate);
294+
builder.field(Fields.EMW_RATE, recentSearchLoad);
295295

296296
return builder;
297297
}
@@ -315,7 +315,7 @@ public boolean equals(Object o) {
315315
&& suggestCount == that.suggestCount
316316
&& suggestTimeInMillis == that.suggestTimeInMillis
317317
&& suggestCurrent == that.suggestCurrent
318-
&& exponentiallyWeightedMovingRate == that.exponentiallyWeightedMovingRate;
318+
&& recentSearchLoad == that.recentSearchLoad;
319319
}
320320

321321
@Override
@@ -335,7 +335,7 @@ public int hashCode() {
335335
suggestCount,
336336
suggestTimeInMillis,
337337
suggestCurrent,
338-
exponentiallyWeightedMovingRate
338+
recentSearchLoad
339339
);
340340
}
341341
}

server/src/main/java/org/elasticsearch/index/search/stats/SearchStatsSettings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public class SearchStatsSettings {
3838
Setting.Property.NodeScope
3939
);
4040

41-
private TimeValue recentReadLoadHalfLifeForNewShards = RECENT_READ_LOAD_HALF_LIFE_SETTING.getDefault(Settings.EMPTY);
41+
private volatile TimeValue recentReadLoadHalfLifeForNewShards = RECENT_READ_LOAD_HALF_LIFE_SETTING.getDefault(Settings.EMPTY);
4242

4343
public SearchStatsSettings(ClusterSettings clusterSettings) {
4444
clusterSettings.initializeAndWatch(RECENT_READ_LOAD_HALF_LIFE_SETTING, value -> recentReadLoadHalfLifeForNewShards = value);

server/src/main/java/org/elasticsearch/index/search/stats/ShardSearchStats.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@ public void onFailedQueryPhase(SearchContext searchContext) {
8585
@Override
8686
public void onQueryPhase(SearchContext searchContext, long tookInNanos) {
8787
computeStats(searchContext, searchContext.hasOnlySuggest() ? statsHolder -> {
88-
statsHolder.exponentiallyWeightedMovingRate.addIncrement(tookInNanos, System.nanoTime());
88+
statsHolder.recentSearchLoad.addIncrement(tookInNanos, System.nanoTime());
8989
statsHolder.suggestMetric.inc(tookInNanos);
9090
statsHolder.suggestCurrent.dec();
9191
} : statsHolder -> {
92-
statsHolder.exponentiallyWeightedMovingRate.addIncrement(tookInNanos, System.nanoTime());
92+
statsHolder.recentSearchLoad.addIncrement(tookInNanos, System.nanoTime());
9393
statsHolder.queryMetric.inc(tookInNanos);
9494
statsHolder.queryCurrent.dec();
9595
});
@@ -111,7 +111,7 @@ public void onFailedFetchPhase(SearchContext searchContext) {
111111
@Override
112112
public void onFetchPhase(SearchContext searchContext, long tookInNanos) {
113113
computeStats(searchContext, statsHolder -> {
114-
statsHolder.exponentiallyWeightedMovingRate.addIncrement(tookInNanos, System.nanoTime());
114+
statsHolder.recentSearchLoad.addIncrement(tookInNanos, System.nanoTime());
115115
statsHolder.fetchMetric.inc(tookInNanos);
116116
statsHolder.fetchCurrent.dec();
117117
});
@@ -183,11 +183,11 @@ static final class StatsHolder {
183183
final CounterMetric queryFailure = new CounterMetric();
184184
final CounterMetric fetchFailure = new CounterMetric();
185185

186-
final ExponentiallyWeightedMovingRate exponentiallyWeightedMovingRate;
186+
final ExponentiallyWeightedMovingRate recentSearchLoad;
187187

188188
StatsHolder(SearchStatsSettings searchStatsSettings) {
189189
double lambdaInInverseNanos = Math.log(2.0) / searchStatsSettings.getRecentReadLoadHalfLifeForNewShards().nanos();
190-
this.exponentiallyWeightedMovingRate = new ExponentiallyWeightedMovingRate(lambdaInInverseNanos, System.nanoTime());
190+
this.recentSearchLoad = new ExponentiallyWeightedMovingRate(lambdaInInverseNanos, System.nanoTime());
191191
}
192192

193193
SearchStats.Stats stats() {
@@ -206,7 +206,7 @@ SearchStats.Stats stats() {
206206
suggestMetric.count(),
207207
TimeUnit.NANOSECONDS.toMillis(suggestMetric.sum()),
208208
suggestCurrent.count(),
209-
exponentiallyWeightedMovingRate.getRate(System.nanoTime())
209+
recentSearchLoad.getRate(System.nanoTime())
210210
);
211211
}
212212
}

server/src/main/java/org/elasticsearch/index/shard/IndexShard.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1429,7 +1429,7 @@ public GetStats getStats() {
14291429
* Returns the search load rate stats for this shard.
14301430
*/
14311431
public double getSearchLoadRate() {
1432-
return searchStats.stats().getTotal().getExponentiallyWeightedMovingRate();
1432+
return searchStats.stats().getTotal().getSearchLoadRate();
14331433
}
14341434

14351435
public StoreStats storeStats() {

x-pack/plugin/security/qa/operator-privileges-tests/src/javaRestTest/java/org/elasticsearch/xpack/security/operator/Constants.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,7 @@ public class Constants {
637637
"internal:gateway/local/started_shards",
638638
"internal:admin/indices/prevalidate_shard_path",
639639
"internal:index/metadata/migration_version/update",
640-
"internal:search/stats",
640+
"internal:search/load",
641641
"indices:admin/migration/reindex_status",
642642
"indices:admin/data_stream/index/reindex",
643643
"indices:admin/data_stream/reindex",

0 commit comments

Comments
 (0)