Commit graph

65 commits

Author SHA1 Message Date
Filippo Giunchedi
667b17a319 monolog: add CeeFormatter
This formatter extends LogstashFormatter to prefix records with "cee token"
used for syslog and JSON structured logging. See also related task for more
context.

Bug: T211124
Change-Id: I3cdeb4c666f54039b5e8ecc67bd4937220333526
2018-12-07 09:04:54 +01:00
C. Scott Ananian
8025629395 Ensure disabled deprecation warnings are re-enabled before next test
Tests should not interfere with each other; disabled deprecation
warnings should be disabled for a single test case only.

Bug: T191960
Change-Id: Ic9b892bc83ba6d71c1077df0d93c95dde36988bb
2018-09-25 16:30:38 +00:00
Gergő Tisza
4aedefdbfd
Add helper trait for deprecating properties
Change-Id: I83e6ee4e8eedd49acef2b5d92132d37af715bff3
2018-07-18 15:15:46 +02:00
Kunal Mehta
b9e8e9a681 Fix KafkaHandlerTest hack to work with PHPUnit 6
Change-Id: I2b2ae31b327976c7c6ba72a49f1d7d068e234928
2018-04-12 09:49:54 -07:00
Umherirrender
63d96c15fd build: Updating mediawiki/mediawiki-codesniffer to 16.0.0
Change-Id: I59b59f79bbf3ce4feff3b3a20c1c31bc16370531
2018-02-17 13:29:13 +01:00
Reedy
39f0f919c5 Update suppressWarning()/restoreWarning() calls
Bug: T182273
Change-Id: I9e1b628fe5949ca54258424c2e45b2fb6d491d0f
2018-02-10 08:50:12 +00:00
Umherirrender
45da581551 Use ::class to resolve class names in tests
This helps to find renamed or misspelled classes earlier.
Phan will check the class names

Change-Id: Ie541a7baae10ab6f5c13f95ac2ff6598b8f8950c
2018-01-26 22:49:13 +01:00
Kunal Mehta
389d0a0958 Add @covers tags to includes/debug tests
Change-Id: Ida6562c87204f1680239d0bdbfde4d6fdc9bf748
2017-12-27 17:44:18 +00:00
Brad Jorsch
92013dcadd Fix MWDebugTest::testAppendDebugInfoToApiResultXmlFormat
When this test was added in Ifb2e392d3, it did not pass the correct
number of arguments to ApiFormatXml::recXmlPrint().

Bug: T182368
Change-Id: I63aee08307054137c6b50b6fbd271e03f6d4e45f
2017-12-08 11:55:52 -05:00
Gergő Tisza
525bfbc8df Switch to librarized version of TestingAccessWrapper
Replaces \TestingAccessWrapper (defined in core) with
\Wikimedia\TestingAccessWrapper (defined in the composer package
wikimedia/testing-access-wrapper).

See https://gerrit.wikimedia.org/r/#/q/topic:librarize-testing-access-wrapper
for downstream patches.

The core version of the class is kept around for a while to avoid
circular dependency problems.

Bug: T163434
Change-Id: I52cc257e593da3d6c3b01a909e554a950225aec8
2017-04-20 14:15:57 +00:00
Timo Tijhof
447ce7e39a phpunit: Avoid use of deprecated getMock for PHPUnit 5 compat
The default will remain PHPUnit 4.x due to PHP 5.5 support.

But, we should allow developers to run tests with newer PHPUnit
versions which are noticably faster (especially for code coverage
reports).

* <https://github.com/sebastianbergmann/phpunit/wiki/Release-Announcement-for-PHPUnit-5.4.0>
  PHPUnit 5 deprecates the getMock() shortcut for getMockBuilder()->getMock().
  It instead introduces the shortcut createMock() which has better defaults
  than getMockBuilder(). For example, it sets 'disableArgumentCloning' and
  other things by default.

  Going forward, code should either use getMockBuilder directly and configure
  it using the setter methods (instead of the confusing variadic arguments
  of getMock) or simply use the new minimalistic createMock method. This patch
  backports the createMock method to MediaWikiTestCase so that we can start
  using it.

Change-Id: I091c0289b21d2b1c876adba89529dc3e72b99af2
2017-04-06 00:44:32 +00:00
Gergő Tisza
98f143e0f4 Rewrite logstash key conflict warning from I6677dbf6
* do not warn if something is overwritten with an identical value
  (happens a lot with 'ip')
* move to LogstashFormatter so we can check for the value
* instead of spamming errors, just add a flag to the logstash data

Bug: T145133
Change-Id: I31caee865cd60c785126478ac75c9aefce78eaaf
2016-11-29 11:14:08 +00:00
jenkins-bot
6cc415a26e Merge "kafka: Implement ack handling" 2016-06-29 12:18:45 +00:00
Erik Bernhardson
e761c8847a kafka: Implement ack handling
By default the kafka implementation we use doesn't require any kind of
acknowledgment, it just throws messages into the wind and lets them sit
where they may. Implement an option for KafkaHandler to specify the
number of acks (number of replicas that must record the message) and
some error handling to throw exceptions as necessary when there is a
problem.

Bug: T135159
Change-Id: I859dc791072db407f908b2f36be0d6704f1a6256
2016-06-23 08:12:29 -07:00
Kunal Mehta
7ca37f1585 Remove no-longer needed backported class from phpunit
Since we finally upgraded our phpunit version, we no longer need a copy
of this phpunit matcher.

Change-Id: I9bf3db344a2e8789a264a453e4e6d87fedc4dc49
2016-06-17 02:19:32 +00:00
Ori Livneh
78e47bbc54 Fix-up for I52c511be04: call parent setup / teardown methods
Change-Id: Ic66fa5ae61f1d1822d7cc20eafa6c01a2bdb6e37
2016-05-18 12:18:34 -07:00
Ori Livneh
66afa6ecd0 MWDebugTest: disable MWDebug on test teardown
MWDebug::init() is currently irreversible -- once MWDebug is enabled, it cannot
be disabled in that execution context. This means that the MWDebug test suite
(which enables MWDebug) has a nasty side-effect -- all the tests that run after
it run with MWDebug enabled. So add an MWDebug::deinit(), and call it on test
teardown.

Ostensibly this is a great use-case for services and dependency injection. The
reason I am not going that route is that it's not entirely clear to me what the
MWDebug class is supposed to represent. If I were going to spend any
substantial amount of time on this, I would be trying to move it out of core
and into an extension, not converting it into a service.

Change-Id: I52c511be049bc276d203d07283e3aa0944f22d34
2016-05-18 02:23:26 -07:00
Reedy
291126d927 Update monolog to 1.18.2
https://github.com/Seldaek/monolog/compare/1.17.2...1.18.2

Update KafkaHandlerTest.php

Depends-On: I32e9ebe0a10d97a1ccb0f4d605bd0ee9ba4e97f6
Change-Id: I35eedb6d95b68ebf90c00bb54469c9ff5731cdab
2016-04-05 20:01:26 +00:00
addshore
72738d6476 Remove use of deprecated wfSuppress/RestoreWarnings
Change-Id: I8f7a77a66f027d853c3532021a24425339571f7c
2016-04-03 12:24:00 +03:00
Timo Tijhof
4193700b19 Add missing namespace to @covers comments
PHP_CodeCoverage_Exception:
> Trying to @cover not existing method "SwiftFileBackend::sanitzeHdrs".
> Trying to @cover not existing method "LineFormatter::normalizeException".
> Trying to @cover not existing method "MonologSpi::mergeConfig".
> Trying to @cover not existing method "ProcessCacheLRU::het".
> Trying to @cover not existing method "BitmapHandler::swapICCProfile".
> Trying to @cover not existing class or interface "checkParseSafety".
> Trying to @cover not existing method "Article::__call". (was removed).
> Trying to @cover not existing method "ExtensionProcessor::extracttExtensionMessagesFiles".
> Trying to @cover not existing method "FileContentsHasher::getFileContentHash".

Makes code coverage run fail at the moment. These used to be warnings
in PHPUnit 3.x, but are now hard exceptions in PHPUnit 4.x when requesting
a coverage report.

Change-Id: If7f45ca57fd7d480d35b1414a889398837c0c472
2016-02-23 03:56:49 +00:00
Timo Tijhof
e7939ffcd4 Add missing namespace to @covers comment in LegacyLoggerTest
> Trying to @cover or @use not existing method "LegacyLogger::interpolate"

