Skip to content

[9.3] Privmon User Count - use grouping with count in place of count distinct for > 4000 users limitation (#249775)#249927

Merged
kibanamachine merged 1 commit intoelastic:9.3from
kibanamachine:backport/9.3/pr-249775
Jan 21, 2026
Merged

[9.3] Privmon User Count - use grouping with count in place of count distinct for > 4000 users limitation (#249775)#249927
kibanamachine merged 1 commit intoelastic:9.3from
kibanamachine:backport/9.3/pr-249775

Conversation

@kibanamachine
Copy link
Copy Markdown
Contributor

Backport

This will backport the following commits from main to 9.3:

Questions ?

Please refer to the Backport tool documentation

…ct for > 4000 users limitation (elastic#249775)

### Summary
This PR fixes the eggbox on privileged monitoring not showing > 4000
user count accurately due to [limitation with ESQL's count
distinct](https://www.elastic.co/docs/reference/query-languages/esql/functions-operators/aggregation-functions#esql-agg-count-distinct-approximate)

The main change here is ~~using lensAttributes instead to use a DSL
query instead~~.
[**EDIT**] Changing the ESQL query to use double STATS.

```
FROM ${getPrivilegedMonitorUsersIndex(namespace)}
      | WHERE user.is_privileged == true
      | STATS BY user.name
      | STATS count = COUNT(*)
```

Works well for 1k, 4k, and 10k user counts.

<img width="1655" height="464" alt="Screenshot 2026-01-21 at 3 26 37 PM"
src="https://github.com/user-attachments/assets/4dbae045-e1fd-40d0-aca2-8918181bed43"
/>
<img width="819" height="339" alt="Screenshot 2026-01-21 at 3 14 52 PM"
src="https://github.com/user-attachments/assets/28bc8ace-897c-4712-aed1-28a03c0243be"
/>
<img width="1659" height="353" alt="Screenshot 2026-01-21 at 2 56 33 PM"
src="https://github.com/user-attachments/assets/c1435265-e2d7-4dda-bbaf-9c91b12b49b8"
/>

**To test:**
1. Navigate to kibana (loaded up etc)
2. Upload > 1000 users, previously tested with 1008 users.
3. Should see on eggbox, privileged user count is accurate and matching
with dev tools result below:
4. dev tools command:
```
GET .entity_analytics.monitoring.users-*/_search
{
  "size": 0,
  "aggs": {
    "by_priv": {
      "terms": {
        "field": "user.is_privileged"
      }
    }
  }
}
```
5. Edit your csv, remove some of these users and re-upload.
6. Ensure the count is accurate to the new number of csv uploaded users
and the omitted users show privileged false in dev tools.

If someone wants to use a scripted way to generate csv users, may use
the below cli command

```
for i in {1..10000}; do echo "bulk_user_$i" >> privileged_users.csv; done && wc -l privileged_users.csv
```

---------

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: abhishekbhatia1710 <abhishek.bhatia@elastic.co>
Co-authored-by: Abhishek Bhatia <117628830+abhishekbhatia1710@users.noreply.github.com>
(cherry picked from commit 56b7cdf)
@kibanamachine kibanamachine merged commit b266d20 into elastic:9.3 Jan 21, 2026
17 checks passed
@elasticmachine
Copy link
Copy Markdown
Contributor

💛 Build succeeded, but was flaky

Failed CI Steps

Test Failures

  • [job] [logs] FTR Configs #21 / integrations When on the Endpoint Policy Details Page "after all" hook in "When on the Endpoint Policy Details Page"
  • [job] [logs] FTR Configs #21 / integrations When on the Endpoint Policy Details Page "before all" hook in "When on the Endpoint Policy Details Page"

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
securitySolution 10.8MB 10.8MB -17.0B

cc @CAWilson94

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport This PR is a backport of another PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants