Skip to content

Commit 413a3d0

Browse files
authored
Add new /_security/stats endpoint (#134835)
Empty multi-node skeleton response to start.
1 parent e89c613 commit 413a3d0

File tree

17 files changed

+356
-3
lines changed

17 files changed

+356
-3
lines changed

docs/changelog/134835.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 134835
2+
summary: Add new `/_security/stats` endpoint
3+
area: Authorization
4+
type: enhancement
5+
issues: []
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"security.get_stats": {
3+
"documentation": {
4+
"url": "https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-get-stats",
5+
"description": "Get security statistics for all nodes"
6+
},
7+
"stability": "stable",
8+
"visibility": "public",
9+
"headers": {
10+
"accept": [
11+
"application/json"
12+
],
13+
"content_type": [
14+
"application/json"
15+
]
16+
},
17+
"url": {
18+
"paths": [
19+
{
20+
"path": "/_security/stats",
21+
"methods": [
22+
"GET"
23+
]
24+
}
25+
]
26+
},
27+
"params": {}
28+
}
29+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
9168000
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
index_request_include_tsid,9167000
1+
security_stats_endpoint,9168000

x-pack/plugin/core/src/main/java/module-info.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
exports org.elasticsearch.xpack.core.security.action.token;
156156
exports org.elasticsearch.xpack.core.security.action.user;
157157
exports org.elasticsearch.xpack.core.security.action.settings;
158+
exports org.elasticsearch.xpack.core.security.action.stats;
158159
exports org.elasticsearch.xpack.core.security.action;
159160
exports org.elasticsearch.xpack.core.security.authc.esnative;
160161
exports org.elasticsearch.xpack.core.security.authc.file;
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
package org.elasticsearch.xpack.core.security.action.stats;
8+
9+
import org.elasticsearch.action.ActionType;
10+
11+
public class GetSecurityStatsAction extends ActionType<GetSecurityStatsNodesResponse> {
12+
13+
public static final GetSecurityStatsAction INSTANCE = new GetSecurityStatsAction();
14+
public static final String NAME = "cluster:monitor/xpack/security/stats";
15+
16+
private GetSecurityStatsAction() {
17+
super(NAME);
18+
}
19+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.core.security.action.stats;
9+
10+
import org.elasticsearch.TransportVersion;
11+
import org.elasticsearch.common.io.stream.StreamInput;
12+
import org.elasticsearch.common.io.stream.StreamOutput;
13+
import org.elasticsearch.transport.AbstractTransportRequest;
14+
15+
import java.io.IOException;
16+
17+
public class GetSecurityStatsNodeRequest extends AbstractTransportRequest {
18+
19+
private static final TransportVersion SECURITY_STATS_ENDPOINT = TransportVersion.fromName("security_stats_endpoint");
20+
21+
public GetSecurityStatsNodeRequest() {}
22+
23+
public GetSecurityStatsNodeRequest(final StreamInput in) throws IOException {
24+
super(in);
25+
}
26+
27+
@Override
28+
public void writeTo(final StreamOutput out) throws IOException {
29+
if (out.getTransportVersion().supports(SECURITY_STATS_ENDPOINT) == false) { // shouldn't happen, blocked at RestAction
30+
throw new UnsupportedOperationException("node doesn't support security stats endpoint");
31+
}
32+
super.writeTo(out);
33+
}
34+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.core.security.action.stats;
9+
10+
import org.elasticsearch.action.support.nodes.BaseNodeResponse;
11+
import org.elasticsearch.cluster.node.DiscoveryNode;
12+
import org.elasticsearch.common.io.stream.StreamInput;
13+
import org.elasticsearch.common.io.stream.StreamOutput;
14+
import org.elasticsearch.xcontent.ToXContentObject;
15+
import org.elasticsearch.xcontent.XContentBuilder;
16+
17+
import java.io.IOException;
18+
19+
public class GetSecurityStatsNodeResponse extends BaseNodeResponse implements ToXContentObject {
20+
21+
public GetSecurityStatsNodeResponse(final StreamInput in) throws IOException {
22+
super(in);
23+
}
24+
25+
public GetSecurityStatsNodeResponse(final DiscoveryNode node) {
26+
super(node);
27+
}
28+
29+
@Override
30+
public void writeTo(final StreamOutput out) throws IOException {
31+
super.writeTo(out);
32+
}
33+
34+
@Override
35+
public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException {
36+
return builder;
37+
}
38+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.core.security.action.stats;
9+
10+
import org.elasticsearch.action.support.nodes.BaseNodesRequest;
11+
12+
public class GetSecurityStatsNodesRequest extends BaseNodesRequest {
13+
public GetSecurityStatsNodesRequest() {
14+
super((String[]) null);
15+
}
16+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
package org.elasticsearch.xpack.core.security.action.stats;
9+
10+
import org.elasticsearch.action.FailedNodeException;
11+
import org.elasticsearch.action.support.nodes.BaseNodesResponse;
12+
import org.elasticsearch.cluster.ClusterName;
13+
import org.elasticsearch.common.io.stream.StreamInput;
14+
import org.elasticsearch.common.io.stream.StreamOutput;
15+
import org.elasticsearch.xcontent.ToXContentObject;
16+
import org.elasticsearch.xcontent.XContentBuilder;
17+
18+
import java.io.IOException;
19+
import java.util.List;
20+
21+
public class GetSecurityStatsNodesResponse extends BaseNodesResponse<GetSecurityStatsNodeResponse> implements ToXContentObject {
22+
23+
public GetSecurityStatsNodesResponse(
24+
final ClusterName clusterName,
25+
final List<GetSecurityStatsNodeResponse> nodes,
26+
final List<FailedNodeException> failures
27+
) {
28+
super(clusterName, nodes, failures);
29+
}
30+
31+
@Override
32+
protected List<GetSecurityStatsNodeResponse> readNodesFrom(final StreamInput in) throws IOException {
33+
return in.readCollectionAsList(GetSecurityStatsNodeResponse::new);
34+
}
35+
36+
@Override
37+
protected void writeNodesTo(final StreamOutput out, final List<GetSecurityStatsNodeResponse> nodes) throws IOException {
38+
out.writeCollection(nodes);
39+
}
40+
41+
@Override
42+
public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException {
43+
builder.startObject();
44+
builder.startObject("nodes");
45+
for (GetSecurityStatsNodeResponse response : getNodes()) {
46+
builder.startObject(response.getNode().getId());
47+
response.toXContent(builder, params);
48+
builder.endObject();
49+
}
50+
builder.endObject();
51+
builder.endObject();
52+
return builder;
53+
}
54+
}

0 commit comments

Comments
 (0)