Generating datasets
This describes how to use the dataset provider and its API to generate datasets for load testing.
|
Never install this provider in a production environment as its endpoints are not secured. |
Prerequisites
When using Quarkus or the minikube installation, all URLs start with /realms/master.
For the Wildfly distribution, the URL starts with /auth/realms/master.
Using the dataset provider
Scripted usage
This script contains a subset of the operations described in the next sections around realms, users and clients.
The script assumes that the dataset provider is installed as described in Installing on minikube setup and that it is available at
https://keycloak-keycloak.$(minikube ip).nip.io/realms/master/dataset/.
Run the following command to receive a help description:
./dataset-import.sh -a help
You will see these options:
Dataset import to the local minikube Keycloak application - usage: 1) create realm/s with clients, users and password hash algorithm & iterations - run -a (action) with or without other arguments: -a create-realms -r 10 -g argon2 -i 5 -c 100 -u 100 -l 'https://keycloak.url.com' 2) create clients in specific realm: -a create-clients -c 100 -n realm-0 -l 'https://keycloak.url.com' 3) create users in specific realm: -a create-users -u 100 -n realm-0 -l 'https://keycloak.url.com' 4) create events in specific realm: -a create-events -e 100 -n realm-0 -l 'https://keycloak.url.com' 5) create offline sessions in specific realm: -a create-offline-sessions -o 100 -n realm-0 -l 'https://keycloak.url.com' 6) delete specific realm/s with prefix -a delete-realms -p realm -l 'https://keycloak.url.com' 7) dataset provider status -a status 'https://keycloak.url.com' 8) dataset provider status check of last completed job -a status-completed -t 10 -l 'https://keycloak.url.com' 9) dataset provider clear status of last completed job -a clear-status-completed -l 'https://keycloak.url.com' 10) dataset import script usage -a help
Example of creating 10 new realms:
./dataset-import.sh -a create-realms -r 10
Alternatively, the user could also run the Taskfile from within the provision/minikube module to execute the dataset-import task, to seamlessly execute the automation for Kubernetes style deployments.
The dataset-import task re-uses the command line arguments defined above to make it convenient for the user.
Note the two dashes (--) that separate the task name from the command line options passed to the script.
task dataset-import -- -a create-realms -r 10
To learn more about the tool, see Automation using the tool task for details.
Dataset Provider APIs
Create many realms
You need to call this HTTP REST requests. This request is useful for create 10 realms. Each realm will contain a set of roles, clients, groups and users:
.../realms/master/dataset/create-realms?count=10
Create many clients
This is a request to create 200 new clients in the realm realm-5.
Each client will have service account enabled and secret like <client_id>-secret (For example client-156-secret in the case of the client client-156):
.../realms/master/dataset/create-clients?count=200&realm-name=realm-5
You can also configure the access-type (bearer-only, confidential or public) and whether the client should be a service-account-client with these two parameters:
...&client-access-type=bearer-only&service-account-client=false
Create many users
This is a request to create 1000 new users in the realm realm-5:
.../realms/master/dataset/create-users?count=1000&realm-name=realm-5
Each user will have the specified amount of roles, client roles and groups, which were already created by the create-realms endpoint.
Each user will be assigned a password in the format <username>-password. For example user-156 will have the password user-156-password.
Speed up user creation by limiting the total number of passwords
When creating users, the bottleneck is CPU time to hash the passwords that are by default unique for each user.
To reduce total time to create a large number of users, configure the dataset to only create a limited
pool of hashed passwords and reuse these credentials when creating users. Specify the unique-credential-count parameter
in order to limit the number of passwords created.
When limiting the total number of passwords, individual passwords for a given user are calculated as "password-" + i
where i is the user’s number % unique-credential-count.
For example, after executing:
.../realms/master/dataset/create-users?realm-name=realm-0&count=1000&unique-credential-count=10`
the user user-156 will have the password password-6 as we calculate i = 156 % 10.
Create many groups
Groups are created as part of the realm creation. The number of groups and the structure of the created groups can be managed by using the following parameters:
groups-per-realm-
Total number of groups per realm. The default value is
20. groups-with-hierarchy-
trueorfalse, the default value isfalse. With the default value, only top-level groups are created. With groups-with-hierarchy set totruea tree structure of groups is created; the depth of the tree is defined by the parametergroups-hierarchy-depthandgroups-count-each-leveldefines how many subgroups each created group will have. groups-hierarchy-depth-
The depth of the groups tree structure. The default value is 3. With the default value, top level groups will have
groups-count-each-levelsubgroups and each subgroup will havegroups-count-each-levelthemselves. This parameter is active only whengroups-with-hierarchyistrue. groups-count-each-level-
The Number of subgroups each created group will have. This parameter is active only when
groups-with-hierarchyistrue.
With the default values, only top-level groups are created.
With groups-with-hierarchy set to true, the groups-per-realm parameter is ignored and the group tree structure is created as defined by the other parameters. groups-count-each-levelgroups-hierarchy-depth will be the total number of groups created.
The hierarchical groups implementation honors groups-per-transaction.
The adopted subgroup naming convention uses a dot (.) in the group names which allows finding the parent group even if it was created in a previous transaction.
.../realms/master/dataset/create-realms?count=1&groups-with-hierarchy=true&groups-hierarchy-depth=3&groups-count-each-level=50
You can also create groups in an existing realm by invoking the create-groups endpoint and setting the realm-name parameter:
.../realms/master/dataset/create-groups?realm-name=realm-0&count=10&groups-with-hierarchy=true&groups-hierarchy-depth=3&groups-count-each-level=5
Create many events
This is a request to create 10M new events in the available realms with prefix realm-.
For example if we have 100 realms like realm-0, realm-1, … realm-99, it will create 10M events in realm-99.
.../realms/master/dataset/create-events?count=10000000
Create many sessions
This is a request to create 10M new sessions in the available realms with prefix realm-.
For example if we have 100 realms like realm-0, realm-1, … realm-99, it will create 10M sessions in realm-99 distributed across all users and clients of the realm as defined by clients-per-realm and users-per-realm.
.../realms/master/dataset/create-sessions?count=10000000&clients-per-realm=100&users-per-realm=1000
You can also specify the optional parameter session-expiration-interval to stagger the expiration times of the created
sessions. The interval is specified in seconds, and the sessions will be randomly distributed in the interval.
The below example creates 100 sessions,
with sessions expiring in a 3600-second interval:
.../realms/master/dataset/create-sessions?count=100&session-expiration-interval=3600
Create many offline sessions
This is a request to create 10M new offline sessions in the available realms with prefix realm-.
For example if we have 100 realms like realm-0, realm-1, … realm-99, it will create 10M offline sessions in realm-99
for user user-0.
.../realms/master/dataset/create-offline-sessions?count=10000000
Remove many realms
To remove all realms with the default realm prefix realm
.../realms/master/dataset/remove-realms?remove-all=true
You can use realm-prefix to change the default realm prefix.
You can use parameters to remove all realms for example just from foorealm5 to foorealm15
.../realms/master/dataset/remove-realms?realm-prefix=foorealm&first-to-remove=5&last-to-remove=15
Change default parameters
For change the parameters, take a look at DataSetConfig class
to see available parameters and default values and which endpoint the particular parameter is applicable.
For example to create realms with prefix foo and with just 1000 hash iterations (with the default hashing algorithm) used for the password policy you can use these parameters:
.../realms/master/dataset/create-realms?count=10&realm-prefix=foo&password-hash-iterations=1000
Another example would be to specify a particular hashing algorithm in combination with the hashing iterations with the below parameters:
.../realms/master/dataset/create-realms?count=10&realm-prefix=foo&password-hash-algorithm=argon2&password-hash-iterations=1000
The configuration is written to the server log when HTTP endpoint is triggered, so you can monitor the progress and what parameters were effectively applied.
Note that creation of new objects will automatically start from the next available index.
For example when you trigger endpoint above for creation many clients, and you already had 230 clients in your DB (client-0, client-1, … client-229), then your HTTP request will start creating clients from client-230 .
Check if the task is still running
Call the following URL using the GET method:
.../realms/master/dataset/status
If there is a task still running, it returns information like the following:
{"status":"Task in progress","task-id":{"startTimeMs":"1662115169043","message":"Creation of 1 realms from realm-6 to realm-6"}}
If there is no task running, it returns information like the following:
{"status":"No task in progress. New task can be started"}
Check the result of the last completed task
Call the following URL using the GET method:
.../realms/master/dataset/status-completed
If there is a task still running, it returns information like the following:
{"status":"previous task completed","task":{"success":"true","startTimeMs":"1662115169043","message":"Creation of 1 realms from realm-1 to realm-1","endTimeMs":"1662115173323"}}
If there is no completed task, it returns this information with status code 404:
{"status":"No completed task"}
Clear the result of the last completed task
Call the following URL using the DELETE method:
.../realms/master/dataset/status-completed
Check the last items of a particular object
To see the last created realm index
.../realms/master/dataset/last-realm
To see the last created client in given realm
.../realms/master/dataset/last-client?realm-name=realm5
To see the last created user in a given realm
.../realms/master/dataset/last-user?realm-name=realm5
Provisioning organizations
Before provisioning organizations, make sure to manually create or provision a realm. For example,
provision a realm-0 realm as follows:
.../realms/master/dataset/create-realms?count=1&users-per-realm=5000
As a result, you have a realm realm-0 with 5k users in it.
This is the request to create 1000 organizations in a realm with prefix org-:
.../realms/realm-0/dataset/orgs/create?count=1000
Alternatively, you can create a single organization with a given name:
realms/realm-0/dataset/orgs/create?name=myorg.com&domains=myorg.com,myorg.org,myorg.net&count=1
You can also specify how many managed and unmanaged members and how many identity providers should be linked to each organization created:
.../realms/realm-0/dataset/orgs/create?count=1000&unmanaged-members-count=500&identity-providers-count=10
As a result, 1k organizations with the following configuration:
-
500 unmanaged members
-
10 identity providers
It is also possible to specify a number of identity provider mappers per each identity provider:
.../realms/realm-0/dataset/orgs/create?count=1000&unmanaged-members-count=500&identity-providers-count=10&identity-provider-mappers-count=3
This creates 1k organizations with 500 unmanaged members each, 10 identity providers and with identity provider having 3 identity provider mappers.
You can also provision data to a specific organization. For instance, to provision more identity providers to a specific organization:
.../realms/realm-0/dataset/orgs/org-0/identity-providers/create?count=1000
Optionally, it’s possible to specify a number of identity provider mappers per each identity provider
.../realms/realm-0/dataset/orgs/org-0/identity-providers/create?count=1000&identity-provider-mappers-count=5
Or to provision more unmanaged members to a specific organization:
.../realms/realm-0/dataset/orgs/org-0/members/create-unmanaged?count=100
Or to provision more managed members to a specific organization:
.../realms/realm-0/dataset/orgs/org-0/members/create-managed?count=100
When provisioning members, make sure you have created enough users in the realm. For managed members, you also need at least a single identity provider linked to an organization.
If you want to remove an organization:
.../realms/realm-0/dataset/orgs/org-0/remove