-
Notifications
You must be signed in to change notification settings - Fork 83
feat(integration-tests): Spin up and tear down the clp-text and clp-json packages.
#1437
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
Open
quinntaylormitchell
wants to merge
59
commits into
y-scope:main
Choose a base branch
from
quinntaylormitchell:testing-start-stop
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 35 commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
8e75e15
Test a generic clp package start up and spin down (default: clp-text).
quinntaylormitchell 44ee20e
Merge branch 'main' into feature branch
quinntaylormitchell bbe0575
Expand to clp-text and clp-json; store JSON config pairs in temp conf…
quinntaylormitchell 5cd47f8
Merge branch 'main' into feature branch
quinntaylormitchell c5375eb
Include and employ clp_py_utils.clp_config; refrain from using the us…
quinntaylormitchell 2be837f
Lint.
quinntaylormitchell bf14b5e
Refactor; move all utility functions to utils files as appropriate.
quinntaylormitchell 27b7f5b
Add comments.
quinntaylormitchell e041f0e
Streamline logger calls.
quinntaylormitchell 75672fc
Deduplicate fixture code.
quinntaylormitchell 0822a79
Merge branch 'main' into feature branch
quinntaylormitchell 2df9515
Change method of clp_config import; temporary, will change again once…
quinntaylormitchell 63f3ae4
Generalize code so that it's better equipped to handle future CLP_MOD…
quinntaylormitchell 0011447
Merge branch 'main' into feature branch
quinntaylormitchell 0ff9465
Combine PackageConfig, PackageModeConfig, and PackageInstanceConfig i…
quinntaylormitchell cdcfaee
Employ a 'CLPConfig'-centric approach rather than 'dict'-centric.
quinntaylormitchell 53e7343
Store list of required components for each mode
quinntaylormitchell 796ffe3
Generalize the method by which the mode of operation is determined.
quinntaylormitchell bae12de
Move all mode-related utilities to their own file.
quinntaylormitchell 9c9ef74
Minor error.
quinntaylormitchell 0f3dcd5
Move load_yaml_to_dict to general utilities file.
quinntaylormitchell f9865a8
Add taskfile tasks for package tests.
quinntaylormitchell 865e9ed
Address rabbit comments.
quinntaylormitchell 09d5200
Add mariadb_config install for linting purposes (will be unecessary a…
quinntaylormitchell 5fffc32
Lint YAML.
quinntaylormitchell 571f313
Merge branch 'main' into feature branch
quinntaylormitchell e348be0
Adapt code after #1549 merge.
quinntaylormitchell 30f186f
Merge branch 'main' into feature branch
quinntaylormitchell e5da7e9
Merge branch 'main' into feature branch
quinntaylormitchell 292ec70
Merge branch 'main' into feature branch
quinntaylormitchell 0c4cfa4
Remove 'python -m'.
quinntaylormitchell bee738a
Address Bill-hbrhbr comments.
quinntaylormitchell 49eaf97
Brush up docstrings.
quinntaylormitchell e3c4a3b
Merge branch 'main' into feature branch
quinntaylormitchell 4cd92e6
Adapt to PascalCase ClpConfig.
quinntaylormitchell 87c4809
Merge branch 'main' into feature branch
quinntaylormitchell baddcfe
Address Bill's comments; add helper function that returns a list of r…
quinntaylormitchell 7cf597d
Rabbit.
quinntaylormitchell 8372a9f
Refactor PackageConfig and PackageInstance classes into three separat…
quinntaylormitchell b92ee22
Apply suggestions from code review
Bill-hbrhbr f950df0
Merge branch 'main' into testing-start-stop
Bill-hbrhbr aac6fcb
lint fix and variable substitution
Bill-hbrhbr 9f995b9
Update according to coderabbit AI suggestion.
Bill-hbrhbr 03cb974
Merge branch 'main' into testing-start-stop
Bill-hbrhbr 0e0567a
Apply Bill's comments.
quinntaylormitchell d44ab95
Merge branch 'main' into feature branch
quinntaylormitchell 324ade4
Add ClpConfig data member to PackageConfig class; use 'fixt_' at begi…
quinntaylormitchell e7e79e1
Merge branch 'main' into feature branch
quinntaylormitchell 7116cfc
Post-merge main.
quinntaylormitchell 3471168
Remove return from _write_temp_config_file.
quinntaylormitchell a324248
Remove unecessary logging statements.
quinntaylormitchell 6caf53a
Move content to other PRs.
quinntaylormitchell f3e533d
Add task for package integration tests.
quinntaylormitchell a71bcb0
Revert "Move content to other PRs."
quinntaylormitchell b5cf248
Revert "Revert "Move content to other PRs.""
quinntaylormitchell b496025
Revert "Add task for package integration tests."
quinntaylormitchell 86ab692
Address Bill's comments.
quinntaylormitchell ce822d8
Address missed comments.
quinntaylormitchell 8224985
Merge branch 'main' into feature branch
quinntaylormitchell 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
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
70 changes: 70 additions & 0 deletions
70
integration-tests/tests/fixtures/package_config_fixtures.py
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| """Fixtures that create and remove temporary config files for CLP packages.""" | ||
|
|
||
| import contextlib | ||
| import logging | ||
| from collections.abc import Iterator | ||
| from pathlib import Path | ||
|
|
||
| import pytest | ||
|
|
||
| from tests.utils.clp_mode_utils import CLP_MODE_CONFIGS, get_clp_config_from_mode | ||
| from tests.utils.config import PackageConfig | ||
| from tests.utils.utils import get_env_var | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| def _build_package_config_for_mode(mode_name: str) -> PackageConfig: | ||
| """ | ||
| Constructs a PackageConfig for the specified CLP mode. | ||
|
|
||
| :param mode_name: | ||
| :return: A PackageConfig object configured for the given mode. | ||
| :raise KeyError: if the mode name is unknown. | ||
| """ | ||
| if mode_name not in CLP_MODE_CONFIGS: | ||
| err_msg = f"Unknown CLP mode '{mode_name}'." | ||
| raise KeyError(err_msg) | ||
|
|
||
| clp_package_dir = Path(get_env_var("CLP_PACKAGE_DIR")).expanduser().resolve() | ||
| test_root_dir = Path(get_env_var("CLP_BUILD_DIR")).expanduser().resolve() / "integration-tests" | ||
|
|
||
| return PackageConfig( | ||
| clp_package_dir=clp_package_dir, | ||
| test_root_dir=test_root_dir, | ||
| mode_name=mode_name, | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def clp_config( | ||
| request: pytest.FixtureRequest, | ||
| ) -> Iterator[PackageConfig]: | ||
| """ | ||
| Creates and maintains a PackageConfig object for a specific CLP mode. | ||
|
|
||
| :param request: | ||
| :return: An iterator that yields the PackageConfig object for the specified mode. | ||
| """ | ||
| mode_name: str = request.param | ||
| logger.info("Creating a temporary config file for the %s package...", mode_name) | ||
|
|
||
| package_config = _build_package_config_for_mode(mode_name) | ||
|
|
||
| # Create the temp config file. | ||
| clp_config_obj = get_clp_config_from_mode(mode_name) | ||
| temp_config_file_path = PackageConfig.write_temp_config_file( | ||
| clp_config=clp_config_obj, | ||
| temp_config_dir=package_config.temp_config_dir, | ||
| mode_name=mode_name, | ||
| ) | ||
|
|
||
| logger.info("The temporary config file has been written for the %s package.", mode_name) | ||
|
|
||
| try: | ||
| yield package_config | ||
| finally: | ||
| logger.info("Removing the temporary config file...") | ||
| with contextlib.suppress(FileNotFoundError): | ||
| temp_config_file_path.unlink() | ||
| logger.info("The temporary config file has been removed.") |
56 changes: 56 additions & 0 deletions
56
integration-tests/tests/fixtures/package_instance_fixtures.py
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| """Fixtures that start and stop CLP package instances for integration tests.""" | ||
|
|
||
| import logging | ||
| import subprocess | ||
| from collections.abc import Iterator | ||
|
|
||
| import pytest | ||
|
|
||
| from tests.utils.clp_mode_utils import CLP_MODE_CONFIGS | ||
| from tests.utils.config import ( | ||
| PackageConfig, | ||
| PackageInstance, | ||
| ) | ||
| from tests.utils.package_utils import ( | ||
| start_clp_package, | ||
| stop_clp_package, | ||
| ) | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def clp_package( | ||
| clp_config: PackageConfig, | ||
| ) -> Iterator[PackageInstance]: | ||
| """ | ||
| Starts a CLP package instance for the given configuration and stops it during teardown. | ||
| :param clp_config: | ||
| :return: Iterator that yields the running package instance. | ||
| """ | ||
| mode_name = clp_config.mode_name | ||
| logger.info("Starting up the %s package...", mode_name) | ||
|
|
||
| # Start the package. | ||
| start_clp_package(clp_config) | ||
|
|
||
| instance: PackageInstance | None = None | ||
| try: | ||
| required_components = CLP_MODE_CONFIGS[mode_name][1] | ||
| instance = PackageInstance(package_config=clp_config, component_list=required_components) | ||
| instance_id = instance.clp_instance_id | ||
| logger.info( | ||
| "An instance of the %s package was started successfully. Its instance ID is '%s'", | ||
| mode_name, | ||
| instance_id, | ||
| ) | ||
| yield instance | ||
| finally: | ||
| logger.info("Now stopping the %s package...", mode_name) | ||
| if instance is not None: | ||
| stop_clp_package(instance) | ||
| else: | ||
| # This means setup failed after start; fall back to calling stop script directly | ||
| subprocess.run([str(clp_config.stop_script_path)], check=True) | ||
| logger.info("The %s package was stopped successfully.", mode_name) | ||
Bill-hbrhbr marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| """Integration tests verifying that the CLP package can be started and stopped.""" | ||
|
|
||
| import logging | ||
|
|
||
| import pytest | ||
|
|
||
| from tests.utils.clp_mode_utils import CLP_MODE_CONFIGS | ||
| from tests.utils.config import PackageInstance | ||
| from tests.utils.package_utils import ( | ||
| validate_package_running, | ||
| validate_running_mode_correct, | ||
| ) | ||
|
|
||
| TEST_MODES = CLP_MODE_CONFIGS.keys() | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
|
|
||
| @pytest.mark.package | ||
| @pytest.mark.parametrize("clp_config", TEST_MODES, indirect=True) | ||
| def test_clp_package(clp_package: PackageInstance) -> None: | ||
| """ | ||
| Validate that all of the components of the CLP package start up successfully for the selected | ||
| mode of operation. | ||
| :param clp_package: | ||
| """ | ||
| mode_name = clp_package.package_config.mode_name | ||
| instance_id = clp_package.clp_instance_id | ||
|
|
||
| # Ensure that all package components are running. | ||
| logger.info( | ||
| "Checking if all components of %s package with instance ID '%s' are running properly...", | ||
| mode_name, | ||
| instance_id, | ||
| ) | ||
quinntaylormitchell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| running, fail_msg = validate_package_running(clp_package) | ||
| if not running: | ||
| assert fail_msg is not None | ||
quinntaylormitchell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| pytest.fail(fail_msg) | ||
|
|
||
quinntaylormitchell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| logger.info( | ||
| "All components of the %s package with instance ID '%s' are running properly.", | ||
| mode_name, | ||
| instance_id, | ||
| ) | ||
quinntaylormitchell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| # Ensure that the package is running in the correct mode. | ||
| logger.info( | ||
| "Checking that the %s package with instance ID '%s' is running in the correct mode...", | ||
| mode_name, | ||
| instance_id, | ||
| ) | ||
quinntaylormitchell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
quinntaylormitchell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| correct, fail_msg = validate_running_mode_correct(clp_package) | ||
| if not correct: | ||
| assert fail_msg is not None | ||
| pytest.fail(fail_msg) | ||
quinntaylormitchell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| logger.info( | ||
| "The %s package with instance ID '%s' is running in the correct mode.", | ||
| mode_name, | ||
| instance_id, | ||
| ) | ||
quinntaylormitchell marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or 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 |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| """Provides utilities related to the user-level configurations of CLP's operating modes.""" | ||
|
|
||
| from collections.abc import Callable | ||
| from typing import Any | ||
|
|
||
| from clp_py_utils.clp_config import ( | ||
| ClpConfig, | ||
| COMPRESSION_SCHEDULER_COMPONENT_NAME, | ||
| COMPRESSION_WORKER_COMPONENT_NAME, | ||
| DB_COMPONENT_NAME, | ||
| GARBAGE_COLLECTOR_COMPONENT_NAME, | ||
| Package, | ||
| QUERY_SCHEDULER_COMPONENT_NAME, | ||
| QUERY_WORKER_COMPONENT_NAME, | ||
| QueryEngine, | ||
| QUEUE_COMPONENT_NAME, | ||
| REDIS_COMPONENT_NAME, | ||
| REDUCER_COMPONENT_NAME, | ||
| RESULTS_CACHE_COMPONENT_NAME, | ||
| StorageEngine, | ||
| WEBUI_COMPONENT_NAME, | ||
| ) | ||
|
|
||
|
|
||
| # TODO: This will eventually be replaced by a formalized mapping between component and service. | ||
| def _to_docker_compose_service_name(name: str) -> str: | ||
| """ | ||
| Convert a component name to a Docker Compose service name. | ||
|
|
||
| :param name: | ||
| :return: Service name with underscores replaced by hyphens | ||
| """ | ||
| return name.replace("_", "-") | ||
|
|
||
|
|
||
| CLP_MODE_CONFIGS: dict[str, tuple[Callable[[], ClpConfig], list[str]]] = { | ||
| "clp-text": ( | ||
| lambda: ClpConfig( | ||
| package=Package( | ||
| storage_engine=StorageEngine.CLP, | ||
| query_engine=QueryEngine.CLP, | ||
| ), | ||
| ), | ||
| [ | ||
| _to_docker_compose_service_name(DB_COMPONENT_NAME), | ||
| _to_docker_compose_service_name(QUEUE_COMPONENT_NAME), | ||
| _to_docker_compose_service_name(REDIS_COMPONENT_NAME), | ||
| _to_docker_compose_service_name(REDUCER_COMPONENT_NAME), | ||
| _to_docker_compose_service_name(RESULTS_CACHE_COMPONENT_NAME), | ||
| _to_docker_compose_service_name(COMPRESSION_SCHEDULER_COMPONENT_NAME), | ||
| _to_docker_compose_service_name(QUERY_SCHEDULER_COMPONENT_NAME), | ||
| _to_docker_compose_service_name(COMPRESSION_WORKER_COMPONENT_NAME), | ||
| _to_docker_compose_service_name(QUERY_WORKER_COMPONENT_NAME), | ||
| _to_docker_compose_service_name(WEBUI_COMPONENT_NAME), | ||
| _to_docker_compose_service_name(GARBAGE_COLLECTOR_COMPONENT_NAME), | ||
| ], | ||
| ), | ||
| "clp-json": ( | ||
| lambda: ClpConfig( | ||
| package=Package( | ||
| storage_engine=StorageEngine.CLP_S, | ||
| query_engine=QueryEngine.CLP_S, | ||
| ), | ||
| ), | ||
| [ | ||
| _to_docker_compose_service_name(DB_COMPONENT_NAME), | ||
| _to_docker_compose_service_name(QUEUE_COMPONENT_NAME), | ||
| _to_docker_compose_service_name(REDIS_COMPONENT_NAME), | ||
| _to_docker_compose_service_name(REDUCER_COMPONENT_NAME), | ||
| _to_docker_compose_service_name(RESULTS_CACHE_COMPONENT_NAME), | ||
| _to_docker_compose_service_name(COMPRESSION_SCHEDULER_COMPONENT_NAME), | ||
| _to_docker_compose_service_name(QUERY_SCHEDULER_COMPONENT_NAME), | ||
| _to_docker_compose_service_name(COMPRESSION_WORKER_COMPONENT_NAME), | ||
| _to_docker_compose_service_name(QUERY_WORKER_COMPONENT_NAME), | ||
| _to_docker_compose_service_name(WEBUI_COMPONENT_NAME), | ||
| _to_docker_compose_service_name(GARBAGE_COLLECTOR_COMPONENT_NAME), | ||
| ], | ||
| ), | ||
| } | ||
|
|
||
|
|
||
| def compute_mode_signature(config: ClpConfig) -> tuple[Any, ...]: | ||
| """ | ||
| Constructs a signature that captures the mode-defining aspects of a ClpConfig object. | ||
|
|
||
| :param config: | ||
| :return: Tuple that encodes fields used to determine an operating mode. | ||
| """ | ||
| return ( | ||
| config.logs_input.type, | ||
| config.package.storage_engine.value, | ||
| config.package.query_engine.value, | ||
| config.mcp_server is not None, | ||
| config.presto is not None, | ||
| config.archive_output.storage.type, | ||
| config.stream_output.storage.type, | ||
| config.aws_config_directory is not None, | ||
| config.get_deployment_type(), | ||
| ) | ||
|
|
||
|
|
||
| def get_clp_config_from_mode(mode_name: str) -> ClpConfig: | ||
| """ | ||
| Return a ClpConfig object for the given mode name. | ||
|
|
||
| :param mode_name: | ||
| :return: ClpConfig object corresponding to the mode. | ||
| :raise ValueError: If the mode is not supported. | ||
| """ | ||
| try: | ||
| config = CLP_MODE_CONFIGS[mode_name][0] | ||
| except KeyError as err: | ||
| err_msg = f"Unsupported mode: {mode_name}" | ||
| raise ValueError(err_msg) from err | ||
| return config() |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.