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

More accurate reported runtime when pantsd is in use #14177

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 6 additions & 0 deletions src/python/pants/bin/daemon_pants_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ def single_daemonized_run(
# Capture the client's start time, which we propagate here in order to get an accurate
# view of total time.
env_start_time = env.get("PANTSD_RUNTRACKER_CLIENT_START_TIME", None)
if not env_start_time:
# NB: We warn rather than erroring here because it eases use of non-Pants nailgun
# clients for testing.
logger.warning(
"No start time was reported by the client! Metrics may be inaccurate."
)
start_time = float(env_start_time) if env_start_time else time.time()

options_bootstrapper = OptionsBootstrapper.create(
Expand Down
2 changes: 1 addition & 1 deletion src/python/pants/bin/pants_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def run(self, start_time: float) -> ExitCode:
if self._should_run_with_pantsd(global_bootstrap_options):
try:
remote_runner = RemotePantsRunner(self.args, self.env, options_bootstrapper)
return remote_runner.run()
return remote_runner.run(start_time)
except RemotePantsRunner.Fallback as e:
logger.warning(f"Client exception: {e!r}, falling back to non-daemon mode")

Expand Down
11 changes: 6 additions & 5 deletions src/python/pants/bin/remote_pants_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,24 @@ def __init__(
:param env: The environment (e.g. os.environ) for this run.
:param options_bootstrapper: The bootstrap options.
"""
self._start_time = time.time()
self._args = args
self._env = env
self._options_bootstrapper = options_bootstrapper
self._bootstrap_options = options_bootstrapper.bootstrap_options
self._client = PantsDaemonClient(self._bootstrap_options)

def run(self) -> ExitCode:
def run(self, start_time: float) -> ExitCode:
"""Starts up a pantsd instance if one is not already running, then connects to it via
nailgun."""

pantsd_handle = self._client.maybe_launch()
logger.debug(f"Connecting to pantsd on port {pantsd_handle.port}")

return self._connect_and_execute(pantsd_handle)
return self._connect_and_execute(pantsd_handle, start_time)

def _connect_and_execute(self, pantsd_handle: PantsDaemonClient.Handle) -> ExitCode:
def _connect_and_execute(
self, pantsd_handle: PantsDaemonClient.Handle, start_time: float
) -> ExitCode:
global_options = self._bootstrap_options.for_global_scope()
executor = GlobalOptions.create_py_executor(global_options)

Expand All @@ -126,7 +127,7 @@ def _connect_and_execute(self, pantsd_handle: PantsDaemonClient.Handle) -> ExitC
modified_env = {
**self._env,
**ng_env,
"PANTSD_RUNTRACKER_CLIENT_START_TIME": str(self._start_time),
"PANTSD_RUNTRACKER_CLIENT_START_TIME": str(start_time),
"PANTSD_REQUEST_TIMEOUT_LIMIT": str(
global_options.pantsd_timeout_when_multiple_invocations
),
Expand Down