-
Notifications
You must be signed in to change notification settings - Fork 1
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
Make nginx readiness endpoint dependant on a working socket to fpm #763
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,7 +34,6 @@ class Metrics | |
*/ | ||
public function __construct() | ||
{ | ||
|
||
// Get the ip group of the incoming request. | ||
$ip_group = $_SERVER['HTTP_X_MOJ_IP_GROUP'] ?? 0; | ||
|
||
|
@@ -49,36 +48,42 @@ public function __construct() | |
|
||
$this->home_url = env('WP_HOME'); | ||
|
||
// Define an array of metrics that we want to generate. | ||
// Define an array of metrics that we want to generate for all environments. | ||
$this->metrics_properties = [ | ||
'http_status_code_control' => [ | ||
'help' => 'The http status code when accessing an open site.', | ||
'type' => 'gauge', | ||
'callback' => [$this, 'getStatusCode'], | ||
'args' => [$this::OPEN_URL] | ||
], | ||
'http_status_code_invalid_header' => [ | ||
'help' => 'The http status code of when sending X-Moj-Ip-Group header.', | ||
'type' => 'gauge', | ||
'callback' => [$this, 'getStatusCode'], | ||
'args' => [ | ||
$this->home_url, | ||
['headers' => ['X-Moj-Ip-Group' => 0]] | ||
] | ||
], | ||
'http_status_code_health' => [ | ||
'help' => 'The http status code of /health.', | ||
'type' => 'gauge', | ||
'callback' => [$this, 'getStatusCode'], | ||
'args' => ["{$this->home_url}/health"] | ||
], | ||
'http_status_code_wp_home' => [ | ||
'help' => 'The http status code when accessing this service via it\'s full url as defined in WP_HOME.', | ||
'type' => 'gauge', | ||
'callback' => [$this, 'getStatusCode'], | ||
'args' => [$this->home_url] | ||
] | ||
]; | ||
|
||
if ('production' !== env('WP_ENV')) { | ||
// Add other metrics for non-production. | ||
$this->metrics_properties = array_merge($this->metrics_properties, [ | ||
'http_status_code_control' => [ | ||
'help' => 'The http status code when accessing an open site.', | ||
'type' => 'gauge', | ||
'callback' => [$this, 'getStatusCode'], | ||
'args' => [$this::OPEN_URL] | ||
], | ||
'http_status_code_invalid_header' => [ | ||
'help' => 'The http status code of when sending X-Moj-Ip-Group header.', | ||
'type' => 'gauge', | ||
'callback' => [$this, 'getStatusCode'], | ||
'args' => [ | ||
$this->home_url, | ||
['headers' => ['X-Moj-Ip-Group' => 0]] | ||
] | ||
], | ||
'http_status_code_health' => [ | ||
'help' => 'The http status code of /health.', | ||
'type' => 'gauge', | ||
'callback' => [$this, 'getStatusCode'], | ||
'args' => ["{$this->home_url}/health"] | ||
] | ||
]); | ||
} | ||
} | ||
|
||
/** | ||
|
@@ -140,6 +145,7 @@ public function serveMetrics(): void | |
{ | ||
header('Content-Type', 'text/plain'); | ||
echo $this->getServiceMetrics(); | ||
unset($this->guzzle_client); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We tested this, but it had no visual effect. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think it can do any harm. |
||
exit(); | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
echo 'OK'; |
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.
Would this also benefit from skipping the cache?
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.
Good shout, I'll make the change.