Ticket 13063

Summary: slurm rest api '/users' return more users than CLI
Product: Slurm Reporter: azoshima
Component: slurmrestdAssignee: Director of Support <support>
Status: RESOLVED FIXED QA Contact:
Severity: 4 - Minor Issue    
Priority: --- CC: alin4, andrew.phillips2, ihmesa, nate, tim
Version: 20.11.8   
Hardware: Linux   
OS: Linux   
See Also: https://bugs.schedmd.com/show_bug.cgi?id=13661
Site: U WA Health Metrics Alineos Sites: ---
Atos/Eviden Sites: --- Confidential Site: ---
Coreweave sites: --- Cray Sites: ---
DS9 clusters: --- HPCnow Sites: ---
HPE Sites: --- IBM Sites: ---
NOAA SIte: --- OCF Sites: ---
Recursion Pharma Sites: --- SFW Sites: ---
SNIC sites: --- Linux Distro: ---
Machine Name: CLE Version:
Version Fixed: 22.05.0 Target Release: ---
DevPrio: --- Emory-Cloud Sites: ---

Description azoshima 2021-12-20 14:19:29 MST
Hello support team,

We are trying to retrieve users data from REST API.
We compared the returned users data between API and CLI (sacctmgr show users), but the number of returned users are different. API returned more.


```
curl -X GET -s -H 'X-SLURM-USER-NAME: xxxx' -H 'X-SLURM-USER-TOKEN: yyyy' -H 'Content-Type: application/json' https://api-dev.cluster.ihme.washington.edu/slurmdb/v0.0.36/users | jq '.users | length'

740
```

```
sacctmgr show users -n | wc -l

731
```

How can we get the same values with CLI with REST API?
Thank you for your support.
Comment 1 Nate Rini 2021-12-20 14:30:21 MST
(In reply to azoshima from comment #0)
> How can we get the same values with CLI with REST API?
> Thank you for your support.

Try calling:
> sacctmgr show users withdeleted -n | wc -l
Comment 2 azoshima 2021-12-20 16:59:41 MST
Thank you!

That returned the same value with RestAPI.
```
sacctmgr show users withdeleted -n | wc -l
740
```

If we want to get users without deleted users from RestAPI, how can we achieve it?
Comment 5 Nate Rini 2021-12-21 10:50:05 MST
(In reply to azoshima from comment #2)
> If we want to get users without deleted users from RestAPI, how can we
> achieve it?

The flag in the RPC is currently not getting added to the output to make it possible to filter. I will see about getting that added to the output but it will most likely go into dbv0.0.38 if approved.

In the mean time, your site can apply this patch to avoid dumping deleted users:
> diff --git a/src/slurmrestd/plugins/openapi/dbv0.0.36/users.c b/src/slurmrestd/plugins/openapi/dbv0.0.36/users.c
> index 6ca66ff..89cdc69 100644
> --- a/src/slurmrestd/plugins/openapi/dbv0.0.36/users.c
> +++ b/src/slurmrestd/plugins/openapi/dbv0.0.36/users.c
> @@ -106,7 +106,7 @@ static int _dump_users(data_t *resp, data_t *errors, rest_auth_context_t *auth,
>               .assoc_cond = &assoc_cond,
>               .with_assocs = true,
>               .with_coords = true,
> -             .with_deleted = true,
> +             .with_deleted = false,
>               .with_wckeys = true,
>       };
>
Comment 7 azoshima 2021-12-21 15:50:47 MST
Thank you for patch information.

It is great to know that filter functionality may be included in near future release. It will be very helpful.

Please go ahead to close this ticket.
Thank you for your support.
Comment 11 Michael Hinton 2022-04-11 16:08:26 MDT
*** Ticket 13807 has been marked as a duplicate of this ticket. ***
Comment 31 Michael Hinton 2022-05-10 11:13:36 MDT
Hello,

This has been fixed for users in the upcoming 22.05.0 release, in dbv38, with the following commits: https://github.com/SchedMD/slurm/compare/4049afa4b2b0...d6478de31324

Here's a quick summary of the relevant changes:

* /user[s] now defaults to with_deleted=false
* /user[s] now has a "with_deleted" input you can specify in the URL. E.g. slurmdb/v0.0.38/users?with_deleted=true
* /user[s] now has a "flags" output that will contain a DELETED flag for user records that are deleted.

With that, I'll go ahead and close this out. Let me know if you have any questions.

Thanks!
-Michael
Comment 32 Ali Nikkhah 2022-05-10 19:28:32 MDT
(In reply to Michael Hinton from comment #31)
> Hello,
> 
> This has been fixed for users in the upcoming 22.05.0 release, in dbv38,
> with the following commits:
> https://github.com/SchedMD/slurm/compare/4049afa4b2b0...d6478de31324
> 

This is great! Thanks!