Jump to content

Tool:Event Metrics

From Wikitech
Toolforge tools
Event Metrics
Website https://eventmetrics.wmflabs.org/
Keywords statistics, analytics, events
Author(s) MusikAnimal, Samwilson, MaxSem, Mooeypoo
Maintainer(s) MusikAnimal, Samwilson, HMonroy, Dmaza (View all)
Source code GitHub
License GNU General Public License 3.0 or later
Issues Open tasks · Report a bug

This page documents the production and staging instances of Event Metrics. Some things in this guide still use the old name "Grant Metrics", such as references to the Toolforge account.

Note to maintainers: we don't backup any server configuration, so please document everything here.

Contact

The maintainers can be emailed at tools.grantmetricsattoolforge.org (note that this means that the maintainers of the VPS account and the Toolforge account need to be in sync).

Production

Production Event Metrics is hosted on on a Cloud VPS instance. To log into the server, make sure you've been added as a maintainer to the eventmetrics project. Then set up SSH and connect via ssh prod03.eventmetrics.eqiad1.wikimedia.cloud and go to the /var/www directory.

Logs are written to /var/www/var/logs/prod.log, but only during a request where an error or high-priority log entry was made. This is why you'll see debug-level log entries in prod.log. You might also need to check /var/log/apache2/error.log for Apache-level errors.

OAuth consumer: Event Metrics 2.0

Database is s53550__grantmetrics on tools.labsdb, we're connecting as user s53550.

Web server configuration is all in /etc/apache2/sites-available/eventmetrics.conf.

There's a deploy script that runs every 10 minutes (from www-data's crontab) and if required updates to the latest release. The output of this is mailed to the maintainers.

Building a new instance

First create a new instance running on the latest Debian. Any production node should be at least a m1.medium with 4 GB of RAM, but for the main app server a m1.large is probably best.

Once the instance has been spawned, SSH in and follow these steps:

  1. Install PHP and Apache, along with some dependencies.
    sudo apt-get update
    sudo apt-get install -y apache2 php php-cli php-common php-curl php-json php-apcu php-mysql
    sudo apt-get install -y php-intl php-xml php-mbstring libapache2-mod-php zip unzip php-zip php-bz2 cron
    sudo a2dismod mpm_event && sudo a2enmod mpm_prefork && sudo a2enmod php8.2
    
  2. Install composer by following these instructions, but make sure to install to the /usr/local/bin directory and with the filename composer, e.g.:
    sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
    
  3. Clone the repository, first removing the html directory created by Apache.
    cd /var/www && sudo rm -rf html
    sudo git clone https://github.com/wikimedia/eventmetrics.git .
    
  4. Become the root user with sudo su root
  5. Run sudo composer install and fill in the necessary parameters. For most options you can use the default. Moving forward we will not run composer as root or with sudo, but via the webserver (see step #13 below).
  6. Create the web server configuration file at /etc/apache2/sites-available/eventmetrics.conf with the following:
    <VirtualHost *:80>
            # Wikimetrics was sunset and should redirect to Event Metrics.
            ServerName metrics.wmflabs.org
            RedirectMatch 301 (.*) https://eventmetrics.wmcloud.org
    </VirtualHost>
    <VirtualHost *:80>
            DocumentRoot /var/www/public
            ServerName eventmetrics.wmcloud.org
    
            ErrorLog ${APACHE_LOG_DIR}/error.log
            CustomLog ${APACHE_LOG_DIR}/access.log combined
    
            <Directory /var/www/public/>
                 Options Indexes FollowSymLinks
                 AllowOverride All
                 Require all granted
            </Directory>
    
            <Directory /var/www/>
                    Options Indexes FollowSymLinks
                    AllowOverride None
                    Require all granted
            </Directory>
            
            RewriteEngine On
            RewriteCond %{HTTP:X-Forwarded-Proto} !https
            RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
    </VirtualHost>
    
  7. Enable the mod-rewrite Apache module, and enable the web server configuration.
    sudo a2enmod rewrite
    sudo a2ensite eventmetrics
    sudo service apache2 reload
    
  8. Setup the crontab to run the deploy script every 10 minutes, and spawn unstarted jobs every minute (this will respect database quota). We'll do this under the www-data user.
    sudo crontab -e -u www-data
    
    Then add this to the bottom of the crontab:
    MAILTO=tools.grantmetrics@toolforge.org
    */10 * * * * /var/www/vendor/wikimedia/toolforge-bundle/bin/deploy.sh prod /var/www/
    * * * * * php /var/www/bin/console app:spawn-jobs >/dev/null
    
  9. Wait for the email indicating composer ran successfully. If all goes well, you need only to gracefully (re)start apache, which is how you should always restart apache on production:
    sudo apachectl -k graceful