mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
fix(PHP): sanitize and produce metrics at shutdown
This change now requires that PHP routes do not return HTTP 404 to be considered for the /metrics population. Additionally, we make a small sanitization here to avoid trailing '/' characters, unless we're on the homepage route. Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
parent
3d971bfc8d
commit
22b3af61b5
2 changed files with 40 additions and 22 deletions
|
@ -13,28 +13,8 @@ $query_string = $_SERVER['QUERY_STRING'];
|
|||
|
||||
// If no options.cache is configured, we no-op metric storage operations.
|
||||
$is_cached = defined('EXTENSION_LOADED_APC') || defined('EXTENSION_LOADED_MEMCACHE');
|
||||
if ($is_cached) {
|
||||
$method = $_SERVER['REQUEST_METHOD'];
|
||||
// We'll always add +1 to our total request count to this $path,
|
||||
// unless this path == /metrics.
|
||||
if ($path !== "/metrics")
|
||||
add_metric("http_requests_count", $method, $path);
|
||||
|
||||
// Extract $type out of $query_string, if we can.
|
||||
$type = null;
|
||||
$query = array();
|
||||
if ($query_string)
|
||||
parse_str($query_string, $query);
|
||||
$type = $query['type'];
|
||||
|
||||
// Only store RPC metrics for valid types.
|
||||
$good_types = [
|
||||
"info", "multiinfo", "search", "msearch",
|
||||
"suggest", "suggest-pkgbase", "get-comment-form"
|
||||
];
|
||||
if ($path === "/rpc" && in_array($type, $good_types))
|
||||
add_metric("api_requests_count", $method, $path, $type);
|
||||
}
|
||||
if ($is_cached)
|
||||
register_shutdown_function('update_metrics');
|
||||
|
||||
if (config_get_bool('options', 'enable-maintenance') && (empty($tokens[1]) || ($tokens[1] != "css" && $tokens[1] != "images"))) {
|
||||
if (!in_array($_SERVER['REMOTE_ADDR'], explode(" ", config_get('options', 'maintenance-exceptions')))) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue