[MediaWiki-commits] [Gerrit] mediawiki...PoolCounter[master]: Show the hostname in error messages

2017-08-05 Thread jenkins-bot (Code Review)
jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/366983 )

Change subject: Show the hostname in error messages
..


Show the hostname in error messages

It's helpful for the system administrator to know which PC server is
giving connection errors and the like.

Error messages from the core will not give the hostname, but they are
less likely to be specific to a PC server.

Bug: T65027
Change-Id: Ic8bfc927b6fa6086b7ae9cc694e848f5808ff58b
---
M PoolCounterClient_body.php
M PoolCounter_ConnectionManager.php
M i18n/en.json
M i18n/qqq.json
4 files changed, 24 insertions(+), 17 deletions(-)

Approvals:
  Platonides: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/PoolCounterClient_body.php b/PoolCounterClient_body.php
index 52066e9..07a51c8 100644
--- a/PoolCounterClient_body.php
+++ b/PoolCounterClient_body.php
@@ -8,6 +8,11 @@
private $conn;
 
/**
+* @var string The server host name
+*/
+   private $hostName;
+
+   /**
 * @var PoolCounter_ConnectionManager
 */
static private $manager;
@@ -35,7 +40,8 @@
if ( !$status->isOK() ) {
return $status;
}
-   $this->conn = $status->value;
+   $this->conn = $status->value['conn'];
+   $this->hostName = $status->value['hostName'];
 
// Set the read timeout to be 1.5 times the pool 
timeout.
// This allows the server to time out gracefully before 
we give up on it.
@@ -58,11 +64,11 @@
$conn = $status->value;
wfDebug( "Sending pool counter command: $cmd\n" );
if ( fwrite( $conn, "$cmd\n" ) === false ) {
-   return Status::newFatal( 'poolcounter-write-error' );
+   return Status::newFatal( 'poolcounter-write-error', 
$this->hostName );
}
$response = fgets( $conn );
if ( $response === false ) {
-   return Status::newFatal( 'poolcounter-read-error' );
+   return Status::newFatal( 'poolcounter-read-error', 
$this->hostName );
}
$response = rtrim( $response, "\r\n" );
wfDebug( "Got pool counter response: $response\n" );
@@ -85,7 +91,7 @@
default:
$parts = explode( ' ', $parts[1], 2 );
$errorMsg = isset( $parts[1] ) ? $parts[1] : 
'(no message given)';
-   return Status::newFatal( 
'poolcounter-remote-error', $errorMsg );
+   return Status::newFatal( 
'poolcounter-remote-error', $errorMsg, $this->hostName );
}
return Status::newGood( constant( "PoolCounter::$responseType" 
) );
}
diff --git a/PoolCounter_ConnectionManager.php 
b/PoolCounter_ConnectionManager.php
index a1f5b62..91df439 100644
--- a/PoolCounter_ConnectionManager.php
+++ b/PoolCounter_ConnectionManager.php
@@ -29,12 +29,13 @@
$hashes[$hostName] = md5( $hostName . $key );
}
asort( $hashes );
-   $errno = $errstr = '';
+   $errno = $errstr = $hostName = '';
$conn = null;
foreach ( $hashes as $hostName => $hash ) {
if ( isset( $this->conns[$hostName] ) ) {
$this->refCounts[$hostName]++;
-   return Status::newGood( $this->conns[$hostName] 
);
+   return Status::newGood(
+   [ 'conn' => $this->conns[$hostName], 
'hostName' => $hostName ] );
}
$parts = explode( ':', $hostName, 2 );
if ( count( $parts ) < 2 ) {
@@ -48,12 +49,12 @@
}
}
if ( !$conn ) {
-   return Status::newFatal( 
'poolcounter-connection-error', $errstr );
+   return Status::newFatal( 
'poolcounter-connection-error', $errstr, $hostName );
}
wfDebug( "Connected to pool counter server: $hostName\n" );
$this->conns[$hostName] = $conn;
$this->refCounts[$hostName] = 1;
-   return Status::newGood( $conn );
+   return Status::newGood( [ 'conn' => $conn, 'hostName' => 
$hostName ] );
}
 