Makes code coverage run fail at the moment.

Change-Id: I8417b5c2f1fc116583758c7507770c796127bb67
2016-02-23 03:18:31 +00:00
Kunal Mehta
6e9b4f0e9c Convert all array() syntax to []
Per wikitech-l consensus:
 https://lists.wikimedia.org/pipermail/wikitech-l/2016-February/084821.html

Notes:
* Disabled CallTimePassByReference due to false positives (T127163)

Change-Id: I2c8ce713ce6600a0bb7bf67537c87044c7a45c4b
2016-02-17 01:33:00 -08:00
jenkins-bot
5a4fdb5b4e Merge "[debug] Remove BC code from AvroFormatter" 2016-02-04 13:17:31 +00:00
Erik Bernhardson
a964ca2ba9 [debug] Remove BC code from AvroFormatter
Deployed usages of avro now use the new format, allowing
this old style will only cause pain to those that attempt
to use it in the future.

Change-Id: Id27ed7b529153ef7983b9fc3c1250b19dc4a516f
2015-12-28 16:21:50 -08:00
umherirrender
54c1e18eec Remove various double empty newlines
The double empty newline is not needed between functions, variable or at
end of file

Change-Id: Ib866a95084c4601ac150a2b402cfa184ebc18afa
2015-12-27 18:55:12 +00:00
Alex Monk
23f633c5a6 Use the frame 'type' in wfFormatStackFrame, like MWExceptionHandler::prettyPrintTrace
Instead of assuming '::'

Change-Id: I2452bc5ebd3716eb61f53da41a0050f4833fb5a4
2015-10-14 16:40:02 +01:00
Amir E. Aharoni
3cd3b7ac9f Make lines short to pass phpcs in 3 files under tests/phpunit/includes/
Bug: T102614
Change-Id: I8f3d570fb6e9866d4376f42d4efa05f9c5e7f14d
2015-10-01 19:00:40 +00:00
Reedy
0ea1898b4e Re-enable MediaWiki.WhiteSpace.SpaceyParenthesis.SingleSpaceAfterOpenParenthesis
Fixed some SingleSpaceBeforeCloseParenthesis too

Change-Id: I1695c706a9b23ab98074ff7d6a3687eb5cdce6e7
2015-09-26 16:13:12 +00:00
Erik Bernhardson
593e7257e3 Include phpunit license for backported classes
Bug: T113765
Change-Id: I3f4242d4323d447097b2de42bfade969a6e3fd9d
2015-09-25 11:18:20 -07:00
aude
4bfbaaf682 Set visibility of monolog tests setUp method to protected
In phpunit and MediaWikiTestCase, the setUp method is protected,
and it's nice if the subclasses are consistent.

Change-Id: I4b8ac612951168913bb2dc9cf16d3dc18762a211
2015-09-22 16:57:55 +02:00
aude
641e6ed336 Also check Kafka class exists in KafkaHandlerTest
I have monolog installed but not Kafka, so still
the test was run and broken for me.

Change-Id: If396815d77b0ae25fbd5c16b628f217478062b43
2015-09-22 16:54:58 +02:00
aude
063fb8f39a Fix typo in KafkaHandlerTest
Change-Id: Ib73152a269e01bc64a4b1e7a9157de2088d152d2
2015-09-22 16:35:36 +02:00
Adrian Heine
3d7b910bc3 Fix typo in AvroFormatterTest
Also removes trailing whitespace in that file.

Change-Id: Icf30a68ea7356735f416baae8a435e0f10d5caaa
2015-09-22 10:07:09 +02:00
Erik Bernhardson
f66559b616 Produce monolog messages through kafka+avro
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
2015-09-21 12:45:23 -07:00
Bryan Davis
ba1835f159 Enhance debug log output for stacktraces
Make MediaWiki\Logger\LegacyLogger and
MediaWiki\Logger\Monolog\LineFormatter better at outputting stacktrace
information and provide support for 'exception' data in the logging
context that is a structured array in addition to the default Exception
object support. This works with MWExceptionHandler::handleFatalError
generated data that is provided by an HHVM interpreter and cannot be
delivered as an Exception class.

