jenkins-bot has submitted this change and it was merged. Change subject: Make the format of UDP-logged stats configurable ......................................................................
Make the format of UDP-logged stats configurable The format of datagrams generated by StatCounter and ProfilerSimpleUDP is not described by any standard and appears to have been designed for compatibility with the logging setup of the Wikimedia Foundation, which limits reusability. This patch adds two configuration variables, $wgUDPProfilerFormatString and $wgStatsFormatString, that can be used to specify the precise format that MediaWiki will use. The default values for these variables causes MediaWiki to generate the same output as before. The secret evil plan is to change the defaults so that MediaWiki emits metrics that are compatible with the popular StatsD format (see <https://github.com/b/statsd_spec>). This would allow us to replace udpprofiler with a generic StatsD instance instead. Change-Id: Iaf00811d3f8d6b89c1c68e84fc1f2c93425d5a2d --- M RELEASE-NOTES-1.22 M includes/DefaultSettings.php M includes/StatCounter.php M includes/profiler/ProfilerSimpleUDP.php 4 files changed, 32 insertions(+), 5 deletions(-) Approvals: Aaron Schulz: Looks good to me, approved jenkins-bot: Verified diff --git a/RELEASE-NOTES-1.22 b/RELEASE-NOTES-1.22 index 7933e06..66fde1a 100644 --- a/RELEASE-NOTES-1.22 +++ b/RELEASE-NOTES-1.22 @@ -58,6 +58,9 @@ default Sidebar. * The 'vector-simplesearch' preference is now enabled by default. Previously it was only enabled if the Vector extension was installed. +* The precise format of metric datagrams produced by the UDP profiler and stats counter + may now be specified as $wgUDPProfilerFormatString and $wgStatsFormatString, + respectively. === New features in 1.22 === * (bug 44525) mediawiki.jqueryMsg can now parse (whitelisted) HTML elements and attributes. diff --git a/includes/DefaultSettings.php b/includes/DefaultSettings.php index 19b2f41..a577f71 100644 --- a/includes/DefaultSettings.php +++ b/includes/DefaultSettings.php @@ -5053,6 +5053,17 @@ $wgUDPProfilerPort = '3811'; /** + * Format string for the UDP profiler. The UDP profiler invokes sprintf() with + * (profile id, count, cpu, cpu_sq, real, real_sq, entry name) as arguments. + * You can use sprintf's argument numbering/swapping capability to repeat, + * re-order or omit fields. + * + * @see $wgStatsFormatString + * @since 1.22 + */ +$wgUDPProfilerFormatString = "%s - %d %f %f %f %f %s\n"; + +/** * Detects non-matching wfProfileIn/wfProfileOut calls */ $wgDebugProfiling = false; @@ -5079,6 +5090,19 @@ $wgAggregateStatsID = false; /** + * When $wgStatsMethod is 'udp', this variable specifies how stats should be + * formatted. Its value should be a format string suitable for a sprintf() + * invocation with (id, count, key) arguments, where 'id' is either + * $wgAggregateStatsID or the DB name, 'count' is the value by which the metric + * is being incremented, and 'key' is the metric name. + * + * @see $wgUDPProfilerFormatString + * @see $wgAggregateStatsID + * @since 1.22 + */ +$wgStatsFormatString = "stats/%s - %s 1 1 1 1 %s\n"; + +/** * Whereas to count the number of time an article is viewed. * Does not work if pages are cached (for example with squid). */ diff --git a/includes/StatCounter.php b/includes/StatCounter.php index 374d5ca..1373f3d 100644 --- a/includes/StatCounter.php +++ b/includes/StatCounter.php @@ -91,20 +91,20 @@ * @return void */ protected function sendDeltasUDP( array $deltas ) { - global $wgUDPProfilerHost, $wgUDPProfilerPort, $wgAggregateStatsID; + global $wgUDPProfilerHost, $wgUDPProfilerPort, $wgAggregateStatsID, + $wgStatsFormatString; $id = strlen( $wgAggregateStatsID ) ? $wgAggregateStatsID : wfWikiID(); $lines = array(); foreach ( $deltas as $key => $count ) { - $lines[] = "stats/{$id} - {$count} 1 1 1 1 {$key}\n"; + $lines[] = sprintf( $wgStatsFormatString, $id, $count, $key ); } if ( count( $lines ) ) { static $socket = null; if ( !$socket ) { $socket = socket_create( AF_INET, SOCK_DGRAM, SOL_UDP ); - array_unshift( $lines, "stats/{$id} - 1 1 1 1 1 -total\n" ); } $packet = ''; $packets = array(); diff --git a/includes/profiler/ProfilerSimpleUDP.php b/includes/profiler/ProfilerSimpleUDP.php index 9204763..0a1f3b1 100644 --- a/includes/profiler/ProfilerSimpleUDP.php +++ b/includes/profiler/ProfilerSimpleUDP.php @@ -32,7 +32,7 @@ } public function logData() { - global $wgUDPProfilerHost, $wgUDPProfilerPort; + global $wgUDPProfilerHost, $wgUDPProfilerPort, $wgUDPProfilerFormatString; $this->close(); @@ -57,7 +57,7 @@ || !isset( $pfdata['real_sq'] ) ) { continue; } - $pfline = sprintf( "%s %s %d %f %f %f %f %s\n", $this->getProfileID(), "-", $pfdata['count'], + $pfline = sprintf( $wgUDPProfilerFormatString, $this->getProfileID(), $pfdata['count'], $pfdata['cpu'], $pfdata['cpu_sq'], $pfdata['real'], $pfdata['real_sq'], $entry ); $length = strlen( $pfline ); /* printf("<!-- $pfline -->"); */ -- To view, visit https://gerrit.wikimedia.org/r/87030 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: merged Gerrit-Change-Id: Iaf00811d3f8d6b89c1c68e84fc1f2c93425d5a2d Gerrit-PatchSet: 3 Gerrit-Project: mediawiki/core Gerrit-Branch: master Gerrit-Owner: Ori.livneh <[email protected]> Gerrit-Reviewer: Aaron Schulz <[email protected]> Gerrit-Reviewer: Ori.livneh <[email protected]> Gerrit-Reviewer: Parent5446 <[email protected]> Gerrit-Reviewer: Ryan Lane <[email protected]> Gerrit-Reviewer: jenkins-bot _______________________________________________ MediaWiki-commits mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits
