MediaWiki-Docker/Configuration recipes/EventLogging

Event PlatformEdit

Setting up and configuring your MediaWiki-Docker instance as below will leave you with a Wikimedia production Event Platform-like environment. You will be able to log events to a containerized EventGate instance (herein "EventGate") from both MediaWiki and JavaScript. EventGate will validate events against schemas fetched from https://schema.wikimedia.org.

Project SetupEdit

ExtensionsEdit

You need to install these extensions:

i.e.

for extension in EventBus EventStreamConfig EventLogging WikimediaEvents; do
  git clone "https://gerrit.wikimedia.org/r/mediawiki/extensions/${extension}" "extensions/${extension}"
done

ConfigurationEdit

docker-compose.override.ymlEdit
version: "3.7"
services:
  eventlogging:
    build: "./extensions/EventLogging/devserver"
    ports:
      - "8192:8192"
LocalSettings.phpEdit
<?php

wfLoadExtensions( [
  'EventBus',
  'EventStreamConfig',
  'EventLogging',
  'WikimediaEvents'
] );

// EventBus Configuration
// ======================

// Send all events produced on the server to the event intake service, including
// events produced by \EventLogging::submit().
$wgEventServices = [
  '*' => [ 'url' => 'http://eventlogging:8192/v1/events' ],
];
$wgEventServiceDefault = '*';
$wgEnableEventBus = 'TYPE_EVENT';

// EventStreamConfig Configuration
// ===============================

// When $wgEventLoggingStreamNames is false (not falsy), the EventLogging
// JavaScript client will treat all streams as if they are configured and
// registered.
$wgEventLoggingStreamNames = false;

// EventLogging Configuration
// ==========================

$wgEventLoggingServiceUri = "http://localhost:8192/v1/events";

// The EventLogging JavaScript client maintains an queue of events to send to
// the event intake service (see $wgEventLoggingServiceUri above). The queue is
// flushed every $wgEventLoggingQueueLingerSeconds seconds.
//
// 1 second is just long enough for you to begin to doubt that your code is
// working...
$wgEventLoggingQueueLingerSeconds = 1;

RunningEdit

docker-compose up --detach
docker-compose logs --no-log-prefix --follow eventlogging

You can test the above by running this in your browser's JavaScript console:

mw.eventLog.submit( 'test.event', {
    '$schema': '/test/event/1.0.0',
    'test': 'Hello from JavaScript!'
} );

Event Platform with Local Schema RepositoriesEdit

Iterating on the above, setting up and configuring your MediaWiki-Docker instance as below will reconfigure EventGate to validate events against schemas from clones of the schema repositories.

Project SetupEdit

RepositoriesEdit

You need to clone these repositories into the cache directory:

e.g.

for suffix in primary secondary; do
  git clone "https://gerrit.wikimedia.org/r/schemas/event/${suffix}" "cache/${suffix}"
done

ConfigurationEdit

docker-composer.override.ymlEdit
version: "3.7"
  eventlogging:
    build: "./extensions/EventLogging/devserver"
    volumes:
      - "./cache/eventgate.config.yaml:/opt/eventlogging/eventgate.config.yaml"
      - "./cache/primary:/opt/eventlogging/primary"
      - "./cache/secondary:/opt/eventlogging/secondary"
    ports:
      - "8192:8192"
cache/eventgate.config.yamlEdit
# See extension/EventLogging/devserver/eventlogging.config.yaml and
# https://gerrit.wikimedia.org/r/plugins/gitiles/eventgate-wikimedia/+/refs/heads/master/config.yaml
# for detail.

num_workers: 0
worker_heap_limit_mb: 200
logging:
  level: trace

services:
  - name: eventgate-devserver
    module: eventgate
    entrypoint: app
    conf:
      port: 8192
      max_body_size: 1mb
      eventgate_factory_module: "eventgate-wikimedia/eventgate-wikimedia-dev"

      schema_base_uris:
        - ./primary/jsonschema
        - ./secondary/jsonschema

      output_path: ./events.json
      should_pretty_print: false

RunningEdit

docker-compose up --force-recreate eventlogging
docker-compose logs --no-log-prefix --follow eventlogging

Legacy EventLoggingEdit

In the legacy EventLogging pipeline, schemas were defined and documented on metawiki. Event though the legacy EventLogging pipeline is being migrated away from, you might still be called on to modify an instrument that uses one such schema.

Following on from the section above, setting up and configuring your MediaWiki-Docker instance as below will allow you to log events to a containerized legacy EventLogging event intake service.

Project SetupEdit

ConfigurationEdit

docker-compose.override.ymlEdit
version: "3.7"
services:
  eventlogging-legacy:
    image: docker-registry.wikimedia.org/dev/eventlogging:0.0.1
    ports:
      - "8100:8100"
LocalSettings.phpEdit
<?php

// EventLogging Configuration
// ==========================

// ...

$wgEventLoggingBaseUri = 'http://localhost:8100/event.gif';

RunningEdit

docker-compose up --detach
docker-compose logs --no-log-prefix --follow eventlogging-legacy