AdGuardHome/internal/stats/stats_internal_test.go

175 lines
3.8 KiB
Go
Raw Normal View History

Pull request: 4358 stats races Merge in DNS/adguard-home from 4358-stats-races to master Updates #4358 Squashed commit of the following: commit 162d17b04d95adad21fb9b3c5a6fb64df2e037ec Merge: 17732cfa d4c3a43b Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 17 14:04:20 2022 +0300 Merge branch 'master' into 4358-stats-races commit 17732cfa0f3b2589bf2c252697eee1d6b358a66c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 17 13:53:42 2022 +0300 stats: imp docs, locking commit 4ee090869af0fa2b777c12027c3b77d5acd6e4de Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 16 20:26:19 2022 +0300 stats: revert const commit a7681a1b882cef04511fcd5d569f5abe2f955239 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 16 20:23:00 2022 +0300 stats: imp concurrency commit a6c6c1a0572e4201cd24644fd3f86f51fc27f633 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 16 19:51:30 2022 +0300 stats: imp code, tests, docs commit 954196b49f5ad91d91f445ff656e63c318e4124c Merge: 281e00da 6e63757f Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 16 13:07:32 2022 +0300 Merge branch 'master' into 4358-stats-races commit 281e00daf781d045269584ce0158eed1d77918df Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Aug 12 16:22:18 2022 +0300 stats: imp closing commit ed036d9aa7e25498869edfb866b6e923538970eb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Aug 12 16:11:12 2022 +0300 stats: imp tests more commit f848a12487ecd2afc8416e800510090cc1be7330 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Aug 12 13:54:19 2022 +0300 stats: imp tests, code commit 60e11f042d51ec68850143129e61c701c5e4f3a4 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Aug 11 16:36:07 2022 +0300 stats: fix test commit 6d97f1db093b5ce0d37984ff96a9ef6f4e02dba1 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Aug 11 14:53:21 2022 +0300 stats: imp code, docs commit 20c70c2847b0de6c7f9271a8d9a831175ed0c499 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 10 20:53:36 2022 +0300 stats: imp shared memory safety commit 8b3945670a190bab070171e6b4976edab1e3e2a2 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 10 17:22:55 2022 +0300 stats: imp code
2022-08-17 12:09:13 +01:00
package stats
import (
"fmt"
"path/filepath"
"sync"
"sync/atomic"
Pull request: 4358 stats races Merge in DNS/adguard-home from 4358-stats-races to master Updates #4358 Squashed commit of the following: commit 162d17b04d95adad21fb9b3c5a6fb64df2e037ec Merge: 17732cfa d4c3a43b Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 17 14:04:20 2022 +0300 Merge branch 'master' into 4358-stats-races commit 17732cfa0f3b2589bf2c252697eee1d6b358a66c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 17 13:53:42 2022 +0300 stats: imp docs, locking commit 4ee090869af0fa2b777c12027c3b77d5acd6e4de Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 16 20:26:19 2022 +0300 stats: revert const commit a7681a1b882cef04511fcd5d569f5abe2f955239 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 16 20:23:00 2022 +0300 stats: imp concurrency commit a6c6c1a0572e4201cd24644fd3f86f51fc27f633 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 16 19:51:30 2022 +0300 stats: imp code, tests, docs commit 954196b49f5ad91d91f445ff656e63c318e4124c Merge: 281e00da 6e63757f Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 16 13:07:32 2022 +0300 Merge branch 'master' into 4358-stats-races commit 281e00daf781d045269584ce0158eed1d77918df Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Aug 12 16:22:18 2022 +0300 stats: imp closing commit ed036d9aa7e25498869edfb866b6e923538970eb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Aug 12 16:11:12 2022 +0300 stats: imp tests more commit f848a12487ecd2afc8416e800510090cc1be7330 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Aug 12 13:54:19 2022 +0300 stats: imp tests, code commit 60e11f042d51ec68850143129e61c701c5e4f3a4 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Aug 11 16:36:07 2022 +0300 stats: fix test commit 6d97f1db093b5ce0d37984ff96a9ef6f4e02dba1 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Aug 11 14:53:21 2022 +0300 stats: imp code, docs commit 20c70c2847b0de6c7f9271a8d9a831175ed0c499 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 10 20:53:36 2022 +0300 stats: imp shared memory safety commit 8b3945670a190bab070171e6b4976edab1e3e2a2 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 10 17:22:55 2022 +0300 stats: imp code
2022-08-17 12:09:13 +01:00
"testing"
"time"
Pull request: 4358 stats races Merge in DNS/adguard-home from 4358-stats-races to master Updates #4358 Squashed commit of the following: commit 162d17b04d95adad21fb9b3c5a6fb64df2e037ec Merge: 17732cfa d4c3a43b Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 17 14:04:20 2022 +0300 Merge branch 'master' into 4358-stats-races commit 17732cfa0f3b2589bf2c252697eee1d6b358a66c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 17 13:53:42 2022 +0300 stats: imp docs, locking commit 4ee090869af0fa2b777c12027c3b77d5acd6e4de Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 16 20:26:19 2022 +0300 stats: revert const commit a7681a1b882cef04511fcd5d569f5abe2f955239 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 16 20:23:00 2022 +0300 stats: imp concurrency commit a6c6c1a0572e4201cd24644fd3f86f51fc27f633 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 16 19:51:30 2022 +0300 stats: imp code, tests, docs commit 954196b49f5ad91d91f445ff656e63c318e4124c Merge: 281e00da 6e63757f Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 16 13:07:32 2022 +0300 Merge branch 'master' into 4358-stats-races commit 281e00daf781d045269584ce0158eed1d77918df Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Aug 12 16:22:18 2022 +0300 stats: imp closing commit ed036d9aa7e25498869edfb866b6e923538970eb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Aug 12 16:11:12 2022 +0300 stats: imp tests more commit f848a12487ecd2afc8416e800510090cc1be7330 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Aug 12 13:54:19 2022 +0300 stats: imp tests, code commit 60e11f042d51ec68850143129e61c701c5e4f3a4 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Aug 11 16:36:07 2022 +0300 stats: fix test commit 6d97f1db093b5ce0d37984ff96a9ef6f4e02dba1 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Aug 11 14:53:21 2022 +0300 stats: imp code, docs commit 20c70c2847b0de6c7f9271a8d9a831175ed0c499 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 10 20:53:36 2022 +0300 stats: imp shared memory safety commit 8b3945670a190bab070171e6b4976edab1e3e2a2 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 10 17:22:55 2022 +0300 stats: imp code
2022-08-17 12:09:13 +01:00
"github.com/AdguardTeam/golibs/logutil/slogutil"
"github.com/AdguardTeam/golibs/testutil"
Pull request 1736: 4299-querylog-stats-api Merge in DNS/adguard-home from 4299-querylog-stats-api to master Updates #1717. Updates #4299. Squashed commit of the following: commit 5b706b7997a536bc4fd2c532fb89ca5ab3536848 Merge: 48b62b0f 306c1983 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 22 13:53:09 2023 +0300 Merge branch 'master' into 4299-querylog-stats-api commit 48b62b0f1882f1ad120c6cdd90cd7dd8cb8a7738 Author: Vladislav Abdulmyanov <v.abdulmyanov@adguard.com> Date: Wed Mar 22 12:25:04 2023 +0200 client: fix styles, add titles and descrs commit 97e31cff70d05b51bd0e5ea2d20e8e7a251a7e41 Author: Vladislav Abdulmyanov <v.abdulmyanov@adguard.com> Date: Tue Mar 21 18:38:12 2023 +0200 client: add ignored domains for querylog commit 24d75c4376382205ae6b8f731b1cd23d517772c9 Author: Vladislav Abdulmyanov <v.abdulmyanov@adguard.com> Date: Tue Mar 21 18:21:13 2023 +0200 client: add ignore domains for stats commit eefc3891d01f90af79fdac9ba8eea06d4d54a0bc Merge: 978675ea 1daabb97 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Mar 21 10:53:35 2023 +0300 Merge branch 'master' into 4299-querylog-stats-api commit 978675ea2c07bf248b4c8f26ebdf78cf59a12ef5 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Mar 21 10:53:11 2023 +0300 openapi: fix chlog commit 2ed33007aade115d38b0ca582206cc10678b084c Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 17:49:07 2023 +0300 home: fix tests commit 6af11520c164553ee9fce8f214ea169672188d7e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 17:40:16 2023 +0300 home: fix typo commit 56acdfde5b1ee8d16b232c1293b91affbe319ad1 Merge: 319da34d 48431f8b Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Mar 20 17:32:58 2023 +0300 Merge branch 'master' into 4299-querylog-stats-api commit 319da34de41ec84310b23bba2ad79c8a3a4c14ff Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 3 17:34:38 2023 +0300 querylog: fix docs commit d5a8f24d5b336e7bdbbca18069f6ede8c96bcc2c Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 3 11:42:00 2023 +0300 stats: fix docs commit e0cbfc1c4078180a05835ce7587e9f45484adc81 Merge: 4743c810 012e5beb Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 1 18:45:17 2023 +0300 Merge branch 'master' into 4299-querylog-stats-api commit 4743c81038052b9e0ca29ae5f1565021d36ca1ef Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 1 18:14:16 2023 +0300 all: imp code; fix time conversion commit 34310cffd7e331d098c535590245387051674fa8 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 1 12:34:11 2023 +0300 chlog: restore order commit cadd864a66655242948f1cb16e6d4945c0235d7e Merge: 2f3e25be bb226434 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 1 12:26:06 2023 +0300 Merge branch 'master' into 4299-querylog-stats-api commit 2f3e25bee56d2c6ddcf4aa2fc6a1dc51ed9b06e1 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 1 12:25:14 2023 +0300 all: fix fmt commit d54022baa6c8a3d0d3c308a9b6b1a6a9dc6ac7b6 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Feb 28 16:16:40 2023 +0300 all: imp code; fix chlog commit df22de91f59a51194c55e7bcbe5bc3fcc60cb8e3 Merge: e1ea4797 a772212d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Feb 27 17:24:09 2023 +0300 Merge branch 'master' into 4299-querylog-stats-api commit e1ea4797af974c36f06683ffc6eaaae917921a43 Merge: d7db0a5a bb80a7c2 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Feb 27 17:23:20 2023 +0300 Merge branch 'master' into 4299-querylog-stats-api commit d7db0a5af1e1f49f6174c1c42e6d9306f2381d16 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Feb 27 17:12:20 2023 +0300 all: imp docs ... and 15 more commits
2023-03-23 10:46:57 +00:00
"github.com/AdguardTeam/golibs/timeutil"
Pull request: 4358 stats races Merge in DNS/adguard-home from 4358-stats-races to master Updates #4358 Squashed commit of the following: commit 162d17b04d95adad21fb9b3c5a6fb64df2e037ec Merge: 17732cfa d4c3a43b Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 17 14:04:20 2022 +0300 Merge branch 'master' into 4358-stats-races commit 17732cfa0f3b2589bf2c252697eee1d6b358a66c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 17 13:53:42 2022 +0300 stats: imp docs, locking commit 4ee090869af0fa2b777c12027c3b77d5acd6e4de Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 16 20:26:19 2022 +0300 stats: revert const commit a7681a1b882cef04511fcd5d569f5abe2f955239 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 16 20:23:00 2022 +0300 stats: imp concurrency commit a6c6c1a0572e4201cd24644fd3f86f51fc27f633 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 16 19:51:30 2022 +0300 stats: imp code, tests, docs commit 954196b49f5ad91d91f445ff656e63c318e4124c Merge: 281e00da 6e63757f Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Aug 16 13:07:32 2022 +0300 Merge branch 'master' into 4358-stats-races commit 281e00daf781d045269584ce0158eed1d77918df Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Aug 12 16:22:18 2022 +0300 stats: imp closing commit ed036d9aa7e25498869edfb866b6e923538970eb Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Aug 12 16:11:12 2022 +0300 stats: imp tests more commit f848a12487ecd2afc8416e800510090cc1be7330 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Aug 12 13:54:19 2022 +0300 stats: imp tests, code commit 60e11f042d51ec68850143129e61c701c5e4f3a4 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Aug 11 16:36:07 2022 +0300 stats: fix test commit 6d97f1db093b5ce0d37984ff96a9ef6f4e02dba1 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Aug 11 14:53:21 2022 +0300 stats: imp code, docs commit 20c70c2847b0de6c7f9271a8d9a831175ed0c499 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 10 20:53:36 2022 +0300 stats: imp shared memory safety commit 8b3945670a190bab070171e6b4976edab1e3e2a2 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Aug 10 17:22:55 2022 +0300 stats: imp code
2022-08-17 12:09:13 +01:00
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestStats_races(t *testing.T) {
var r uint32
idGen := func() (id uint32) { return atomic.LoadUint32(&r) }
conf := Config{
Logger: slogutil.NewDiscardLogger(),
Pull request 1791: 4299-querylog-stats-clients Merge in DNS/adguard-home from 4299-querylog-stats-clients to master Squashed commit of the following: commit 33b80b67224f7c1a15bee8e6a23d9d5bab6ac629 Merge: 61964fdd 5d5a7295 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Apr 7 12:43:22 2023 +0300 Merge branch 'master' into 4299-querylog-stats-clients commit 61964fdd02221abbddedf2d6d02bb0bce6845362 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Apr 7 12:42:01 2023 +0300 dnsforward: imp code commit 7382168500bab6ca7494d39aabfc2d7bfceb5d24 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Apr 7 11:13:07 2023 +0300 all: imp code, chlog commit c7852902f635af6c296dcb6735f7b0bfb83f4e87 Merge: aa4dc0a5 a55cbbe7 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Apr 6 14:34:24 2023 +0300 Merge branch 'master' into 4299-querylog-stats-clients commit aa4dc0a54e95bc5b24718ec158340b631a822801 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Apr 6 12:54:02 2023 +0300 all: imp code commit dd541f0cd7ecbf0afcf10ccbd130fd1d1fa4c1c4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 31 13:01:53 2023 +0300 querylog: fix typo commit d2c8fdb35b04d27c8957fa027882fde704cc07be Merge: 83d0baa1 2eb3bf6e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 31 12:36:49 2023 +0300 Merge branch 'master' into 4299-querylog-stats-clients commit 83d0baa1f1202f9c62d4be2041d7aed12ee9ab2c Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Mar 31 12:35:15 2023 +0300 all: add tests commit a459f19f25cf9646d145813fe7834b2d9979c516 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Mar 29 16:51:53 2023 +0300 all: add clients querylog stats ignore
2023-04-07 11:17:40 +01:00
ShouldCountClient: func([]string) bool { return true },
UnitID: idGen,
Filename: filepath.Join(t.TempDir(), "./stats.db"),
Limit: timeutil.Day,
}
s, err := New(conf)
require.NoError(t, err)
s.Start()
startTime := time.Now()
testutil.CleanupAndRequireSuccess(t, s.Close)
writeFunc := func(start, fin *sync.WaitGroup, waitCh <-chan unit, i int) {
Pull request 1928: 1453-stats-tests Updates #1453. Squashed commit of the following: commit f08f68ef5493dad03d3eb120d886f2df1af28be6 Merge: b70b088af 54aee2272 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Aug 8 19:04:06 2023 +0300 Merge branch 'master' into 1453-stats-tests commit b70b088af0fdc7d6d048d688160048bad1fceb12 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Aug 3 19:32:04 2023 +0300 stats: imp code commit c341012ba61894c255c1868624be1cac0d26a6fa Merge: a2ac8c34e 5eb3cd0f9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Aug 3 13:36:24 2023 +0300 Merge branch 'master' into 1453-stats-tests commit a2ac8c34ee32606ca5e259c3e2a47db0dd5858de Author: Ildar Kamalov <ik@adguard.com> Date: Thu Aug 3 13:25:12 2023 +0300 client: add top upstreams and average processing time tables commit 11118947f9bf945be0b056f8475cf3b848c6e66e Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Aug 1 17:24:57 2023 +0300 stats: imp docs commit 904cf81d02a1f327b9647fa7ad9e181cfabb68a4 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Jul 31 17:34:06 2023 +0300 stats: imp code commit 34f0c96dd5865d1470385322a88842dd0b3d996d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Jul 31 15:43:46 2023 +0300 all: imp docs commit 2cb2d0d8bef3580f64bc25c414fe9b5ea6b9f997 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Fri Jul 28 17:24:31 2023 +0300 all: imp code commit 5251a899fecc21e50a0ba06042f96f5b404e196a Merge: b6c2b12d4 300821a7f Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Jul 27 20:34:39 2023 +0300 Merge branch 'master' into 1453-stats-tests commit b6c2b12d4425012efd73549c3a426735f3a677cd Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Jul 27 20:32:18 2023 +0300 stats: imp code commit 5546b82a78326f9cc6d8c87df5083f8fc66a0178 Merge: 8a3d6b1b4 5f8fa006c Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Jul 27 14:24:01 2023 +0300 Merge branch 'master' into 1453-stats-tests commit 8a3d6b1b49ce189f95adfa7406a34108e885e676 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Jul 27 14:17:47 2023 +0300 all: imp code commit 2a48001e275e3cdcf70e13e1c9cebd4e502f3259 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Jul 25 18:27:20 2023 +0300 all: imp docs commit 3dd21890175af32a3368378f7e013383f6d040ec Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Jul 25 16:00:39 2023 +0300 all: imp naming commit 6124456fc3149b71f6bd58d35ecf24eb6cf40d5d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Jul 20 16:15:56 2023 +0300 all: add upstreams avg processing time commit 187ad0c77a81c9fd95c24e23141355db2e83e50d Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Jul 18 16:42:19 2023 +0300 all: add top upstreams
2023-08-09 12:33:52 +01:00
e := &Entry{
Domain: fmt.Sprintf("example-%d.org", i),
Client: fmt.Sprintf("client_%d", i),
Result: Result(i)%(resultLast-1) + 1,
ProcessingTime: time.Since(startTime),
}
start.Done()
defer fin.Done()
<-waitCh
s.Update(e)
}
readFunc := func(start, fin *sync.WaitGroup, waitCh <-chan unit) {
start.Done()
defer fin.Done()
<-waitCh
_, _ = s.getData(24)
}
const (
roundsNum = 3
writersNum = 10
readersNum = 5
)
for round := 0; round < roundsNum; round++ {
atomic.StoreUint32(&r, uint32(round))
startWG, finWG := &sync.WaitGroup{}, &sync.WaitGroup{}
waitCh := make(chan unit)
for i := range writersNum {
startWG.Add(1)
finWG.Add(1)
go writeFunc(startWG, finWG, waitCh, i)
}
for range readersNum {
startWG.Add(1)
finWG.Add(1)
go readFunc(startWG, finWG, waitCh)
}
startWG.Wait()
close(waitCh)
finWG.Wait()
}
}
Pull request 1963: AG-24051-stats-collector Updates #6108. Squashed commit of the following: commit ca584c8dbbece70b90f6298a0a18a933a698fcf6 Merge: b6e136232 28cfde921 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Aug 23 17:00:52 2023 +0300 Merge branch 'master' into AG-24051-stats-collector commit b6e136232dd619ce09150b608ae5017676031e25 Merge: bbd4780b0 3722c2846 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Aug 23 16:25:45 2023 +0300 Merge branch 'master' into AG-24051-stats-collector commit bbd4780b03a1c954fe2b349d27f1ab3bf7739518 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Aug 22 17:47:51 2023 +0300 stats: imp test commit cfe3b9bdf5fd75bff98f985884b3bff8a88ae8ee Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Aug 22 16:57:31 2023 +0300 stats: add test commit cb579a157056f79c1c3d08479a718698a74e0bb9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Aug 21 15:24:40 2023 +0300 stats: imp docs commit 3c6ab3affb9ac402db7e3cc3d9696154770e1037 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Aug 17 14:41:35 2023 +0300 stats: imp code commit 125a31b73bb31f7f4886daad9ce7e3bbc97b38c9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Aug 16 12:29:10 2023 +0300 stats: imp test commit 1ba1eb3b7bd540621bf17ca50d4c2ba4bc55a9f8 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Aug 15 19:57:34 2023 +0300 stats: add test commit 46622f4fdf2775ddaba626b9786af183680e8889 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Aug 15 15:47:06 2023 +0300 stats: rm stats collector
2023-08-23 15:09:42 +01:00
func TestStatsCtx_FillCollectedStats_daily(t *testing.T) {
const (
daysCount = 10
timeUnits = "days"
)
s, err := New(Config{
Logger: slogutil.NewDiscardLogger(),
Pull request 1963: AG-24051-stats-collector Updates #6108. Squashed commit of the following: commit ca584c8dbbece70b90f6298a0a18a933a698fcf6 Merge: b6e136232 28cfde921 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Aug 23 17:00:52 2023 +0300 Merge branch 'master' into AG-24051-stats-collector commit b6e136232dd619ce09150b608ae5017676031e25 Merge: bbd4780b0 3722c2846 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Aug 23 16:25:45 2023 +0300 Merge branch 'master' into AG-24051-stats-collector commit bbd4780b03a1c954fe2b349d27f1ab3bf7739518 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Aug 22 17:47:51 2023 +0300 stats: imp test commit cfe3b9bdf5fd75bff98f985884b3bff8a88ae8ee Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Aug 22 16:57:31 2023 +0300 stats: add test commit cb579a157056f79c1c3d08479a718698a74e0bb9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Aug 21 15:24:40 2023 +0300 stats: imp docs commit 3c6ab3affb9ac402db7e3cc3d9696154770e1037 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Aug 17 14:41:35 2023 +0300 stats: imp code commit 125a31b73bb31f7f4886daad9ce7e3bbc97b38c9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Aug 16 12:29:10 2023 +0300 stats: imp test commit 1ba1eb3b7bd540621bf17ca50d4c2ba4bc55a9f8 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Aug 15 19:57:34 2023 +0300 stats: add test commit 46622f4fdf2775ddaba626b9786af183680e8889 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Aug 15 15:47:06 2023 +0300 stats: rm stats collector
2023-08-23 15:09:42 +01:00
ShouldCountClient: func([]string) bool { return true },
Filename: filepath.Join(t.TempDir(), "./stats.db"),
Limit: time.Hour,
})
require.NoError(t, err)
testutil.CleanupAndRequireSuccess(t, s.Close)
sum := make([][]uint64, resultLast)
sum[RFiltered] = make([]uint64, daysCount)
sum[RSafeBrowsing] = make([]uint64, daysCount)
sum[RParental] = make([]uint64, daysCount)
total := make([]uint64, daysCount)
dailyData := []*unitDB{}
for i := range daysCount * 24 {
Pull request 1963: AG-24051-stats-collector Updates #6108. Squashed commit of the following: commit ca584c8dbbece70b90f6298a0a18a933a698fcf6 Merge: b6e136232 28cfde921 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Aug 23 17:00:52 2023 +0300 Merge branch 'master' into AG-24051-stats-collector commit b6e136232dd619ce09150b608ae5017676031e25 Merge: bbd4780b0 3722c2846 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Aug 23 16:25:45 2023 +0300 Merge branch 'master' into AG-24051-stats-collector commit bbd4780b03a1c954fe2b349d27f1ab3bf7739518 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Aug 22 17:47:51 2023 +0300 stats: imp test commit cfe3b9bdf5fd75bff98f985884b3bff8a88ae8ee Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Aug 22 16:57:31 2023 +0300 stats: add test commit cb579a157056f79c1c3d08479a718698a74e0bb9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Aug 21 15:24:40 2023 +0300 stats: imp docs commit 3c6ab3affb9ac402db7e3cc3d9696154770e1037 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Aug 17 14:41:35 2023 +0300 stats: imp code commit 125a31b73bb31f7f4886daad9ce7e3bbc97b38c9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Aug 16 12:29:10 2023 +0300 stats: imp test commit 1ba1eb3b7bd540621bf17ca50d4c2ba4bc55a9f8 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Aug 15 19:57:34 2023 +0300 stats: add test commit 46622f4fdf2775ddaba626b9786af183680e8889 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Aug 15 15:47:06 2023 +0300 stats: rm stats collector
2023-08-23 15:09:42 +01:00
n := uint64(i)
nResult := make([]uint64, resultLast)
nResult[RFiltered] = n
nResult[RSafeBrowsing] = n
nResult[RParental] = n
day := i / 24
sum[RFiltered][day] += n
sum[RSafeBrowsing][day] += n
sum[RParental][day] += n
t := n * 3
total[day] += t
dailyData = append(dailyData, &unitDB{
NTotal: t,
NResult: nResult,
})
}
data := &StatsResp{}
// In this way we will not skip first hours.
curID := uint32(daysCount * 24)
s.fillCollectedStats(data, dailyData, curID)
assert.Equal(t, timeUnits, data.TimeUnits)
assert.Equal(t, sum[RFiltered], data.BlockedFiltering)
assert.Equal(t, sum[RSafeBrowsing], data.ReplacedSafebrowsing)
assert.Equal(t, sum[RParental], data.ReplacedParental)
assert.Equal(t, total, data.DNSQueries)
}
func TestStatsCtx_DataFromUnits_month(t *testing.T) {
const hoursInMonth = 720
s, err := New(Config{
Logger: slogutil.NewDiscardLogger(),
Pull request 1963: AG-24051-stats-collector Updates #6108. Squashed commit of the following: commit ca584c8dbbece70b90f6298a0a18a933a698fcf6 Merge: b6e136232 28cfde921 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Aug 23 17:00:52 2023 +0300 Merge branch 'master' into AG-24051-stats-collector commit b6e136232dd619ce09150b608ae5017676031e25 Merge: bbd4780b0 3722c2846 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Aug 23 16:25:45 2023 +0300 Merge branch 'master' into AG-24051-stats-collector commit bbd4780b03a1c954fe2b349d27f1ab3bf7739518 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Aug 22 17:47:51 2023 +0300 stats: imp test commit cfe3b9bdf5fd75bff98f985884b3bff8a88ae8ee Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Aug 22 16:57:31 2023 +0300 stats: add test commit cb579a157056f79c1c3d08479a718698a74e0bb9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Mon Aug 21 15:24:40 2023 +0300 stats: imp docs commit 3c6ab3affb9ac402db7e3cc3d9696154770e1037 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Thu Aug 17 14:41:35 2023 +0300 stats: imp code commit 125a31b73bb31f7f4886daad9ce7e3bbc97b38c9 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Wed Aug 16 12:29:10 2023 +0300 stats: imp test commit 1ba1eb3b7bd540621bf17ca50d4c2ba4bc55a9f8 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Aug 15 19:57:34 2023 +0300 stats: add test commit 46622f4fdf2775ddaba626b9786af183680e8889 Author: Stanislav Chzhen <s.chzhen@adguard.com> Date: Tue Aug 15 15:47:06 2023 +0300 stats: rm stats collector
2023-08-23 15:09:42 +01:00
ShouldCountClient: func([]string) bool { return true },
Filename: filepath.Join(t.TempDir(), "./stats.db"),
Limit: time.Hour,
})
require.NoError(t, err)
testutil.CleanupAndRequireSuccess(t, s.Close)
units, curID := s.loadUnits(hoursInMonth)
require.Len(t, units, hoursInMonth)
var h uint32
for h = 1; h <= hoursInMonth; h++ {
data := s.dataFromUnits(units[:h], curID)
require.NotNil(t, data)
}
}