⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 287045 in webkit


Ignore:
Timestamp:
Dec 14, 2021, 1:31:59 PM (5 years ago)
Author:
Jonathan Bedard
Message:

[reporelaypy] Update checkout with hook instead of polling
https://bugs.webkit.org/show_bug.cgi?id=234243
<rdar://problem/86413065>

Reviewed by Dewei Zhu.

  • Tools/Scripts/libraries/reporelaypy/reporelaypy/init.py: Bump version,

export HookProcessor and HookReceiver.

  • Tools/Scripts/libraries/reporelaypy/reporelaypy/checkout.py:

(Checkout.update_for): If a branch is new, we need to track it.

  • Tools/Scripts/libraries/reporelaypy/reporelaypy/database.py:

(Database.init): Use self.host and self.password.

  • Tools/Scripts/libraries/reporelaypy/reporelaypy/hooks.py: Added.

(HookProcessor): Class to process received hooks.
(HookReceiver): Class to receive hooks and queue them for processing.

  • Tools/Scripts/libraries/reporelaypy/reporelaypy/tests/hooks_unittest.py: Added.

(HooksUnittest):
(HooksUnittest.setUp):
(HooksUnittest.test_receive):
(HooksUnittest.test_invalid):
(HooksUnittest.test_process):
(HooksUnittest.test_hmac):
(HooksUnittest.test_invalid_hmac):

  • Tools/Scripts/libraries/reporelaypy/reporelaypy/webserver.py: Add hook routes,

if hooks are enabled.

  • Tools/Scripts/libraries/reporelaypy/run: Allow caller to enable hooks.
  • Tools/Scripts/libraries/reporelaypy/setup.py: Bump version.

Canonical link: https://commits.webkit.org/245242@main

