-
Notifications
You must be signed in to change notification settings - Fork 6
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 #73 from JarvusInnovations/develop
Release: gatekeeper v2.2.1
- Loading branch information
Showing
6 changed files
with
192 additions
and
161 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Projections | ||
|
||
on: | ||
push: | ||
tags: | ||
- 'v2.*' | ||
|
||
|
||
jobs: | ||
holobranch-projections: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: 'Update holobranch: emergence/skeleton/v2' | ||
uses: JarvusInnovations/hologit@actions/projector/v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
HAB_LICENSE: accept | ||
with: | ||
ref: releases/v2 | ||
holobranch: emergence-skeleton | ||
commit-to: emergence/skeleton/v2 | ||
- name: 'Update holobranch: emergence/vfs-site/v2' | ||
uses: JarvusInnovations/hologit@actions/projector/v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
HAB_LICENSE: accept | ||
with: | ||
ref: releases/v2 | ||
holobranch: emergence-vfs-site | ||
commit-to: emergence/vfs-site/v2 |
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,7 @@ | ||
<?php | ||
|
||
printf('Flushing metrics...') && flush(); | ||
|
||
$flushed = Gatekeeper\Metrics\Metrics::flushMetricSamples(); | ||
|
||
printf('%u metrics flushed' . PHP_EOL, $flushed); |
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 |
---|---|---|
@@ -1,100 +1,3 @@ | ||
<?php | ||
|
||
namespace Gatekeeper; | ||
|
||
use DB; | ||
use HttpProxy; | ||
use Gatekeeper\Alerts\TestFailed; | ||
use Gatekeeper\Endpoints\Endpoint; | ||
use Gatekeeper\Transactions\PingTransaction; | ||
|
||
|
||
// find all endpoints that are overdue or near due for a ping | ||
$endpoints = Endpoint::getAllByQuery( | ||
'SELECT Endpoint.*' | ||
.' FROM `%s` Endpoint' | ||
.' WHERE' | ||
.' Endpoint.PingFrequency IS NOT NULL AND' | ||
.' IFNULL((' | ||
.' SELECT Created FROM `%s` Transaction WHERE EndpointID = Endpoint.ID AND Class = "%s" ORDER BY ID DESC LIMIT 1' | ||
.' ), 0) < DATE_SUB(CURRENT_TIMESTAMP, INTERVAL (Endpoint.PingFrequency * 0.7) MINUTE)' | ||
,[ | ||
Endpoint::$tableName, | ||
PingTransaction::$tableName, | ||
DB::escape(PingTransaction::class) | ||
] | ||
); | ||
|
||
|
||
// loop through all endpoints to execute, test, and record the ping URI | ||
foreach ($endpoints AS $Endpoint) { | ||
printf('Testing endpoint %s...', $Endpoint->getTitle()); | ||
|
||
// execute and capture request | ||
// TODO: use curl_multi_exec somehow? | ||
$response = HttpProxy::relayRequest([ | ||
'autoAppend' => false, | ||
'autoQuery' => false, | ||
'url' => rtrim($Endpoint->InternalEndpoint, '/') . '/' . ltrim($Endpoint->PingURI, '/'), | ||
'interface' => ApiRequestHandler::$sourceInterface, | ||
'timeout' => 15, | ||
'timeoutConnect' => 5, | ||
'returnResponse' => true | ||
]); | ||
|
||
|
||
// evaluate success | ||
$testPassed = | ||
$response['info']['http_code'] == 200 && | ||
( | ||
!$Endpoint->PingTestPattern || | ||
preg_match($Endpoint->PingTestPattern, $response['body']) | ||
); | ||
|
||
|
||
// record transaction | ||
list($path, $query) = array_pad(explode('?', $Endpoint->PingURI, 2), 2, null); | ||
|
||
$Transaction = PingTransaction::create([ | ||
'Endpoint' => $Endpoint, | ||
'ClientIP' => ip2long($response['info']['local_ip']), | ||
'Method' => 'GET', | ||
'Path' => $path, | ||
'Query' => $query, | ||
'ResponseTime' => $response['info']['starttransfer_time'] * 1000, | ||
'ResponseCode' => $response['info']['http_code'], | ||
'ResponseBytes' => $response['info']['size_download'], | ||
'TestPassed' => $testPassed | ||
], true); | ||
|
||
|
||
// open alert if necessary, or close any existing one | ||
if (!$testPassed) { | ||
TestFailed::open($Endpoint, [ | ||
'transactionId' => $Transaction->ID, | ||
'request' => [ | ||
'uri' => $Endpoint->PingURI | ||
], | ||
'response' => [ | ||
'status' => $Transaction->ResponseCode, | ||
'headers' => $response['headers'], | ||
'body' => $response['body'], | ||
'bytes' => $Transaction->ResponseBytes, | ||
'time' => $Transaction->ResponseTime | ||
] | ||
]); | ||
} else { | ||
$OpenAlert = TestFailed::getByWhere([ | ||
'Class' => TestFailed::class, | ||
'EndpointID' => $Endpoint->ID, | ||
'Status' => 'open' | ||
]); | ||
|
||
if ($OpenAlert) { | ||
$OpenAlert->Status = 'closed'; | ||
$OpenAlert->save(); | ||
} | ||
} | ||
|
||
printf("%s\n", $testPassed ? 'passed' : 'failed'); | ||
} | ||
Gatekeeper\Endpoints\Pinger::pingOverdueEndpoints(true); |
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,114 @@ | ||
<?php | ||
|
||
namespace Gatekeeper\Endpoints; | ||
|
||
use Cache; | ||
use HttpProxy; | ||
|
||
use Gatekeeper\ApiRequestHandler; | ||
use Gatekeeper\Alerts\TestFailed; | ||
use Gatekeeper\Transactions\PingTransaction; | ||
|
||
|
||
class Pinger | ||
{ | ||
public static function pingOverdueEndpoints($verbose = false) | ||
{ | ||
$endpoints = Endpoint::getAllByWhere('PingFrequency IS NOT NULL'); | ||
|
||
foreach ($endpoints as $Endpoint) { | ||
$lastPing = Cache::fetch("endpoints/{$Endpoint->ID}/last-ping"); | ||
|
||
if ( | ||
$lastPing === false | ||
|| $Endpoint->PingFrequency < time()-$lastPing['time'] // * 60 | ||
) { | ||
static::pingEndpoint($Endpoint, $verbose); | ||
} | ||
} | ||
} | ||
|
||
public static function pingEndpoint(Endpoint $Endpoint, $verbose = false) | ||
{ | ||
$verbose && printf('Testing endpoint: /%s...', $Endpoint->Path) && flush(); | ||
|
||
|
||
// execute and capture request | ||
// TODO: use curl_multi_exec somehow? | ||
$response = HttpProxy::relayRequest([ | ||
'autoAppend' => false, | ||
'autoQuery' => false, | ||
'url' => rtrim($Endpoint->InternalEndpoint, '/') . '/' . ltrim($Endpoint->PingURI, '/'), | ||
'interface' => ApiRequestHandler::$sourceInterface, | ||
'timeout' => 15, | ||
'timeoutConnect' => 5, | ||
'returnResponse' => true | ||
]); | ||
|
||
|
||
// evaluate success | ||
$testPassed = | ||
$response['info']['http_code'] == 200 && | ||
( | ||
!$Endpoint->PingTestPattern || | ||
preg_match($Endpoint->PingTestPattern, $response['body']) | ||
); | ||
|
||
|
||
// record transaction | ||
list($path, $query) = array_pad(explode('?', $Endpoint->PingURI, 2), 2, null); | ||
|
||
$Transaction = PingTransaction::create([ | ||
'Endpoint' => $Endpoint, | ||
'ClientIP' => ip2long($response['info']['local_ip']), | ||
'Method' => 'GET', | ||
'Path' => $path, | ||
'Query' => $query, | ||
'ResponseTime' => $response['info']['starttransfer_time'] * 1000, | ||
'ResponseCode' => $response['info']['http_code'], | ||
'ResponseBytes' => $response['info']['size_download'], | ||
'TestPassed' => $testPassed | ||
], true); | ||
|
||
|
||
// open alert if necessary, or close any existing one | ||
if (!$testPassed) { | ||
TestFailed::open($Endpoint, [ | ||
'transactionId' => $Transaction->ID, | ||
'request' => [ | ||
'uri' => $Endpoint->PingURI | ||
], | ||
'response' => [ | ||
'status' => $Transaction->ResponseCode, | ||
'headers' => $response['headers'], | ||
'body' => $response['body'], | ||
'bytes' => $Transaction->ResponseBytes, | ||
'time' => $Transaction->ResponseTime | ||
] | ||
]); | ||
} else { | ||
$OpenAlert = TestFailed::getByWhere([ | ||
'Class' => TestFailed::class, | ||
'EndpointID' => $Endpoint->ID, | ||
'Status' => 'open' | ||
]); | ||
|
||
if ($OpenAlert) { | ||
$OpenAlert->Status = 'closed'; | ||
$OpenAlert->save(); | ||
} | ||
} | ||
|
||
|
||
$verbose && printf("%s\n", $testPassed ? 'passed' : 'failed') && flush(); | ||
|
||
|
||
// cache result and timestamp | ||
Cache::store("endpoints/{$Endpoint->ID}/last-ping", [ | ||
'time' => time(), | ||
'testPassed' => $testPassed | ||
], ($Endpoint->PingFrequency+5)); // * 60 | ||
|
||
return $testPassed; | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.