Skip to content

Commit f1d7291

Browse files
committed
joe comments
1 parent 9b4c171 commit f1d7291

File tree

5 files changed

+19
-3
lines changed

5 files changed

+19
-3
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ static TransportVersion def(int id) {
334334
public static final TransportVersion INFERENCE_REQUEST_ADAPTIVE_RATE_LIMITING_REMOVED = def(9_164_0_00);
335335
public static final TransportVersion SEARCH_SOURCE_EXCLUDE_INFERENCE_FIELDS_PARAM = def(9_165_0_00);
336336
public static final TransportVersion INFERENCE_RESULTS_MAP_WITH_CLUSTER_ALIAS = def(9_166_0_00);
337+
public static final TransportVersion SECURITY_STATS_ENDPOINT = def(9_167_0_00);
337338

338339
/*
339340
* STOP! READ THIS FIRST! No, really,

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/action/stats/GetSecurityStatsNodeRequest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
package org.elasticsearch.xpack.core.security.action.stats;
99

10+
import org.elasticsearch.TransportVersions;
1011
import org.elasticsearch.common.io.stream.StreamInput;
1112
import org.elasticsearch.common.io.stream.StreamOutput;
1213
import org.elasticsearch.transport.AbstractTransportRequest;
@@ -23,6 +24,9 @@ public GetSecurityStatsNodeRequest(final StreamInput in) throws IOException {
2324

2425
@Override
2526
public void writeTo(final StreamOutput out) throws IOException {
27+
if (out.getTransportVersion().before(TransportVersions.SECURITY_STATS_ENDPOINT)) { // shouldn't happen
28+
throw new UnsupportedOperationException("node doesn't support security stats endpoint");
29+
}
2630
super.writeTo(out);
2731
}
2832
}

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/Security.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1828,7 +1828,7 @@ public List<RestHandler> getRestHandlers(
18281828
new RestDisableProfileAction(settings, getLicenseState()),
18291829
new RestGetSecuritySettingsAction(settings, getLicenseState()),
18301830
new RestUpdateSecuritySettingsAction(settings, getLicenseState()),
1831-
new RestSecurityStatsAction(settings, getLicenseState())
1831+
new RestSecurityStatsAction(settings, getLicenseState(), clusterSupportsFeature)
18321832
).filter(Objects::nonNull).toList();
18331833
}
18341834

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/SecurityFeatures.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
public class SecurityFeatures implements FeatureSpecification {
1818

19-
private static final NodeFeature SECURITY_STATS_ENDPOINT = new NodeFeature("security_stats_endpoint");
19+
public static final NodeFeature SECURITY_STATS_ENDPOINT = new NodeFeature("security_stats_endpoint");
2020

2121
@Override
2222
public Set<NodeFeature> getFeatures() {

x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/rest/action/stats/RestSecurityStatsAction.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,32 @@
88

99
import org.elasticsearch.client.internal.node.NodeClient;
1010
import org.elasticsearch.common.settings.Settings;
11+
import org.elasticsearch.features.NodeFeature;
1112
import org.elasticsearch.license.XPackLicenseState;
1213
import org.elasticsearch.rest.RestRequest;
1314
import org.elasticsearch.rest.Scope;
1415
import org.elasticsearch.rest.ServerlessScope;
1516
import org.elasticsearch.rest.action.RestToXContentListener;
1617
import org.elasticsearch.xpack.core.security.action.stats.GetSecurityStatsAction;
1718
import org.elasticsearch.xpack.core.security.action.stats.GetSecurityStatsNodesRequest;
19+
import org.elasticsearch.xpack.security.SecurityFeatures;
1820
import org.elasticsearch.xpack.security.rest.action.SecurityBaseRestHandler;
1921

2022
import java.util.List;
23+
import java.util.function.Predicate;
2124

2225
import static org.elasticsearch.rest.RestRequest.Method.GET;
2326

2427
@ServerlessScope(Scope.INTERNAL)
2528
public class RestSecurityStatsAction extends SecurityBaseRestHandler {
2629

27-
public RestSecurityStatsAction(final Settings settings, final XPackLicenseState licenseState) {
30+
private final Predicate<NodeFeature> clusterSupportsFeature;
31+
32+
public RestSecurityStatsAction(final Settings settings,
33+
final XPackLicenseState licenseState,
34+
final Predicate<NodeFeature> clusterSupportsFeature) {
2835
super(settings, licenseState);
36+
this.clusterSupportsFeature = clusterSupportsFeature;
2937
}
3038

3139
@Override
@@ -40,6 +48,9 @@ public String getName() {
4048

4149
@Override
4250
public RestChannelConsumer innerPrepareRequest(final RestRequest request, final NodeClient client) {
51+
if (clusterSupportsFeature.test(SecurityFeatures.SECURITY_STATS_ENDPOINT) == false) {
52+
throw new IllegalArgumentException("endpoint not supported on all nodes in the cluster");
53+
}
4354
final var req = new GetSecurityStatsNodesRequest();
4455
return channel -> client.execute(GetSecurityStatsAction.INSTANCE, req, new RestToXContentListener<>(channel));
4556
}

0 commit comments

Comments
 (0)