Skip to content
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

Fix performance of grafana_user #285

Merged
merged 1 commit into from
May 27, 2022

Conversation

alexjfisher
Copy link
Member

@alexjfisher alexjfisher commented May 26, 2022

Previously, the number of API calls to look up the details of a single user was equal to 1 + the number of existing users.
This made managing multiple users exponentially slow.

The way the types in this module are written, (with the Grafana API user credentials being parameters of each resource), we can't implement prefetch to fetch all users just once; but we can change the implementation to directly lookup the user we're trying to manage.

This is much faster!

@alexjfisher alexjfisher force-pushed the user_performance branch 2 times, most recently from ad8a9a7 to b009abf Compare May 27, 2022 09:15
@alexjfisher alexjfisher changed the title Improve performance of grafana_user Fix performance of grafana_user May 27, 2022
Previously, the number of API calls to look up the details of a single
user was equal to `1 + the number of existing users`.  This made
managing multiple users exponentially slow.

The way the types in this module are written, (with the Grafana API
user credentials being parameters of each resource), we can't implement
`prefetch` to fetch all users just once; but we can change the
implementation to directly lookup the user we're trying to manage.
This is _much_ faster!
@alexjfisher alexjfisher marked this pull request as ready for review May 27, 2022 10:24
@bastelfreak bastelfreak added the enhancement New feature or request label May 27, 2022
@bastelfreak bastelfreak merged commit e2fccf8 into voxpupuli:master May 27, 2022
@alexjfisher
Copy link
Member Author

For reference, using the following puppet code and puppet apply to talk to a remote grafana server (in the same datacenter, but not as quick as localhost with no ssl!).

grafana_user { range("testuser00","testuser99"):
  ensure           => present,                                                                                                                                                                                               
  grafana_url      => 'https://remotegrafana.example.com',                                                                                                                                                               
  grafana_user     => 'admin',                                                                                                                                                                                                            
  grafana_password => 'admin',                                                                                                                                                                                                            }

Before change...

Creating 100 users
Notice: Applied catalog in 126.45 seconds

Running Puppet again (ensuring those 100 users are still present)
Notice: Applied catalog in 224.31 seconds

Second run is slower as the average number of grafana users is > 100 for the entire duration, and not ~ 50.

After change...
1st puppet run
Notice: Applied catalog in 5.58 seconds
2nd puppet run
Notice: Applied catalog in 2.11 seconds

ie 100 times faster for this use case of just 100 users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants