This repository has been archived by the owner on Aug 17, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #25 from loveOSS/introduced-monitoring
Introduced Monitoring feature
- Loading branch information
Showing
27 changed files
with
482 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Resiliency\Contracts\Monitoring; | ||
|
||
use Resiliency\Contracts\Event; | ||
|
||
/** | ||
* If you need to monitor and collect information about the circuit breaker | ||
* use the monitor to collect the information when events are dispatched. | ||
*/ | ||
interface Monitor | ||
{ | ||
/** | ||
* @param Event $event the dispatched event | ||
*/ | ||
public function collect(Event $event): void; | ||
|
||
/** | ||
* @return Report the Monitor Report | ||
*/ | ||
public function getReport(): Report; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
namespace Resiliency\Contracts\Monitoring; | ||
|
||
/** | ||
* The Monitor report | ||
*/ | ||
interface Report | ||
{ | ||
/** | ||
* @var ReportEntry the report entry | ||
* | ||
* @return self | ||
*/ | ||
public function add(ReportEntry $reportEntry): self; | ||
|
||
/** | ||
* @return array the list of report entries | ||
*/ | ||
public function all(): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Resiliency\Contracts\Monitoring; | ||
|
||
use Resiliency\Contracts\CircuitBreaker; | ||
use Resiliency\Contracts\Service; | ||
|
||
/** | ||
* A report entry store information used to generate a report | ||
* about Circuit Breaker activity over time. | ||
*/ | ||
interface ReportEntry | ||
{ | ||
/** | ||
* @return Service the service called | ||
*/ | ||
public function getService(): Service; | ||
|
||
/** | ||
* @return CircuitBreaker the circuit breaker used | ||
*/ | ||
public function getCircuitBreaker(): CircuitBreaker; | ||
|
||
/** | ||
* @return string the current transition of the circuit breaker | ||
*/ | ||
public function getTransition(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
namespace Resiliency\Monitors; | ||
|
||
use Resiliency\Contracts\Monitoring\Monitor; | ||
use Resiliency\Contracts\Monitoring\Report; | ||
use Resiliency\Contracts\Event; | ||
|
||
final class SimpleMonitor implements Monitor | ||
{ | ||
/** | ||
* @var Report the report | ||
*/ | ||
private $report; | ||
|
||
public function __construct() | ||
{ | ||
$this->report = new SimpleReport(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function collect(Event $event): void | ||
{ | ||
$reportEntry = new SimpleReportEntry( | ||
$event->getService(), | ||
$event->getCircuitBreaker(), | ||
get_class($event) | ||
); | ||
|
||
$this->report->add($reportEntry); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getReport(): Report | ||
{ | ||
return $this->report; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace Resiliency\Monitors; | ||
|
||
use Resiliency\Contracts\Monitoring\Report; | ||
use Resiliency\Contracts\Monitoring\ReportEntry; | ||
|
||
final class SimpleReport implements Report | ||
{ | ||
/** | ||
* @var array the report entries | ||
*/ | ||
private $reportEntries; | ||
|
||
public function __construct() | ||
{ | ||
$this->reportEntries = []; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function add(ReportEntry $reportEntry): Report | ||
{ | ||
$this->reportEntries[] = $reportEntry; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function all(): array | ||
{ | ||
return $this->reportEntries; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Resiliency\Monitors; | ||
|
||
use Resiliency\Contracts\CircuitBreaker; | ||
use Resiliency\Contracts\Monitoring\ReportEntry; | ||
use Resiliency\Contracts\Service; | ||
|
||
final class SimpleReportEntry implements ReportEntry | ||
{ | ||
/** | ||
* @var Service the Service called | ||
*/ | ||
private $service; | ||
|
||
/** | ||
* @var CircuitBreaker the Circuit Breaker called | ||
*/ | ||
private $circuitBreaker; | ||
|
||
/** | ||
* @var string the Circuit Breaker transition | ||
*/ | ||
private $transition; | ||
|
||
public function __construct(Service $service, CircuitBreaker $circuitBreaker, string $transition) | ||
{ | ||
$this->service = $service; | ||
$this->circuitBreaker = $circuitBreaker; | ||
$this->transition = $transition; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getService(): Service | ||
{ | ||
return $this->service; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getCircuitBreaker(): CircuitBreaker | ||
{ | ||
return $this->circuitBreaker; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function getTransition(): string | ||
{ | ||
return $this->transition; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.