Help:Extension:EventStreamConfig

From mediawiki.org
This page is a translated version of the page Help:Extension:EventStreamConfig and the translation is 80% complete.
PD 注意: このページを編集すると、編集内容が CC0 のもとで公開されることに同意したと見なされます。詳細はパブリック・ドメインのヘルプ ページを参照してください。 PD

この EventStreamConfig 拡張機能は、MediaWiki の構成変数 $wgEventStreams からイベント ストリームの構成をエクスポートするためのライブラリ関数と API エンドポイントを提供します。

これにより、MediaWiki および外部利用におけるストリームの集中的な設定が可能となります。

  • EventLogging 拡張機能は、ResourceLoader と組み合わせて使用し、特定のページで使用されるストリームの設定を動的に構成するためにクライアントのストリーム設定 (サンプルレートなど) を読み込みます。
  • モバイル アプリは、API エンドポイントを使用してクライアントのストリーム設定 (サンプルレートなど) を動的に構成します。
  • EventGate のイベント受信サービスは、特定のスキーマ タイトルのイベントのみをストリームに許可するためにこれを使用します。
  • EventBus および他のサーバー サイドのイベント プロデューサーは、特定のストリームをどのイベント受信サービスに送信するかを特定するためにこれを使用します。

使用法

MediaWiki Config

$wgEventStreams is a list of individual stream configs. Each stream config must minimally specify its schema_title and its stream name settings. In $wgEventStreams, stream may either be a static stream name string, or a regex that matches stream names for which the stream config should be used.

Example:

$wgEventStreams = [
    'test.event' => [
        'stream' => 'test.event',
        'schema_title' => 'test/event',
        'sample_rate' => 0.15,
    ],
    'nonya' => [
        'stream' => 'nonya',
        'schema_title' => 'mediawiki/nonya',
        'sample_rate' => 0.5,
    ],
    'mediawiki.virtual_page_view' => [
        'stream' => 'mediawiki.virtual_page_view',
        'schema_title' => 'mediawiki/page/virtual-view',
        'sample_rate' => 0.1,
    ],
    '/^mediawiki.edit(\..+)?/' => [
        'stream' => '/^mediawiki.edit(\..+)?/',
        'schema_title' => 'mediawiki/edit',
        'sample_rate' => 0.8,
    ],
];

(Note: sample_rate is just an example setting)

Getting configs for a list of streams

StreamConfigs#get takes a list of stream names to return configs for. $wgEventStreams is keyed by stream name or stream regex pattern, and it is searched for stream names that match. The return value is a map from requested stream name to the matched stream config. By default any settings in StreamConfig::INTERNAL_SETTINGS are removed from the returned stream configs; as they are often not useful for client side configuration. The $includeAllSettings parameter disables this behavior.

Example:

$streamConfigs = MediaWikiServices::getInstance()->getService('EventStreamConfig.StreamConfigs');
$streamConfigs->get( ['test.event', 'mediawiki.edit.cohort1'] );

returns

[
   'test.event' => [
       'sample_rate' => 0.15,
   ],
   'mediawiki.edit.cohort1' => [
       'sample_rate' => 0.8,
   ]
]

streamconfigs MW API endpoint

curl http://wiki.domain.org/w/api.php?action=streamconfigs&format=json&streams=test.event|mediawiki.edit.cohort1
# returns
{
    "test.event" => {
        "sample_rate" => 0.15
    },
    "mediawiki.edit.cohort1": {
        "sample_rate" => 0.8
    }
}