-
-
Notifications
You must be signed in to change notification settings - Fork 646
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ensure that metrics are gathered during abnormal exits (#11793)
### Problem As described in #11788, `RunTracker.end_run` is not called for `help`, runs with no goals, or runs that end in `Ctrl+C`. This can prevent metrics gathering. ### Solution Adjust `LocalPantsRunner` to ensure that the run is ended in the `RunTracker` before the `StreamingWorkunitHandler` is torn down. ### Result Fixes #11788.
- Loading branch information
Showing
8 changed files
with
173 additions
and
108 deletions.
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
70 changes: 57 additions & 13 deletions
70
src/python/pants/engine/streaming_workunit_handler_integration_test.py
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 |
---|---|---|
@@ -1,23 +1,67 @@ | ||
# Copyright 2020 Pants project contributors (see CONTRIBUTORS.md). | ||
# Licensed under the Apache License, Version 2.0 (see LICENSE). | ||
|
||
from __future__ import annotations | ||
|
||
import os | ||
import signal | ||
from typing import List, Mapping, Tuple | ||
|
||
from workunit_logger.register import FINISHED_SUCCESSFULLY | ||
|
||
from pants.testutil.pants_integration_test import run_pants, setup_tmpdir | ||
from pants.testutil.pants_integration_test import ( | ||
PantsResult, | ||
run_pants, | ||
setup_tmpdir, | ||
temporary_workdir, | ||
) | ||
from pants.util.dirutil import maybe_read_file | ||
from pants_test.pantsd.pantsd_integration_test_base import attempts, launch_waiter | ||
|
||
|
||
def workunit_logger_config(log_dest: str) -> Mapping: | ||
return { | ||
"GLOBAL": { | ||
"backend_packages.add": ["workunit_logger", "pants.backend.python"], | ||
}, | ||
"workunit-logger": {"dest": log_dest}, | ||
} | ||
|
||
def test_workunits_logger() -> None: | ||
|
||
def run(args: List[str], success: bool = True) -> Tuple[PantsResult, str | None]: | ||
with setup_tmpdir({}) as tmpdir: | ||
dest = os.path.join(tmpdir, "dest.log") | ||
pants_run = run_pants( | ||
[ | ||
"--backend-packages=+['workunit_logger','pants.backend.python']", | ||
f"--workunit-logger-dest={dest}", | ||
"list", | ||
"3rdparty::", | ||
] | ||
) | ||
pants_run.assert_success() | ||
# Assert that the file was created and non-empty. | ||
assert maybe_read_file(dest) | ||
pants_run = run_pants(args, config=workunit_logger_config(dest)) | ||
log_content = maybe_read_file(dest) | ||
if success: | ||
pants_run.assert_success() | ||
assert log_content | ||
assert FINISHED_SUCCESSFULLY in log_content | ||
else: | ||
pants_run.assert_failure() | ||
return pants_run, log_content | ||
|
||
|
||
def test_list() -> None: | ||
run(["list", "3rdparty::"]) | ||
|
||
|
||
def test_help() -> None: | ||
run(["help"]) | ||
run(["--version"]) | ||
|
||
|
||
def test_ctrl_c() -> None: | ||
with temporary_workdir() as workdir: | ||
dest = os.path.join(workdir, "dest.log") | ||
|
||
# Start a pantsd run that will wait forever, then kill the pantsd client. | ||
client_handle, _, _ = launch_waiter(workdir=workdir, config=workunit_logger_config(dest)) | ||
client_pid = client_handle.process.pid | ||
os.kill(client_pid, signal.SIGINT) | ||
|
||
# Confirm that finish is still called (even though it may be backgrounded in the server). | ||
for _ in attempts("The log should eventually show that the SWH shut down."): | ||
content = maybe_read_file(dest) | ||
if content and FINISHED_SUCCESSFULLY in content: | ||
break |
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
Oops, something went wrong.