-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Add DLS stats to _security/stats
#135271
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
Add DLS stats to _security/stats
#135271
Changes from 6 commits
ca99025
5d1135a
8dd801f
fadf041
9fca013
06f3f98
61d6bee
eed12d1
1d43baa
f3c503d
8459878
31892e0
698bb78
8559de0
6ac2653
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| pr: 135271 | ||
| summary: Add role stats to `_security/stats` | ||
| area: Authorization | ||
| type: enhancement | ||
| issues: [] | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| 9170000 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1 @@ | ||
| inference_api_openai_embeddings_headers,9169000 | ||
| roles_security_stats,9170000 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| /* | ||
| * 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.cluster.node.DiscoveryNodeUtils; | ||
| import org.elasticsearch.common.io.stream.Writeable; | ||
| import org.elasticsearch.test.AbstractWireSerializingTestCase; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.Map; | ||
|
|
||
| public class GetSecurityStatsNodeResponseTests extends AbstractWireSerializingTestCase<GetSecurityStatsNodeResponse> { | ||
|
|
||
| @Override | ||
| protected Writeable.Reader<GetSecurityStatsNodeResponse> instanceReader() { | ||
| return GetSecurityStatsNodeResponse::new; | ||
| } | ||
|
|
||
| @Override | ||
| protected GetSecurityStatsNodeResponse createTestInstance() { | ||
| return new GetSecurityStatsNodeResponse( | ||
| DiscoveryNodeUtils.create(randomUUID()), | ||
| randomBoolean() ? null : Map.of("key", randomUUID()) | ||
| ); | ||
| } | ||
|
|
||
| @Override | ||
| protected GetSecurityStatsNodeResponse mutateInstance(GetSecurityStatsNodeResponse instance) throws IOException { | ||
| return switch (randomIntBetween(0, 1)) { | ||
| case 0 -> new GetSecurityStatsNodeResponse(DiscoveryNodeUtils.create(randomUUID()), instance.getRolesStoreStats()); | ||
| case 1 -> new GetSecurityStatsNodeResponse(instance.getDiscoveryNode(), Map.of("key", randomUUID())); | ||
szybia marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| default -> throw new IllegalStateException("Unexpected value"); | ||
| }; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,12 +6,14 @@ | |
| */ | ||
| package org.elasticsearch.xpack.security.action.stats; | ||
|
|
||
| import org.elasticsearch.action.ActionListener; | ||
| 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.core.Nullable; | ||
| import org.elasticsearch.injection.guice.Inject; | ||
| import org.elasticsearch.tasks.Task; | ||
| import org.elasticsearch.threadpool.ThreadPool; | ||
|
|
@@ -21,9 +23,12 @@ | |
| 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 org.elasticsearch.xpack.security.authz.store.CompositeRolesStore; | ||
|
|
||
| import java.io.IOException; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.concurrent.CompletableFuture; | ||
|
|
||
| public class TransportSecurityStatsAction extends TransportNodesAction< | ||
| GetSecurityStatsNodesRequest, | ||
|
|
@@ -32,12 +37,16 @@ public class TransportSecurityStatsAction extends TransportNodesAction< | |
| GetSecurityStatsNodeResponse, | ||
| Void> { | ||
|
|
||
| @Nullable | ||
| private final CompositeRolesStore rolesStore; | ||
|
|
||
| @Inject | ||
| public TransportSecurityStatsAction( | ||
| ThreadPool threadPool, | ||
| ClusterService clusterService, | ||
| TransportService transportService, | ||
| ActionFilters actionFilters | ||
| ActionFilters actionFilters, | ||
| CompositeRolesStore rolesStore | ||
| ) { | ||
| super( | ||
| GetSecurityStatsAction.INSTANCE.name(), | ||
|
|
@@ -47,6 +56,7 @@ public TransportSecurityStatsAction( | |
| GetSecurityStatsNodeRequest::new, | ||
| threadPool.executor(ThreadPool.Names.MANAGEMENT) | ||
| ); | ||
| this.rolesStore = rolesStore; | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -70,6 +80,12 @@ protected GetSecurityStatsNodeResponse newNodeResponse(final StreamInput in, fin | |
|
|
||
| @Override | ||
| protected GetSecurityStatsNodeResponse nodeOperation(final GetSecurityStatsNodeRequest request, final Task task) { | ||
| return new GetSecurityStatsNodeResponse(clusterService.localNode()); | ||
| final CompletableFuture<Map<String, Object>> rolesStatsFuture = new CompletableFuture<>(); | ||
| if (rolesStore == null) { | ||
| rolesStatsFuture.complete(null); | ||
| } else { | ||
| rolesStore.usageStats(ActionListener.wrap(rolesStatsFuture::complete, rolesStatsFuture::completeExceptionally)); | ||
| } | ||
| return new GetSecurityStatsNodeResponse(clusterService.localNode(), rolesStatsFuture.join()); | ||
|
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| --- | ||
| "Security stats return roles stats": | ||
| - requires: | ||
| cluster_features: [ "security_stats_endpoint" ] | ||
| reason: Introduced in 9.2 | ||
|
|
||
| - do: | ||
| security.get_stats: {} | ||
|
|
||
| - set: | ||
| nodes._arbitrary_key_: node_id | ||
| - gte: { nodes.$node_id.roles.dls.bit_set_cache.count: 0 } | ||
| - gte: { nodes.$node_id.roles.file.size: 0 } | ||
| - gte: { nodes.$node_id.roles.native.size: 0 } |
Uh oh!
There was an error while loading. Please reload this page.