Pull request: all: fix client id handling in querylog

Merge in DNS/adguard-home from 2607-querylog-client-id to master

Closes #2607.

Squashed commit of the following:

commit 95367a82469af3b042489fb650b962b48cb73236
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Jan 28 19:02:02 2021 +0300

    all: fix client, imp docs

commit b652a7ef2373a75f7e897d29f5c9e36b0e076f8e
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Thu Jan 28 18:36:17 2021 +0300

    all: fix client id handling in querylog
This commit is contained in:
Ainar Garipov
2021-01-28 19:39:33 +03:00
parent 3af079a81b
commit eeeb03839a
3 changed files with 20 additions and 9 deletions

View File

@@ -12,7 +12,7 @@ const enrichWithClientInfo = async (logs) => {
if (Object.keys(clientsParams).length > 0) {
const clients = await apiClient.findClients(clientsParams);
return addClientInfo(logs, clients, 'client');
return addClientInfo(logs, clients, 'client_id', 'client');
}
return logs;

View File

@@ -128,12 +128,21 @@ export const normalizeTopStats = (stats) => (
}))
);
export const addClientInfo = (data, clients, param) => data.map((row) => {
const clientIp = row[param];
const info = clients.find((item) => item[clientIp]) || '';
export const addClientInfo = (data, clients, ...params) => data.map((row) => {
let info = '';
params.find((param) => {
const id = row[param];
if (id) {
const client = clients.find((item) => item[id]) || '';
info = client?.[id] ?? '';
}
return info;
});
return {
...row,
info: info?.[clientIp] ?? '',
info,
};
});