Updates#3404
Squashed commit of the following:
commit b68a1d08b0676ebb7abbb13c9274c8d509cd6eed
Merge: 81265147 6d402dc8
Author: Artem Krisanov <a.krisanov@adguard.com>
Date: Mon Apr 17 15:48:33 2023 +0300
Merge master
commit 81265147b5613be11a6621a416f9588c0e1c0ef5
Author: Artem Krisanov <a.krisanov@adguard.com>
Date: Thu Apr 13 10:54:39 2023 +0300
Changed query log 'retention' --> 'rotation'.
commit 02c5dc0b54bca9ec293ee8629d769489bc5dc533
Author: Artem Krisanov <a.krisanov@adguard.com>
Date: Wed Apr 12 13:22:22 2023 +0300
Custom inputs for query log and stats configs.
commit 21dbfbd8aac868baeea0f8b25d14786aecf09a0d
Author: Artem Krisanov <a.krisanov@adguard.com>
Date: Tue Apr 11 18:12:40 2023 +0300
Temporary changes.
105 lines
3.7 KiB
JavaScript
105 lines
3.7 KiB
JavaScript
import { handleActions } from 'redux-actions';
|
|
import { normalizeTopClients } from '../helpers/helpers';
|
|
import { DAY, HOUR, STATS_INTERVALS_DAYS } from '../helpers/constants';
|
|
|
|
import * as actions from '../actions/stats';
|
|
|
|
const defaultStats = {
|
|
dnsQueries: [],
|
|
blockedFiltering: [],
|
|
replacedParental: [],
|
|
replacedSafebrowsing: [],
|
|
topBlockedDomains: [],
|
|
topClients: [],
|
|
topQueriedDomains: [],
|
|
numBlockedFiltering: 0,
|
|
numDnsQueries: 0,
|
|
numReplacedParental: 0,
|
|
numReplacedSafebrowsing: 0,
|
|
numReplacedSafesearch: 0,
|
|
avgProcessingTime: 0,
|
|
};
|
|
|
|
const stats = handleActions(
|
|
{
|
|
[actions.getStatsConfigRequest]: (state) => ({ ...state, processingGetConfig: true }),
|
|
[actions.getStatsConfigFailure]: (state) => ({ ...state, processingGetConfig: false }),
|
|
[actions.getStatsConfigSuccess]: (state, { payload }) => ({
|
|
...state,
|
|
...payload,
|
|
customInterval: !STATS_INTERVALS_DAYS.includes(payload.interval)
|
|
? payload.interval / HOUR
|
|
: null,
|
|
processingGetConfig: false,
|
|
}),
|
|
|
|
[actions.setStatsConfigRequest]: (state) => ({ ...state, processingSetConfig: true }),
|
|
[actions.setStatsConfigFailure]: (state) => ({ ...state, processingSetConfig: false }),
|
|
[actions.setStatsConfigSuccess]: (state, { payload }) => ({
|
|
...state,
|
|
...payload,
|
|
processingSetConfig: false,
|
|
}),
|
|
|
|
[actions.getStatsRequest]: (state) => ({ ...state, processingStats: true }),
|
|
[actions.getStatsFailure]: (state) => ({ ...state, processingStats: false }),
|
|
[actions.getStatsSuccess]: (state, { payload }) => {
|
|
const {
|
|
dns_queries: dnsQueries,
|
|
blocked_filtering: blockedFiltering,
|
|
replaced_parental: replacedParental,
|
|
replaced_safebrowsing: replacedSafebrowsing,
|
|
top_blocked_domains: topBlockedDomains,
|
|
top_clients: topClients,
|
|
top_queried_domains: topQueriedDomains,
|
|
num_blocked_filtering: numBlockedFiltering,
|
|
num_dns_queries: numDnsQueries,
|
|
num_replaced_parental: numReplacedParental,
|
|
num_replaced_safebrowsing: numReplacedSafebrowsing,
|
|
num_replaced_safesearch: numReplacedSafesearch,
|
|
avg_processing_time: avgProcessingTime,
|
|
} = payload;
|
|
|
|
const newState = {
|
|
...state,
|
|
processingStats: false,
|
|
dnsQueries,
|
|
blockedFiltering,
|
|
replacedParental,
|
|
replacedSafebrowsing,
|
|
topBlockedDomains,
|
|
topClients,
|
|
normalizedTopClients: normalizeTopClients(topClients),
|
|
topQueriedDomains,
|
|
numBlockedFiltering,
|
|
numDnsQueries,
|
|
numReplacedParental,
|
|
numReplacedSafebrowsing,
|
|
numReplacedSafesearch,
|
|
avgProcessingTime,
|
|
};
|
|
|
|
return newState;
|
|
},
|
|
|
|
[actions.resetStatsRequest]: (state) => ({ ...state, processingReset: true }),
|
|
[actions.resetStatsFailure]: (state) => ({ ...state, processingReset: false }),
|
|
[actions.resetStatsSuccess]: (state) => ({
|
|
...state,
|
|
...defaultStats,
|
|
processingReset: false,
|
|
}),
|
|
},
|
|
{
|
|
processingGetConfig: false,
|
|
processingSetConfig: false,
|
|
processingStats: true,
|
|
processingReset: false,
|
|
interval: DAY,
|
|
customInterval: null,
|
|
...defaultStats,
|
|
},
|
|
);
|
|
|
|
export default stats;
|