-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add new /_security/stats
endpoint
#134835
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
fb698c3
Add new `/_security/stats` endpoint
szybia c539883
[CI] Update transport version definitions
2c41482
Merge branch 'main' into security-stats
szybia c9828ab
add action as non-operator
szybia d0e2b20
Merge remote-tracking branch 'upstream/main' into security-stats
szybia 9b30290
Update docs/changelog/134835.yaml
szybia 9b4c171
Merge branch 'main' into security-stats
joegallo f1d7291
joe comments
szybia efa5c30
Merge remote-tracking branch 'upstream/main' into security-stats
szybia b795b2a
[CI] Auto commit changes from spotless
a477c70
Merge remote-tracking branch 'upstream/main' into security-stats
szybia 45db05c
use new transport version
szybia 09b9668
Merge branch 'main' into security-stats
joegallo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
pr: 134835 | ||
summary: Add new `/_security/stats` endpoint | ||
area: Authorization | ||
type: enhancement | ||
issues: [] |
29 changes: 29 additions & 0 deletions
29
rest-api-spec/src/main/resources/rest-api-spec/api/security.get_stats.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"security.get_stats": { | ||
"documentation": { | ||
"url": "https://www.elastic.co/docs/api/doc/elasticsearch/operation/operation-security-get-stats", | ||
"description": "Get security statistics for all nodes" | ||
}, | ||
"stability": "stable", | ||
"visibility": "public", | ||
"headers": { | ||
"accept": [ | ||
"application/json" | ||
], | ||
"content_type": [ | ||
"application/json" | ||
] | ||
}, | ||
"url": { | ||
"paths": [ | ||
{ | ||
"path": "/_security/stats", | ||
"methods": [ | ||
"GET" | ||
] | ||
} | ||
] | ||
}, | ||
"params": {} | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
server/src/main/resources/transport/definitions/referable/security_stats_endpoint.csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
9168000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
index_request_include_tsid,9167000 | ||
security_stats_endpoint,9168000 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
.../main/java/org/elasticsearch/xpack/core/security/action/stats/GetSecurityStatsAction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
package org.elasticsearch.xpack.core.security.action.stats; | ||
|
||
import org.elasticsearch.action.ActionType; | ||
|
||
public class GetSecurityStatsAction extends ActionType<GetSecurityStatsNodesResponse> { | ||
|
||
public static final GetSecurityStatsAction INSTANCE = new GetSecurityStatsAction(); | ||
public static final String NAME = "cluster:monitor/xpack/security/stats"; | ||
|
||
private GetSecurityStatsAction() { | ||
super(NAME); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
.../java/org/elasticsearch/xpack/core/security/action/stats/GetSecurityStatsNodeRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.security.action.stats; | ||
|
||
import org.elasticsearch.TransportVersion; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.transport.AbstractTransportRequest; | ||
|
||
import java.io.IOException; | ||
|
||
public class GetSecurityStatsNodeRequest extends AbstractTransportRequest { | ||
|
||
private static final TransportVersion SECURITY_STATS_ENDPOINT = TransportVersion.fromName("security_stats_endpoint"); | ||
|
||
public GetSecurityStatsNodeRequest() {} | ||
|
||
public GetSecurityStatsNodeRequest(final StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
@Override | ||
public void writeTo(final StreamOutput out) throws IOException { | ||
if (out.getTransportVersion().supports(SECURITY_STATS_ENDPOINT) == false) { // shouldn't happen, blocked at RestAction | ||
throw new UnsupportedOperationException("node doesn't support security stats endpoint"); | ||
} | ||
super.writeTo(out); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...java/org/elasticsearch/xpack/core/security/action/stats/GetSecurityStatsNodeResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.security.action.stats; | ||
|
||
import org.elasticsearch.action.support.nodes.BaseNodeResponse; | ||
import org.elasticsearch.cluster.node.DiscoveryNode; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.xcontent.ToXContentObject; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
|
||
public class GetSecurityStatsNodeResponse extends BaseNodeResponse implements ToXContentObject { | ||
|
||
public GetSecurityStatsNodeResponse(final StreamInput in) throws IOException { | ||
super(in); | ||
} | ||
|
||
public GetSecurityStatsNodeResponse(final DiscoveryNode node) { | ||
super(node); | ||
} | ||
|
||
@Override | ||
public void writeTo(final StreamOutput out) throws IOException { | ||
super.writeTo(out); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException { | ||
return builder; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...java/org/elasticsearch/xpack/core/security/action/stats/GetSecurityStatsNodesRequest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.security.action.stats; | ||
|
||
import org.elasticsearch.action.support.nodes.BaseNodesRequest; | ||
|
||
public class GetSecurityStatsNodesRequest extends BaseNodesRequest { | ||
public GetSecurityStatsNodesRequest() { | ||
super((String[]) null); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...ava/org/elasticsearch/xpack/core/security/action/stats/GetSecurityStatsNodesResponse.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
package org.elasticsearch.xpack.core.security.action.stats; | ||
|
||
import org.elasticsearch.action.FailedNodeException; | ||
import org.elasticsearch.action.support.nodes.BaseNodesResponse; | ||
import org.elasticsearch.cluster.ClusterName; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.common.io.stream.StreamOutput; | ||
import org.elasticsearch.xcontent.ToXContentObject; | ||
import org.elasticsearch.xcontent.XContentBuilder; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class GetSecurityStatsNodesResponse extends BaseNodesResponse<GetSecurityStatsNodeResponse> implements ToXContentObject { | ||
|
||
public GetSecurityStatsNodesResponse( | ||
final ClusterName clusterName, | ||
final List<GetSecurityStatsNodeResponse> nodes, | ||
final List<FailedNodeException> failures | ||
) { | ||
super(clusterName, nodes, failures); | ||
} | ||
|
||
@Override | ||
protected List<GetSecurityStatsNodeResponse> readNodesFrom(final StreamInput in) throws IOException { | ||
return in.readCollectionAsList(GetSecurityStatsNodeResponse::new); | ||
} | ||
|
||
@Override | ||
protected void writeNodesTo(final StreamOutput out, final List<GetSecurityStatsNodeResponse> nodes) throws IOException { | ||
out.writeCollection(nodes); | ||
} | ||
|
||
@Override | ||
public XContentBuilder toXContent(final XContentBuilder builder, final Params params) throws IOException { | ||
builder.startObject(); | ||
builder.startObject("nodes"); | ||
for (GetSecurityStatsNodeResponse response : getNodes()) { | ||
builder.startObject(response.getNode().getId()); | ||
response.toXContent(builder, params); | ||
builder.endObject(); | ||
} | ||
builder.endObject(); | ||
builder.endObject(); | ||
return builder; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
...main/java/org/elasticsearch/xpack/security/action/stats/TransportSecurityStatsAction.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
package org.elasticsearch.xpack.security.action.stats; | ||
|
||
import org.elasticsearch.action.FailedNodeException; | ||
import org.elasticsearch.action.support.ActionFilters; | ||
import org.elasticsearch.action.support.nodes.TransportNodesAction; | ||
import org.elasticsearch.cluster.node.DiscoveryNode; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.injection.guice.Inject; | ||
import org.elasticsearch.tasks.Task; | ||
import org.elasticsearch.threadpool.ThreadPool; | ||
import org.elasticsearch.transport.TransportService; | ||
import org.elasticsearch.xpack.core.security.action.stats.GetSecurityStatsAction; | ||
import org.elasticsearch.xpack.core.security.action.stats.GetSecurityStatsNodeRequest; | ||
import org.elasticsearch.xpack.core.security.action.stats.GetSecurityStatsNodeResponse; | ||
import org.elasticsearch.xpack.core.security.action.stats.GetSecurityStatsNodesRequest; | ||
import org.elasticsearch.xpack.core.security.action.stats.GetSecurityStatsNodesResponse; | ||
|
||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class TransportSecurityStatsAction extends TransportNodesAction< | ||
GetSecurityStatsNodesRequest, | ||
GetSecurityStatsNodesResponse, | ||
GetSecurityStatsNodeRequest, | ||
GetSecurityStatsNodeResponse, | ||
Void> { | ||
|
||
@Inject | ||
public TransportSecurityStatsAction( | ||
ThreadPool threadPool, | ||
ClusterService clusterService, | ||
TransportService transportService, | ||
ActionFilters actionFilters | ||
) { | ||
super( | ||
GetSecurityStatsAction.INSTANCE.name(), | ||
clusterService, | ||
transportService, | ||
actionFilters, | ||
GetSecurityStatsNodeRequest::new, | ||
threadPool.executor(ThreadPool.Names.MANAGEMENT) | ||
); | ||
} | ||
|
||
@Override | ||
protected GetSecurityStatsNodesResponse newResponse( | ||
final GetSecurityStatsNodesRequest request, | ||
final List<GetSecurityStatsNodeResponse> responses, | ||
final List<FailedNodeException> failures | ||
) { | ||
return new GetSecurityStatsNodesResponse(clusterService.getClusterName(), responses, failures); | ||
} | ||
|
||
@Override | ||
protected GetSecurityStatsNodeRequest newNodeRequest(final GetSecurityStatsNodesRequest request) { | ||
return new GetSecurityStatsNodeRequest(); | ||
} | ||
|
||
@Override | ||
protected GetSecurityStatsNodeResponse newNodeResponse(final StreamInput in, final DiscoveryNode node) throws IOException { | ||
return new GetSecurityStatsNodeResponse(in); | ||
} | ||
|
||
@Override | ||
protected GetSecurityStatsNodeResponse nodeOperation(final GetSecurityStatsNodeRequest request, final Task task) { | ||
return new GetSecurityStatsNodeResponse(clusterService.localNode()); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.