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

Add assert concurrency configuration #797

Merged
merged 3 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion spectacles/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from spectacles.logger import set_file_handler
from spectacles.runner import Runner
from spectacles.utils import log_duration
from spectacles.validators.data_test import QUERY_SLOT_LIMIT

__version__ = importlib.metadata.version("spectacles")

Expand Down Expand Up @@ -341,6 +342,7 @@ def main() -> None:
api_version=args.api_version,
remote_reset=args.remote_reset,
pin_imports=pin_imports,
concurrency=args.concurrency,
)
)
elif args.command == "content":
Expand Down Expand Up @@ -709,6 +711,16 @@ def _build_assert_subparser(
_build_validator_subparser(subparser_action, subparser)
_build_select_subparser(subparser_action, subparser)

subparser.add_argument(
"--concurrency",
type=int,
default=QUERY_SLOT_LIMIT,
help=(
"Specify the number of concurrent queries you want to have running "
f"against your data warehouse. The default is {QUERY_SLOT_LIMIT}."
),
)


def _build_content_subparser(
subparser_action: argparse._SubParsersAction, # type: ignore[type-arg]
Expand Down Expand Up @@ -896,6 +908,7 @@ async def run_assert(
api_version: float,
remote_reset: bool,
pin_imports: Dict[str, str],
concurrency: int,
) -> None:
# Don't trust env to ignore .netrc credentials
async_client = httpx.AsyncClient(trust_env=False)
Expand All @@ -905,7 +918,9 @@ async def run_assert(
)
runner = Runner(client, project, remote_reset, pin_imports)

results = await runner.validate_data_tests(ref, filters)
results = await runner.validate_data_tests(
ref, filters, query_slot_limit=concurrency
)
finally:
await async_client.aclose()

Expand Down
4 changes: 3 additions & 1 deletion spectacles/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
LookMLValidator,
SqlValidator,
)
from spectacles.validators.data_test import QUERY_SLOT_LIMIT
from spectacles.validators.sql import (
DEFAULT_CHUNK_SIZE,
DEFAULT_QUERY_CONCURRENCY,
Expand Down Expand Up @@ -444,6 +445,7 @@ async def validate_data_tests(
self,
ref: Optional[str] = None,
filters: Optional[List[str]] = None,
query_slot_limit: int = QUERY_SLOT_LIMIT,
) -> JsonDict:
if filters is None:
filters = ["*/*"]
Expand All @@ -462,7 +464,7 @@ async def validate_data_tests(
f"{'explore' if explore_count == 1 else 'explores'}"
)
tests = await validator.get_tests(project)
await validator.validate(tests)
await validator.validate(tests, query_slot_limit)

results = project.get_results(validator="data_test")
return results
Expand Down
6 changes: 4 additions & 2 deletions spectacles/validators/data_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,11 @@ async def get_tests(self, project: Project) -> List[DataTest]:

return selected_tests

async def validate(self, tests: List[DataTest]) -> List[DataTestError]:
async def validate(
self, tests: List[DataTest], query_slot_limit: int = QUERY_SLOT_LIMIT
DylanBaker marked this conversation as resolved.
Show resolved Hide resolved
) -> List[DataTestError]:
data_test_errors: List[DataTestError] = []
query_slot = asyncio.Semaphore(QUERY_SLOT_LIMIT)
query_slot = asyncio.Semaphore(query_slot_limit)

async def run_test(test: DataTest, query_slot: asyncio.Semaphore) -> None:
async with query_slot:
Expand Down