Location:
trunk/Tools
Files:
2 added
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/Tools/ChangeLog

    r287040 r287045  
     12021-12-13  Jonathan Bedard  <jbedard@apple.com>
     2
     3        [reporelaypy] Update checkout with hook instead of polling
     4        https://bugs.webkit.org/show_bug.cgi?id=234243
     5        <rdar://problem/86413065>
     6
     7        Reviewed by Dewei Zhu.
     8
     9        * Scripts/libraries/reporelaypy/reporelaypy/__init__.py: Bump version,
     10        export HookProcessor and HookReceiver.
     11        * Scripts/libraries/reporelaypy/reporelaypy/checkout.py:
     12        (Checkout.update_for): If a branch is new, we need to track it.
     13        * Scripts/libraries/reporelaypy/reporelaypy/database.py:
     14        (Database.__init__): Use self.host and self.password.
     15        * Scripts/libraries/reporelaypy/reporelaypy/hooks.py: Added.
     16        (HookProcessor): Class to process received hooks.
     17        (HookReceiver): Class to receive hooks and queue them for processing.
     18        * Scripts/libraries/reporelaypy/reporelaypy/tests/hooks_unittest.py: Added.
     19        (HooksUnittest):
     20        (HooksUnittest.setUp):
     21        (HooksUnittest.test_receive):
     22        (HooksUnittest.test_invalid):
     23        (HooksUnittest.test_process):
     24        (HooksUnittest.test_hmac):
     25        (HooksUnittest.test_invalid_hmac):
     26        * Scripts/libraries/reporelaypy/reporelaypy/webserver.py: Add hook routes,
     27        if hooks are enabled.
     28        * Scripts/libraries/reporelaypy/run: Allow caller to enable hooks.
     29        * Scripts/libraries/reporelaypy/setup.py: Bump version.
     30
    1312021-12-14  Alex Christensen  <achristensen@webkit.org>
    232
  • trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/__init__.py

    r286623 r287045  
    4545    )
    4646
    47 version = Version(0, 2, 0)
     47version = Version(0, 3, 0)
    4848
    4949import webkitflaskpy
     
    5252from reporelaypy.database import Database
    5353from reporelaypy.checkoutroute import CheckoutRoute, Redirector
     54from reporelaypy.hooks import HookProcessor, HookReceiver
    5455
    5556AutoInstall.register(Package('fakeredis', Version(1, 5, 2)))
  • trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/checkout.py

    r286623 r287045  
    165165        return False
    166166
    167     def update_for(self, branch=None, remote='origin'):
     167    def update_for(self, branch=None, remote='origin', track=False):
    168168        if not self.repository:
    169169            sys.stderr.write("Cannot update '{}', clone still pending...\n".format(branch))
     
    171171
    172172        branch = branch or self.repository.default_branch
    173         if branch == self.repository.default_branch:
     173        if not self.repository.prod_branches.match(branch):
     174            return False
     175        elif track and branch not in self.repository.branches_for(remote=remote):
     176            run(
     177                [self.repository.executable(), 'branch', '--track', branch, 'remotes/{}/{}'.format(remote, branch)],
     178                cwd=self.repository.root_path,
     179            )
     180            self.repository.cache.populate(branch=branch)
     181        elif branch == self.repository.default_branch:
    174182            self.repository.pull(remote=remote)
    175183            self.repository.cache.populate(branch=branch)
    176184            return True
    177         if not self.repository.prod_branches.match(branch):
    178             return False
    179         if self.is_updated(branch, remote=remote):
     185        elif not track and self.is_updated(branch, remote=remote):
    180186            return True
    181187
  • trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/database.py

    r286576 r287045  
    4747        self.password = password or Environment.instance().get(self.PASSWORD_ENV)
    4848
    49         if host:
     49        if self.host:
    5050            import redis
    51             self._redis = redis.Redis(host=host, password=password)
     51            self._redis = redis.StrictRedis(host=self.host, password=self.password)
    5252        else:
    5353            import fakeredis
  • trunk/Tools/Scripts/libraries/reporelaypy/reporelaypy/webserver.py

    r286576 r287045  
    2121# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    2222
     23import json
    2324import os
    2425
     
    2930
    3031from flask import Flask, current_app, json as fjson
    31 from reporelaypy import Checkout, CheckoutRoute, Database, Redirector
     32from reporelaypy import Checkout, CheckoutRoute, Database, Redirector, HookReceiver
    3233
    3334app = Flask(__name__)
     
    4041)
    4142
     43hook_args = json.loads(os.environ.get('HOOKS', '{}'))
     44if hook_args.get('enabled', False):
     45    hook_routes = HookReceiver(
     46        import_name=__name__, database=database,
     47        debug=hook_args.get('debug', False), secret=os.environ.get(HookReceiver.SECRET_ENV),
     48    )
     49else:
     50    hook_routes = None
     51
    4252
    4353@app.route('/__health')
     
    4757
    4858app.register_blueprint(checkout_routes)
     59if hook_routes:
     60    app.register_blueprint(hook_routes)
    4961
    5062
  • trunk/Tools/Scripts/libraries/reporelaypy/run

    r286623 r287045  
    3939    import webkitpy
    4040
    41 from reporelaypy import Checkout, Database, Redirector
     41from reporelaypy import Checkout, Database, HookProcessor, HookReceiver, Redirector
    4242from webkitcorepy import arguments, AutoInstall
    4343from whichcraft import which
     
    102102    )
    103103
     104    group = parser.add_argument_group('Hooks')
     105    group.add_argument(
     106        '--hooks', '--no-hooks', action=arguments.NoAction, dest='hooks', default=False,
     107        help='Enable or disable hook end-points (disabled by default)',
     108    )
     109    group.add_argument(
     110        '--debug', '--no-debug', action=arguments.NoAction, dest='hooks_debug', default=True,
     111        help='Enable endpoint to report hooks being processed (enabled by default)',
     112    )
     113
    104114    args = parser.parse_args(args=args)
    105115
     
    141151            print('    {}: {}'.format(redirector.name, redirector.url))
    142152
    143     env = dict(
     153    passenv = dict(
    144154        PYTHONPATH=':'.join(sys.path),
    145155        CHECKOUT=json.dumps(checkout, cls=Checkout.Encoder),
    146         REDIRECTORS=json.dumps([Redirector(url) for url in args.redirector or []], cls=Redirector.Encoder)
     156        REDIRECTORS=json.dumps([Redirector(url) for url in args.redirector or []], cls=Redirector.Encoder),
     157        HOOKS=json.dumps({'enabled': args.hooks, 'debug': args.hooks_debug}),
    147158    )
    148159
    149160    if AutoInstall.directory:
    150         env['AUTOINSTALL_PATH'] = AutoInstall.directory
     161        passenv['AUTOINSTALL_PATH'] = AutoInstall.directory
    151162    if database.host:
    152         env[database.HOST_ENV] = database.host
     163        passenv[database.HOST_ENV] = database.host
    153164    if database.password:
    154         env[database.PASSWORD_ENV] = database.password
     165        passenv[database.PASSWORD_ENV] = database.password
    155166    if database.default_expiration:
    156         env[database.EXPIRATION_ENV] = str(database.default_expiration)
     167        passenv[database.EXPIRATION_ENV] = str(database.default_expiration)
     168    if os.environ.get(HookReceiver.SECRET_ENV):
     169        passenv[HookReceiver.SECRET_ENV] = os.environ.get(HookReceiver.SECRET_ENV)
     170
     171    processor = HookProcessor(checkout=checkout, database=database) if args.hooks else None
    157172
    158173    with subprocess.Popen(
    159174        [which('gunicorn'), 'reporelaypy.webserver:app'],
    160175        cwd=os.path.dirname(os.path.dirname(reporelaypy.__file__)),
    161         env=env,
     176        env=passenv,
    162177    ) as webserver:
    163178        last_poll = time.time()
     
    170185                last_poll = time.time()
    171186            if last_pull + args.update_interval < time.time():
    172                 checkout.update_all()
     187                processor.process_hooks() if processor else checkout.update_all()
    173188                last_pull = time.time()
    174189            time.sleep(math.gcd(args.poll, args.update_interval))
  • trunk/Tools/Scripts/libraries/reporelaypy/setup.py

    r286623 r287045  
    3131setup(
    3232    name='reporelaypy',
    33     version='0.2.0',
     33    version='0.3.0',
    3434    description='Library for visualizing, processing and storing test results.',
    3535    long_description=readme(),
Note: See TracChangeset for help on using the changeset viewer.