-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the /status endpoint #1945
Closed
Closed
Add the /status endpoint #1945
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
f1721f9
Add scopes to Component model
adammbalogh 9816b7b
Add fixed status related methods to Incident model
adammbalogh 4ee366c
Add MajorOutagePolicy
adammbalogh c43652d
Add SystemStatusQuery
adammbalogh 14fd2e0
Add SystemStatusViewObject
adammbalogh 5ab7fe7
Refactor StatusPageComposer
adammbalogh 8df2b2c
Add /status api route
adammbalogh 348f211
Add /status api controller method
adammbalogh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
47 changes: 47 additions & 0 deletions
47
app/Foundation/Policies/SystemStatus/MajorOutagePolicy.php
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,47 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Cachet. | ||
* | ||
* (c) Alt Three Services Limited | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace CachetHQ\Cachet\Foundation\Policies\SystemStatus; | ||
|
||
class MajorOutagePolicy | ||
{ | ||
/** | ||
* @var int | ||
*/ | ||
private $numOfMajorOutages; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
private $numOfTotalEnabledComponents; | ||
|
||
/** | ||
* @param int $numOfMajorOutages | ||
* @param int $numOfTotalEnabledComponents | ||
*/ | ||
public function __construct($numOfMajorOutages, $numOfTotalEnabledComponents) | ||
{ | ||
$this->numOfMajorOutages = $numOfMajorOutages; | ||
$this->numOfTotalEnabledComponents = $numOfTotalEnabledComponents; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isMajorOutaged() | ||
{ | ||
return ( | ||
$this->numOfTotalEnabledComponents | ||
? ($this->numOfMajorOutages / $this->numOfTotalEnabledComponents) >= 0.5 | ||
: false | ||
); | ||
} | ||
} |
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,62 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Cachet. | ||
* | ||
* (c) Alt Three Services Limited | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace CachetHQ\Cachet\Foundation\Queries; | ||
|
||
use Illuminate\Database\Eloquent; | ||
use CachetHQ\Cachet\Models\Incident; | ||
use CachetHQ\Cachet\Models\Component; | ||
use CachetHQ\Cachet\Foundation\Policies\SystemStatus\MajorOutagePolicy; | ||
|
||
class SystemStatusQuery | ||
{ | ||
/** | ||
* @return string | ||
*/ | ||
public function getSystemStatus() | ||
{ | ||
$systemStatus = 'info'; | ||
|
||
if ($this->isMajorOutaged()) { | ||
$systemStatus = 'danger'; | ||
} elseif ($this->isAllTheEnabledComponentsWork() && $this->isAllTheIncidentsFixed()) { | ||
$systemStatus = 'success'; | ||
} | ||
|
||
return $systemStatus; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isMajorOutaged() | ||
{ | ||
return | ||
(new MajorOutagePolicy(Component::majorOutaged()->count(), Component::enabled()->count())) | ||
->isMajorOutaged(); | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isAllTheEnabledComponentsWork() | ||
{ | ||
return Component::notOperationaled()->count() === 0; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function isAllTheIncidentsFixed() | ||
{ | ||
return Incident::isAllAreFixed(); | ||
} | ||
} |
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,60 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of Cachet. | ||
* | ||
* (c) Alt Three Services Limited | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace CachetHQ\Cachet\Foundation\ViewObjects; | ||
|
||
use CachetHQ\Cachet\Models\Component; | ||
use CachetHQ\Cachet\Foundation\Queries\SystemStatusQuery; | ||
|
||
class SystemStatusViewObject | ||
{ | ||
/** | ||
* @var SystemStatusQuery | ||
*/ | ||
private $systemStatusQuery; | ||
|
||
/** | ||
* @param SystemStatusQuery $systemStatusQuery | ||
*/ | ||
public function __construct(SystemStatusQuery $systemStatusQuery) { | ||
$this->systemStatusQuery = $systemStatusQuery; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function toArray() | ||
{ | ||
$systemStatus = $this->systemStatusQuery->getSystemStatus(); | ||
$numOfEnabledComponents = Component::enabled()->count(); | ||
$viewData = [ | ||
'system_status' => $systemStatus, | ||
'system_message' => trans_choice('cachet.service.bad', $numOfEnabledComponents), | ||
'favicon' => 'favicon-high-alert', | ||
]; | ||
|
||
if ($systemStatus === 'danger') { | ||
$viewData['system_message'] = trans_choice('cachet.service.major', $numOfEnabledComponents); | ||
$viewData['favicon'] = 'favicon-high-alert'; | ||
} elseif ($systemStatus === 'success') { | ||
$viewData['system_message'] = trans_choice('cachet.service.major', $numOfEnabledComponents); | ||
$viewData['favicon'] = 'favicon'; | ||
} | ||
|
||
if ( ! $this->systemStatusQuery->isMajorOutaged() | ||
&& ! $this->systemStatusQuery->isAllTheEnabledComponentsWork() | ||
&& Component::enabled()->whereIn('status', [2, 3])->count() > 0) { | ||
$viewData['favicon'] = 'favicon-medium-alert'; | ||
} | ||
|
||
return $viewData; | ||
} | ||
} |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
View object isn't really right. It's not used in the context of views exclusively?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it's not quite right. I'm thinking about how we should name this object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't really need an object tbh. Just pass about an array.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That can work but how about a transformer object maybe?