public function testGetInjectsParameters()
 {
     $config = new \Zend\Config\Config(self::$baseConfig);
     $circuitBreaker = $this->factory->get('TestCommand', $config, $this->metrics);
     $this->assertAttributeEquals('TestCommand', 'commandKey', $circuitBreaker);
     $this->assertAttributeEquals($config, 'config', $circuitBreaker);
     $this->assertAttributeInstanceOf('Odesk\\Phystrix\\CommandMetrics', 'metrics', $circuitBreaker);
     $this->assertAttributeInstanceOf('Odesk\\Phystrix\\StateStorageInterface', 'stateStorage', $circuitBreaker);
 }
 /**
  * Finds all commands currently running (having any metrics recorded within the statistical rolling window).
  * For each command key prepares a set of statistic. Returns all sets.
  *
  * @return array
  */
 public function getStatsForCommandsRunning()
 {
     $stats = array();
     $commandKeys = $this->getCommandsRunning();
     foreach ($commandKeys as $commandKey) {
         $commandConfig = $this->getCommandConfig($commandKey);
         $commandMetrics = $this->commandMetricsFactory->get($commandKey, $commandConfig);
         $circuitBreaker = $this->circuitBreakerFactory->get($commandKey, $commandConfig, $commandMetrics);
         $healtCounts = $commandMetrics->getHealthCounts();
         $commandStats = array('type' => 'HystrixCommand', 'name' => $commandKey, 'group' => $commandKey, 'currentTime' => $this->getTimeInMilliseconds(), 'isCircuitBreakerOpen' => $circuitBreaker->isOpen(), 'errorPercentage' => $healtCounts->getErrorPercentage(), 'errorCount' => $healtCounts->getFailure(), 'requestCount' => $healtCounts->getTotal(), 'rollingCountCollapsedRequests' => 0, 'rollingCountExceptionsThrown' => $commandMetrics->getRollingCount(MetricsCounter::EXCEPTION_THROWN), 'rollingCountFailure' => $commandMetrics->getRollingCount(MetricsCounter::FAILURE), 'rollingCountFallbackFailure' => $commandMetrics->getRollingCount(MetricsCounter::FALLBACK_FAILURE), 'rollingCountFallbackRejection' => 0, 'rollingCountFallbackSuccess' => $commandMetrics->getRollingCount(MetricsCounter::FALLBACK_SUCCESS), 'rollingCountResponsesFromCache' => $commandMetrics->getRollingCount(MetricsCounter::RESPONSE_FROM_CACHE), 'rollingCountSemaphoreRejected' => 0, 'rollingCountShortCircuited' => $commandMetrics->getRollingCount(MetricsCounter::SHORT_CIRCUITED), 'rollingCountSuccess' => $commandMetrics->getRollingCount(MetricsCounter::SUCCESS), 'rollingCountThreadPoolRejected' => 0, 'rollingCountTimeout' => 0, 'currentConcurrentExecutionCount' => 0, 'latencyExecute_mean' => 0, 'latencyExecute' => array('0' => 0, '25' => 0, '50' => 0, '75' => 0, '90' => 0, '95' => 0, '99' => 0, '99.5' => 0, '100' => 0), 'latencyTotal_mean' => 15, 'latencyTotal' => array('0' => 0, '25' => 0, '50' => 0, '75' => 0, '90' => 0, '95' => 0, '99' => 0, '99.5' => 0, '100' => 0), 'propertyValue_circuitBreakerRequestVolumeThreshold' => $commandConfig->get('circuitBreaker')->get('requestVolumeThreshold'), 'propertyValue_circuitBreakerSleepWindowInMilliseconds' => $commandConfig->get('circuitBreaker')->get('sleepWindowInMilliseconds'), 'propertyValue_circuitBreakerErrorThresholdPercentage' => $commandConfig->get('circuitBreaker')->get('errorThresholdPercentage'), 'propertyValue_circuitBreakerForceOpen' => $commandConfig->get('circuitBreaker')->get('forceOpen'), 'propertyValue_circuitBreakerForceClosed' => $commandConfig->get('circuitBreaker')->get('forceClosed'), 'propertyValue_circuitBreakerEnabled' => $commandConfig->get('circuitBreaker')->get('enabled'), 'propertyValue_executionIsolationStrategy' => 'THREAD', 'propertyValue_executionIsolationThreadTimeoutInMilliseconds' => 0, 'propertyValue_executionIsolationThreadInterruptOnTimeout' => false, 'propertyValue_executionIsolationThreadPoolKeyOverride' => 'null', 'propertyValue_executionIsolationSemaphoreMaxConcurrentRequests' => 0, 'propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests' => 0, 'propertyValue_metricsRollingStatisticalWindowInMilliseconds' => $commandConfig->get('metrics')->get('rollingStatisticalWindowInMilliseconds'), 'propertyValue_requestCacheEnabled' => $commandConfig->get('requestCache')->get('enabled'), 'propertyValue_requestLogEnabled' => $commandConfig->get('requestLog')->get('enabled'), 'reportingHosts' => 1);
         $stats[] = $commandStats;
     }
     return $stats;
 }
Example #3
0
 /**
  * Circuit breaker for this command key
  *
  * @return CircuitBreaker
  */
 private function getCircuitBreaker()
 {
     return $this->circuitBreakerFactory->get($this->getCommandKey(), $this->config, $this->getMetrics());
 }