mirror of
https://gitlab.archlinux.org/archlinux/aurweb.git
synced 2025-02-03 10:43:03 +01:00
Revert "fix(PHP): sanitize and produce metrics at shutdown"
This reverts commit 22b3af61b5
.
This commit is contained in:
parent
22b3af61b5
commit
5bfc1e9094
2 changed files with 22 additions and 40 deletions
|
@ -13,8 +13,28 @@ $query_string = $_SERVER['QUERY_STRING'];
|
||||||
|
|
||||||
// If no options.cache is configured, we no-op metric storage operations.
|
// If no options.cache is configured, we no-op metric storage operations.
|
||||||
$is_cached = defined('EXTENSION_LOADED_APC') || defined('EXTENSION_LOADED_MEMCACHE');
|
$is_cached = defined('EXTENSION_LOADED_APC') || defined('EXTENSION_LOADED_MEMCACHE');
|
||||||
if ($is_cached)
|
if ($is_cached) {
|
||||||
register_shutdown_function('update_metrics');
|
$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 (config_get_bool('options', 'enable-maintenance') && (empty($tokens[1]) || ($tokens[1] != "css" && $tokens[1] != "images"))) {
|
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')))) {
|
if (!in_array($_SERVER['REMOTE_ADDR'], explode(" ", config_get('options', 'maintenance-exceptions')))) {
|
||||||
|
|
|
@ -13,44 +13,6 @@ use \Prometheus\RenderTextFormat;
|
||||||
// and will start again at 0 if it's restarted.
|
// and will start again at 0 if it's restarted.
|
||||||
$registry = new CollectorRegistry(new InMemory());
|
$registry = new CollectorRegistry(new InMemory());
|
||||||
|
|
||||||
function update_metrics() {
|
|
||||||
// With no code given to http_response_code, it gets the current
|
|
||||||
// response code set (via http_response_code or header).
|
|
||||||
if(http_response_code() == 404)
|
|
||||||
return;
|
|
||||||
|
|
||||||
$path = $_SERVER['PATH_INFO'];
|
|
||||||
$method = $_SERVER['REQUEST_METHOD'];
|
|
||||||
$query_string = $_SERVER['QUERY_STRING'];
|
|
||||||
|
|
||||||
// If $path is at least 1 character, strip / off the end.
|
|
||||||
// This turns $paths like '/packages/' into '/packages'.
|
|
||||||
if (strlen($path) > 1)
|
|
||||||
$path = rtrim($path, "/");
|
|
||||||
|
|
||||||
// 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);
|
|
||||||
|
|
||||||
if (array_key_exists("type", $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);
|
|
||||||
}
|
|
||||||
|
|
||||||
function add_metric($anchor, $method, $path, $type = null) {
|
function add_metric($anchor, $method, $path, $type = null) {
|
||||||
|
|
||||||
global $registry;
|
global $registry;
|
||||||
|
|
Loading…
Add table
Reference in a new issue