This program monitors source code repositories that have been mirrored in Phabricator.
It measures and reports the replication delay between the mirrored repository and its upstream repository.
The program runs an internal scheduler that triggers a check-and-report routine every five minutes.
To check the Phabricator repository replication delay the program reads Mercurial
repository push messages off of the Mozilla Pulse
hgpush
message queue. There is one hgpush
message for each push made to the upstream
repository. Each push contains multiple commits. Pushes and the
commits inside them are in order, oldest to newest.
For each commit in an upstream push the program checks for the existence of that commit in the downstream Phabricator repository mirror. If all commits in the push exist in Phabricator then we assume the push has been fully mirrored to Phabricator. The push message is removed from the queue, a replication delay of zero seconds is reported, and the program moves on to the next push message.
If one or more commits in a push is missing from Phabricator then we assume the Phabricator repository replication program is still working to catch up to the upstream repo. Our program reports the replication delay as the difference between the current time and the time the push to the source repo took place. The delay-checking routine exits early and the push message is left at the head of the queue for the next check-and-report run.
You should use pyenv to make sure you are using the same Python version listed in the Program's Pipfile.
This project's dependencies are managed with Pipenv. After you have
installed pipenv
on your system run the following in the project root:
$ pipenv install
You will need to create an account on Mozilla Pulse to collect messages about hgpush events.
This program is designed to run on Heroku and follows the Heroku Architectural Principles. It reads its settings from environment variables.
See the file dotenv.example.txt in the project root for possible values. These values must be present in your local and/or heroku execution environments:
$ cp dotenv.example.txt .env
$ vim .env
# Add your personal environment's configuration
Run the following command to check that everything works. It won't send any data:
$ env PYTHONPATH=src pipenv run bin/report-lag --no-send
Install the development dependencies with pipenv
:
$ pipenv install --dev
Code formatting is done with black.
Push event messages are read from a Pulse message queue. You can inspect a live hgpush message queue with Pulse Inspector.
Messages use the hgpush message format.
Push events are generated from the mercurial repo pushlogs.
The unit test suite can be run with pytest:
$ pipenv run pytest
You can smoke-test the program as follows:
$ env PYTHONPATH=src pipenv run bin/report-lag --no-send --debug
To get command-line help run the following:
$ env PYTHONPATH=src pipenv run bin/report-lag --help
This script should be run on a Heroku standard dyno.