Skip to content

Commit

Permalink
Add further API debugging to top_client generation and fix an incorre…
Browse files Browse the repository at this point in the history
…ct condition that skipped all clients without a name

Signed-off-by: DL6ER <[email protected]>
  • Loading branch information
DL6ER committed Aug 13, 2024
1 parent 57b9bac commit f2ae6db
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions src/api/stats.c
Original file line number Diff line number Diff line change
Expand Up @@ -388,12 +388,26 @@ cJSON *get_top_clients(struct ftl_conn *api, const int count,

// Skip invalid clients and also those managed by alias clients
if(client == NULL || (!client->flags.aliasclient && client->aliasclient_id >= 0))
{
log_debug(DEBUG_API, "Skipping client %i because %s", clientID,
client == NULL ? "it is invalid" : "it is an alias client");
continue;
}

// Skip recycled clients
if(client->ippos == 0)
{
log_debug(DEBUG_API, "Skipping client %i because it is recycled", clientID);
continue;
}

const char *client_ip = getstr(client->ippos);
// Hidden client, probably due to privacy level. Skip this in the top lists
if(strcmp(client_ip, HIDDEN_CLIENT) == 0)
{
log_debug(DEBUG_API, "Skipping client %i because it is hidden", clientID);
continue;
}

// Use either blocked or total count based on request string
top_clients[added_clients].count = blocked ? client->blockedcount : client->count;
Expand All @@ -405,6 +419,8 @@ cJSON *get_top_clients(struct ftl_conn *api, const int count,
added_clients++;
}

log_debug(DEBUG_API, "Found %u clients", added_clients);

// Unlock shared memory
unlock_shm();

Expand All @@ -426,10 +442,6 @@ cJSON *get_top_clients(struct ftl_conn *api, const int count,

for(unsigned int i = 0; i < added_clients; i++)
{
// Skip e.g. recycled clients
if(top_clients[i].namepos == 0)
continue;

const char *client_ip = getstr(top_clients[i].ippos);
const char *client_name = getstr(top_clients[i].namepos);

Expand Down Expand Up @@ -457,7 +469,11 @@ cJSON *get_top_clients(struct ftl_conn *api, const int count,
}

if(skip_client || top_clients[i].count < 1)
{
log_debug(DEBUG_API, "Skipping client %s because it %s", client_ip,
skip_client ? "matches a filter" : "has no queries");
continue;
}

if(clients_only)
{
Expand Down

0 comments on commit f2ae6db

Please sign in to comment.