Commit graph

161 commits

Author SHA1 Message Date
Umherirrender
b5cddfb27b Remove empty lines at begin of function, if, foreach, switch
Organize phpcs.xml a bit

Change-Id: Ifb767729b481b4b686e6d6444cf48b1f580cc478
2017-07-01 11:34:16 +00:00
Bryan Davis
aaf1e17088 Remove "@author Bryan Davis" and "Brad Jorsch" annotations
Undo traces of a practice we carried over from past projects and
existing examples that is neither universal nor actively encouraged in
the MediaWiki codebase.

Bug: T139301
Change-Id: I5c9c89b72a45a44aa4264a5e57b003c1a86cdf6e
Co-Authored-By: Brad Jorsch <bjorsch@wikimedia.org>
2017-06-26 15:25:46 -06:00
Thiemo Mättig
e16191caa3 Remove unused and unnecessary imports
Change-Id: I26e623a4e4ba965c07670369a90c8a95185ea1e4
2017-06-12 15:50:43 +00:00
Tim Starling
a59ed5f3de Add ConsoleLogger, use it for eval.php -d
eval.php previously set $wgDebugLogFile to /dev/stdout. This had the
following problems:

* It doesn't work if the maintenance script is executed via sudo, since
  /dev/stdout is typically owned by the original user, so MW can't open
  it. Using php://stdout worked on HHVM but not PHP.
* Setting $wgDebugLogFile has no effect if the wiki uses MonologSpi.
* Setting $wgDebugLogFile has no effect on channels configured with
  $wgDebugLogGroups.
* stderr is a more appropriate place to send logging output.
* Writing to configuration variables is discouraged.

So, add ConsoleSpi, which is a very simple logging service provider
which sends all messages to stderr. This should be suitable for
debugging with eval.php or shell.php in WMF production or beta.

Change-Id: Ib0d6ce45e0cbecd58263fc4e360c63d4149acb3a
2017-04-28 10:05:05 +10:00
Bartosz Dziewoński
ecdef925bb Miscellaneous indentation tweaks
I was bored. What? Don't look at me that way.

I mostly targetted mixed tabs and spaces, but others were not spared.
Note that some of the whitespace changes are inside HTML output,
extended regexps or SQL snippets.

Change-Id: Ie206cc946459f6befcfc2d520e35ad3ea3c0f1e0
2017-02-27 19:23:54 +01:00
jenkins-bot
8bb5a6c461 Merge "Improve logging of exceptions which are not thrown but attached to context" 2017-02-24 12:04:20 +00:00
Timo Tijhof
f89eaf4312 phpunit: Fix AvroFormatterTest failure on PHP 7
Fix the following error on PHP 7.

> MediaWiki\Logger\Monolog\AvroFormatterTest::testDoesSomethingWhenSchemaAvailable
> Only variables should be passed by reference
> includes/debug/logger/monolog/AvroFormatter.php:143

Per https://github.com/researchgate/avro-php/blob/1.8.0/lib/avro/schema.php#L311-L314
the default for &$schemata is null, which is filled with a plain AvroNamedSchemata
instance. So this parameter is obsolete.

Either it needs to be assigned here and then passed. But since we don't use
it anywhere and don't pass it any constructor arguments, the default
should suffice.

Bug: T75176
Bug: T141588
Change-Id: I144bed8a78eb267a97e41f379b89c5faaae30625
2017-02-22 20:47:46 -08:00
Gergő Tisza
74aa6b07db Improve logging of exceptions which are not thrown but attached to context
Bug: T151290
Change-Id: I9cc9f54c2987cf960343b5eca2a1c6d006b892bf
2017-02-21 19:33:22 -08:00
jenkins-bot
8373bf3fc0 Merge "Decrease the number of 'function says it should return something' errors" 2016-12-16 17:20:16 +00:00
Max Semenik
d4f3e554d7 Decrease the number of 'function says it should return something' errors
Change-Id: Ib5115fe5bbaa67d8a6e54cc3ba1ba7020e239e11
2016-12-15 16:05:52 -08:00
Erik Bernhardson
d67197fa11 Cleanup some incorrect return annotations
Most of these are simply changing annotations to reflect
reality. If a function can return false to indicate failure
the @return should indicate it.

Some are fixing preg_match calls, preg match returns 1, 0 or false,
but the functions all claim to return booleans.

This is far from all the incorrect return types in mediawiki, there
are around 250 detected by phan, but have to start somewhere.

Change-Id: I1bbdfee6190747bde460f8a7084212ccafe169ef
2016-12-12 10:15:05 -08: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
Gergő Tisza
057b870b47 Warn when a log context accidentally overrides a log processor
Bug: T145133
Change-Id: I6677dbf608aac1d7fd6036f5e51977d56ce2fc57
2016-11-22 03:07:05 +00:00
Timo Tijhof
ecfd8c3934 LegacyLogger: Fix @return documentation for formatAsWfDebugLog()
Follows-up 81e8d7af4.

Change-Id: I04a1bb53e5d35434166596edda4cdb1fe189964b
2016-11-16 10:56:04 -08:00
Sam Wilson
66e215baee Remove spaces after cast operators
This fixes the outstanding mis-spaced cast operators to bring them
into line with the coding standards on mediawiki.org (and with the
more common usage within this codebase).

Bug: T149545
Change-Id: Ib7bcf95bbee83d20c05f6d621ce7b4e1fb58a347
2016-10-31 13:57:39 +00:00
Bryan Davis
2082923175 LegacyLogger: Be consistent about converting log levels to int
Normalize $level arguments to integers early to avoid confusion later
about what type the argument is.

Change-Id: I7305c0514f4383ec552afea2deb0e3fc6ba3fe8a
2016-09-30 17:54:45 -06:00
Aaron Schulz
094105f017 Fix wfLogDBError channel redirect logic
Change-Id: I1249f9a097625c2fab6601059177594e5f3a21fc
2016-09-30 16:37:00 -07:00
Aaron Schulz
e861191b2c Only send DB query profiling to MWDebug::query
This should avoid massive dberror log spam in jenkins.

Change-Id: Ifa60843e78b99921768e7a62109c505ff9330e41
2016-09-20 15:42:00 -07:00
Aaron Schulz
81e8d7af41 Avoid MWDebug usage in DatabaseBase
This class is in /libs and cannot depend on all of MediaWiki.
Replace the call with a simple debug() call instead.

Also, make the legacy logger route/format errors from the two
new DB log types (DBConnection, DBQuery) to the old wfLogDBError
locations, including MWDebug::debugMsg().

Change-Id: I64895d3f5b9a000d8186ab6a6ffb4b76a7e9ff40
2016-09-17 18:49:30 -07:00
Aaron Schulz
3802f088f1 Allow quotes in $wgDebugComments HTML comments
Change-Id: Id1fbab9ad3d6d645b6efea1d1e66a18ab4fe0b89
2016-09-15 12:53:43 -07:00
Amir Sarabadani
d56829dca8 Clean up array() syntax from docs, part VI
Change-Id: Ib0eea494e2065c7ab356dc45fd174544a9c1c942
2016-09-12 14:36:37 +04:30
Amir Sarabadani
6b221fa96a Clean up array() syntax in docs, part IV
Change-Id: If626409a93d31bf90c054c9bf7ba44a78ea9a621
2016-08-26 16:06:58 +04:30
Kunal Mehta
d186cce511 debug: Interpolate log messages
Change-Id: Ib61a50863022db796d69264bf738fb0b22f776e9
2016-08-24 16:22:52 -07:00
Kunal Mehta
b71ff434dd debug: Merge mediawiki.debug.init module into mediawiki.debug
It just calls mw.Debug.init() on document ready, which can easily be
done inside mediawiki.debug.

Change-Id: Ifaa5a4884c9e430241a4bff51454bb96f468cd61
2016-08-24 16:22:39 -07:00
Kunal Mehta
14037fd04d debug: Don't show git branch if on a detached HEAD
The short SHA1 is already shown with the MediaWiki version, and
displaying the full SHA1 again adds 40+ more characters. Mostly this
annoys me as it causes the toolbar to wrap earlier when making my
browser window smaller.

Change-Id: If7474a090466de708d65cef6dcc30a36df56621f
2016-08-24 15:44:41 -07:00
Kunal Mehta
78b167b763 debug: Don't separately calculate query runtime
It is already calculated for the transaction profiler, so re-use that.

Change-Id: Ifcc43484c25e00e2409fbfb421ca2f9cecd67492
2016-08-21 06:43:15 +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
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
umherirrender
e1864398d7 cleanUp all invalid utf8 in sql for debug toolbar
Some sql still contains utf8 which is not replaced by ■, clean up this
bytes by using UtfNormal.

Change-Id: I548ffd783536c65b023b1598a5c57fb9b86c6db2
2016-04-22 21:50:44 +02: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
Ori Livneh
465199e023 Fix-up for Iaf90c20c33: add missing slash
Change-Id: I92169a3b74123db8ceaca222db760095a7c06d4f
2016-03-25 09:38:26 -07:00
Ori Livneh
5360a3497f Provide a unique request identifier
When MediaWiki encounters an unhandled exception, the error message it produces
includes a randomly-generated token, which allows the exception details to be
looked up in the error logs. This is useful but narrow: would it not be useful
to have the ability to retrieve all log records associated with a particular
request, rather than just exception details? (Hint: yes.)

So: introduce the notion of a request-global unique ID, retrievable via
WebRequest::getRequestId(). When MediaWiki is behind Apache + mod_unique_id
(which provides the same facility) or some other software which sets a
UNIQUE_ID envvar, the value of that envvar is used as the request ID.
Otherwise, it is a randomly-generated 24-character string.

The request ID supplants exception-specific IDs; MWExceptionHandler::getLogId()
is deprecated, accordingly. The request ID is also added as an annotation to
all Monolog-processed log records, and is exposed client-side as 'wgRequestId'.
This allows developers to associate a page view with log records even when the
page view does not result in an unhandled exception. (For the WMF, I also
intend to add it as an annotation to profiling data).

The request ID is not a tracking token; it does not persist, and it is
associated with a backend request, not with a particular user or a particular
session. Like the data in the NewPP report, the request ID is designed to be
cacheable, so that if, for example, a developer notices something weird in the
HTML, s/he can associate the output with a backend request regardless of
whether the response was served from the cache or directly from the backend.

Some prior art:
* https://httpd.apache.org/docs/2.4/mod/mod_unique_id.html
* http://api.rubyonrails.org/classes/ActionDispatch/RequestId.html
* https://github.com/dabapps/django-log-request-id
* https://packagist.org/packages/php-middleware/request-id
* https://github.com/rhyselsmore/flask-request-id

Change-Id: Iaf90c20c330e0470b9b98627a0228cadefd301d1
2016-03-25 16:09:05 +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
umherirrender
4eb7d282d3 Remove PHP < 5.3.6 compatibility in LegacyLogger
Change-Id: Iaa820accce207ce48022bf7e72264c3c247331ba
2016-02-11 19:50:43 +01:00
Bryan Davis
6add6cef3e Add $wgVersion to MediaWiki\Logger\Monolog\WikiProcessor
Add a 'mwversion' value to log events processed by WikiProcessor to help
with classifying log events emitted by a wiki farm running mixed
versions of MediaWiki.

Bug: T125707
Change-Id: I5f5dfd051ebf251bec0d6e6a83a15e81f59540f3
2016-02-07 15:03:34 -07:00
jenkins-bot
5a4fdb5b4e Merge "[debug] Remove BC code from AvroFormatter" 2016-02-04 13:17:31 +00:00
Max Semenik
15d85cf20d KafkaHandler: allow customizing timeouts
Bug: T125084
Change-Id: I8f01fa61d916aeaa831a84e12b6fae08d04ca046
2016-01-28 18:01:13 -08:00
PranavK
6a857f6cc1 MWDebug: Add support for passing objects
Change-Id: I121acab012676e486e19b3f8b0fae50af3d3a567
2016-01-24 05:55:45 +00:00
Bryan Davis
0affda7edf Remove use of $dest = 'log' for wfDebugLog
The functionality for marking a debug log message for delivery to a log
file but not to MWDebug was removed in 1.25 with the introduction of
the PSR-3 logging system. Convert the messages that were marked for this
special handling in a7a0883 to use 'private' instead.

Bug: T122644
Change-Id: Iefaac07a5922c16c2899904c7b678199c5b1efe9
2015-12-30 13:03:14 -07:00
Bryan Davis
459c0e28bf Exclude debug log events marked "private" from MWDebug
Respect the "private" context variable for debug log events when passing
events from MediaWiki\Logger\LegacyLogger to MWDebug::debugMsg. Passing
debug log events marked as private to MWDebug  was a regression
introduced by the PSR-3 logging system.

Restore handling of $dest argument to wfDebug which was removed in 1.25
with the PSR-3 logging conversion. The documentation for $dest = 'log'
has also been removed. This third debug log event handling option was
not implemented in the PSR-3 logging conversion in 1.25. A follow up
change will remove known usage of $dest = 'log' in core.

Bug: T122644
Change-Id: Ib1d999b8b54e584e3944b46e9163a700f11c2e72
2015-12-30 13:01:37 -07: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
Gergő Tisza
c3ea1b85b4 Move PSR-3 support check right after autoloader setup
This ensures that, in case "composer install" has not been run,
the user will see the error message about setting up dependencies
(as opposed a plain "Class not found" error because some other
dependency was used first).

Change-Id: Ib6026123770d21cc9f8960a1de361c8178b1b044
2015-12-13 22:18:07 -08:00
jenkins-bot
38489f18c8 Merge "Supports schema revision id in avro binary formatter" 2015-12-03 18:10:39 +00:00
Reedy
56634389cc Fixup MW for HHVM Repo Authorative mode
https://github.com/facebook/hhvm/issues/5834
https://github.com/facebook/hhvm/issues/5833

Change-Id: I138ffa5df874c5660897dc7feab36adef9f32aea
2015-11-30 17:25:47 +00:00
dcausse
f0ed13eec5 Supports schema revision id in avro binary formatter
Avro formatter now supports a revision defined in schema configuration:

$wmgMonologAvroSchemas = array(
  'CirrusSearchRequestSet' => array(
    'schema' => file_get_contents( __DIR__ . '/schema.avsc' ),
    'revision' => 11144802,
  ),
);

The formatter still supports old style configuration:
$wmgMonologAvroSchemas = array(
  'CirrusSearchRequestSet' => file_get_contents( __DIR__ . '/schema.avsc' ),
);

Change-Id: Icc0f92be23305e77a69b92fee4d9f9de2edda81e
2015-11-24 13:31:45 +01:00
Timo Tijhof
41b5aa343f Remove redundant escaping for namespace references in documentation
Follows-up b264cee. No longer needed as of 0c9e9cc.

Change-Id: I31745f55885eeec2bb8cf2c9ffe9e98242cd5baa
2015-11-23 23:02:32 +00:00
Bryan Davis
f2db70dc14 MonologSpi: add support for customizing Monolog\Logger instances
Proposed upstream changes to Monolog\Logger will require an ability to
call setter methods on newly created Logger instances to tune them for
use in high volume logging situations. Adding support for making these
types of adjustments to MediaWiki's Monolog integration will benefit
users of the updated library when they land upstream.

Arbitrary setters are called by adding a 'calls' array to the logger
specification. This array uses method names as keys and method arguments
as values. This syntax mirrors the setter invocation behavior of
ObjectFactory with the notable omission of Closure expansion in the
argument list before calling the Logger's setter method.

Bug: T116550
Change-Id: I990c7f00f57451f14954542f5404491b2660a0b7
2015-11-04 18:07:19 +00:00
Bryan Davis
701b9a0dc8 LoggerFactory: Only check for Psr\Log\LoggerInterface once
LoggerFactory::getInstance() will be called many times during the course
of handling a typical MediaWiki request. The interface_exists() guard
condition it uses is an attempt to provide an informative error message
when Composer managed libraries are not installed. This check is only
needed on the first invocation of getInstance() to be effective. Using
an additional boolean to guard the interface_exists() call will allow
the PHP runtime to avoid a potentially expensive (at least compared to
a static boolean comparison) function call.

This is the sort of thing that smells of premature optimization, but its
addition is in fact informed by examination of performance reports from
the Wikimedia production environment.

Bug: T115729
Change-Id: I437bcb5326b06145081f2b86f6c4d0c8dc1a318c
2015-10-26 12:57:28 -06:00
Bryan Davis
b264cee6d4 Fix namespaced class references for Doxygen
Doxygen doesn't quite grok PHP's use of the reverse solidus (backslash)
character as a namespace separator. The C++ based parser it uses needs
them to be escaped in comments just as if they were being used in
a literal string context in PHP.

Change-Id: I9aff9dd0fb74a95039da1091c2f247cf71fd085a
2015-10-08 11:10:33 -06:00