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

Improve amazon.aws.ec2_metadata_facts module performance #2216

Open
1 task done
tzfromaz opened this issue Aug 8, 2024 · 1 comment
Open
1 task done

Improve amazon.aws.ec2_metadata_facts module performance #2216

tzfromaz opened this issue Aug 8, 2024 · 1 comment
Labels
needs_verified Some one might want to take a look at this and reproduce it to confirm waiting_on_contributor Needs help. Feel free to engage to get things unblocked

Comments

@tzfromaz
Copy link

tzfromaz commented Aug 8, 2024

Summary

The amazon.aws.ec2_metadata_facts module performance can be improved to eliminate a 20s+ delay especially focusing on better fact gathering.

For example:

import logging
logger = logging.getLogger(__name__)
logging.basicConfig(
    format='%(asctime)s %(levelname)-8s %(message)s',
    level=logging.WARNING,
    datefmt='%Y-%m-%d %H:%M:%S')
def get_facts_from_ec2_metadata():
    ec2_metadata_facts = {}
    logger.info("faking metadata using ec2_metadata module")
    from ec2_metadata import ec2_metadata
    from ec2_metadata import NetworkInterface
    import inspect
    import requests
    for attribute_name in dir(ec2_metadata):
        if not attribute_name.startswith('_'):
            try:
                attribute = getattr(ec2_metadata, attribute_name)
                logger.info(f"{attribute_name}:  {type(getattr(ec2_metadata, attribute_name))}  {getattr(ec2_metadata, attribute_name)}")
                if (not inspect.ismethod(attribute)) and (attribute_name != "network_interfaces"):
                    ec2_metadata_facts[attribute_name] = attribute
            except requests.exceptions.HTTPError as ex:
                logger.info(f"Failed to get {attribute_name}: {ex}")
    return ec2_metadata_facts
...
    #ec2_metadata_facts = Ec2Metadata(module).run()
     
    ec2_metadata_facts = get_facts_from_ec2_metadata()
...

Issue Type

Feature Idea

Component Name

amazon.aws.ec2_metadata_facts

Additional Information

This improves performance for the module overall and speeds up any runbooks using the module.

Code of Conduct

  • I agree to follow the Ansible Code of Conduct
@alinabuzachis alinabuzachis added waiting_on_contributor Needs help. Feel free to engage to get things unblocked needs_verified Some one might want to take a look at this and reproduce it to confirm and removed needs_triage labels Aug 22, 2024
@alinabuzachis
Copy link
Contributor

@tzfromaz Thank you for reporting this issue. Would you be willing to take the time to work on a fix and open a pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs_verified Some one might want to take a look at this and reproduce it to confirm waiting_on_contributor Needs help. Feel free to engage to get things unblocked
Projects
None yet
Development

No branches or pull requests

2 participants