-
Notifications
You must be signed in to change notification settings - Fork 4
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
Enable MITM proxy for requestor probes #535
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fd67f97
Enable proxy for provider agent Market API calls
azawlocki 6fc3001
Handle the `use_proxy` config setting when setting up requestor proxies
azawlocki 92f41c4
Add unit test for method Probe.get_yagna_api_url()
azawlocki a4f3fcc
Map ports 6000-6100 in nginx-proxy to ports 16000-16100 on Docker host
azawlocki ae8d9ec
Correctly return yagna REST port for access through proxy
azawlocki e9b0285
Fix some typing issues in probe/__init__.py
azawlocki becf964
Fix some type annotations in compose.py
azawlocki b23700e
Apply suggestions from code review
azawlocki 318fb5f
Address requests from code review (and then some)
azawlocki 737e724
Adjust unit tests
azawlocki File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
import logging | ||
import os | ||
from pathlib import Path | ||
from typing import ClassVar, Dict, Optional | ||
from typing import AsyncIterator, ClassVar, Dict, List, Optional | ||
|
||
from docker import DockerClient | ||
import yaml | ||
|
@@ -16,7 +16,7 @@ | |
build_yagna_image, | ||
YagnaBuildEnvironment, | ||
) | ||
from goth.runner.container.utils import get_container_address | ||
from goth.runner.container.utils import get_container_network_info | ||
from goth.runner.exceptions import ContainerNotFoundError | ||
from goth.runner.log import LogConfig | ||
from goth.runner.log_monitor import LogEventMonitor | ||
|
@@ -47,6 +47,20 @@ class ComposeConfig: | |
""" | ||
|
||
|
||
@dataclass | ||
class ContainerInfo: | ||
"""Info on a Docker container started by Docker compose.""" | ||
|
||
address: str | ||
"""The container's IP address in the Docker network""" | ||
|
||
aliases: List[str] | ||
"""Container aliases in the Docker network""" | ||
|
||
image: str | ||
"""The container's image name""" | ||
|
||
|
||
class ComposeNetworkManager: | ||
"""Class which manages a docker-compose network. | ||
|
||
|
@@ -82,9 +96,12 @@ def __init__( | |
self._log_monitors = {} | ||
self._network_gateway_address = "" | ||
|
||
async def start_network(self, log_dir: Path, force_build: bool = False) -> None: | ||
async def start_network( | ||
self, log_dir: Path, force_build: bool = False | ||
) -> Dict[str, ContainerInfo]: | ||
"""Start the compose network based on this manager's compose file. | ||
|
||
Returns information on containers started in the compose network. | ||
This step may include (re)building the network's docker images. | ||
""" | ||
# Stop the network in case it's already running (e.g. from a previous test) | ||
|
@@ -106,7 +123,12 @@ async def start_network(self, log_dir: Path, force_build: bool = False) -> None: | |
|
||
self._start_log_monitors(log_dir) | ||
await self._wait_for_containers() | ||
self._log_running_containers() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can safely remove this function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done (318fb5f) |
||
container_infos = self._get_running_containers() | ||
for name, info in container_infos.items(): | ||
logger.info( | ||
"[%-25s] IP address: %-15s image: %s", name, info.address, info.image | ||
) | ||
return container_infos | ||
|
||
async def _wait_for_containers(self) -> None: | ||
logger.info("Waiting for compose containers to be ready") | ||
|
@@ -162,14 +184,15 @@ def network_gateway_address(self) -> str: | |
|
||
return self._network_gateway_address | ||
|
||
def _log_running_containers(self): | ||
def _get_running_containers(self) -> Dict[str, ContainerInfo]: | ||
info = {} | ||
for container in self._docker_client.containers.list(): | ||
logger.info( | ||
"[%-25s] IP address: %-15s image: %s", | ||
container.name, | ||
get_container_address(self._docker_client, container.name), | ||
container.image.tags[0], | ||
address, aliases = get_container_network_info( | ||
self._docker_client, container.name | ||
) | ||
image = container.image.tags[0] | ||
info[container.name] = ContainerInfo(address, aliases, image) | ||
return info | ||
|
||
def _start_log_monitors(self, log_dir: Path) -> None: | ||
for service_name in self._get_compose_services(): | ||
|
@@ -195,15 +218,18 @@ def _start_log_monitors(self, log_dir: Path) -> None: | |
@contextlib.asynccontextmanager | ||
async def run_compose_network( | ||
compose_manager: ComposeNetworkManager, log_dir: Path, force_build: bool = False | ||
) -> None: | ||
"""Implement AsyncContextManager for starting/stopping docker compose network.""" | ||
) -> AsyncIterator[Dict[str, ContainerInfo]]: | ||
"""Implement AsyncContextManager for starting/stopping docker compose network. | ||
|
||
Yields information on containers started in the compose network. | ||
""" | ||
|
||
try: | ||
logger.debug( | ||
"Starting compose network. log_dir=%s, force_build=%s", log_dir, force_build | ||
) | ||
await compose_manager.start_network(log_dir, force_build) | ||
yield | ||
containers = await compose_manager.start_network(log_dir, force_build) | ||
yield containers | ||
finally: | ||
logger.debug("Stopping compose network") | ||
await compose_manager.stop_network() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's mention the newly-added return value here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (318fb5f)