With this patch, a good value for LineFormatter's format would be:
"%datetime% %extra.host% %extra.wiki% %channel% %level_name%: %message%
%context% %exception%\n"

Bug: T89169
Bug: T107440
Change-Id: Ida01ed51c573e1654346e716723e543a1be63090
2015-09-08 07:03:52 +00:00
Kunal Mehta
fa1123a012 Skip monolog tests if monolog is not installed
Change-Id: Ib3f4f76651da183901634a0ac6787666e47d74d4
2015-08-30 23:42:56 -07:00
Bryan Davis
27dcc9f051 Monolog: Add Formatter that uses MWExceptionHandler::getRedactedTraceAsString
Add a Monolog Formatter class that uses
MWExceptionHandler::getRedactedTraceAsString when outputting stack
traces.

Bug: T107440
Change-Id: Ic580c137e27aac95435f7b073a18cf61820b172f
2015-07-31 13:02:39 -06:00
Timo Tijhof
5d2f9d08ee logger: Fix undefined variable $data
Follows-up 77a397125f. Also add unit test that would've caught
this "PHP Notice: Undefined variable: data" error.

Change-Id: I8a3bd9c8b685c2aa7a466e3d3c61ffa027be02fa
2015-07-29 18:26:52 -07:00
Bryan Davis
77a397125f Convert MWExceptionHandler to use structured logging
Replace wfDebugLog() calls in MWExceptionHandler with direct use of
LoggerFactory and LoggerInterface. Logged exceptions are added to the
log message context.

LegacyLogger is also updated to append stack traces to any log event
when $wgLogExceptionBacktrace is true and the PSR-3 recommendation of
passing the exception as an 'exception' context item.

Handling of context data in LegacyLogger is expanded to support arrays,
exceptions and common object types.

Bug: T88649
Change-Id: I71499d895582bdea033a2516c902e23e38084080
2015-07-15 21:03:46 -05:00
Bryan Davis
3a577ce8f0 MonologSpi: Add method to provide additional configuration
Allow post-initialization configuration of MonologSpi by providing
a `mergeConfig()` method that can be used to merge a given collection of
configuration data with the existing configuration.

Bug: T104584
Change-Id: Iba6f115a79dbc0060f64a9095467d147cf53b8ae
2015-07-10 09:43:07 -06:00
Kunal Mehta
f6e5079a69 Use mediawiki/at-ease library for suppressing warnings
wfSuppressWarnings() and wfRestoreWarnings() were split out into a
separate library. All usages in core were replaced with the new
functions, and the wf* global functions are marked as deprecated.

Additionally, some uses of @ were replaced due to composer's autoloader
being loaded even earlier.

Ie1234f8c12693408de9b94bf6f84480a90bd4f8e adds the library to
mediawiki/vendor.

Bug: T100923
Change-Id: I5c35079a0a656180852be0ae6b1262d40f6534c4
2015-06-11 18:49:29 +00:00
Brad Jorsch
1c57794e37 API: Overhaul ApiResult, make format=xml not throw, and add json formatversion
ApiResult was a mess: some methods could only be used with an array
reference instead of manipulating the stored data, methods that had both
array-ref and internal-data versions had names that didn't at all
correspond, some methods that worked on an array reference were
annoyingly non-static, and then the whole mess with setIndexedTagName.

ApiFormatXml is also entirely annoying to deal with, as it liked to
throw exceptions if certain metadata wasn't provided that no other
formatter required. Its legacy also means we have this silly convention
of using empty-string rather than boolean true, annoying restrictions on
keys (leading to things that should be hashes being arrays of key-value
object instead), '*' used as a key all over the place, and so on.

So, changes here:
* ApiResult is no longer an ApiBase or a ContextSource.
* Wherever sensible, ApiResult provides a static method working on an
  arrayref and a non-static method working on internal data.
* Metadata is now always added to ApiResult's internal data structure.
  Formatters are responsible for stripping it if necessary. "raw mode"
  is deprecated.
* New metadata to replace the '*' key, solve the array() => '[]' vs '{}'
  question, and so on.
* New class for formatting warnings and errors using i18n messages, and
  support for multiple errors and a more machine-readable format for
  warnings. For the moment, though, the actual output will not be changing
  yet (see T47843 for future plans).
