Calculate percentage of blocked queries only of there is at least one blocked query to prevent division-by-zero issues (leading to None)

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER 2023-01-08 19:04:31 +01:00
parent 4ac52263e9
commit a9e93ba1f8
No known key found for this signature in database
GPG Key ID: 00135ACBD90B28DD
6 changed files with 15 additions and 5 deletions

View File

@ -417,7 +417,11 @@ int api_stats_database_summary(struct ftl_conn *api)
"WHERE timestamp >= :from AND timestamp <= :until";
const int total_clients = db_query_int_from_until(db, querystr, from, until);
const float percent_blocked = 1e2f*sum_blocked/sum_queries;
// Calculate percentage of blocked queries, substituting 0.0 if there
// are no blocked queries
float percent_blocked = 0.0;
if(sum_queries > 0.0)
percent_blocked = 1e2f*sum_blocked/sum_queries;
if(sum_queries < 0 || sum_blocked < 0 || total_clients < 0)
{

View File

@ -37,6 +37,9 @@ void set_all_debug(const bool status)
// Set status
conf_item->v.b = status;
}
// Update debug flags
set_debug_flags();
}
// Extract and store key from full path

View File

@ -821,7 +821,7 @@ static void readDebugingSettingsLegacy(FILE *fp)
}
// Parse debug options
parse_debug_options();
set_debug_flags();
if(debug_any)
{

View File

@ -74,7 +74,7 @@ bool readFTLtoml(void)
}
// Report debug config if enabled
parse_debug_options();
set_debug_flags();
reportDebugConfig();
// Free memory allocated by the TOML parser and return success

View File

@ -30,7 +30,10 @@ static const char *process = "";
bool debug_any = false;
bool debug_flags[DEBUG_MAX] = { false };
void parse_debug_options(void)
// Set debug flags from config struct to global debug_flags array
// This is called whenever the config is reloaded and debug flags may have
// changed
void set_debug_flags(void)
{
// Reset debug flags
debug_any = false;

View File

@ -21,7 +21,7 @@
extern bool debug_any;
extern bool debug_flags[DEBUG_MAX];
void parse_debug_options(void);
void set_debug_flags(void);
void init_FTL_log(const char *name);
void log_counter_info(void);
void format_memory_size(char prefix[2], unsigned long long int bytes,