diff --git a/resources/sql/autopatches/20181106.repo.02.hook.sql b/resources/sql/autopatches/20181106.repo.02.hook.sql new file mode 100644 index 0000000000..be06923044 --- /dev/null +++ b/resources/sql/autopatches/20181106.repo.02.hook.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_repository.repository_pushevent + ADD hookWait BIGINT UNSIGNED; diff --git a/scripts/repository/commit_hook.php b/scripts/repository/commit_hook.php index 64b7b0ec24..df49aa7b00 100755 --- a/scripts/repository/commit_hook.php +++ b/scripts/repository/commit_hook.php @@ -17,6 +17,8 @@ // subclasses of PhabricatorConfigSiteSource to read it and build an instance // environment. +$hook_start = microtime(true); + if ($argc > 1) { $context = $argv[1]; $context = explode(':', $context, 2); @@ -35,7 +37,8 @@ if ($argc < 2) { throw new Exception(pht('usage: commit-hook ')); } -$engine = new DiffusionCommitHookEngine(); +$engine = id(new DiffusionCommitHookEngine()) + ->setStartTime($hook_start); $repository = id(new PhabricatorRepositoryQuery()) ->setViewer(PhabricatorUser::getOmnipotentUser()) diff --git a/src/applications/diffusion/engine/DiffusionCommitHookEngine.php b/src/applications/diffusion/engine/DiffusionCommitHookEngine.php index 59fb4b5e12..d22635e859 100644 --- a/src/applications/diffusion/engine/DiffusionCommitHookEngine.php +++ b/src/applications/diffusion/engine/DiffusionCommitHookEngine.php @@ -31,6 +31,7 @@ final class DiffusionCommitHookEngine extends Phobject { private $mercurialHook; private $mercurialCommits = array(); private $gitCommits = array(); + private $startTime; private $heraldViewerProjects; private $rejectCode = PhabricatorRepositoryPushLog::REJECT_BROKEN; @@ -70,6 +71,15 @@ final class DiffusionCommitHookEngine extends Phobject { return $this->requestIdentifier; } + public function setStartTime($start_time) { + $this->startTime = $start_time; + return $this; + } + + public function getStartTime() { + return $this->startTime; + } + public function setSubversionTransactionInfo($transaction, $repository) { $this->subversionTransaction = $transaction; $this->subversionRepository = $repository; @@ -1102,11 +1112,15 @@ final class DiffusionCommitHookEngine extends Phobject { private function newPushEvent() { $viewer = $this->getViewer(); + $hook_start = $this->getStartTime(); + $hook_end = microtime(true); + $event = PhabricatorRepositoryPushEvent::initializeNewEvent($viewer) ->setRepositoryPHID($this->getRepository()->getPHID()) ->setRemoteAddress($this->getRemoteAddress()) ->setRemoteProtocol($this->getRemoteProtocol()) - ->setEpoch(PhabricatorTime::getNow()); + ->setEpoch(PhabricatorTime::getNow()) + ->setHookWait((int)(1000000 * ($hook_end - $hook_start))); $identifier = $this->getRequestIdentifier(); if (strlen($identifier)) { diff --git a/src/applications/repository/storage/PhabricatorRepositoryPushEvent.php b/src/applications/repository/storage/PhabricatorRepositoryPushEvent.php index 682b367926..ac97aa2bcf 100644 --- a/src/applications/repository/storage/PhabricatorRepositoryPushEvent.php +++ b/src/applications/repository/storage/PhabricatorRepositoryPushEvent.php @@ -19,6 +19,7 @@ final class PhabricatorRepositoryPushEvent protected $writeWait; protected $readWait; protected $hostWait; + protected $hookWait; private $repository = self::ATTACHABLE; private $logs = self::ATTACHABLE; @@ -41,6 +42,7 @@ final class PhabricatorRepositoryPushEvent 'writeWait' => 'uint64?', 'readWait' => 'uint64?', 'hostWait' => 'uint64?', + 'hookWait' => 'uint64?', ), self::CONFIG_KEY_SCHEMA => array( 'key_repository' => array(