/**
diff --git a/i18n/en.json b/i18n/en.json
index 2190e6a..10e180a 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -5,8 +5,8 @@
]
},
"poolcounter-desc": "MediaWiki client for the pool counter daemon",
-   "poolcounter-connection-error": "Error 

[MediaWiki-commits] [Gerrit] mediawiki...PoolCounter[master]: Show the hostname in error messages

2017-07-21 Thread Tim Starling (Code Review)
Tim Starling has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/366983 )

Change subject: Show the hostname in error messages
..

Show the hostname in error messages

It's helpful for the system administrator to know which PC server is
giving connection errors and the like.

Error messages from the core will not give the hostname, but they are
less likely to be specific to a PC server.

Bug: T65027
Change-Id: Ic8bfc927b6fa6086b7ae9cc694e848f5808ff58b
---
M PoolCounterClient_body.php
M PoolCounter_ConnectionManager.php
M i18n/en.json
M i18n/qqq.json
4 files changed, 24 insertions(+), 17 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/PoolCounter 
refs/changes/83/366983/1

diff --git a/PoolCounterClient_body.php b/PoolCounterClient_body.php
index 52066e9..07a51c8 100644
--- a/PoolCounterClient_body.php
+++ b/PoolCounterClient_body.php
@@ -8,6 +8,11 @@
private $conn;
 
/**
+* @var string The server host name
+*/
+   private $hostName;
+
+   /**
 * @var PoolCounter_ConnectionManager
 */
static private $manager;
@@ -35,7 +40,8 @@
if ( !$status->isOK() ) {
return $status;
}
-   $this->conn = $status->value;
+   $this->conn = $status->value['conn'];
+   $this->hostName = $status->value['hostName'];
 
// Set the read timeout to be 1.5 times the pool 
timeout.
// This allows the server to time out gracefully before 
we give up on it.
@@ -58,11 +64,11 @@
$conn = $status->value;
wfDebug( "Sending pool counter command: $cmd\n" );
if ( fwrite( $conn, "$cmd\n" ) === false ) {
-   return Status::newFatal( 'poolcounter-write-error' );
+   return Status::newFatal( 'poolcounter-write-error', 
$this->hostName );
}
$response = fgets( $conn );
if ( $response === false ) {
-   return Status::newFatal( 'poolcounter-read-error' );
+   return Status::newFatal( 'poolcounter-read-error', 
$this->hostName );
}
$response = rtrim( $response, "\r\n" );
wfDebug( "Got pool counter response: $response\n" );
@@ -85,7 +91,7 @@
default:
$parts = explode( ' ', $parts[1], 2 );
$errorMsg = isset( $parts[1] ) ? $parts[1] : 
'(no message given)';
-   return Status::newFatal( 
'poolcounter-remote-error', $errorMsg );
+   return Status::newFatal( 
'poolcounter-remote-error', $errorMsg, $this->hostName );
}
return Status::newGood( constant( "PoolCounter::$responseType" 
) );
}
diff --git a/PoolCounter_ConnectionManager.php 
b/PoolCounter_ConnectionManager.php
index a1f5b62..91df439 100644
--- a/PoolCounter_ConnectionManager.php
+++ b/PoolCounter_ConnectionManager.php
@@ -29,12 +29,13 @@
$hashes[$hostName] = md5( $hostName . $key );
}
asort( $hashes );
-   $errno = $errstr = '';
+   $errno = $errstr = $hostName = '';
$conn = null;
foreach ( $hashes as $hostName => $hash ) {
if ( isset( $this->conns[$hostName] ) ) {
$this->refCounts[$hostName]++;
-   return Status::newGood( $this->conns[$hostName] 
);
+   return Status::newGood(
+   [ 'conn' => $this->conns[$hostName], 
'hostName' => $hostName ] );
}
$parts = explode( ':', $hostName, 2 );
if ( count( $parts ) < 2 ) {
@@ -48,12 +49,12 @@
}
}
if ( !$conn ) {
-   return Status::newFatal( 
'poolcounter-connection-error', $errstr );
+   return Status::newFatal( 
'poolcounter-connection-error', $errstr, $hostName );
}
wfDebug( "Connected to pool counter server: $hostName\n" );
$this->conns[$hostName] = $conn;
$this->refCounts[$hostName] = 1;
-   return Status::newGood( $conn );
+   return Status::newGood( [ 'conn' => $conn, 'hostName' => 
$hostName ] );
}
 
/**
diff --git a/i18n/en.json b/i18n/en.json
index 2190e6a..10e180a 100644
--- a/i18n/en.json
+++ b/i18n/en.json
@@ -5,8 +5,8 @@
]
},
"poolcounter-desc": "MediaWiki client for the pool counter daemon",
-