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

refactor: store project-group association in api instead of keycloak #3612

Merged
merged 21 commits into from
Mar 12, 2024

Conversation

shreddedbacon
Copy link
Member

@shreddedbacon shreddedbacon commented Dec 3, 2023

General Checklist

  • Affected Issues have been mentioned in the Closing issues section
  • Documentation has been written/updated
  • PR title is ready for inclusion in changelog

Database Migrations

  • If your PR contains a database migation, it MUST be the latest in date order alphabetically

This changes the way that project ids are stored against groups. It currently retains the function of adding the attributes in keycloak still for backwards compatibility with tools that use these attributes, but with a plan to remove this functionality once the other tools can be updated to use the project ids from the api-db.

The big changes are

  • store the group id to project id association in a table
  • store the group id to organization id association in a table
  • cache the group name to group id reference (purged when anything related to groups is performed)
  • cache the group response payload (purged when anything related to groups is performed)
  • cache the group members (purged when membership is modified)
  • a migration script that will retrieve existing groups/projects from keycloak and add them to the database
  • uses a custom mapper in keycloak to allow the opensearch token mapper to retrieve project ids from the api-db

Considerations

  • The biggest issue Lagoon has with using the attributes to store the project id assocation in keycloak is how we work out which groups a project has associated, as this requires us to retrieve all the groups from keycloak and iterate over them to check the attributes. This all groups query from keycloak is slow*number of groups, as more groups are added, slowness increases.
    • Adding these associations in the api-db, we can now query the api-db and get the information we need so we only need to go to keycloak if we absolutely have to.
    • While one or two calls to the allgroups query is usually fine, the way that a large number of lagoon queries work results in this query needing to be performed potentially multiple times, or a large number of times when users interact with the API in busy periods. This results in keycloak CPU utilization spiking. refactor: optimize keycloak interactions #3397 was a first attempt at reducing how often the allgroups query was called, and it purged the data when groups were modified, but as the number of groups increases, this query gets slower and slower resulting in slow API responses or timeouts during busy periods
  • The lagoon-projects attribute on groups would need remain, at least for a period of time, as there are other systems that use these that would need to be refactored. While these other systems/tools use this attribute though, when a group is added/removed to a project, there is the potential due to the non-atomic nature of a lot of requests in Lagoon, that keycloak may not receive the attribute update, but the api-db does, or vice versa. This would result in incorrect access in either api or the other tools depending on the failure point. This not-atomic nature exists now, so this out of sync condition can and already does occur at times.
  • More data is cached from keycloak to speed up performance of group and member based queries. As organizations exposes a part of Lagoon that has typically been hidden away from users for so long, and thus relatively unused. Organizations is very heavy on group and group member queries, it made sense to cache a lot of this where possible.
    • an entire group response is cached, this query when performed against keycloak is not that bad, but if a large number of groups are requested against keycloak directly, the response time can be long.
    • a groups membership is also cached, this sort of query can also be quite heavy as it can request a considerable amount of information from keycloak if multiple groups and their members are requested, pulling this from the cache is ideal.
    • any changes to a groups project ids, or a member/role change within a group results in that groups entire cache data being purged, and will be re-populated when it is requested next.

@shreddedbacon shreddedbacon force-pushed the project-groups-db-cache branch from 33d3e80 to 2835fb4 Compare December 6, 2023 00:06
@shreddedbacon shreddedbacon changed the title refactor: use apidb to store project-group and org-group association refactor: store project-group association in api instead of keycloak Dec 6, 2023
@shreddedbacon shreddedbacon marked this pull request as ready for review January 15, 2024 02:04
@shreddedbacon shreddedbacon added this to the 2.18.0 milestone Jan 17, 2024
@shreddedbacon shreddedbacon force-pushed the project-groups-db-cache branch from 61325ea to d121d35 Compare March 8, 2024 00:31
Copy link
Member

@rocketeerbkw rocketeerbkw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will work as a middle ground while we continue to explore options for all group data.

@tobybellwood tobybellwood merged commit 6af5ae3 into main Mar 12, 2024
2 checks passed
@tobybellwood tobybellwood deleted the project-groups-db-cache branch March 13, 2024 01:45
smlx added a commit to uselagoon/lagoon-opensearch-sync that referenced this pull request Apr 19, 2024
The lagoon-projects attribute is deprecated as of Lagoon v2.18.

See uselagoon/lagoon#3612 for details.
smlx added a commit to uselagoon/lagoon-opensearch-sync that referenced this pull request Apr 19, 2024
The lagoon-projects attribute is deprecated as of Lagoon v2.18.

See uselagoon/lagoon#3612 for details.
smlx added a commit to uselagoon/lagoon-opensearch-sync that referenced this pull request May 6, 2024
The lagoon-projects attribute is deprecated as of Lagoon v2.18.

See uselagoon/lagoon#3612 for details.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants