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

Feature/organization caching #789

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

igordust
Copy link
Contributor

@igordust igordust commented Feb 26, 2025

Why?

With version 4.0, we noticed an increase in the number of Organizations API Calls that are performed during account management and bootstrap, leading to errors or longer execution times.

*Issue #788, #784, #781

What?

Description of changes:

Now Organizations class always use the Cache object, even when it's not passed to the constructor. If passed in the constructor, allow the user of the class to share the same cache with different instances of Organizations. This happens for example in the bootstrap pipeline, where a worker thread for each account is created.
The following methods now make use of Cache:

  • get_organization_info
  • describe_ou_name
  • describe_account_name
  • list_parents
  • get_ou_root_id
  • list_organizational_units_for_parent
  • build_account_path

By submitting this pull request, I confirm that you can use, modify, copy, and
redistribute this contribution, under the terms of your choice.

Comment on lines +73 to +76
if cache is not None:
self.cache = cache
else:
self.cache = Cache()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
if cache is not None:
self.cache = cache
else:
self.cache = Cache()
self.cache = cache or Cache()

@@ -256,14 +256,14 @@ def worker_thread(

organizations = Organizations(
role=boto3,
account_id=account_id
account_id=account_id,
cache=cache
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
cache=cache
cache=cache,

self.account_id = account_id
self.root_id = None
Copy link
Collaborator

Choose a reason for hiding this comment

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

For those who wonder, this wasn't used externally, hence we agreed to refactor it.

return organizational_units

def list_organizational_units_for_parent(self, parent_ou):
print(f'looking for children in {parent_ou}')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
print(f'looking for children in {parent_ou}')
LOGGER.debug(f'Looking for children in {parent_ou}')

current.get("Id"),
self.describe_ou_name(current.get("Id")),
)
ou_name = cache.get(current.get("Id"))
ou_name = self.cache.get(current.get("Id"))
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't need to cache this at this layer anymore, as you added caching in the describe_ou_name function 👍

Hence, this would suffice:

Suggested change
ou_name = self.cache.get(current.get("Id"))
ou_name = self.describe_ou_name(current.get("Id"))

Comment on lines +429 to 433
if not self.cache.exists(current.get("Id")):
self.cache.add(
current.get("Id"),
self.describe_ou_name(current.get("Id")),
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not required, see next comment.

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.

2 participants