* New formatversion parameter for format=json and format=php, to select
  between BC mode and the modern output.
* In BC mode, booleans will be converted to empty-string presence style;
  modules currently returning booleans will need to use
  ApiResult::META_BC_BOOLS to preserve their current output.

Actual changes to the API modules' output (e.g. actually returning
booleans for the new formatversion) beyond the use of
ApiResult::setContentValue() are left for a future change.

Bug: T76728
Bug: T57371
Bug: T33629
Change-Id: I7b37295e8862b188d1f3b0cd07f66ac34629678f
2015-04-10 16:57:15 -04:00
Bryan Davis
1195e11a8a Move MWLogger classes to MediaWiki\Logger namespace
Move the MWLogger PSR-3 logging related classes into the
MediaWiki\Logger namespace. Create shim classes to ease migration of
existing MWLoggerFactory usage to the namespaced classes.

Bug: T93406
Change-Id: I359cc81fbd2dcf8937742311dcc7d3dee08747b0
2015-04-03 11:32:24 -07:00
Kunal Mehta
4316c8c48b Implement support for a minimum log level in $wgDebugLogGroups
For some log groups, we only want to log them if they meet a certain
level of severity. An example of this is the current 'memcached-serious'
log group, which can be merged with the normal 'memcached' group
in the future, and report at a severity of ERROR.

This adds a 'level' parameter to the $wgDebugLogGroups, for example:
    $wgDebugLogGroups['memcached'] = array(
        'destination' => '/var/log/mw/memcached.log',
        'level' => \Psr\Log\LogLevel::ERROR,
    );

Bug: T85073
Change-Id: Ic53bc4c8e318ed188fe6f4e838e6789b3c3fd574
2014-12-31 18:16:17 +00:00
Timo Tijhof
ff6513f28b Remove '@section LICENSE'
This was used in 2 special classes, the logger classes and spread
to a few other random classes.

Afaik this has no meaning. Is for something we don't use, and
goes against the meaning of '@section' in Doxygen, which we do
use.

In Doxygen output, all LICENSE references became links to
ProfilerXhprof (the one Doxygen encoutered first).

Bug: T72328
Change-Id: Icc7c443245c70bc0f549bee7d105eef5691c864d
2014-11-26 02:20:55 +00:00
Bryan Davis
2792ea9783 Add logging context to database logs
* Add optional $context parameter to wfDebug, wfDebugLog, wfLogDBError
  and wfErrorLog that will be passed to MWLogger.
* Add support for PSR-3 style log message parameter interpolation in
  MWLoggerLegacyLogger.
* Add context information to wfLogDBError calls made from DatabaseBase,
  DatabaseMysqlBase and LoadBalancer instances.
* Deprecate wfDebugTimer() which now appears to be unused.

Change-Id: Ic90d593d00a2b0b5b80ed205908cbe624042603c
2014-11-19 17:59:55 +00:00
Chad Horohoe
9144673b5c Remove profiler support from debugging toolbar
It never worked and creates extra dependencies on the profiler

Change-Id: I584c9e94d144baf48a654e23dd9f47690d94f13b
2014-11-17 18:27:46 +00:00
Kevin Israel
b0751af753 Indicate the actual version of HHVM in use
Strings like "5.6.99-hhvm" are not version numbers but merely
a way for HHVM to pass version checks. They should not be
displayed in the UI.

This affects Special:Version, the API (action=query&meta=siteinfo),
the installer welcome page, and the debug toolbar.

Follows-up d09ab9001f.

Change-Id: Ia99dca64779e9c4eaddf5f0e0101674d029b8d55
2014-08-05 16:36:47 -04:00
umherirrender
2b021dc48a Fixed spacing
- Added/removed spaces around parenthesis
- Added space after switch/if/foreach
- changed else if to elseif

Change-Id: I99cda543e0e077320091addd75c188cb6e3a42c2
2014-07-19 23:12:10 +02:00
aude
aabf9345f0 Fix uncaught ApiFormatXml exception with api debuginfo
Also added tests to cover this.

Bug: 67246
Change-Id: Ifb2e392d3277a4702832727f70c77b170d4b2bf5
2014-06-28 20:35:52 +02:00