This allows a logging channel to be configured to write
directly to kafka. Logs can be serialized either to json
blobs or the more compact apache avro format.
The Kafka handler for monolog needs a list of one of more
kafka servers to query cluster metadata from. This should be
able to use any monolog formatter, although some like
JsonFormatter require you to disable formatBatch as Kafka
protocol would prefer to encode each record independently in
the protocol. This requires the nmred/kafka-php library,
version >= 1.3.0.
Adds a new formatter which serializes to the apache avro
format. This is a compact binary format which uses pre-
defined schemas. This initial implementation is very simple
and takes the plain schemas as a constructor argument.
Adds a new option to MonologSpi to wrap handlers in a
BufferHandler. This doesn't flush until the request shuts
down and prevents any network requests in the logger from
adding latency to web requests.
Related mediawiki/vendor update: Ibfe4bd2036ae8e998e2973f07bd9a6f057691578
The necessary config is something like:
array(
'loggers' => array(
'CirrusSearchRequests' => array(
'handlers' => array( 'kafka' ),
),
),
'handlers' => array(
'kafka' => array(
'factory' => '\\MediaWiki\\Logger\\Monolog\\KafkaHandler::factory',
'args' => array( 'localhost:9092' ),
'formatter' => 'avro',
'buffer' => true,
),
),
'formatters' => array(
'avro' => array(
'class' => '\\MediaWiki\\Logger\\Monolog\\AvroFormatter',
'args' => array(
array(
'CirrusSearchRequests' => array(
'type' => 'record',
'name' => 'CirrusSearchRequests'
'fields' => array( ... )
),
),
),
),
),
)
Bug: T106256
Change-Id: I6ee744b3e5306af0bed70811b558a543eed22840
123 lines
3.7 KiB
PHP
123 lines
3.7 KiB
PHP
<?php
|
|
/*
|
|
* This file is part of the PHPUnit_MockObject package.
|
|
*
|
|
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
|
*
|
|
* For the full copyright and license information, please view the LICENSE
|
|
* file that was distributed with this source code.
|
|
*/
|
|
|
|
/**
|
|
* Invocation matcher which looks for sets of specific parameters in the invocations.
|
|
*
|
|
* Checks the parameters of the incoming invocations, the parameter list is
|
|
* checked against the defined constraints in $parameters. If the constraint
|
|
* is met it will return true in matches().
|
|
*
|
|
* It takes a list of match groups and and increases a call index after each invocation.
|
|
* So the first invocation uses the first group of constraints, the second the next and so on.
|
|
*/
|
|
class PHPUnit_Framework_MockObject_Matcher_ConsecutiveParameters extends PHPUnit_Framework_MockObject_Matcher_StatelessInvocation
|
|
{
|
|
/**
|
|
* @var array
|
|
*/
|
|
private $_parameterGroups = array();
|
|
|
|
/**
|
|
* @var array
|
|
*/
|
|
private $_invocations = array();
|
|
|
|
/**
|
|
* @param array $parameterGroups
|
|
*/
|
|
public function __construct(array $parameterGroups)
|
|
{
|
|
foreach ($parameterGroups as $index => $parameters) {
|
|
foreach ($parameters as $parameter) {
|
|
if (!($parameter instanceof \PHPUnit_Framework_Constraint)) {
|
|
$parameter = new \PHPUnit_Framework_Constraint_IsEqual($parameter);
|
|
}
|
|
$this->_parameterGroups[$index][] = $parameter;
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* @return string
|
|
*/
|
|
public function toString()
|
|
{
|
|
$text = 'with consecutive parameters';
|
|
|
|
return $text;
|
|
}
|
|
|
|
/**
|
|
* @param PHPUnit_Framework_MockObject_Invocation $invocation
|
|
* @return bool
|
|
*/
|
|
public function matches(PHPUnit_Framework_MockObject_Invocation $invocation)
|
|
{
|
|
$this->_invocations[] = $invocation;
|
|
$callIndex = count($this->_invocations) - 1;
|
|
$this->verifyInvocation($invocation, $callIndex);
|
|
|
|
return false;
|
|
}
|
|
|
|
public function verify()
|
|
{
|
|
foreach ($this->_invocations as $callIndex => $invocation) {
|
|
$this->verifyInvocation($invocation, $callIndex);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Verify a single invocation
|
|
*
|
|
* @param PHPUnit_Framework_MockObject_Invocation $invocation
|
|
* @param int $callIndex
|
|
* @throws PHPUnit_Framework_ExpectationFailedException
|
|
*/
|
|
private function verifyInvocation(PHPUnit_Framework_MockObject_Invocation $invocation, $callIndex)
|
|
{
|
|
|
|
if (isset($this->_parameterGroups[$callIndex])) {
|
|
$parameters = $this->_parameterGroups[$callIndex];
|
|
} else {
|
|
// no parameter assertion for this call index
|
|
return;
|
|
}
|
|
|
|
if ($invocation === null) {
|
|
throw new PHPUnit_Framework_ExpectationFailedException(
|
|
'Mocked method does not exist.'
|
|
);
|
|
}
|
|
|
|
if (count($invocation->parameters) < count($parameters)) {
|
|
throw new PHPUnit_Framework_ExpectationFailedException(
|
|
sprintf(
|
|
'Parameter count for invocation %s is too low.',
|
|
$invocation->toString()
|
|
)
|
|
);
|
|
}
|
|
|
|
foreach ($parameters as $i => $parameter) {
|
|
$parameter->evaluate(
|
|
$invocation->parameters[$i],
|
|
sprintf(
|
|
'Parameter %s for invocation #%d %s does not match expected ' .
|
|
'value.',
|
|
$i,
|
|
$callIndex,
|
|
$invocation->toString()
|
|
)
|
|
);
|
|
}
|
|
}
|
|
}
|