Skip to content

Commit

Permalink
update Cluster\Health properties and its own test (ruflin#1309)
Browse files Browse the repository at this point in the history
  • Loading branch information
p365labs authored and Marek Hernik committed Jul 24, 2017
1 parent 8ba895f commit bbaa0cf
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file based on the
### Added

- Parameter `filter_path` for response filtering (e.g. `$index->search($query, ['filter_path' => 'hits.hits._source'])`)
- Add support for Health parameters for Cluster\Health endpoint (new prop : delayed_unassigned_shards, number_of_pending_tasks, number_of_in_flight_fetch, task_max_waiting_in_queue_millis, active_shards_percent_as_number)

### Improvements

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ build:

.PHONY: start
start:
docker-compose up -d
docker-compose up -d --build

.PHONY: stop
stop:
Expand Down
42 changes: 42 additions & 0 deletions lib/Elastica/Cluster/Health.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,48 @@ public function getUnassignedShards()
return $this->_data['unassigned_shards'];
}

/**
* get the number of delayed unassined shards
*
* @return int
*/
public function getDelayedUnassignedShards()
{
return $this->_data['delayed_unassigned_shards'];
}

/**
* @return int
*/
public function getNumberOfPendingTasks()
{
return $this->_data['number_of_pending_tasks'];
}

/**
* @return int
*/
public function getNumberOfInFlightFetch()
{
return $this->_data['number_of_in_flight_fetch'];
}

/**
* @return int
*/
public function getTaskMaxWaitingInQueueMillis()
{
return $this->_data['task_max_waiting_in_queue_millis'];
}

/**
* @return int
*/
public function getActiveShardsPercentAsNumber()
{
return $this->_data['active_shards_percent_as_number'];
}

/**
* Gets the status of the indices.
*
Expand Down
46 changes: 46 additions & 0 deletions test/Elastica/Cluster/HealthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ protected function setUp()
'relocating_shards' => 2,
'initializing_shards' => 7,
'unassigned_shards' => 5,
'delayed_unassigned_shards' => 4,
'number_of_pending_tasks' => 1,
'number_of_in_flight_fetch' => 2,
'task_max_waiting_in_queue_millis' => 634,
'active_shards_percent_as_number' => 50.0,

'indices' => [
'index_one' => [
],
Expand Down Expand Up @@ -132,6 +138,46 @@ public function testGetUnassignedShards()
$this->assertEquals(5, $this->_health->getUnassignedShards());
}

/**
* @group unit
*/
public function testGetDelayedUnassignedShards()
{
$this->assertEquals(4, $this->_health->getDelayedUnassignedShards());
}

/**
* @group unit
*/
public function testNumberOfPendingTasks()
{
$this->assertEquals(1, $this->_health->getNumberOfPendingTasks());
}

/**
* @group unit
*/
public function testNumberOfInFlightFetch()
{
$this->assertEquals(2, $this->_health->getNumberOfInFlightFetch());
}

/**
* @group unit
*/
public function testTaskMaxWaitingInQueueMillis()
{
$this->assertEquals(634, $this->_health->getTaskMaxWaitingInQueueMillis());
}

/**
* @group unit
*/
public function testActiveShardsPercentAsNumber()
{
$this->assertEquals(50, $this->_health->getActiveShardsPercentAsNumber());
}

/**
* @group unit
*/
Expand Down

0 comments on commit bbaa0cf

Please sign in to comment.