Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge pull request #2676 from tomaszdurka/include-index-names-in-es-s…
Browse files Browse the repository at this point in the history
…tats

CM-CR-115 FB-1038 Move stat logging to ES client, log index names and types
  • Loading branch information
Tomasz Durka authored Jul 17, 2017
2 parents 00ebd86 + 6f0144e commit 6e3f133
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
24 changes: 20 additions & 4 deletions library/CM/Elasticsearch/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ class CM_Elasticsearch_Client {
/** @var Elasticsearch\Client */
protected $_client;

/** @var CM_Debug|null */
private $_debug;

/**
* @param \Elasticsearch\Client $client
* @param CM_Debug|null $debug
*/
public function __construct(Elasticsearch\Client $client) {
public function __construct(Elasticsearch\Client $client, CM_Debug $debug = null) {
$this->_client = $client;
$this->_debug = $debug;
}

/**
Expand Down Expand Up @@ -234,7 +239,7 @@ public function putIndexSettings($indexName, array $settings) {
'index' => $paramIndex,
'body' => [
'settings' => $settings,
]
],
]);
}

Expand Down Expand Up @@ -264,12 +269,16 @@ public function search($indexNameList, $typeNameList, array $data) {
'type' => self::_prepareIndexNameParam($typeNameList),
'body' => $data,
];

if ($debug = $this->_getDebug()) {
$debug->incStats('search', json_encode($params));
}
return $this->_getClient()->search($params);
}

public function awaitReady() {
$this->_client->cluster()->health([
'wait_for_status' => 'yellow'
'wait_for_status' => 'yellow',
]);
}

Expand All @@ -295,7 +304,7 @@ protected function _processBulkResponse(array $response) {

throw new CM_Exception_Invalid('Error(s) in bulk request action(s)', null, [
'errorsCount' => count($response['items']),
'message' => $message
'message' => $message,
]);
}
}
Expand All @@ -314,6 +323,13 @@ protected function _getIndices() {
return $this->_client->indices();
}

/**
* @return CM_Debug|null
*/
protected function _getDebug() {
return $this->_debug;
}

/**
* @param string[]|string $indexName
* @return string
Expand Down
5 changes: 1 addition & 4 deletions library/CM/Elasticsearch/Cluster.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function __construct(array $servers, $disabled = null) {
$elasticsearchClient = \Elasticsearch\ClientBuilder::create()->setHosts($hosts)->build();
//By default it uses RoundRobinSelector and number of retries equals to nodes quantity

$this->_client = new CM_Elasticsearch_Client($elasticsearchClient);
$this->_client = new CM_Elasticsearch_Client($elasticsearchClient, $this->getServiceManager()->getDebug());
}

/**
Expand Down Expand Up @@ -67,15 +67,12 @@ public function query(array $types, array $data = null) {
if (!$this->getEnabled()) {
return array();
}
$this->getServiceManager()->getDebug()->incStats('search', json_encode($data));

$indexNameList = [];
$typeNameList = [];
foreach ($types as $type) {
$indexNameList[] = $type->getIndexName();
$typeNameList[] = $type->getTypeName();
}

return $this->getClient()->search($indexNameList, $typeNameList, $data);
}
}

0 comments on commit 6e3f133

Please sign in to comment.