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

feat(anta): Experimental feature - Add AIOHTTP transport for HTTPX #1088

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

carl-baillargeon
Copy link
Contributor

@carl-baillargeon carl-baillargeon commented Mar 11, 2025

Description

Add option to support AIOHTTP transport for HTTPX, related to encode/httpx#3215

Requires #680

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have run pre-commit for code linting and typing (pre-commit run)
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes (tox -e testenv)

Copy link

codspeed-hq bot commented Mar 11, 2025

CodSpeed Performance Report

Merging #1088 will not alter performance

Comparing carl-baillargeon:feat/aiohttp_transport (591789a) with main (4d8506a)

Summary

✅ 22 untouched benchmarks

@carl-baillargeon carl-baillargeon marked this pull request as ready for review March 11, 2025 21:22
@carl-baillargeon carl-baillargeon requested a review from gmuloc March 11, 2025 21:36
Copy link
Collaborator

@gmuloc gmuloc left a comment

Choose a reason for hiding this comment

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

Need to reviww tests

@@ -57,6 +57,7 @@ coverage.xml
.hypothesis/
cover/
report.html
.codspeed/
Copy link
Collaborator

Choose a reason for hiding this comment

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

do you need this? we have a codspeed file in .github I think

self._session = Device(**common_settings)
return self._session

async def _get_ssh_opts(self) -> SSHClientConnectionOptions:
Copy link
Collaborator

Choose a reason for hiding this comment

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

does it need to be async?

@@ -466,6 +515,7 @@ async def _collect(self, command: AntaCommand, *, collection_id: str | None = No
An identifier used to build the eAPI request ID.
"""
semaphore = await self._get_semaphore()
session = await self._get_session()
Copy link
Collaborator

Choose a reason for hiding this comment

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

should we call this everytime? if self._session is alreaedy set we don't need ti right?

@@ -544,7 +590,8 @@ async def refresh(self) -> None:
- hw_model: The hardware model of the device
"""
logger.debug("Refreshing device %s", self.name)
self.is_online = await self._session.check_connection()
session = await self._get_session()
Copy link
Collaborator

Choose a reason for hiding this comment

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

same here

@@ -555,14 +602,21 @@ async def refresh(self) -> None:
if self.hw_model is None:
logger.critical("Cannot parse 'show version' returned by device %s", self.name)
# in some cases it is possible that 'modelName' comes back empty
# and it is nice to get a meaninfule error message
Copy link
Collaborator

Choose a reason for hiding this comment

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

what the heck is meaninfule? :p and how did codespell not catch this?

@@ -342,3 +376,16 @@ async def connect_inventory(self) -> None:
if isinstance(r, Exception):
message = "Error when refreshing inventory"
anta_log_exception(r, message, logger)

async def disconnect_inventory(self) -> None:
"""Try to disconnect all devices in the inventory using their `close()` coroutine if available."""
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
"""Try to disconnect all devices in the inventory using their `close()` coroutine if available."""
"""Try to disconnect from all devices in the inventory using their `close()` coroutine if available."""

with Catchtime(logger=logger, message="Preparing the tests"):
selected_tests = prepare_tests(selected_inventory, catalog, tests, tags)
if selected_tests is None:
try:
Copy link
Collaborator

Choose a reason for hiding this comment

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

I feel like we should implement disconnecting the inventory in a separate PR for clarity



def find_deepest_os_error(exc: BaseException) -> OSError | None:
"""Find the most specific/deepest OSError in the chain of exceptions.
Copy link
Collaborator

Choose a reason for hiding this comment

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

can we document why we need this in the docstring? (as we are taking it out from where it was)

~ that can be found in the LICENSE file.
-->

ANTA offers experimental features that may improve performance or add capabilities, but haven't been thoroughly tested in all environments. These features might require additional dependencies and special configuration.
Copy link
Collaborator

Choose a reason for hiding this comment

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

lets add a warning box :D


### Using AIOHTTP Transport

As an experimental alternative, ANTA supports using [AIOHTTP](https://docs.aiohttp.org/en/stable/) as the transport layer for HTTPX. This can improve performance for high-scale deployments by delegating connection pooling and socket-level message to AIOHTTP while maintaining HTTPX's API for higher-level HTTP operations.
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
As an experimental alternative, ANTA supports using [AIOHTTP](https://docs.aiohttp.org/en/stable/) as the transport layer for HTTPX. This can improve performance for high-scale deployments by delegating connection pooling and socket-level message to AIOHTTP while maintaining HTTPX's API for higher-level HTTP operations.
As an experimental alternative, ANTA supports using [AIOHTTP](https://docs.aiohttp.org/en/stable/) as the transport layer for HTTPX. This can improve performance for high-scale deployments by delegating connection pooling and socket-level messages to AIOHTTP while maintaining HTTPX API for higher-level HTTP operations.

@gmuloc gmuloc added this to the v.1.4.0 milestone Mar 12, 2025
@carl-baillargeon carl-baillargeon marked this pull request as draft March 12, 2025 16:05
Copy link
Contributor

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants