From e26f8178667d6d9e94ee4b8ecc42e92040a385a8 Mon Sep 17 00:00:00 2001 From: Andrew Otto Date: Wed, 19 Jun 2019 10:05:50 -0400 Subject: [PATCH] Remove deprecated ApiAction logging code from ApiMain.php ApiAction was disabled in WMF production in https://gerrit.wikimedia.org/r/c/operations/mediawiki-config/+/516303 Bug: T222267 Change-Id: I527811ef84506cf35fe7b9b981fb405776fceb1a --- includes/api/ApiMain.php | 26 ++++++++------------------ 1 file changed, 8 insertions(+), 18 deletions(-) diff --git a/includes/api/ApiMain.php b/includes/api/ApiMain.php index ed17e07c9c..d901f54357 100644 --- a/includes/api/ApiMain.php +++ b/includes/api/ApiMain.php @@ -1629,24 +1629,17 @@ class ApiMain extends ApiBase { */ protected function logRequest( $time, $e = null ) { $request = $this->getRequest(); - $legacyLogCtx = [ - 'ts' => time(), - 'ip' => $request->getIP(), - 'userAgent' => $this->getUserAgent(), - 'wiki' => WikiMap::getCurrentWikiDbDomain()->getId(), - 'timeSpentBackend' => (int)round( $time * 1000 ), - 'hadError' => $e !== null, - 'errorCodes' => [], - 'params' => [], - ]; $logCtx = [ + // https://gerrit.wikimedia.org/r/plugins/gitiles/mediawiki/event-schemas/+/master/jsonschema/mediawiki/api/request '$schema' => '/mediawiki/api/request/0.0.1', 'meta' => [ 'request_id' => WebRequest::getRequestId(), 'id' => UIDGenerator::newUUIDv4(), 'dt' => wfTimestamp( TS_ISO_8601 ), 'domain' => $this->getConfig()->get( 'ServerName' ), + // If using the EventBus extension (as intended) with this log channel, + // this stream name will map to a Kafka topic. 'stream' => 'mediawiki.api-request' ], 'http' => [ @@ -1669,7 +1662,6 @@ class ApiMain extends ApiBase { if ( $e ) { $logCtx['api_error_codes'] = []; foreach ( $this->errorMessagesFromException( $e ) as $msg ) { - $legacyLogCtx['errorCodes'][] = $msg->getApiCode(); $logCtx['api_error_codes'][] = $msg->getApiCode(); } } @@ -1677,8 +1669,8 @@ class ApiMain extends ApiBase { // Construct space separated message for 'api' log channel $msg = "API {$request->getMethod()} " . wfUrlencode( str_replace( ' ', '_', $this->getUser()->getName() ) ) . - " {$legacyLogCtx['ip']} " . - "T={$legacyLogCtx['timeSpentBackend']}ms"; + " {$logCtx['http']['client_ip']} " . + "T={$logCtx['backend_time_ms']}ms"; $sensitive = array_flip( $this->getSensitiveParams() ); foreach ( $this->getParamsUsed() as $name ) { @@ -1697,16 +1689,14 @@ class ApiMain extends ApiBase { $encValue = $this->encodeRequestLogValue( $value ); } - $legacyLogCtx['params'][$name] = $value; $logCtx['params'][$name] = $value; $msg .= " {$name}={$encValue}"; } + // Log an unstructured message to the api channel. wfDebugLog( 'api', $msg, 'private' ); - // ApiAction channel is for structured data consumers. - // The ApiAction was using logging channel is deprecated and is replaced - // by the api-request channel. - wfDebugLog( 'ApiAction', '', 'private', $legacyLogCtx ); + + // The api-request channel a structured data log channel. wfDebugLog( 'api-request', '', 'private', $logCtx ); } -- 2.20.1