Skip to content

Commit 097df5e

Browse files
committed
add index parameter
1 parent 408a685 commit 097df5e

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@
99
package org.elasticsearch.test.seektracker;
1010

1111
import org.elasticsearch.client.internal.node.NodeClient;
12+
import org.elasticsearch.common.Strings;
1213
import org.elasticsearch.rest.BaseRestHandler;
1314
import org.elasticsearch.rest.RestHandler;
1415
import org.elasticsearch.rest.RestRequest;
1516
import org.elasticsearch.rest.action.RestToXContentListener;
1617

1718
import java.util.List;
1819

19-
public class RestSeekCountAction extends BaseRestHandler {
20+
public class RestSeekStatsAction extends BaseRestHandler {
2021

2122
@Override
2223
public String getName() {
@@ -25,11 +26,14 @@ public String getName() {
2526

2627
@Override
2728
public List<Route> routes() {
28-
return List.of(new RestHandler.Route(RestRequest.Method.GET, "/_seek_stats"));
29+
return List.of(new RestHandler.Route(RestRequest.Method.GET, "/_seek_stats"),
30+
new RestHandler.Route(RestRequest.Method.GET, "/{index}/_seek_stats"));
2931
}
3032

3133
@Override
3234
protected RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) {
33-
return channel -> client.executeLocally(SeekStatsAction.INSTANCE, new SeekStatsRequest(), new RestToXContentListener<>(channel));
35+
String[] indices = request.paramAsStringArray("index", Strings.EMPTY_ARRAY);
36+
SeekStatsRequest seekStatsRequest = new SeekStatsRequest(indices);
37+
return channel -> client.executeLocally(SeekStatsAction.INSTANCE, seekStatsRequest, new RestToXContentListener<>(channel));
3438
}
3539
}

test/external-modules/seek-tracking-directory/src/main/java/org/elasticsearch/test/seektracker/SeekStatsRequest.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,34 @@
1010

1111
import org.elasticsearch.action.ActionRequestValidationException;
1212
import org.elasticsearch.action.support.nodes.BaseNodesRequest;
13+
import org.elasticsearch.common.Strings;
1314
import org.elasticsearch.common.io.stream.StreamInput;
15+
import org.elasticsearch.common.io.stream.StreamOutput;
1416

1517
import java.io.IOException;
1618

1719
public class SeekStatsRequest extends BaseNodesRequest<SeekStatsRequest> {
1820

19-
public SeekStatsRequest(String... nodeIds) {
20-
super(nodeIds);
21+
private final String[] indices;
22+
23+
public SeekStatsRequest(String... indices) {
24+
super(Strings.EMPTY_ARRAY);
25+
this.indices = indices;
2126
}
2227

2328
public SeekStatsRequest(StreamInput in) throws IOException {
2429
super(in);
30+
this.indices = in.readStringArray();
31+
}
32+
33+
@Override
34+
public void writeTo(StreamOutput out) throws IOException {
35+
super.writeTo(out);
36+
out.writeStringArray(indices);
37+
}
38+
39+
public String[] getIndices() {
40+
return indices;
2541
}
2642

2743
@Override

test/external-modules/seek-tracking-directory/src/main/java/org/elasticsearch/test/seektracker/SeekTrackerPlugin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public List<RestHandler> getRestHandlers(
8181
IndexNameExpressionResolver indexNameExpressionResolver,
8282
Supplier<DiscoveryNodes> nodesInCluster
8383
) {
84-
return Collections.singletonList(new RestSeekCountAction());
84+
return Collections.singletonList(new RestSeekStatsAction());
8585
}
8686

8787
@Override

test/external-modules/seek-tracking-directory/src/main/java/org/elasticsearch/test/seektracker/TransportSeekStatsAction.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,15 @@ protected SeekStats newNodeResponse(StreamInput in, DiscoveryNode node) throws I
7070
@Override
7171
protected SeekStats nodeOperation(SeekStatsRequest request, Task task) {
7272
Map<String, Long> seeks = new HashMap<>();
73-
for (Map.Entry<String, LongAdder> entry : seekStatsService.seeks.entrySet()) {
74-
seeks.put(entry.getKey(), entry.getValue().longValue());
73+
if (request.getIndices().length == 0) {
74+
for (Map.Entry<String, LongAdder> entry : seekStatsService.seeks.entrySet()) {
75+
seeks.put(entry.getKey(), entry.getValue().longValue());
76+
}
77+
} else {
78+
for (String index : request.getIndices()) {
79+
LongAdder longAdder = seekStatsService.seeks.get(index);
80+
seeks.put(index, longAdder.longValue());
81+
}
7582
}
7683
return new SeekStats(clusterService.localNode(), seeks);
7784
}

0 commit comments

Comments
 (0)