code_before
stringlengths
16
1.81M
edits
stringlengths
4
328k
next_edit
stringlengths
0
76.5k
code_after
stringlengths
3
49.9M
label_window
sequencelengths
4
1.81k
instruction
stringlengths
20
51.9k
html_url
stringlengths
74
116
file_name
stringlengths
3
311
func newBucketWalker( tx *bolt.Tx, unitDelPtr *int, firstID uint32, ) (f func(name []byte, b *bolt.Bucket) (err error)) { return func(name []byte, _ *bolt.Bucket) (err error) { nameID, ok := unitNameToID(name) if !ok || nameID < firstID { err = tx.DeleteBucket(name) if err != nil { log.Debug("stats: tx.DeleteBucket: %s", err)
</s> remove tx *bolt.Tx, </s> add tx *bbolt.Tx, </s> remove firstID := id - s.conf.limit - 1 </s> add firstID := id - s.limitHours - 1 </s> remove func (s *statsCtx) dbOpen() bool { var err error </s> add // dbOpen returns an error if the database can't be opened from the specified // file. It's safe for concurrent use. func (s *StatsCtx) dbOpen() (err error) { </s> remove func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id uint32, udb *unitDB) bool { </s> add func flushUnitToDB(tx *bbolt.Tx, id uint32, udb *unitDB) bool { </s> remove s, err := createObject(conf) </s> add s, err := New(conf)
) (f func(name []byte, b *bbolt.Bucket) (err error)) { return func(name []byte, _ *bbolt.Bucket) (err error) {
func newBucketWalker( tx *bolt.Tx, unitDelPtr *int, firstID uint32, ) (f func(name []byte, b *bbolt.Bucket) (err error)) { return func(name []byte, _ *bbolt.Bucket) (err error) { ) (f func(name []byte, b *bbolt.Bucket) (err error)) { return func(name []byte, _ *bbolt.Bucket) (err error) { nameID, ok := unitNameToID(name) if !ok || nameID < firstID { err = tx.DeleteBucket(name) if err != nil { log.Debug("stats: tx.DeleteBucket: %s", err)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
return errStop } } func (s *statsCtx) Start() { s.initWeb() go s.periodicFlush() } func checkInterval(days uint32) bool {
</s> remove func checkInterval(days uint32) bool { </s> add // checkInterval returns true if days is valid to be used as statistics // retention interval. The valid values are 0, 1, 7, 30 and 90. func checkInterval(days uint32) (ok bool) { </s> remove func (s *statsCtx) loadUnitFromDB(tx *bolt.Tx, id uint32) *unitDB { </s> add func (s *StatsCtx) loadUnitFromDB(tx *bbolt.Tx, id uint32) *unitDB { </s> remove func (s *statsCtx) loadUnits(limit uint32) ([]*unitDB, uint32) { tx := s.beginTxn(false) </s> add func (s *StatsCtx) loadUnits(limit uint32) ([]*unitDB, uint32) { tx := beginTxn(s.database(), false) </s> remove // Delete unit's data from file func (s *statsCtx) deleteUnit(tx *bolt.Tx, id uint32) bool { </s> add // deleteUnit removes the unit by it's id from the database the tx belongs to. func (s *StatsCtx) deleteUnit(tx *bbolt.Tx, id uint32) bool { </s> remove func (s *statsCtx) dbOpen() bool { var err error </s> add // dbOpen returns an error if the database can't be opened from the specified // file. It's safe for concurrent use. func (s *StatsCtx) dbOpen() (err error) {
// Start makes s process the incoming data. func (s *StatsCtx) Start() {
return errStop } } // Start makes s process the incoming data. func (s *StatsCtx) Start() { s.initWeb() go s.periodicFlush() } func checkInterval(days uint32) bool {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
s.initWeb() go s.periodicFlush() } func checkInterval(days uint32) bool { return days == 0 || days == 1 || days == 7 || days == 30 || days == 90 } func (s *statsCtx) dbOpen() bool { var err error
</s> remove func (s *statsCtx) dbOpen() bool { var err error </s> add // dbOpen returns an error if the database can't be opened from the specified // file. It's safe for concurrent use. func (s *StatsCtx) dbOpen() (err error) { </s> remove e.Result >= rLast || </s> add e.Result >= resultLast || </s> remove func (s *statsCtx) Update(e Entry) { if s.conf.limit == 0 { </s> add func (s *StatsCtx) Update(e Entry) { if !s.isEnabled() { </s> remove func (s *statsCtx) Start() { </s> add // Start makes s process the incoming data. func (s *StatsCtx) Start() { </s> remove ok1 := s.flushUnitToDB(tx, u.id, udb) ok2 := s.deleteUnit(tx, id-s.conf.limit) if ok1 || ok2 { </s> add flushOK := flushUnitToDB(tx, u.id, udb) delOK := s.deleteUnit(tx, id-atomic.LoadUint32(&s.limitHours)) if flushOK || delOK {
// checkInterval returns true if days is valid to be used as statistics // retention interval. The valid values are 0, 1, 7, 30 and 90. func checkInterval(days uint32) (ok bool) {
s.initWeb() go s.periodicFlush() } // checkInterval returns true if days is valid to be used as statistics // retention interval. The valid values are 0, 1, 7, 30 and 90. func checkInterval(days uint32) (ok bool) { return days == 0 || days == 1 || days == 7 || days == 30 || days == 90 } func (s *statsCtx) dbOpen() bool { var err error
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
func checkInterval(days uint32) bool { return days == 0 || days == 1 || days == 7 || days == 30 || days == 90 } func (s *statsCtx) dbOpen() bool { var err error log.Tracef("db.Open...") s.db, err = bolt.Open(s.conf.Filename, 0o644, nil) if err != nil { log.Error("stats: open DB: %s: %s", s.conf.Filename, err) if err.Error() == "invalid argument" {
</s> remove func checkInterval(days uint32) bool { </s> add // checkInterval returns true if days is valid to be used as statistics // retention interval. The valid values are 0, 1, 7, 30 and 90. func checkInterval(days uint32) (ok bool) { </s> remove s.db, err = bolt.Open(s.conf.Filename, 0o644, nil) </s> add s.dbMu.Lock() defer s.dbMu.Unlock() s.db, err = bbolt.Open(s.filename, 0o644, nil) </s> remove log.Error("stats: open DB: %s: %s", s.conf.Filename, err) </s> add log.Error("stats: open DB: %s: %s", s.filename, err) </s> remove e.Result >= rLast || </s> add e.Result >= resultLast || </s> remove func (s *statsCtx) Update(e Entry) { if s.conf.limit == 0 { </s> add func (s *StatsCtx) Update(e Entry) { if !s.isEnabled() {
// dbOpen returns an error if the database can't be opened from the specified // file. It's safe for concurrent use. func (s *StatsCtx) dbOpen() (err error) {
func checkInterval(days uint32) bool { return days == 0 || days == 1 || days == 7 || days == 30 || days == 90 } // dbOpen returns an error if the database can't be opened from the specified // file. It's safe for concurrent use. func (s *StatsCtx) dbOpen() (err error) { // dbOpen returns an error if the database can't be opened from the specified // file. It's safe for concurrent use. func (s *StatsCtx) dbOpen() (err error) { log.Tracef("db.Open...") s.db, err = bolt.Open(s.conf.Filename, 0o644, nil) if err != nil { log.Error("stats: open DB: %s: %s", s.conf.Filename, err) if err.Error() == "invalid argument" {
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
func (s *statsCtx) dbOpen() bool { var err error log.Tracef("db.Open...") s.db, err = bolt.Open(s.conf.Filename, 0o644, nil) if err != nil { log.Error("stats: open DB: %s: %s", s.conf.Filename, err) if err.Error() == "invalid argument" { log.Error("AdGuard Home cannot be initialized due to an incompatible file system.\nPlease read the explanation here: https://github.com/AdguardTeam/AdGuardHome/wiki/Getting-Started#limitations") }
</s> remove log.Error("stats: open DB: %s: %s", s.conf.Filename, err) </s> add log.Error("stats: open DB: %s: %s", s.filename, err) </s> remove return false } log.Tracef("db.Open") return true } </s> add </s> remove func (s *statsCtx) dbOpen() bool { var err error </s> add // dbOpen returns an error if the database can't be opened from the specified // file. It's safe for concurrent use. func (s *StatsCtx) dbOpen() (err error) { </s> remove log.Debug("tx.Commit: %s", err) </s> add log.Error("stats: committing a transaction: %s", err) </s> remove func checkInterval(days uint32) bool { </s> add // checkInterval returns true if days is valid to be used as statistics // retention interval. The valid values are 0, 1, 7, 30 and 90. func checkInterval(days uint32) (ok bool) {
s.dbMu.Lock() defer s.dbMu.Unlock() s.db, err = bbolt.Open(s.filename, 0o644, nil)
func (s *statsCtx) dbOpen() bool { var err error log.Tracef("db.Open...") s.dbMu.Lock() defer s.dbMu.Unlock() s.db, err = bbolt.Open(s.filename, 0o644, nil) if err != nil { log.Error("stats: open DB: %s: %s", s.conf.Filename, err) if err.Error() == "invalid argument" { log.Error("AdGuard Home cannot be initialized due to an incompatible file system.\nPlease read the explanation here: https://github.com/AdguardTeam/AdGuardHome/wiki/Getting-Started#limitations") }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
var err error log.Tracef("db.Open...") s.db, err = bolt.Open(s.conf.Filename, 0o644, nil) if err != nil { log.Error("stats: open DB: %s: %s", s.conf.Filename, err) if err.Error() == "invalid argument" { log.Error("AdGuard Home cannot be initialized due to an incompatible file system.\nPlease read the explanation here: https://github.com/AdguardTeam/AdGuardHome/wiki/Getting-Started#limitations") } return false }
</s> remove s.db, err = bolt.Open(s.conf.Filename, 0o644, nil) </s> add s.dbMu.Lock() defer s.dbMu.Unlock() s.db, err = bbolt.Open(s.filename, 0o644, nil) </s> remove return false } log.Tracef("db.Open") return true } </s> add </s> remove func (s *statsCtx) dbOpen() bool { var err error </s> add // dbOpen returns an error if the database can't be opened from the specified // file. It's safe for concurrent use. func (s *StatsCtx) dbOpen() (err error) { </s> remove log.Debug("tx.Commit: %s", err) </s> add log.Error("stats: committing a transaction: %s", err) </s> remove log.Error("db.Begin: %s", err) </s> add log.Error("stats: opening a transaction: %s", err)
log.Error("stats: open DB: %s: %s", s.filename, err)
var err error log.Tracef("db.Open...") s.db, err = bolt.Open(s.conf.Filename, 0o644, nil) if err != nil { log.Error("stats: open DB: %s: %s", s.filename, err) if err.Error() == "invalid argument" { log.Error("AdGuard Home cannot be initialized due to an incompatible file system.\nPlease read the explanation here: https://github.com/AdguardTeam/AdGuardHome/wiki/Getting-Started#limitations") } return false }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
log.Error("stats: open DB: %s: %s", s.conf.Filename, err) if err.Error() == "invalid argument" { log.Error("AdGuard Home cannot be initialized due to an incompatible file system.\nPlease read the explanation here: https://github.com/AdguardTeam/AdGuardHome/wiki/Getting-Started#limitations") } return false } log.Tracef("db.Open") return true } // Atomically swap the currently active unit with a new value // Return old value func (s *statsCtx) swapUnit(new *unit) (u *unit) { s.mu.Lock()
</s> remove log.Error("stats: open DB: %s: %s", s.conf.Filename, err) </s> add log.Error("stats: open DB: %s: %s", s.filename, err) </s> remove // Atomically swap the currently active unit with a new value // Return old value func (s *statsCtx) swapUnit(new *unit) (u *unit) { s.mu.Lock() defer s.mu.Unlock() </s> add return err } </s> remove s.db, err = bolt.Open(s.conf.Filename, 0o644, nil) </s> add s.dbMu.Lock() defer s.dbMu.Unlock() s.db, err = bbolt.Open(s.filename, 0o644, nil) </s> remove u = s.current s.current = new </s> add log.Tracef("db.Open") </s> remove func (s *statsCtx) dbOpen() bool { var err error </s> add // dbOpen returns an error if the database can't be opened from the specified // file. It's safe for concurrent use. func (s *StatsCtx) dbOpen() (err error) {
log.Error("stats: open DB: %s: %s", s.conf.Filename, err) if err.Error() == "invalid argument" { log.Error("AdGuard Home cannot be initialized due to an incompatible file system.\nPlease read the explanation here: https://github.com/AdguardTeam/AdGuardHome/wiki/Getting-Started#limitations") } // Atomically swap the currently active unit with a new value // Return old value func (s *statsCtx) swapUnit(new *unit) (u *unit) { s.mu.Lock()
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
log.Tracef("db.Open") return true } // Atomically swap the currently active unit with a new value // Return old value func (s *statsCtx) swapUnit(new *unit) (u *unit) { s.mu.Lock() defer s.mu.Unlock() u = s.current s.current = new return u
</s> remove return false } log.Tracef("db.Open") return true } </s> add </s> remove u = s.current s.current = new </s> add log.Tracef("db.Open") </s> remove func (s *statsCtx) ongoing() (u *unit) { s.mu.Lock() defer s.mu.Unlock() return s.current } </s> add </s> remove return u </s> add return nil </s> remove s.mu.Lock() defer s.mu.Unlock() </s> add u := s.ongoing() if u == nil { return }
return err }
log.Tracef("db.Open") return true } return err } return err } return err } return err } return err } u = s.current s.current = new return u
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
func (s *statsCtx) swapUnit(new *unit) (u *unit) { s.mu.Lock() defer s.mu.Unlock() u = s.current s.current = new return u } // Get unit ID for the current hour
</s> remove // Atomically swap the currently active unit with a new value // Return old value func (s *statsCtx) swapUnit(new *unit) (u *unit) { s.mu.Lock() defer s.mu.Unlock() </s> add return err } </s> remove return u </s> add return nil </s> remove func (s *statsCtx) ongoing() (u *unit) { s.mu.Lock() defer s.mu.Unlock() return s.current } </s> add </s> remove s.mu.Lock() defer s.mu.Unlock() </s> add u := s.ongoing() if u == nil { return } </s> remove u := s.current </s> add u.mu.Lock() defer u.mu.Unlock()
log.Tracef("db.Open")
func (s *statsCtx) swapUnit(new *unit) (u *unit) { s.mu.Lock() defer s.mu.Unlock() log.Tracef("db.Open") log.Tracef("db.Open") return u } // Get unit ID for the current hour
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
u = s.current s.current = new return u } // Get unit ID for the current hour func newUnitID() uint32 { return uint32(time.Now().Unix() / (60 * 60))
</s> remove // Get unit ID for the current hour func newUnitID() uint32 { return uint32(time.Now().Unix() / (60 * 60)) </s> add // newUnitID is the default UnitIDGenFunc that generates the unique id hourly. func newUnitID() (id uint32) { const secsInHour = int64(time.Hour / time.Second) return uint32(time.Now().Unix() / secsInHour) </s> remove u = s.current s.current = new </s> add log.Tracef("db.Open") </s> remove // Atomically swap the currently active unit with a new value // Return old value func (s *statsCtx) swapUnit(new *unit) (u *unit) { s.mu.Lock() defer s.mu.Unlock() </s> add return err } </s> remove // Initialize a unit func (s *statsCtx) initUnit(u *unit, id uint32) { u.id = id u.nResult = make([]uint64, rLast) u.domains = make(map[string]uint64) u.blockedDomains = make(map[string]uint64) u.clients = make(map[string]uint64) </s> add // newUnit allocates the new *unit. func newUnit(id uint32) (u *unit) { return &unit{ mu: &sync.RWMutex{}, id: id, nResult: make([]uint64, resultLast), domains: make(map[string]uint64), blockedDomains: make(map[string]uint64), clients: make(map[string]uint64), } </s> remove func (s *statsCtx) ongoing() (u *unit) { s.mu.Lock() defer s.mu.Unlock() return s.current } </s> add
return nil
u = s.current s.current = new return nil } // Get unit ID for the current hour func newUnitID() uint32 { return uint32(time.Now().Unix() / (60 * 60))
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
return u } // Get unit ID for the current hour func newUnitID() uint32 { return uint32(time.Now().Unix() / (60 * 60)) } // Initialize a unit func (s *statsCtx) initUnit(u *unit, id uint32) { u.id = id
</s> remove return u </s> add return nil </s> remove // Initialize a unit func (s *statsCtx) initUnit(u *unit, id uint32) { u.id = id u.nResult = make([]uint64, rLast) u.domains = make(map[string]uint64) u.blockedDomains = make(map[string]uint64) u.clients = make(map[string]uint64) </s> add // newUnit allocates the new *unit. func newUnit(id uint32) (u *unit) { return &unit{ mu: &sync.RWMutex{}, id: id, nResult: make([]uint64, resultLast), domains: make(map[string]uint64), blockedDomains: make(map[string]uint64), clients: make(map[string]uint64), } </s> remove u = s.current s.current = new </s> add log.Tracef("db.Open") </s> remove // Delete unit's data from file func (s *statsCtx) deleteUnit(tx *bolt.Tx, id uint32) bool { </s> add // deleteUnit removes the unit by it's id from the database the tx belongs to. func (s *StatsCtx) deleteUnit(tx *bbolt.Tx, id uint32) bool { </s> remove db *bolt.DB conf *Config </s> add // filename is the name of database file. filename string // limitHours is the maximum number of hours to collect statistics into the // current unit. limitHours uint32
// newUnitID is the default UnitIDGenFunc that generates the unique id hourly. func newUnitID() (id uint32) { const secsInHour = int64(time.Hour / time.Second) return uint32(time.Now().Unix() / secsInHour)
return u } // newUnitID is the default UnitIDGenFunc that generates the unique id hourly. func newUnitID() (id uint32) { const secsInHour = int64(time.Hour / time.Second) return uint32(time.Now().Unix() / secsInHour) // newUnitID is the default UnitIDGenFunc that generates the unique id hourly. func newUnitID() (id uint32) { const secsInHour = int64(time.Hour / time.Second) return uint32(time.Now().Unix() / secsInHour) // newUnitID is the default UnitIDGenFunc that generates the unique id hourly. func newUnitID() (id uint32) { const secsInHour = int64(time.Hour / time.Second) return uint32(time.Now().Unix() / secsInHour) } // Initialize a unit func (s *statsCtx) initUnit(u *unit, id uint32) { u.id = id
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
func newUnitID() uint32 { return uint32(time.Now().Unix() / (60 * 60)) } // Initialize a unit func (s *statsCtx) initUnit(u *unit, id uint32) { u.id = id u.nResult = make([]uint64, rLast) u.domains = make(map[string]uint64) u.blockedDomains = make(map[string]uint64) u.clients = make(map[string]uint64) } // Open a DB transaction func (s *statsCtx) beginTxn(wr bool) *bolt.Tx { db := s.db
</s> remove // Get unit ID for the current hour func newUnitID() uint32 { return uint32(time.Now().Unix() / (60 * 60)) </s> add // newUnitID is the default UnitIDGenFunc that generates the unique id hourly. func newUnitID() (id uint32) { const secsInHour = int64(time.Hour / time.Second) return uint32(time.Now().Unix() / secsInHour) </s> remove // Open a DB transaction func (s *statsCtx) beginTxn(wr bool) *bolt.Tx { db := s.db </s> add // beginTxn opens a new database transaction. If writable is true, the // transaction will be opened for writing, and for reading otherwise. It // returns nil if the transaction can't be created. func beginTxn(db *bbolt.DB, writable bool) (tx *bbolt.Tx) { </s> remove return u </s> add return nil </s> remove u.timeSum = uint64(udb.TimeAvg) * u.nTotal </s> add u.timeSum = uint64(udb.TimeAvg) * udb.NTotal
// newUnit allocates the new *unit. func newUnit(id uint32) (u *unit) { return &unit{ mu: &sync.RWMutex{}, id: id, nResult: make([]uint64, resultLast), domains: make(map[string]uint64), blockedDomains: make(map[string]uint64), clients: make(map[string]uint64), }
func newUnitID() uint32 { return uint32(time.Now().Unix() / (60 * 60)) } // newUnit allocates the new *unit. func newUnit(id uint32) (u *unit) { return &unit{ mu: &sync.RWMutex{}, id: id, nResult: make([]uint64, resultLast), domains: make(map[string]uint64), blockedDomains: make(map[string]uint64), clients: make(map[string]uint64), } // newUnit allocates the new *unit. func newUnit(id uint32) (u *unit) { return &unit{ mu: &sync.RWMutex{}, id: id, nResult: make([]uint64, resultLast), domains: make(map[string]uint64), blockedDomains: make(map[string]uint64), clients: make(map[string]uint64), } // newUnit allocates the new *unit. func newUnit(id uint32) (u *unit) { return &unit{ mu: &sync.RWMutex{}, id: id, nResult: make([]uint64, resultLast), domains: make(map[string]uint64), blockedDomains: make(map[string]uint64), clients: make(map[string]uint64), } // newUnit allocates the new *unit. func newUnit(id uint32) (u *unit) { return &unit{ mu: &sync.RWMutex{}, id: id, nResult: make([]uint64, resultLast), domains: make(map[string]uint64), blockedDomains: make(map[string]uint64), clients: make(map[string]uint64), } // newUnit allocates the new *unit. func newUnit(id uint32) (u *unit) { return &unit{ mu: &sync.RWMutex{}, id: id, nResult: make([]uint64, resultLast), domains: make(map[string]uint64), blockedDomains: make(map[string]uint64), clients: make(map[string]uint64), } // newUnit allocates the new *unit. func newUnit(id uint32) (u *unit) { return &unit{ mu: &sync.RWMutex{}, id: id, nResult: make([]uint64, resultLast), domains: make(map[string]uint64), blockedDomains: make(map[string]uint64), clients: make(map[string]uint64), } // newUnit allocates the new *unit. func newUnit(id uint32) (u *unit) { return &unit{ mu: &sync.RWMutex{}, id: id, nResult: make([]uint64, resultLast), domains: make(map[string]uint64), blockedDomains: make(map[string]uint64), clients: make(map[string]uint64), } } // Open a DB transaction func (s *statsCtx) beginTxn(wr bool) *bolt.Tx { db := s.db
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
u.blockedDomains = make(map[string]uint64) u.clients = make(map[string]uint64) } // Open a DB transaction func (s *statsCtx) beginTxn(wr bool) *bolt.Tx { db := s.db if db == nil { return nil } log.Tracef("db.Begin...")
</s> remove // Initialize a unit func (s *statsCtx) initUnit(u *unit, id uint32) { u.id = id u.nResult = make([]uint64, rLast) u.domains = make(map[string]uint64) u.blockedDomains = make(map[string]uint64) u.clients = make(map[string]uint64) </s> add // newUnit allocates the new *unit. func newUnit(id uint32) (u *unit) { return &unit{ mu: &sync.RWMutex{}, id: id, nResult: make([]uint64, resultLast), domains: make(map[string]uint64), blockedDomains: make(map[string]uint64), clients: make(map[string]uint64), } </s> remove func (s *statsCtx) clear() { tx := s.beginTxn(true) </s> add func (s *StatsCtx) clear() { db := s.database() tx := beginTxn(db, true) </s> remove log.Tracef("db.Begin...") tx, err := db.Begin(wr) </s> add log.Tracef("opening a database transaction") tx, err := db.Begin(writable) </s> remove if s.db != nil { </s> add if db != nil { </s> remove db := s.db s.db = nil </s> add _ = s.swapDatabase(nil)
// beginTxn opens a new database transaction. If writable is true, the // transaction will be opened for writing, and for reading otherwise. It // returns nil if the transaction can't be created. func beginTxn(db *bbolt.DB, writable bool) (tx *bbolt.Tx) {
u.blockedDomains = make(map[string]uint64) u.clients = make(map[string]uint64) } // beginTxn opens a new database transaction. If writable is true, the // transaction will be opened for writing, and for reading otherwise. It // returns nil if the transaction can't be created. func beginTxn(db *bbolt.DB, writable bool) (tx *bbolt.Tx) { // beginTxn opens a new database transaction. If writable is true, the // transaction will be opened for writing, and for reading otherwise. It // returns nil if the transaction can't be created. func beginTxn(db *bbolt.DB, writable bool) (tx *bbolt.Tx) { // beginTxn opens a new database transaction. If writable is true, the // transaction will be opened for writing, and for reading otherwise. It // returns nil if the transaction can't be created. func beginTxn(db *bbolt.DB, writable bool) (tx *bbolt.Tx) { if db == nil { return nil } log.Tracef("db.Begin...")
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
if db == nil { return nil } log.Tracef("db.Begin...") tx, err := db.Begin(wr) if err != nil { log.Error("db.Begin: %s", err) return nil } log.Tracef("db.Begin")
</s> remove log.Error("db.Begin: %s", err) </s> add log.Error("stats: opening a transaction: %s", err) </s> remove log.Tracef("db.Begin") </s> add log.Tracef("transaction has been opened") </s> remove func (s *statsCtx) commitTxn(tx *bolt.Tx) { </s> add // commitTxn applies the changes made in tx to the database. func (s *StatsCtx) commitTxn(tx *bbolt.Tx) { </s> remove log.Debug("tx.Commit: %s", err) </s> add log.Error("stats: committing a transaction: %s", err) </s> remove if !s.dbOpen() { return nil, fmt.Errorf("open database") </s> add if err = s.dbOpen(); err != nil { return nil, fmt.Errorf("opening database: %w", err)
log.Tracef("opening a database transaction") tx, err := db.Begin(writable)
if db == nil { return nil } log.Tracef("opening a database transaction") tx, err := db.Begin(writable) log.Tracef("opening a database transaction") tx, err := db.Begin(writable) if err != nil { log.Error("db.Begin: %s", err) return nil } log.Tracef("db.Begin")
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
log.Tracef("db.Begin...") tx, err := db.Begin(wr) if err != nil { log.Error("db.Begin: %s", err) return nil } log.Tracef("db.Begin") return tx }
</s> remove log.Tracef("db.Begin...") tx, err := db.Begin(wr) </s> add log.Tracef("opening a database transaction") tx, err := db.Begin(writable) </s> remove log.Tracef("db.Begin") </s> add log.Tracef("transaction has been opened") </s> remove func (s *statsCtx) commitTxn(tx *bolt.Tx) { </s> add // commitTxn applies the changes made in tx to the database. func (s *StatsCtx) commitTxn(tx *bbolt.Tx) { </s> remove log.Debug("tx.Commit: %s", err) </s> add log.Error("stats: committing a transaction: %s", err) </s> remove if !s.dbOpen() { return nil, fmt.Errorf("open database") </s> add if err = s.dbOpen(); err != nil { return nil, fmt.Errorf("opening database: %w", err)
log.Error("stats: opening a transaction: %s", err)
log.Tracef("db.Begin...") tx, err := db.Begin(wr) if err != nil { log.Error("stats: opening a transaction: %s", err) return nil } log.Tracef("db.Begin") return tx }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
if err != nil { log.Error("db.Begin: %s", err) return nil } log.Tracef("db.Begin") return tx } func (s *statsCtx) commitTxn(tx *bolt.Tx) { err := tx.Commit()
</s> remove func (s *statsCtx) commitTxn(tx *bolt.Tx) { </s> add // commitTxn applies the changes made in tx to the database. func (s *StatsCtx) commitTxn(tx *bbolt.Tx) { </s> remove log.Debug("tx.Commit: %s", err) </s> add log.Error("stats: committing a transaction: %s", err) </s> remove log.Error("db.Begin: %s", err) </s> add log.Error("stats: opening a transaction: %s", err) </s> remove log.Tracef("db.Begin...") tx, err := db.Begin(wr) </s> add log.Tracef("opening a database transaction") tx, err := db.Begin(writable) </s> remove func (s *statsCtx) handleStatsConfig(w http.ResponseWriter, r *http.Request) { </s> add func (s *StatsCtx) handleStatsConfig(w http.ResponseWriter, r *http.Request) {
log.Tracef("transaction has been opened")
if err != nil { log.Error("db.Begin: %s", err) return nil } log.Tracef("transaction has been opened") return tx } func (s *statsCtx) commitTxn(tx *bolt.Tx) { err := tx.Commit()
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
log.Tracef("db.Begin") return tx } func (s *statsCtx) commitTxn(tx *bolt.Tx) { err := tx.Commit() if err != nil { log.Debug("tx.Commit: %s", err) return }
</s> remove log.Tracef("db.Begin") </s> add log.Tracef("transaction has been opened") </s> remove log.Debug("tx.Commit: %s", err) </s> add log.Error("stats: committing a transaction: %s", err) </s> remove log.Error("db.Begin: %s", err) </s> add log.Error("stats: opening a transaction: %s", err) </s> remove log.Tracef("db.Begin...") tx, err := db.Begin(wr) </s> add log.Tracef("opening a database transaction") tx, err := db.Begin(writable) </s> remove func (s *statsCtx) handleStatsConfig(w http.ResponseWriter, r *http.Request) { </s> add func (s *StatsCtx) handleStatsConfig(w http.ResponseWriter, r *http.Request) {
// commitTxn applies the changes made in tx to the database. func (s *StatsCtx) commitTxn(tx *bbolt.Tx) {
log.Tracef("db.Begin") return tx } // commitTxn applies the changes made in tx to the database. func (s *StatsCtx) commitTxn(tx *bbolt.Tx) { err := tx.Commit() if err != nil { log.Debug("tx.Commit: %s", err) return }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
func (s *statsCtx) commitTxn(tx *bolt.Tx) { err := tx.Commit() if err != nil { log.Debug("tx.Commit: %s", err) return } log.Tracef("tx.Commit") }
</s> remove func (s *statsCtx) commitTxn(tx *bolt.Tx) { </s> add // commitTxn applies the changes made in tx to the database. func (s *StatsCtx) commitTxn(tx *bbolt.Tx) { </s> remove log.Tracef("db.Begin") </s> add log.Tracef("transaction has been opened") </s> remove log.Tracef("tx.Commit") </s> add log.Tracef("transaction has been committed") </s> remove log.Error("db.Begin: %s", err) </s> add log.Error("stats: opening a transaction: %s", err) </s> remove func (s *statsCtx) handleStatsConfig(w http.ResponseWriter, r *http.Request) { </s> add func (s *StatsCtx) handleStatsConfig(w http.ResponseWriter, r *http.Request) {
log.Error("stats: committing a transaction: %s", err)
func (s *statsCtx) commitTxn(tx *bolt.Tx) { err := tx.Commit() if err != nil { log.Error("stats: committing a transaction: %s", err) return } log.Tracef("tx.Commit") }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
if err != nil { log.Debug("tx.Commit: %s", err) return } log.Tracef("tx.Commit") } // bucketNameLen is the length of a bucket, a 64-bit unsigned integer. // // TODO(a.garipov): Find out why a 64-bit integer is used when IDs seem to
</s> remove log.Debug("tx.Commit: %s", err) </s> add log.Error("stats: committing a transaction: %s", err) </s> remove func (s *statsCtx) commitTxn(tx *bolt.Tx) { </s> add // commitTxn applies the changes made in tx to the database. func (s *StatsCtx) commitTxn(tx *bbolt.Tx) { </s> remove log.Error("db.Begin: %s", err) </s> add log.Error("stats: opening a transaction: %s", err) </s> remove name = make([]byte, bucketNameLen) binary.BigEndian.PutUint64(name, uint64(id)) </s> add n := [bucketNameLen]byte{} binary.BigEndian.PutUint64(n[:], uint64(id)) </s> remove func (s *statsCtx) ongoing() (u *unit) { s.mu.Lock() defer s.mu.Unlock() return s.current } </s> add
log.Tracef("transaction has been committed")
if err != nil { log.Debug("tx.Commit: %s", err) return } log.Tracef("transaction has been committed") } // bucketNameLen is the length of a bucket, a 64-bit unsigned integer. // // TODO(a.garipov): Find out why a 64-bit integer is used when IDs seem to
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
const bucketNameLen = 8 // idToUnitName converts a numerical ID into a database unit name. func idToUnitName(id uint32) (name []byte) { name = make([]byte, bucketNameLen) binary.BigEndian.PutUint64(name, uint64(id)) return name } // unitNameToID converts a database unit name into a numerical ID. ok is false
</s> remove return name </s> add return n[:] </s> remove db *bolt.DB conf *Config </s> add // filename is the name of database file. filename string // limitHours is the maximum number of hours to collect statistics into the // current unit. limitHours uint32 </s> remove // Get unit ID for the current hour func newUnitID() uint32 { return uint32(time.Now().Unix() / (60 * 60)) </s> add // newUnitID is the default UnitIDGenFunc that generates the unique id hourly. func newUnitID() (id uint32) { const secsInHour = int64(time.Hour / time.Second) return uint32(time.Now().Unix() / secsInHour) </s> remove // Config - module configuration </s> add // Config is the configuration structure for the statistics collecting. </s> remove log.Tracef("tx.Commit") </s> add log.Tracef("transaction has been committed")
n := [bucketNameLen]byte{} binary.BigEndian.PutUint64(n[:], uint64(id))
const bucketNameLen = 8 // idToUnitName converts a numerical ID into a database unit name. func idToUnitName(id uint32) (name []byte) { n := [bucketNameLen]byte{} binary.BigEndian.PutUint64(n[:], uint64(id)) n := [bucketNameLen]byte{} binary.BigEndian.PutUint64(n[:], uint64(id)) return name } // unitNameToID converts a database unit name into a numerical ID. ok is false
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
func idToUnitName(id uint32) (name []byte) { name = make([]byte, bucketNameLen) binary.BigEndian.PutUint64(name, uint64(id)) return name } // unitNameToID converts a database unit name into a numerical ID. ok is false // if name is not a valid database unit name. func unitNameToID(name []byte) (id uint32, ok bool) {
</s> remove name = make([]byte, bucketNameLen) binary.BigEndian.PutUint64(name, uint64(id)) </s> add n := [bucketNameLen]byte{} binary.BigEndian.PutUint64(n[:], uint64(id)) </s> remove db *bolt.DB conf *Config </s> add // filename is the name of database file. filename string // limitHours is the maximum number of hours to collect statistics into the // current unit. limitHours uint32 </s> remove // Config - module configuration </s> add // Config is the configuration structure for the statistics collecting. </s> remove // Get unit ID for the current hour func newUnitID() uint32 { return uint32(time.Now().Unix() / (60 * 60)) </s> add // newUnitID is the default UnitIDGenFunc that generates the unique id hourly. func newUnitID() (id uint32) { const secsInHour = int64(time.Hour / time.Second) return uint32(time.Now().Unix() / secsInHour) </s> remove Filename string // database file name LimitDays uint32 // time limit (in days) UnitID unitIDCallback // user function to get the current unit ID. If nil, the current time hour is used. </s> add // UnitID is the function to generate the identifier for current unit. If // nil, the default function is used, see newUnitID. UnitID UnitIDGenFunc
return n[:]
func idToUnitName(id uint32) (name []byte) { name = make([]byte, bucketNameLen) binary.BigEndian.PutUint64(name, uint64(id)) return n[:] } // unitNameToID converts a database unit name into a numerical ID. ok is false // if name is not a valid database unit name. func unitNameToID(name []byte) (id uint32, ok bool) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
return uint32(binary.BigEndian.Uint64(name)), true } func (s *statsCtx) ongoing() (u *unit) { s.mu.Lock() defer s.mu.Unlock() return s.current } // Flush the current unit to DB and delete an old unit when a new hour is started // If a unit must be flushed: // . lock DB // . atomically set a new empty unit as the current one and get the old unit // This is important to do it inside DB lock, so the reader won't get inconsistent results.
</s> remove func (s *statsCtx) periodicFlush() { for { ptr := s.ongoing() if ptr == nil { break } id := s.conf.UnitID() if ptr.id == id || s.conf.limit == 0 { </s> add func (s *StatsCtx) periodicFlush() { for ptr := s.ongoing(); ptr != nil; ptr = s.ongoing() { id := s.unitIDGen() // Access the unit's ID with atomic to avoid locking the whole unit. if !s.isEnabled() || atomic.LoadUint32(&ptr.id) == id { </s> remove // Atomically swap the currently active unit with a new value // Return old value func (s *statsCtx) swapUnit(new *unit) (u *unit) { s.mu.Lock() defer s.mu.Unlock() </s> add return err } </s> remove u = s.current s.current = new </s> add log.Tracef("db.Open") </s> remove return false } log.Tracef("db.Open") return true } </s> add </s> remove Filename string // database file name LimitDays uint32 // time limit (in days) UnitID unitIDCallback // user function to get the current unit ID. If nil, the current time hour is used. </s> add // UnitID is the function to generate the identifier for current unit. If // nil, the default function is used, see newUnitID. UnitID UnitIDGenFunc
return uint32(binary.BigEndian.Uint64(name)), true } // Flush the current unit to DB and delete an old unit when a new hour is started // If a unit must be flushed: // . lock DB // . atomically set a new empty unit as the current one and get the old unit // This is important to do it inside DB lock, so the reader won't get inconsistent results.
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
// This is important to do it inside DB lock, so the reader won't get inconsistent results. // . write the unit to DB // . remove the stale unit from DB // . unlock DB func (s *statsCtx) periodicFlush() { for { ptr := s.ongoing() if ptr == nil { break } id := s.conf.UnitID() if ptr.id == id || s.conf.limit == 0 { time.Sleep(time.Second) continue }
</s> remove func (s *statsCtx) ongoing() (u *unit) { s.mu.Lock() defer s.mu.Unlock() return s.current } </s> add </s> remove // Initialize a unit func (s *statsCtx) initUnit(u *unit, id uint32) { u.id = id u.nResult = make([]uint64, rLast) u.domains = make(map[string]uint64) u.blockedDomains = make(map[string]uint64) u.clients = make(map[string]uint64) </s> add // newUnit allocates the new *unit. func newUnit(id uint32) (u *unit) { return &unit{ mu: &sync.RWMutex{}, id: id, nResult: make([]uint64, resultLast), domains: make(map[string]uint64), blockedDomains: make(map[string]uint64), clients: make(map[string]uint64), } </s> remove // Open a DB transaction func (s *statsCtx) beginTxn(wr bool) *bolt.Tx { db := s.db </s> add // beginTxn opens a new database transaction. If writable is true, the // transaction will be opened for writing, and for reading otherwise. It // returns nil if the transaction can't be created. func beginTxn(db *bbolt.DB, writable bool) (tx *bbolt.Tx) { </s> remove // Delete unit's data from file func (s *statsCtx) deleteUnit(tx *bolt.Tx, id uint32) bool { </s> add // deleteUnit removes the unit by it's id from the database the tx belongs to. func (s *StatsCtx) deleteUnit(tx *bbolt.Tx, id uint32) bool { </s> remove func (s *statsCtx) dbOpen() bool { var err error </s> add // dbOpen returns an error if the database can't be opened from the specified // file. It's safe for concurrent use. func (s *StatsCtx) dbOpen() (err error) {
func (s *StatsCtx) periodicFlush() { for ptr := s.ongoing(); ptr != nil; ptr = s.ongoing() { id := s.unitIDGen() // Access the unit's ID with atomic to avoid locking the whole unit. if !s.isEnabled() || atomic.LoadUint32(&ptr.id) == id {
// This is important to do it inside DB lock, so the reader won't get inconsistent results. // . write the unit to DB // . remove the stale unit from DB // . unlock DB func (s *StatsCtx) periodicFlush() { for ptr := s.ongoing(); ptr != nil; ptr = s.ongoing() { id := s.unitIDGen() // Access the unit's ID with atomic to avoid locking the whole unit. if !s.isEnabled() || atomic.LoadUint32(&ptr.id) == id { func (s *StatsCtx) periodicFlush() { for ptr := s.ongoing(); ptr != nil; ptr = s.ongoing() { id := s.unitIDGen() // Access the unit's ID with atomic to avoid locking the whole unit. if !s.isEnabled() || atomic.LoadUint32(&ptr.id) == id { func (s *StatsCtx) periodicFlush() { for ptr := s.ongoing(); ptr != nil; ptr = s.ongoing() { id := s.unitIDGen() // Access the unit's ID with atomic to avoid locking the whole unit. if !s.isEnabled() || atomic.LoadUint32(&ptr.id) == id { func (s *StatsCtx) periodicFlush() { for ptr := s.ongoing(); ptr != nil; ptr = s.ongoing() { id := s.unitIDGen() // Access the unit's ID with atomic to avoid locking the whole unit. if !s.isEnabled() || atomic.LoadUint32(&ptr.id) == id { func (s *StatsCtx) periodicFlush() { for ptr := s.ongoing(); ptr != nil; ptr = s.ongoing() { id := s.unitIDGen() // Access the unit's ID with atomic to avoid locking the whole unit. if !s.isEnabled() || atomic.LoadUint32(&ptr.id) == id { func (s *StatsCtx) periodicFlush() { for ptr := s.ongoing(); ptr != nil; ptr = s.ongoing() { id := s.unitIDGen() // Access the unit's ID with atomic to avoid locking the whole unit. if !s.isEnabled() || atomic.LoadUint32(&ptr.id) == id { func (s *StatsCtx) periodicFlush() { for ptr := s.ongoing(); ptr != nil; ptr = s.ongoing() { id := s.unitIDGen() // Access the unit's ID with atomic to avoid locking the whole unit. if !s.isEnabled() || atomic.LoadUint32(&ptr.id) == id { func (s *StatsCtx) periodicFlush() { for ptr := s.ongoing(); ptr != nil; ptr = s.ongoing() { id := s.unitIDGen() // Access the unit's ID with atomic to avoid locking the whole unit. if !s.isEnabled() || atomic.LoadUint32(&ptr.id) == id { func (s *StatsCtx) periodicFlush() { for ptr := s.ongoing(); ptr != nil; ptr = s.ongoing() { id := s.unitIDGen() // Access the unit's ID with atomic to avoid locking the whole unit. if !s.isEnabled() || atomic.LoadUint32(&ptr.id) == id { time.Sleep(time.Second) continue }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
continue } tx := s.beginTxn(true) nu := unit{} s.initUnit(&nu, id) u := s.swapUnit(&nu) udb := serialize(u)
</s> remove nu := unit{} s.initUnit(&nu, id) u := s.swapUnit(&nu) udb := serialize(u) </s> add nu := newUnit(id) u := s.swapCurrent(nu) udb := u.serialize() </s> remove func (s *statsCtx) Close() { u := s.swapUnit(nil) udb := serialize(u) tx := s.beginTxn(true) if tx != nil { if s.flushUnitToDB(tx, u.id, udb) { </s> add func (s *StatsCtx) Close() { u := s.swapCurrent(nil) db := s.database() if tx := beginTxn(db, true); tx != nil { udb := u.serialize() if flushUnitToDB(tx, u.id, udb) { </s> remove u := unit{} s.initUnit(&u, id) if udb != nil { deserialize(&u, udb) } s.current = &u </s> add u := newUnit(id) // This use of deserialize is safe since the accessed unit has just been // created. u.deserialize(udb) s.curr = u </s> remove id := s.conf.UnitID() tx := s.beginTxn(true) </s> add id := s.unitIDGen() tx := beginTxn(s.db, true) </s> remove func (s *statsCtx) clear() { tx := s.beginTxn(true) </s> add func (s *StatsCtx) clear() { db := s.database() tx := beginTxn(db, true)
tx := beginTxn(s.database(), true)
continue } tx := beginTxn(s.database(), true) nu := unit{} s.initUnit(&nu, id) u := s.swapUnit(&nu) udb := serialize(u)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
} tx := s.beginTxn(true) nu := unit{} s.initUnit(&nu, id) u := s.swapUnit(&nu) udb := serialize(u) if tx == nil { continue }
</s> remove tx := s.beginTxn(true) </s> add tx := beginTxn(s.database(), true) </s> remove func (s *statsCtx) Close() { u := s.swapUnit(nil) udb := serialize(u) tx := s.beginTxn(true) if tx != nil { if s.flushUnitToDB(tx, u.id, udb) { </s> add func (s *StatsCtx) Close() { u := s.swapCurrent(nil) db := s.database() if tx := beginTxn(db, true); tx != nil { udb := u.serialize() if flushUnitToDB(tx, u.id, udb) { </s> remove id := s.conf.UnitID() tx := s.beginTxn(true) </s> add id := s.unitIDGen() tx := beginTxn(s.db, true) </s> remove func (s *statsCtx) clear() { tx := s.beginTxn(true) </s> add func (s *StatsCtx) clear() { db := s.database() tx := beginTxn(db, true) </s> remove u := unit{} s.initUnit(&u, id) if udb != nil { deserialize(&u, udb) } s.current = &u </s> add u := newUnit(id) // This use of deserialize is safe since the accessed unit has just been // created. u.deserialize(udb) s.curr = u
nu := newUnit(id) u := s.swapCurrent(nu) udb := u.serialize()
} tx := s.beginTxn(true) nu := newUnit(id) u := s.swapCurrent(nu) udb := u.serialize() nu := newUnit(id) u := s.swapCurrent(nu) udb := u.serialize() nu := newUnit(id) u := s.swapCurrent(nu) udb := u.serialize() nu := newUnit(id) u := s.swapCurrent(nu) udb := u.serialize() if tx == nil { continue }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
if tx == nil { continue } ok1 := s.flushUnitToDB(tx, u.id, udb) ok2 := s.deleteUnit(tx, id-s.conf.limit) if ok1 || ok2 { s.commitTxn(tx) } else { _ = tx.Rollback() } }
</s> remove func (s *statsCtx) Close() { u := s.swapUnit(nil) udb := serialize(u) tx := s.beginTxn(true) if tx != nil { if s.flushUnitToDB(tx, u.id, udb) { </s> add func (s *StatsCtx) Close() { u := s.swapCurrent(nil) db := s.database() if tx := beginTxn(db, true); tx != nil { udb := u.serialize() if flushUnitToDB(tx, u.id, udb) { </s> remove func (s *statsCtx) clear() { tx := s.beginTxn(true) </s> add func (s *StatsCtx) clear() { db := s.database() tx := beginTxn(db, true) </s> remove if s.db != nil { </s> add if db != nil { </s> remove nu := unit{} s.initUnit(&nu, id) u := s.swapUnit(&nu) udb := serialize(u) </s> add nu := newUnit(id) u := s.swapCurrent(nu) udb := u.serialize() </s> remove units, _ := s.loadUnits(s.conf.limit) </s> add units, _ := s.loadUnits(atomic.LoadUint32(&s.limitHours))
flushOK := flushUnitToDB(tx, u.id, udb) delOK := s.deleteUnit(tx, id-atomic.LoadUint32(&s.limitHours)) if flushOK || delOK {
if tx == nil { continue } flushOK := flushUnitToDB(tx, u.id, udb) delOK := s.deleteUnit(tx, id-atomic.LoadUint32(&s.limitHours)) if flushOK || delOK { flushOK := flushUnitToDB(tx, u.id, udb) delOK := s.deleteUnit(tx, id-atomic.LoadUint32(&s.limitHours)) if flushOK || delOK { flushOK := flushUnitToDB(tx, u.id, udb) delOK := s.deleteUnit(tx, id-atomic.LoadUint32(&s.limitHours)) if flushOK || delOK { s.commitTxn(tx) } else { _ = tx.Rollback() } }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
log.Tracef("periodicFlush() exited") } // Delete unit's data from file func (s *statsCtx) deleteUnit(tx *bolt.Tx, id uint32) bool { err := tx.DeleteBucket(idToUnitName(id)) if err != nil { log.Tracef("stats: bolt DeleteBucket: %s", err) return false
</s> remove func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id uint32, udb *unitDB) bool { </s> add func flushUnitToDB(tx *bbolt.Tx, id uint32, udb *unitDB) bool { </s> remove func (s *statsCtx) loadUnitFromDB(tx *bolt.Tx, id uint32) *unitDB { </s> add func (s *StatsCtx) loadUnitFromDB(tx *bbolt.Tx, id uint32) *unitDB { </s> remove log.Debug("tx.Commit: %s", err) </s> add log.Error("stats: committing a transaction: %s", err) </s> remove func (s *statsCtx) dbOpen() bool { var err error </s> add // dbOpen returns an error if the database can't be opened from the specified // file. It's safe for concurrent use. func (s *StatsCtx) dbOpen() (err error) { </s> remove log.Error("stats: open DB: %s: %s", s.conf.Filename, err) </s> add log.Error("stats: open DB: %s: %s", s.filename, err)
// deleteUnit removes the unit by it's id from the database the tx belongs to. func (s *StatsCtx) deleteUnit(tx *bbolt.Tx, id uint32) bool {
log.Tracef("periodicFlush() exited") } // deleteUnit removes the unit by it's id from the database the tx belongs to. func (s *StatsCtx) deleteUnit(tx *bbolt.Tx, id uint32) bool { // deleteUnit removes the unit by it's id from the database the tx belongs to. func (s *StatsCtx) deleteUnit(tx *bbolt.Tx, id uint32) bool { err := tx.DeleteBucket(idToUnitName(id)) if err != nil { log.Tracef("stats: bolt DeleteBucket: %s", err) return false
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
func convertMapToSlice(m map[string]uint64, max int) []countPair { a := []countPair{} for k, v := range m { pair := countPair{} pair.Name = k pair.Count = v a = append(a, pair) } less := func(i, j int) bool { return a[j].Count < a[i].Count } sort.Slice(a, less)
</s> remove ent := map[string]uint64{} ent[it.Name] = it.Count m = append(m, ent) </s> add m = append(m, map[string]uint64{it.Name: it.Count}) </s> remove func convertTopSlice(a []countPair) []map[string]uint64 { m := []map[string]uint64{} </s> add func convertTopSlice(a []countPair) (m []map[string]uint64) { m = make([]map[string]uint64, 0, len(a)) </s> remove func (s *statsCtx) setLimit(limitDays int) { s.conf.limit = uint32(limitDays) * 24 </s> add func (s *StatsCtx) setLimit(limitDays int) { atomic.StoreUint32(&s.limitHours, uint32(24*limitDays)) </s> remove for _, it := range pg(u) { m[it.Name] += it.Count </s> add for _, cp := range pg(u) { m[cp.Name] += cp.Count </s> remove // topsCollector collects statistics about highest values fro the given *unitDB </s> add // topsCollector collects statistics about highest values from the given *unitDB
a = append(a, countPair{Name: k, Count: v})
func convertMapToSlice(m map[string]uint64, max int) []countPair { a := []countPair{} for k, v := range m { a = append(a, countPair{Name: k, Count: v}) a = append(a, countPair{Name: k, Count: v}) a = append(a, countPair{Name: k, Count: v}) a = append(a, countPair{Name: k, Count: v}) } less := func(i, j int) bool { return a[j].Count < a[i].Count } sort.Slice(a, less)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
} return m } func serialize(u *unit) *unitDB { udb := unitDB{} udb.NTotal = u.nTotal udb.NResult = append(udb.NResult, u.nResult...) if u.nTotal != 0 { udb.TimeAvg = uint32(u.timeSum / u.nTotal) }
</s> remove udb.TimeAvg = uint32(u.timeSum / u.nTotal) </s> add timeAvg = uint32(u.timeSum / u.nTotal) </s> remove udb.Domains = convertMapToSlice(u.domains, maxDomains) udb.BlockedDomains = convertMapToSlice(u.blockedDomains, maxDomains) udb.Clients = convertMapToSlice(u.clients, maxClients) return &udb </s> add return &unitDB{ NTotal: u.nTotal, NResult: append([]uint64{}, u.nResult...), Domains: convertMapToSlice(u.domains, maxDomains), BlockedDomains: convertMapToSlice(u.blockedDomains, maxDomains), Clients: convertMapToSlice(u.clients, maxClients), TimeAvg: timeAvg, } </s> remove func deserialize(u *unit, udb *unitDB) { u.nTotal = udb.NTotal n := len(udb.NResult) if n < len(u.nResult) { n = len(u.nResult) // n = min(len(udb.NResult), len(u.nResult)) } for i := 1; i < n; i++ { u.nResult[i] = udb.NResult[i] </s> add // deserealize assigns the appropriate values from udb to u. u must not be nil. // It's safe for concurrent use. func (u *unit) deserialize(udb *unitDB) { if udb == nil { return </s> remove u.timeSum = uint64(udb.TimeAvg) * u.nTotal </s> add u.timeSum = uint64(udb.TimeAvg) * udb.NTotal
// serialize converts u to the *unitDB. It's safe for concurrent use. func (u *unit) serialize() (udb *unitDB) { u.mu.RLock() defer u.mu.RUnlock()
} return m } // serialize converts u to the *unitDB. It's safe for concurrent use. func (u *unit) serialize() (udb *unitDB) { u.mu.RLock() defer u.mu.RUnlock() // serialize converts u to the *unitDB. It's safe for concurrent use. func (u *unit) serialize() (udb *unitDB) { u.mu.RLock() defer u.mu.RUnlock() // serialize converts u to the *unitDB. It's safe for concurrent use. func (u *unit) serialize() (udb *unitDB) { u.mu.RLock() defer u.mu.RUnlock() // serialize converts u to the *unitDB. It's safe for concurrent use. func (u *unit) serialize() (udb *unitDB) { u.mu.RLock() defer u.mu.RUnlock() // serialize converts u to the *unitDB. It's safe for concurrent use. func (u *unit) serialize() (udb *unitDB) { u.mu.RLock() defer u.mu.RUnlock() if u.nTotal != 0 { udb.TimeAvg = uint32(u.timeSum / u.nTotal) }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
defer u.mu.RUnlock() if u.nTotal != 0 { timeAvg = uint32(u.timeSum / u.nTotal) } return &unitDB{ NTotal: u.nTotal,
</s> remove udb.Domains = convertMapToSlice(u.domains, maxDomains) udb.BlockedDomains = convertMapToSlice(u.blockedDomains, maxDomains) udb.Clients = convertMapToSlice(u.clients, maxClients) return &udb </s> add return &unitDB{ NTotal: u.nTotal, NResult: append([]uint64{}, u.nResult...), Domains: convertMapToSlice(u.domains, maxDomains), BlockedDomains: convertMapToSlice(u.blockedDomains, maxDomains), Clients: convertMapToSlice(u.clients, maxClients), TimeAvg: timeAvg, } </s> remove udb.TimeAvg = uint32(u.timeSum / u.nTotal) </s> add timeAvg = uint32(u.timeSum / u.nTotal) </s> remove func serialize(u *unit) *unitDB { udb := unitDB{} udb.NTotal = u.nTotal udb.NResult = append(udb.NResult, u.nResult...) </s> add // serialize converts u to the *unitDB. It's safe for concurrent use. func (u *unit) serialize() (udb *unitDB) { u.mu.RLock() defer u.mu.RUnlock() </s> remove log.Debug("stats: set limit: %d", limitDays) </s> add log.Debug("stats: set limit: %d days", limitDays)
var timeAvg uint32 = 0
defer u.mu.RUnlock() var timeAvg uint32 = 0 if u.nTotal != 0 { timeAvg = uint32(u.timeSum / u.nTotal) } return &unitDB{ NTotal: u.nTotal,
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
udb.NResult = append(udb.NResult, u.nResult...) if u.nTotal != 0 { udb.TimeAvg = uint32(u.timeSum / u.nTotal) } udb.Domains = convertMapToSlice(u.domains, maxDomains) udb.BlockedDomains = convertMapToSlice(u.blockedDomains, maxDomains) udb.Clients = convertMapToSlice(u.clients, maxClients)
</s> remove udb.Domains = convertMapToSlice(u.domains, maxDomains) udb.BlockedDomains = convertMapToSlice(u.blockedDomains, maxDomains) udb.Clients = convertMapToSlice(u.clients, maxClients) return &udb </s> add return &unitDB{ NTotal: u.nTotal, NResult: append([]uint64{}, u.nResult...), Domains: convertMapToSlice(u.domains, maxDomains), BlockedDomains: convertMapToSlice(u.blockedDomains, maxDomains), Clients: convertMapToSlice(u.clients, maxClients), TimeAvg: timeAvg, } </s> remove func serialize(u *unit) *unitDB { udb := unitDB{} udb.NTotal = u.nTotal udb.NResult = append(udb.NResult, u.nResult...) </s> add // serialize converts u to the *unitDB. It's safe for concurrent use. func (u *unit) serialize() (udb *unitDB) { u.mu.RLock() defer u.mu.RUnlock() </s> remove log.Debug("stats: set limit: %d", limitDays) </s> add log.Debug("stats: set limit: %d days", limitDays) </s> remove func (s *statsCtx) WriteDiskConfig(dc *DiskConfig) { dc.Interval = s.conf.limit / 24 </s> add func (s *StatsCtx) WriteDiskConfig(dc *DiskConfig) { dc.Interval = atomic.LoadUint32(&s.limitHours) / 24
timeAvg = uint32(u.timeSum / u.nTotal)
udb.NResult = append(udb.NResult, u.nResult...) if u.nTotal != 0 { timeAvg = uint32(u.timeSum / u.nTotal) } udb.Domains = convertMapToSlice(u.domains, maxDomains) udb.BlockedDomains = convertMapToSlice(u.blockedDomains, maxDomains) udb.Clients = convertMapToSlice(u.clients, maxClients)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
if u.nTotal != 0 { udb.TimeAvg = uint32(u.timeSum / u.nTotal) } udb.Domains = convertMapToSlice(u.domains, maxDomains) udb.BlockedDomains = convertMapToSlice(u.blockedDomains, maxDomains) udb.Clients = convertMapToSlice(u.clients, maxClients) return &udb } func deserialize(u *unit, udb *unitDB) { u.nTotal = udb.NTotal
</s> remove udb.TimeAvg = uint32(u.timeSum / u.nTotal) </s> add timeAvg = uint32(u.timeSum / u.nTotal) </s> remove func serialize(u *unit) *unitDB { udb := unitDB{} udb.NTotal = u.nTotal udb.NResult = append(udb.NResult, u.nResult...) </s> add // serialize converts u to the *unitDB. It's safe for concurrent use. func (u *unit) serialize() (udb *unitDB) { u.mu.RLock() defer u.mu.RUnlock() </s> remove func deserialize(u *unit, udb *unitDB) { u.nTotal = udb.NTotal n := len(udb.NResult) if n < len(u.nResult) { n = len(u.nResult) // n = min(len(udb.NResult), len(u.nResult)) } for i := 1; i < n; i++ { u.nResult[i] = udb.NResult[i] </s> add // deserealize assigns the appropriate values from udb to u. u must not be nil. // It's safe for concurrent use. func (u *unit) deserialize(udb *unitDB) { if udb == nil { return </s> remove u.timeSum = uint64(udb.TimeAvg) * u.nTotal </s> add u.timeSum = uint64(udb.TimeAvg) * udb.NTotal
return &unitDB{ NTotal: u.nTotal, NResult: append([]uint64{}, u.nResult...), Domains: convertMapToSlice(u.domains, maxDomains), BlockedDomains: convertMapToSlice(u.blockedDomains, maxDomains), Clients: convertMapToSlice(u.clients, maxClients), TimeAvg: timeAvg, }
if u.nTotal != 0 { udb.TimeAvg = uint32(u.timeSum / u.nTotal) } return &unitDB{ NTotal: u.nTotal, NResult: append([]uint64{}, u.nResult...), Domains: convertMapToSlice(u.domains, maxDomains), BlockedDomains: convertMapToSlice(u.blockedDomains, maxDomains), Clients: convertMapToSlice(u.clients, maxClients), TimeAvg: timeAvg, } return &unitDB{ NTotal: u.nTotal, NResult: append([]uint64{}, u.nResult...), Domains: convertMapToSlice(u.domains, maxDomains), BlockedDomains: convertMapToSlice(u.blockedDomains, maxDomains), Clients: convertMapToSlice(u.clients, maxClients), TimeAvg: timeAvg, } return &unitDB{ NTotal: u.nTotal, NResult: append([]uint64{}, u.nResult...), Domains: convertMapToSlice(u.domains, maxDomains), BlockedDomains: convertMapToSlice(u.blockedDomains, maxDomains), Clients: convertMapToSlice(u.clients, maxClients), TimeAvg: timeAvg, } return &unitDB{ NTotal: u.nTotal, NResult: append([]uint64{}, u.nResult...), Domains: convertMapToSlice(u.domains, maxDomains), BlockedDomains: convertMapToSlice(u.blockedDomains, maxDomains), Clients: convertMapToSlice(u.clients, maxClients), TimeAvg: timeAvg, } return &unitDB{ NTotal: u.nTotal, NResult: append([]uint64{}, u.nResult...), Domains: convertMapToSlice(u.domains, maxDomains), BlockedDomains: convertMapToSlice(u.blockedDomains, maxDomains), Clients: convertMapToSlice(u.clients, maxClients), TimeAvg: timeAvg, } } func deserialize(u *unit, udb *unitDB) { u.nTotal = udb.NTotal
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
return &udb } func deserialize(u *unit, udb *unitDB) { u.nTotal = udb.NTotal n := len(udb.NResult) if n < len(u.nResult) { n = len(u.nResult) // n = min(len(udb.NResult), len(u.nResult)) } for i := 1; i < n; i++ { u.nResult[i] = udb.NResult[i] } u.domains = convertSliceToMap(udb.Domains) u.blockedDomains = convertSliceToMap(udb.BlockedDomains) u.clients = convertSliceToMap(udb.Clients)
</s> remove u.timeSum = uint64(udb.TimeAvg) * u.nTotal </s> add u.timeSum = uint64(udb.TimeAvg) * udb.NTotal </s> remove udb.Domains = convertMapToSlice(u.domains, maxDomains) udb.BlockedDomains = convertMapToSlice(u.blockedDomains, maxDomains) udb.Clients = convertMapToSlice(u.clients, maxClients) return &udb </s> add return &unitDB{ NTotal: u.nTotal, NResult: append([]uint64{}, u.nResult...), Domains: convertMapToSlice(u.domains, maxDomains), BlockedDomains: convertMapToSlice(u.blockedDomains, maxDomains), Clients: convertMapToSlice(u.clients, maxClients), TimeAvg: timeAvg, } </s> remove u.NResult = make([]uint64, rLast) </s> add u.NResult = make([]uint64, resultLast) </s> remove curID := cur.id </s> add var curID uint32 if cur != nil { curID = atomic.LoadUint32(&cur.id) } else { curID = s.unitIDGen() }
// deserealize assigns the appropriate values from udb to u. u must not be nil. // It's safe for concurrent use. func (u *unit) deserialize(udb *unitDB) { if udb == nil { return
return &udb } // deserealize assigns the appropriate values from udb to u. u must not be nil. // It's safe for concurrent use. func (u *unit) deserialize(udb *unitDB) { if udb == nil { return // deserealize assigns the appropriate values from udb to u. u must not be nil. // It's safe for concurrent use. func (u *unit) deserialize(udb *unitDB) { if udb == nil { return // deserealize assigns the appropriate values from udb to u. u must not be nil. // It's safe for concurrent use. func (u *unit) deserialize(udb *unitDB) { if udb == nil { return // deserealize assigns the appropriate values from udb to u. u must not be nil. // It's safe for concurrent use. func (u *unit) deserialize(udb *unitDB) { if udb == nil { return // deserealize assigns the appropriate values from udb to u. u must not be nil. // It's safe for concurrent use. func (u *unit) deserialize(udb *unitDB) { if udb == nil { return // deserealize assigns the appropriate values from udb to u. u must not be nil. // It's safe for concurrent use. func (u *unit) deserialize(udb *unitDB) { if udb == nil { return // deserealize assigns the appropriate values from udb to u. u must not be nil. // It's safe for concurrent use. func (u *unit) deserialize(udb *unitDB) { if udb == nil { return // deserealize assigns the appropriate values from udb to u. u must not be nil. // It's safe for concurrent use. func (u *unit) deserialize(udb *unitDB) { if udb == nil { return // deserealize assigns the appropriate values from udb to u. u must not be nil. // It's safe for concurrent use. func (u *unit) deserialize(udb *unitDB) { if udb == nil { return } u.domains = convertSliceToMap(udb.Domains) u.blockedDomains = convertSliceToMap(udb.BlockedDomains) u.clients = convertSliceToMap(udb.Clients)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
} u.domains = convertSliceToMap(udb.Domains) u.blockedDomains = convertSliceToMap(udb.BlockedDomains) u.clients = convertSliceToMap(udb.Clients) u.timeSum = uint64(udb.TimeAvg) * udb.NTotal }
</s> remove u.timeSum = uint64(udb.TimeAvg) * u.nTotal </s> add u.timeSum = uint64(udb.TimeAvg) * udb.NTotal </s> remove func deserialize(u *unit, udb *unitDB) { u.nTotal = udb.NTotal n := len(udb.NResult) if n < len(u.nResult) { n = len(u.nResult) // n = min(len(udb.NResult), len(u.nResult)) } for i := 1; i < n; i++ { u.nResult[i] = udb.NResult[i] </s> add // deserealize assigns the appropriate values from udb to u. u must not be nil. // It's safe for concurrent use. func (u *unit) deserialize(udb *unitDB) { if udb == nil { return </s> remove func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id uint32, udb *unitDB) bool { </s> add func flushUnitToDB(tx *bbolt.Tx, id uint32, udb *unitDB) bool { </s> remove // Initialize a unit func (s *statsCtx) initUnit(u *unit, id uint32) { u.id = id u.nResult = make([]uint64, rLast) u.domains = make(map[string]uint64) u.blockedDomains = make(map[string]uint64) u.clients = make(map[string]uint64) </s> add // newUnit allocates the new *unit. func newUnit(id uint32) (u *unit) { return &unit{ mu: &sync.RWMutex{}, id: id, nResult: make([]uint64, resultLast), domains: make(map[string]uint64), blockedDomains: make(map[string]uint64), clients: make(map[string]uint64), } </s> remove if !checkInterval(conf.LimitDays) { conf.LimitDays = 1 </s> add if s.limitHours = conf.LimitDays * 24; !checkInterval(conf.LimitDays) { s.limitHours = 24
u.mu.Lock() defer u.mu.Unlock() u.nTotal = udb.NTotal u.nResult = make([]uint64, resultLast) copy(u.nResult, udb.NResult)
} u.mu.Lock() defer u.mu.Unlock() u.nTotal = udb.NTotal u.nResult = make([]uint64, resultLast) copy(u.nResult, udb.NResult) u.domains = convertSliceToMap(udb.Domains) u.blockedDomains = convertSliceToMap(udb.BlockedDomains) u.clients = convertSliceToMap(udb.Clients) u.timeSum = uint64(udb.TimeAvg) * udb.NTotal }
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
u.domains = convertSliceToMap(udb.Domains) u.blockedDomains = convertSliceToMap(udb.BlockedDomains) u.clients = convertSliceToMap(udb.Clients) u.timeSum = uint64(udb.TimeAvg) * u.nTotal } func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id uint32, udb *unitDB) bool { log.Tracef("Flushing unit %d", id)
</s> remove func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id uint32, udb *unitDB) bool { </s> add func flushUnitToDB(tx *bbolt.Tx, id uint32, udb *unitDB) bool { </s> remove func deserialize(u *unit, udb *unitDB) { u.nTotal = udb.NTotal n := len(udb.NResult) if n < len(u.nResult) { n = len(u.nResult) // n = min(len(udb.NResult), len(u.nResult)) } for i := 1; i < n; i++ { u.nResult[i] = udb.NResult[i] </s> add // deserealize assigns the appropriate values from udb to u. u must not be nil. // It's safe for concurrent use. func (u *unit) deserialize(udb *unitDB) { if udb == nil { return </s> remove // Initialize a unit func (s *statsCtx) initUnit(u *unit, id uint32) { u.id = id u.nResult = make([]uint64, rLast) u.domains = make(map[string]uint64) u.blockedDomains = make(map[string]uint64) u.clients = make(map[string]uint64) </s> add // newUnit allocates the new *unit. func newUnit(id uint32) (u *unit) { return &unit{ mu: &sync.RWMutex{}, id: id, nResult: make([]uint64, resultLast), domains: make(map[string]uint64), blockedDomains: make(map[string]uint64), clients: make(map[string]uint64), } </s> remove // Delete unit's data from file func (s *statsCtx) deleteUnit(tx *bolt.Tx, id uint32) bool { </s> add // deleteUnit removes the unit by it's id from the database the tx belongs to. func (s *StatsCtx) deleteUnit(tx *bbolt.Tx, id uint32) bool {
u.timeSum = uint64(udb.TimeAvg) * udb.NTotal
u.domains = convertSliceToMap(udb.Domains) u.blockedDomains = convertSliceToMap(udb.BlockedDomains) u.clients = convertSliceToMap(udb.Clients) u.timeSum = uint64(udb.TimeAvg) * udb.NTotal } func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id uint32, udb *unitDB) bool { log.Tracef("Flushing unit %d", id)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
u.clients = convertSliceToMap(udb.Clients) u.timeSum = uint64(udb.TimeAvg) * u.nTotal } func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id uint32, udb *unitDB) bool { log.Tracef("Flushing unit %d", id) bkt, err := tx.CreateBucketIfNotExists(idToUnitName(id)) if err != nil { log.Error("tx.CreateBucketIfNotExists: %s", err)
</s> remove u.timeSum = uint64(udb.TimeAvg) * u.nTotal </s> add u.timeSum = uint64(udb.TimeAvg) * udb.NTotal </s> remove // Delete unit's data from file func (s *statsCtx) deleteUnit(tx *bolt.Tx, id uint32) bool { </s> add // deleteUnit removes the unit by it's id from the database the tx belongs to. func (s *StatsCtx) deleteUnit(tx *bbolt.Tx, id uint32) bool { </s> remove log.Debug("tx.Commit: %s", err) </s> add log.Error("stats: committing a transaction: %s", err) </s> remove func deserialize(u *unit, udb *unitDB) { u.nTotal = udb.NTotal n := len(udb.NResult) if n < len(u.nResult) { n = len(u.nResult) // n = min(len(udb.NResult), len(u.nResult)) } for i := 1; i < n; i++ { u.nResult[i] = udb.NResult[i] </s> add // deserealize assigns the appropriate values from udb to u. u must not be nil. // It's safe for concurrent use. func (u *unit) deserialize(udb *unitDB) { if udb == nil { return
func flushUnitToDB(tx *bbolt.Tx, id uint32, udb *unitDB) bool {
u.clients = convertSliceToMap(udb.Clients) u.timeSum = uint64(udb.TimeAvg) * u.nTotal } func flushUnitToDB(tx *bbolt.Tx, id uint32, udb *unitDB) bool { log.Tracef("Flushing unit %d", id) bkt, err := tx.CreateBucketIfNotExists(idToUnitName(id)) if err != nil { log.Error("tx.CreateBucketIfNotExists: %s", err)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
return true } func (s *statsCtx) loadUnitFromDB(tx *bolt.Tx, id uint32) *unitDB { bkt := tx.Bucket(idToUnitName(id)) if bkt == nil { return nil }
</s> remove // Delete unit's data from file func (s *statsCtx) deleteUnit(tx *bolt.Tx, id uint32) bool { </s> add // deleteUnit removes the unit by it's id from the database the tx belongs to. func (s *StatsCtx) deleteUnit(tx *bbolt.Tx, id uint32) bool { </s> remove func (s *statsCtx) GetTopClientsIP(maxCount uint) []net.IP { if s.conf.limit == 0 { </s> add func (s *StatsCtx) GetTopClientsIP(maxCount uint) []net.IP { if !s.isEnabled() { </s> remove func (s *statsCtx) loadUnits(limit uint32) ([]*unitDB, uint32) { tx := s.beginTxn(false) </s> add func (s *StatsCtx) loadUnits(limit uint32) ([]*unitDB, uint32) { tx := beginTxn(s.database(), false) </s> remove if !s.dbOpen() { return nil, fmt.Errorf("open database") </s> add if err = s.dbOpen(); err != nil { return nil, fmt.Errorf("opening database: %w", err) </s> remove func (s *statsCtx) flushUnitToDB(tx *bolt.Tx, id uint32, udb *unitDB) bool { </s> add func flushUnitToDB(tx *bbolt.Tx, id uint32, udb *unitDB) bool {
func (s *StatsCtx) loadUnitFromDB(tx *bbolt.Tx, id uint32) *unitDB {
return true } func (s *StatsCtx) loadUnitFromDB(tx *bbolt.Tx, id uint32) *unitDB { bkt := tx.Bucket(idToUnitName(id)) if bkt == nil { return nil }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
return &udb } func convertTopSlice(a []countPair) []map[string]uint64 { m := []map[string]uint64{} for _, it := range a { ent := map[string]uint64{} ent[it.Name] = it.Count m = append(m, ent) }
</s> remove ent := map[string]uint64{} ent[it.Name] = it.Count m = append(m, ent) </s> add m = append(m, map[string]uint64{it.Name: it.Count}) </s> remove for _, it := range pg(u) { m[it.Name] += it.Count </s> add for _, cp := range pg(u) { m[cp.Name] += cp.Count </s> remove // topsCollector collects statistics about highest values fro the given *unitDB </s> add // topsCollector collects statistics about highest values from the given *unitDB </s> remove pair := countPair{} pair.Name = k pair.Count = v a = append(a, pair) </s> add a = append(a, countPair{Name: k, Count: v}) </s> remove NResult: make([]uint64, rLast), </s> add NResult: make([]uint64, resultLast),
func convertTopSlice(a []countPair) (m []map[string]uint64) { m = make([]map[string]uint64, 0, len(a))
return &udb } func convertTopSlice(a []countPair) (m []map[string]uint64) { m = make([]map[string]uint64, 0, len(a)) func convertTopSlice(a []countPair) (m []map[string]uint64) { m = make([]map[string]uint64, 0, len(a)) for _, it := range a { ent := map[string]uint64{} ent[it.Name] = it.Count m = append(m, ent) }
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
func convertTopSlice(a []countPair) []map[string]uint64 { m := []map[string]uint64{} for _, it := range a { ent := map[string]uint64{} ent[it.Name] = it.Count m = append(m, ent) } return m } func (s *statsCtx) setLimit(limitDays int) {
</s> remove func convertTopSlice(a []countPair) []map[string]uint64 { m := []map[string]uint64{} </s> add func convertTopSlice(a []countPair) (m []map[string]uint64) { m = make([]map[string]uint64, 0, len(a)) </s> remove for _, it := range pg(u) { m[it.Name] += it.Count </s> add for _, cp := range pg(u) { m[cp.Name] += cp.Count </s> remove // topsCollector collects statistics about highest values fro the given *unitDB </s> add // topsCollector collects statistics about highest values from the given *unitDB </s> remove func (s *statsCtx) setLimit(limitDays int) { s.conf.limit = uint32(limitDays) * 24 </s> add func (s *StatsCtx) setLimit(limitDays int) { atomic.StoreUint32(&s.limitHours, uint32(24*limitDays)) </s> remove pair := countPair{} pair.Name = k pair.Count = v a = append(a, pair) </s> add a = append(a, countPair{Name: k, Count: v})
m = append(m, map[string]uint64{it.Name: it.Count})
func convertTopSlice(a []countPair) []map[string]uint64 { m := []map[string]uint64{} for _, it := range a { m = append(m, map[string]uint64{it.Name: it.Count}) m = append(m, map[string]uint64{it.Name: it.Count}) m = append(m, map[string]uint64{it.Name: it.Count}) } return m } func (s *statsCtx) setLimit(limitDays int) {
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
} return m } func (s *statsCtx) setLimit(limitDays int) { s.conf.limit = uint32(limitDays) * 24 if limitDays == 0 { s.clear() } log.Debug("stats: set limit: %d", limitDays)
</s> remove log.Debug("stats: set limit: %d", limitDays) </s> add log.Debug("stats: set limit: %d days", limitDays) </s> remove func (s *statsCtx) WriteDiskConfig(dc *DiskConfig) { dc.Interval = s.conf.limit / 24 </s> add func (s *StatsCtx) WriteDiskConfig(dc *DiskConfig) { dc.Interval = atomic.LoadUint32(&s.limitHours) / 24 </s> remove ent := map[string]uint64{} ent[it.Name] = it.Count m = append(m, ent) </s> add m = append(m, map[string]uint64{it.Name: it.Count}) </s> remove func (s *statsCtx) Update(e Entry) { if s.conf.limit == 0 { </s> add func (s *StatsCtx) Update(e Entry) { if !s.isEnabled() { </s> remove if !checkInterval(conf.LimitDays) { conf.LimitDays = 1 </s> add if s.limitHours = conf.LimitDays * 24; !checkInterval(conf.LimitDays) { s.limitHours = 24
func (s *StatsCtx) setLimit(limitDays int) { atomic.StoreUint32(&s.limitHours, uint32(24*limitDays))
} return m } func (s *StatsCtx) setLimit(limitDays int) { atomic.StoreUint32(&s.limitHours, uint32(24*limitDays)) func (s *StatsCtx) setLimit(limitDays int) { atomic.StoreUint32(&s.limitHours, uint32(24*limitDays)) if limitDays == 0 { s.clear() } log.Debug("stats: set limit: %d", limitDays)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
if limitDays == 0 { s.clear() } log.Debug("stats: set limit: %d", limitDays) } func (s *statsCtx) WriteDiskConfig(dc *DiskConfig) { dc.Interval = s.conf.limit / 24 }
</s> remove func (s *statsCtx) WriteDiskConfig(dc *DiskConfig) { dc.Interval = s.conf.limit / 24 </s> add func (s *StatsCtx) WriteDiskConfig(dc *DiskConfig) { dc.Interval = atomic.LoadUint32(&s.limitHours) / 24 </s> remove func (s *statsCtx) setLimit(limitDays int) { s.conf.limit = uint32(limitDays) * 24 </s> add func (s *StatsCtx) setLimit(limitDays int) { atomic.StoreUint32(&s.limitHours, uint32(24*limitDays)) </s> remove func (s *statsCtx) Close() { u := s.swapUnit(nil) udb := serialize(u) tx := s.beginTxn(true) if tx != nil { if s.flushUnitToDB(tx, u.id, udb) { </s> add func (s *StatsCtx) Close() { u := s.swapCurrent(nil) db := s.database() if tx := beginTxn(db, true); tx != nil { udb := u.serialize() if flushUnitToDB(tx, u.id, udb) { </s> remove func (s *statsCtx) Update(e Entry) { if s.conf.limit == 0 { </s> add func (s *StatsCtx) Update(e Entry) { if !s.isEnabled() { </s> remove func (s *statsCtx) GetTopClientsIP(maxCount uint) []net.IP { if s.conf.limit == 0 { </s> add func (s *StatsCtx) GetTopClientsIP(maxCount uint) []net.IP { if !s.isEnabled() {
log.Debug("stats: set limit: %d days", limitDays)
if limitDays == 0 { s.clear() } log.Debug("stats: set limit: %d days", limitDays) } func (s *statsCtx) WriteDiskConfig(dc *DiskConfig) { dc.Interval = s.conf.limit / 24 }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
log.Debug("stats: set limit: %d", limitDays) } func (s *statsCtx) WriteDiskConfig(dc *DiskConfig) { dc.Interval = s.conf.limit / 24 } func (s *statsCtx) Close() { u := s.swapUnit(nil) udb := serialize(u)
</s> remove log.Debug("stats: set limit: %d", limitDays) </s> add log.Debug("stats: set limit: %d days", limitDays) </s> remove func (s *statsCtx) Close() { u := s.swapUnit(nil) udb := serialize(u) tx := s.beginTxn(true) if tx != nil { if s.flushUnitToDB(tx, u.id, udb) { </s> add func (s *StatsCtx) Close() { u := s.swapCurrent(nil) db := s.database() if tx := beginTxn(db, true); tx != nil { udb := u.serialize() if flushUnitToDB(tx, u.id, udb) { </s> remove func (s *statsCtx) setLimit(limitDays int) { s.conf.limit = uint32(limitDays) * 24 </s> add func (s *StatsCtx) setLimit(limitDays int) { atomic.StoreUint32(&s.limitHours, uint32(24*limitDays)) </s> remove func (s *statsCtx) handleStatsInfo(w http.ResponseWriter, r *http.Request) { </s> add func (s *StatsCtx) handleStatsInfo(w http.ResponseWriter, r *http.Request) { </s> remove resp.IntervalDays = s.conf.limit / 24 </s> add resp.IntervalDays = s.limitHours / 24
func (s *StatsCtx) WriteDiskConfig(dc *DiskConfig) { dc.Interval = atomic.LoadUint32(&s.limitHours) / 24
log.Debug("stats: set limit: %d", limitDays) } func (s *StatsCtx) WriteDiskConfig(dc *DiskConfig) { dc.Interval = atomic.LoadUint32(&s.limitHours) / 24 func (s *StatsCtx) WriteDiskConfig(dc *DiskConfig) { dc.Interval = atomic.LoadUint32(&s.limitHours) / 24 } func (s *statsCtx) Close() { u := s.swapUnit(nil) udb := serialize(u)
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
func (s *statsCtx) WriteDiskConfig(dc *DiskConfig) { dc.Interval = s.conf.limit / 24 } func (s *statsCtx) Close() { u := s.swapUnit(nil) udb := serialize(u) tx := s.beginTxn(true) if tx != nil { if s.flushUnitToDB(tx, u.id, udb) { s.commitTxn(tx) } else { _ = tx.Rollback() } }
</s> remove func (s *statsCtx) WriteDiskConfig(dc *DiskConfig) { dc.Interval = s.conf.limit / 24 </s> add func (s *StatsCtx) WriteDiskConfig(dc *DiskConfig) { dc.Interval = atomic.LoadUint32(&s.limitHours) / 24 </s> remove ok1 := s.flushUnitToDB(tx, u.id, udb) ok2 := s.deleteUnit(tx, id-s.conf.limit) if ok1 || ok2 { </s> add flushOK := flushUnitToDB(tx, u.id, udb) delOK := s.deleteUnit(tx, id-atomic.LoadUint32(&s.limitHours)) if flushOK || delOK { </s> remove log.Debug("stats: set limit: %d", limitDays) </s> add log.Debug("stats: set limit: %d days", limitDays) </s> remove nu := unit{} s.initUnit(&nu, id) u := s.swapUnit(&nu) udb := serialize(u) </s> add nu := newUnit(id) u := s.swapCurrent(nu) udb := u.serialize() </s> remove func (s *statsCtx) clear() { tx := s.beginTxn(true) </s> add func (s *StatsCtx) clear() { db := s.database() tx := beginTxn(db, true)
func (s *StatsCtx) Close() { u := s.swapCurrent(nil) db := s.database() if tx := beginTxn(db, true); tx != nil { udb := u.serialize() if flushUnitToDB(tx, u.id, udb) {
func (s *statsCtx) WriteDiskConfig(dc *DiskConfig) { dc.Interval = s.conf.limit / 24 } func (s *StatsCtx) Close() { u := s.swapCurrent(nil) db := s.database() if tx := beginTxn(db, true); tx != nil { udb := u.serialize() if flushUnitToDB(tx, u.id, udb) { func (s *StatsCtx) Close() { u := s.swapCurrent(nil) db := s.database() if tx := beginTxn(db, true); tx != nil { udb := u.serialize() if flushUnitToDB(tx, u.id, udb) { func (s *StatsCtx) Close() { u := s.swapCurrent(nil) db := s.database() if tx := beginTxn(db, true); tx != nil { udb := u.serialize() if flushUnitToDB(tx, u.id, udb) { func (s *StatsCtx) Close() { u := s.swapCurrent(nil) db := s.database() if tx := beginTxn(db, true); tx != nil { udb := u.serialize() if flushUnitToDB(tx, u.id, udb) { func (s *StatsCtx) Close() { u := s.swapCurrent(nil) db := s.database() if tx := beginTxn(db, true); tx != nil { udb := u.serialize() if flushUnitToDB(tx, u.id, udb) { func (s *StatsCtx) Close() { u := s.swapCurrent(nil) db := s.database() if tx := beginTxn(db, true); tx != nil { udb := u.serialize() if flushUnitToDB(tx, u.id, udb) { s.commitTxn(tx) } else { _ = tx.Rollback() } }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
_ = tx.Rollback() } } if s.db != nil { log.Tracef("db.Close...") _ = s.db.Close() log.Tracef("db.Close") }
</s> remove _ = s.db.Close() </s> add _ = db.Close() </s> remove db := s.db s.db = nil </s> add _ = s.swapDatabase(nil) </s> remove units = append(units, serialize(cur)) </s> add if cur != nil { units = append(units, cur.serialize()) } </s> remove u := unit{} s.initUnit(&u, s.conf.UnitID()) _ = s.swapUnit(&u) </s> add u := newUnit(s.unitIDGen()) _ = s.swapCurrent(u) </s> remove func (s *statsCtx) clear() { tx := s.beginTxn(true) </s> add func (s *StatsCtx) clear() { db := s.database() tx := beginTxn(db, true)
if db != nil {
_ = tx.Rollback() } } if db != nil { log.Tracef("db.Close...") _ = s.db.Close() log.Tracef("db.Close") }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
} if s.db != nil { log.Tracef("db.Close...") _ = s.db.Close() log.Tracef("db.Close") } log.Debug("stats: closed") }
</s> remove if s.db != nil { </s> add if db != nil { </s> remove func (s *statsCtx) clear() { tx := s.beginTxn(true) </s> add func (s *StatsCtx) clear() { db := s.database() tx := beginTxn(db, true) </s> remove u := unit{} s.initUnit(&u, s.conf.UnitID()) _ = s.swapUnit(&u) </s> add u := newUnit(s.unitIDGen()) _ = s.swapCurrent(u) </s> remove db := s.db s.db = nil </s> add _ = s.swapDatabase(nil) </s> remove units = append(units, serialize(cur)) </s> add if cur != nil { units = append(units, cur.serialize()) }
_ = db.Close()
} if s.db != nil { log.Tracef("db.Close...") _ = db.Close() log.Tracef("db.Close") } log.Debug("stats: closed") }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
log.Debug("stats: closed") } // Reset counters and clear database func (s *statsCtx) clear() { tx := s.beginTxn(true) if tx != nil { db := s.db s.db = nil _ = tx.Rollback() // the active transactions can continue using database,
</s> remove db := s.db s.db = nil </s> add _ = s.swapDatabase(nil) </s> remove _ = s.db.Close() </s> add _ = db.Close() </s> remove if s.db != nil { </s> add if db != nil { </s> remove func (s *statsCtx) Close() { u := s.swapUnit(nil) udb := serialize(u) tx := s.beginTxn(true) if tx != nil { if s.flushUnitToDB(tx, u.id, udb) { </s> add func (s *StatsCtx) Close() { u := s.swapCurrent(nil) db := s.database() if tx := beginTxn(db, true); tx != nil { udb := u.serialize() if flushUnitToDB(tx, u.id, udb) { </s> remove // Open a DB transaction func (s *statsCtx) beginTxn(wr bool) *bolt.Tx { db := s.db </s> add // beginTxn opens a new database transaction. If writable is true, the // transaction will be opened for writing, and for reading otherwise. It // returns nil if the transaction can't be created. func beginTxn(db *bbolt.DB, writable bool) (tx *bbolt.Tx) {
func (s *StatsCtx) clear() { db := s.database() tx := beginTxn(db, true)
log.Debug("stats: closed") } // Reset counters and clear database func (s *StatsCtx) clear() { db := s.database() tx := beginTxn(db, true) func (s *StatsCtx) clear() { db := s.database() tx := beginTxn(db, true) if tx != nil { db := s.db s.db = nil _ = tx.Rollback() // the active transactions can continue using database,
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
// Reset counters and clear database func (s *statsCtx) clear() { tx := s.beginTxn(true) if tx != nil { db := s.db s.db = nil _ = tx.Rollback() // the active transactions can continue using database, // but no new transactions will be opened _ = db.Close() log.Tracef("db.Close")
</s> remove func (s *statsCtx) clear() { tx := s.beginTxn(true) </s> add func (s *StatsCtx) clear() { db := s.database() tx := beginTxn(db, true) </s> remove if s.db != nil { </s> add if db != nil { </s> remove // Open a DB transaction func (s *statsCtx) beginTxn(wr bool) *bolt.Tx { db := s.db </s> add // beginTxn opens a new database transaction. If writable is true, the // transaction will be opened for writing, and for reading otherwise. It // returns nil if the transaction can't be created. func beginTxn(db *bbolt.DB, writable bool) (tx *bbolt.Tx) { </s> remove u := unit{} s.initUnit(&u, s.conf.UnitID()) _ = s.swapUnit(&u) </s> add u := newUnit(s.unitIDGen()) _ = s.swapCurrent(u) </s> remove _ = s.db.Close() </s> add _ = db.Close()
_ = s.swapDatabase(nil)
// Reset counters and clear database func (s *statsCtx) clear() { tx := s.beginTxn(true) if tx != nil { _ = s.swapDatabase(nil) _ = s.swapDatabase(nil) _ = tx.Rollback() // the active transactions can continue using database, // but no new transactions will be opened _ = db.Close() log.Tracef("db.Close")
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
log.Tracef("db.Close") // all active transactions are now closed } u := unit{} s.initUnit(&u, s.conf.UnitID()) _ = s.swapUnit(&u) err := os.Remove(s.conf.Filename) if err != nil { log.Error("os.Remove: %s", err) }
</s> remove err := os.Remove(s.conf.Filename) </s> add err := os.Remove(s.filename) </s> remove db := s.db s.db = nil </s> add _ = s.swapDatabase(nil) </s> remove u := unit{} s.initUnit(&u, id) if udb != nil { deserialize(&u, udb) } s.current = &u </s> add u := newUnit(id) // This use of deserialize is safe since the accessed unit has just been // created. u.deserialize(udb) s.curr = u </s> remove log.Error("db.Begin: %s", err) </s> add log.Error("stats: opening a transaction: %s", err) </s> remove log.Debug("tx.Commit: %s", err) </s> add log.Error("stats: committing a transaction: %s", err)
u := newUnit(s.unitIDGen()) _ = s.swapCurrent(u)
log.Tracef("db.Close") // all active transactions are now closed } u := newUnit(s.unitIDGen()) _ = s.swapCurrent(u) u := newUnit(s.unitIDGen()) _ = s.swapCurrent(u) u := newUnit(s.unitIDGen()) _ = s.swapCurrent(u) err := os.Remove(s.conf.Filename) if err != nil { log.Error("os.Remove: %s", err) }
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
u := unit{} s.initUnit(&u, s.conf.UnitID()) _ = s.swapUnit(&u) err := os.Remove(s.conf.Filename) if err != nil { log.Error("os.Remove: %s", err) } _ = s.dbOpen()
</s> remove u := unit{} s.initUnit(&u, s.conf.UnitID()) _ = s.swapUnit(&u) </s> add u := newUnit(s.unitIDGen()) _ = s.swapCurrent(u) </s> remove log.Error("db.Begin: %s", err) </s> add log.Error("stats: opening a transaction: %s", err) </s> remove log.Debug("tx.Commit: %s", err) </s> add log.Error("stats: committing a transaction: %s", err) </s> remove u := unit{} s.initUnit(&u, id) if udb != nil { deserialize(&u, udb) } s.current = &u </s> add u := newUnit(id) // This use of deserialize is safe since the accessed unit has just been // created. u.deserialize(udb) s.curr = u </s> remove ) (f func(name []byte, b *bolt.Bucket) (err error)) { return func(name []byte, _ *bolt.Bucket) (err error) { </s> add ) (f func(name []byte, b *bbolt.Bucket) (err error)) { return func(name []byte, _ *bbolt.Bucket) (err error) {
err := os.Remove(s.filename)
u := unit{} s.initUnit(&u, s.conf.UnitID()) _ = s.swapUnit(&u) err := os.Remove(s.filename) if err != nil { log.Error("os.Remove: %s", err) } _ = s.dbOpen()
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
log.Debug("stats: cleared") } func (s *statsCtx) Update(e Entry) { if s.conf.limit == 0 { return } if e.Result == 0 || e.Result >= rLast ||
</s> remove e.Result >= rLast || </s> add e.Result >= resultLast || </s> remove func checkInterval(days uint32) bool { </s> add // checkInterval returns true if days is valid to be used as statistics // retention interval. The valid values are 0, 1, 7, 30 and 90. func checkInterval(days uint32) (ok bool) { </s> remove func (s *statsCtx) dbOpen() bool { var err error </s> add // dbOpen returns an error if the database can't be opened from the specified // file. It's safe for concurrent use. func (s *StatsCtx) dbOpen() (err error) { </s> remove log.Debug("stats: set limit: %d", limitDays) </s> add log.Debug("stats: set limit: %d days", limitDays) </s> remove func (s *statsCtx) setLimit(limitDays int) { s.conf.limit = uint32(limitDays) * 24 </s> add func (s *StatsCtx) setLimit(limitDays int) { atomic.StoreUint32(&s.limitHours, uint32(24*limitDays))
func (s *StatsCtx) Update(e Entry) { if !s.isEnabled() {
log.Debug("stats: cleared") } func (s *StatsCtx) Update(e Entry) { if !s.isEnabled() { func (s *StatsCtx) Update(e Entry) { if !s.isEnabled() { return } if e.Result == 0 || e.Result >= rLast ||
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
return } if e.Result == 0 || e.Result >= rLast || e.Domain == "" || e.Client == "" { return }
</s> remove func (s *statsCtx) Update(e Entry) { if s.conf.limit == 0 { </s> add func (s *StatsCtx) Update(e Entry) { if !s.isEnabled() { </s> remove func checkInterval(days uint32) bool { </s> add // checkInterval returns true if days is valid to be used as statistics // retention interval. The valid values are 0, 1, 7, 30 and 90. func checkInterval(days uint32) (ok bool) { </s> remove func (s *statsCtx) dbOpen() bool { var err error </s> add // dbOpen returns an error if the database can't be opened from the specified // file. It's safe for concurrent use. func (s *StatsCtx) dbOpen() (err error) { </s> remove ok1 := s.flushUnitToDB(tx, u.id, udb) ok2 := s.deleteUnit(tx, id-s.conf.limit) if ok1 || ok2 { </s> add flushOK := flushUnitToDB(tx, u.id, udb) delOK := s.deleteUnit(tx, id-atomic.LoadUint32(&s.limitHours)) if flushOK || delOK { </s> remove func (s *statsCtx) periodicFlush() { for { ptr := s.ongoing() if ptr == nil { break } id := s.conf.UnitID() if ptr.id == id || s.conf.limit == 0 { </s> add func (s *StatsCtx) periodicFlush() { for ptr := s.ongoing(); ptr != nil; ptr = s.ongoing() { id := s.unitIDGen() // Access the unit's ID with atomic to avoid locking the whole unit. if !s.isEnabled() || atomic.LoadUint32(&ptr.id) == id {
e.Result >= resultLast ||
return } if e.Result == 0 || e.Result >= resultLast || e.Domain == "" || e.Client == "" { return }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
if ip := net.ParseIP(clientID); ip != nil { clientID = ip.String() } s.mu.Lock() defer s.mu.Unlock() u := s.current u.nResult[e.Result]++
</s> remove u := s.current </s> add u.mu.Lock() defer u.mu.Unlock() </s> remove u = s.current s.current = new </s> add log.Tracef("db.Open") </s> remove // Atomically swap the currently active unit with a new value // Return old value func (s *statsCtx) swapUnit(new *unit) (u *unit) { s.mu.Lock() defer s.mu.Unlock() </s> add return err } </s> remove u := unit{} s.initUnit(&u, id) if udb != nil { deserialize(&u, udb) } s.current = &u </s> add u := newUnit(id) // This use of deserialize is safe since the accessed unit has just been // created. u.deserialize(udb) s.curr = u </s> remove return u </s> add return nil
u := s.ongoing() if u == nil { return }
if ip := net.ParseIP(clientID); ip != nil { clientID = ip.String() } u := s.ongoing() if u == nil { return } u := s.ongoing() if u == nil { return } u := s.current u.nResult[e.Result]++
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
s.mu.Lock() defer s.mu.Unlock() u := s.current u.nResult[e.Result]++ if e.Result == RNotFiltered { u.domains[e.Domain]++
</s> remove s.mu.Lock() defer s.mu.Unlock() </s> add u := s.ongoing() if u == nil { return } </s> remove u = s.current s.current = new </s> add log.Tracef("db.Open") </s> remove // Atomically swap the currently active unit with a new value // Return old value func (s *statsCtx) swapUnit(new *unit) (u *unit) { s.mu.Lock() defer s.mu.Unlock() </s> add return err } </s> remove e.Result >= rLast || </s> add e.Result >= resultLast || </s> remove func (s *statsCtx) Update(e Entry) { if s.conf.limit == 0 { </s> add func (s *StatsCtx) Update(e Entry) { if !s.isEnabled() {
u.mu.Lock() defer u.mu.Unlock()
s.mu.Lock() defer s.mu.Unlock() u.mu.Lock() defer u.mu.Unlock() u.nResult[e.Result]++ if e.Result == RNotFiltered { u.domains[e.Domain]++
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
u.timeSum += uint64(e.Time) u.nTotal++ } func (s *statsCtx) loadUnits(limit uint32) ([]*unitDB, uint32) { tx := s.beginTxn(false) if tx == nil { return nil, 0 } cur := s.ongoing()
</s> remove curID := cur.id </s> add var curID uint32 if cur != nil { curID = atomic.LoadUint32(&cur.id) } else { curID = s.unitIDGen() } </s> remove func (s *statsCtx) loadUnitFromDB(tx *bolt.Tx, id uint32) *unitDB { </s> add func (s *StatsCtx) loadUnitFromDB(tx *bbolt.Tx, id uint32) *unitDB { </s> remove id := s.conf.UnitID() tx := s.beginTxn(true) </s> add id := s.unitIDGen() tx := beginTxn(s.db, true) </s> remove func (s *statsCtx) Close() { u := s.swapUnit(nil) udb := serialize(u) tx := s.beginTxn(true) if tx != nil { if s.flushUnitToDB(tx, u.id, udb) { </s> add func (s *StatsCtx) Close() { u := s.swapCurrent(nil) db := s.database() if tx := beginTxn(db, true); tx != nil { udb := u.serialize() if flushUnitToDB(tx, u.id, udb) { </s> remove if !s.dbOpen() { return nil, fmt.Errorf("open database") </s> add if err = s.dbOpen(); err != nil { return nil, fmt.Errorf("opening database: %w", err)
func (s *StatsCtx) loadUnits(limit uint32) ([]*unitDB, uint32) { tx := beginTxn(s.database(), false)
u.timeSum += uint64(e.Time) u.nTotal++ } func (s *StatsCtx) loadUnits(limit uint32) ([]*unitDB, uint32) { tx := beginTxn(s.database(), false) func (s *StatsCtx) loadUnits(limit uint32) ([]*unitDB, uint32) { tx := beginTxn(s.database(), false) if tx == nil { return nil, 0 } cur := s.ongoing()
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
return nil, 0 } cur := s.ongoing() curID := cur.id // Per-hour units. units := []*unitDB{} firstID := curID - limit + 1 for i := firstID; i != curID; i++ {
</s> remove u.NResult = make([]uint64, rLast) </s> add u.NResult = make([]uint64, resultLast) </s> remove id := s.conf.UnitID() tx := s.beginTxn(true) </s> add id := s.unitIDGen() tx := beginTxn(s.db, true) </s> remove func (s *statsCtx) loadUnits(limit uint32) ([]*unitDB, uint32) { tx := s.beginTxn(false) </s> add func (s *StatsCtx) loadUnits(limit uint32) ([]*unitDB, uint32) { tx := beginTxn(s.database(), false) </s> remove firstID := id - s.conf.limit - 1 </s> add firstID := id - s.limitHours - 1 </s> remove func deserialize(u *unit, udb *unitDB) { u.nTotal = udb.NTotal n := len(udb.NResult) if n < len(u.nResult) { n = len(u.nResult) // n = min(len(udb.NResult), len(u.nResult)) } for i := 1; i < n; i++ { u.nResult[i] = udb.NResult[i] </s> add // deserealize assigns the appropriate values from udb to u. u must not be nil. // It's safe for concurrent use. func (u *unit) deserialize(udb *unitDB) { if udb == nil { return
var curID uint32 if cur != nil { curID = atomic.LoadUint32(&cur.id) } else { curID = s.unitIDGen() }
return nil, 0 } cur := s.ongoing() var curID uint32 if cur != nil { curID = atomic.LoadUint32(&cur.id) } else { curID = s.unitIDGen() } // Per-hour units. units := []*unitDB{} firstID := curID - limit + 1 for i := firstID; i != curID; i++ {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
for i := firstID; i != curID; i++ { u := s.loadUnitFromDB(tx, i) if u == nil { u = &unitDB{} u.NResult = make([]uint64, rLast) } units = append(units, u) } _ = tx.Rollback()
</s> remove curID := cur.id </s> add var curID uint32 if cur != nil { curID = atomic.LoadUint32(&cur.id) } else { curID = s.unitIDGen() } </s> remove units = append(units, serialize(cur)) </s> add if cur != nil { units = append(units, cur.serialize()) } </s> remove func deserialize(u *unit, udb *unitDB) { u.nTotal = udb.NTotal n := len(udb.NResult) if n < len(u.nResult) { n = len(u.nResult) // n = min(len(udb.NResult), len(u.nResult)) } for i := 1; i < n; i++ { u.nResult[i] = udb.NResult[i] </s> add // deserealize assigns the appropriate values from udb to u. u must not be nil. // It's safe for concurrent use. func (u *unit) deserialize(udb *unitDB) { if udb == nil { return </s> remove s.mu.Lock() defer s.mu.Unlock() </s> add u := s.ongoing() if u == nil { return } </s> remove NResult: make([]uint64, rLast), </s> add NResult: make([]uint64, resultLast),
u.NResult = make([]uint64, resultLast)
for i := firstID; i != curID; i++ { u := s.loadUnitFromDB(tx, i) if u == nil { u = &unitDB{} u.NResult = make([]uint64, resultLast) } units = append(units, u) } _ = tx.Rollback()
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
} _ = tx.Rollback() units = append(units, serialize(cur)) if len(units) != int(limit) { log.Fatalf("len(units) != limit: %d %d", len(units), limit) }
</s> remove u.NResult = make([]uint64, rLast) </s> add u.NResult = make([]uint64, resultLast) </s> remove log.Debug("stats: set limit: %d", limitDays) </s> add log.Debug("stats: set limit: %d days", limitDays) </s> remove if s.db != nil { </s> add if db != nil { </s> remove func (s *statsCtx) setLimit(limitDays int) { s.conf.limit = uint32(limitDays) * 24 </s> add func (s *StatsCtx) setLimit(limitDays int) { atomic.StoreUint32(&s.limitHours, uint32(24*limitDays)) </s> remove _ = s.db.Close() </s> add _ = db.Close()
if cur != nil { units = append(units, cur.serialize()) }
} _ = tx.Rollback() if cur != nil { units = append(units, cur.serialize()) } if len(units) != int(limit) { log.Fatalf("len(units) != limit: %d %d", len(units), limit) }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
// pairsGetter is a signature for topsCollector argument. type pairsGetter func(u *unitDB) (pairs []countPair) // topsCollector collects statistics about highest values fro the given *unitDB // slice using pg to retrieve data. func topsCollector(units []*unitDB, max int, pg pairsGetter) []map[string]uint64 { m := map[string]uint64{} for _, u := range units { for _, it := range pg(u) {
</s> remove for _, it := range pg(u) { m[it.Name] += it.Count </s> add for _, cp := range pg(u) { m[cp.Name] += cp.Count </s> remove func convertTopSlice(a []countPair) []map[string]uint64 { m := []map[string]uint64{} </s> add func convertTopSlice(a []countPair) (m []map[string]uint64) { m = make([]map[string]uint64, 0, len(a)) </s> remove ent := map[string]uint64{} ent[it.Name] = it.Count m = append(m, ent) </s> add m = append(m, map[string]uint64{it.Name: it.Count}) </s> remove NResult: make([]uint64, rLast), </s> add NResult: make([]uint64, resultLast), </s> remove pair := countPair{} pair.Name = k pair.Count = v a = append(a, pair) </s> add a = append(a, countPair{Name: k, Count: v})
// topsCollector collects statistics about highest values from the given *unitDB
// pairsGetter is a signature for topsCollector argument. type pairsGetter func(u *unitDB) (pairs []countPair) // topsCollector collects statistics about highest values from the given *unitDB // slice using pg to retrieve data. func topsCollector(units []*unitDB, max int, pg pairsGetter) []map[string]uint64 { m := map[string]uint64{} for _, u := range units { for _, it := range pg(u) {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
// slice using pg to retrieve data. func topsCollector(units []*unitDB, max int, pg pairsGetter) []map[string]uint64 { m := map[string]uint64{} for _, u := range units { for _, it := range pg(u) { m[it.Name] += it.Count } } a2 := convertMapToSlice(m, max) return convertTopSlice(a2) }
</s> remove // topsCollector collects statistics about highest values fro the given *unitDB </s> add // topsCollector collects statistics about highest values from the given *unitDB </s> remove ent := map[string]uint64{} ent[it.Name] = it.Count m = append(m, ent) </s> add m = append(m, map[string]uint64{it.Name: it.Count}) </s> remove func convertTopSlice(a []countPair) []map[string]uint64 { m := []map[string]uint64{} </s> add func convertTopSlice(a []countPair) (m []map[string]uint64) { m = make([]map[string]uint64, 0, len(a)) </s> remove NResult: make([]uint64, rLast), </s> add NResult: make([]uint64, resultLast), </s> remove pair := countPair{} pair.Name = k pair.Count = v a = append(a, pair) </s> add a = append(a, countPair{Name: k, Count: v})
for _, cp := range pg(u) { m[cp.Name] += cp.Count
// slice using pg to retrieve data. func topsCollector(units []*unitDB, max int, pg pairsGetter) []map[string]uint64 { m := map[string]uint64{} for _, u := range units { for _, cp := range pg(u) { m[cp.Name] += cp.Count for _, cp := range pg(u) { m[cp.Name] += cp.Count } } a2 := convertMapToSlice(m, max) return convertTopSlice(a2) }
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
* safesearch-blocked * parental-blocked These values are just the sum of data for all units. */ func (s *statsCtx) getData() (statsResponse, bool) { limit := s.conf.limit timeUnit := Hours if limit/24 > 7 { timeUnit = Days }
</s> remove func (s *statsCtx) setLimit(limitDays int) { s.conf.limit = uint32(limitDays) * 24 </s> add func (s *StatsCtx) setLimit(limitDays int) { atomic.StoreUint32(&s.limitHours, uint32(24*limitDays)) </s> remove func checkInterval(days uint32) bool { </s> add // checkInterval returns true if days is valid to be used as statistics // retention interval. The valid values are 0, 1, 7, 30 and 90. func checkInterval(days uint32) (ok bool) { </s> remove if !checkInterval(conf.LimitDays) { conf.LimitDays = 1 </s> add if s.limitHours = conf.LimitDays * 24; !checkInterval(conf.LimitDays) { s.limitHours = 24 </s> remove // Initialize a unit func (s *statsCtx) initUnit(u *unit, id uint32) { u.id = id u.nResult = make([]uint64, rLast) u.domains = make(map[string]uint64) u.blockedDomains = make(map[string]uint64) u.clients = make(map[string]uint64) </s> add // newUnit allocates the new *unit. func newUnit(id uint32) (u *unit) { return &unit{ mu: &sync.RWMutex{}, id: id, nResult: make([]uint64, resultLast), domains: make(map[string]uint64), blockedDomains: make(map[string]uint64), clients: make(map[string]uint64), } </s> remove curID := cur.id </s> add var curID uint32 if cur != nil { curID = atomic.LoadUint32(&cur.id) } else { curID = s.unitIDGen() }
func (s *StatsCtx) getData() (statsResponse, bool) { limit := atomic.LoadUint32(&s.limitHours) if limit == 0 { return statsResponse{ TimeUnits: "days", TopBlocked: []topAddrs{}, TopClients: []topAddrs{}, TopQueried: []topAddrs{}, BlockedFiltering: []uint64{}, DNSQueries: []uint64{}, ReplacedParental: []uint64{}, ReplacedSafebrowsing: []uint64{}, }, true }
* safesearch-blocked * parental-blocked These values are just the sum of data for all units. */ func (s *StatsCtx) getData() (statsResponse, bool) { limit := atomic.LoadUint32(&s.limitHours) if limit == 0 { return statsResponse{ TimeUnits: "days", TopBlocked: []topAddrs{}, TopClients: []topAddrs{}, TopQueried: []topAddrs{}, BlockedFiltering: []uint64{}, DNSQueries: []uint64{}, ReplacedParental: []uint64{}, ReplacedSafebrowsing: []uint64{}, }, true } func (s *StatsCtx) getData() (statsResponse, bool) { limit := atomic.LoadUint32(&s.limitHours) if limit == 0 { return statsResponse{ TimeUnits: "days", TopBlocked: []topAddrs{}, TopClients: []topAddrs{}, TopQueried: []topAddrs{}, BlockedFiltering: []uint64{}, DNSQueries: []uint64{}, ReplacedParental: []uint64{}, ReplacedSafebrowsing: []uint64{}, }, true } timeUnit := Hours if limit/24 > 7 { timeUnit = Days }
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
} // Total counters: sum := unitDB{ NResult: make([]uint64, rLast), } timeN := 0 for _, u := range units { sum.NTotal += u.NTotal sum.TimeAvg += u.TimeAvg
</s> remove for _, it := range pg(u) { m[it.Name] += it.Count </s> add for _, cp := range pg(u) { m[cp.Name] += cp.Count </s> remove u.NResult = make([]uint64, rLast) </s> add u.NResult = make([]uint64, resultLast) </s> remove // topsCollector collects statistics about highest values fro the given *unitDB </s> add // topsCollector collects statistics about highest values from the given *unitDB </s> remove func (s *statsCtx) loadUnits(limit uint32) ([]*unitDB, uint32) { tx := s.beginTxn(false) </s> add func (s *StatsCtx) loadUnits(limit uint32) ([]*unitDB, uint32) { tx := beginTxn(s.database(), false) </s> remove func convertTopSlice(a []countPair) []map[string]uint64 { m := []map[string]uint64{} </s> add func convertTopSlice(a []countPair) (m []map[string]uint64) { m = make([]map[string]uint64, 0, len(a))
NResult: make([]uint64, resultLast),
} // Total counters: sum := unitDB{ NResult: make([]uint64, resultLast), } timeN := 0 for _, u := range units { sum.NTotal += u.NTotal sum.TimeAvg += u.TimeAvg
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
return data, true } func (s *statsCtx) GetTopClientsIP(maxCount uint) []net.IP { if s.conf.limit == 0 { return nil } units, _ := s.loadUnits(s.conf.limit) if units == nil {
</s> remove units, _ := s.loadUnits(s.conf.limit) </s> add units, _ := s.loadUnits(atomic.LoadUint32(&s.limitHours)) </s> remove func (s *statsCtx) loadUnitFromDB(tx *bolt.Tx, id uint32) *unitDB { </s> add func (s *StatsCtx) loadUnitFromDB(tx *bbolt.Tx, id uint32) *unitDB { </s> remove func (s *statsCtx) Update(e Entry) { if s.conf.limit == 0 { </s> add func (s *StatsCtx) Update(e Entry) { if !s.isEnabled() { </s> remove func (s *statsCtx) setLimit(limitDays int) { s.conf.limit = uint32(limitDays) * 24 </s> add func (s *StatsCtx) setLimit(limitDays int) { atomic.StoreUint32(&s.limitHours, uint32(24*limitDays)) </s> remove func (s *statsCtx) initWeb() { if s.conf.HTTPRegister == nil { </s> add func (s *StatsCtx) initWeb() { if s.httpRegister == nil {
func (s *StatsCtx) GetTopClientsIP(maxCount uint) []net.IP { if !s.isEnabled() {
return data, true } func (s *StatsCtx) GetTopClientsIP(maxCount uint) []net.IP { if !s.isEnabled() { func (s *StatsCtx) GetTopClientsIP(maxCount uint) []net.IP { if !s.isEnabled() { return nil } units, _ := s.loadUnits(s.conf.limit) if units == nil {
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
if s.conf.limit == 0 { return nil } units, _ := s.loadUnits(s.conf.limit) if units == nil { return nil } // top clients
</s> remove func (s *statsCtx) GetTopClientsIP(maxCount uint) []net.IP { if s.conf.limit == 0 { </s> add func (s *StatsCtx) GetTopClientsIP(maxCount uint) []net.IP { if !s.isEnabled() { </s> remove u.NResult = make([]uint64, rLast) </s> add u.NResult = make([]uint64, resultLast) </s> remove func (s *statsCtx) Update(e Entry) { if s.conf.limit == 0 { </s> add func (s *StatsCtx) Update(e Entry) { if !s.isEnabled() { </s> remove func (s *statsCtx) initWeb() { if s.conf.HTTPRegister == nil { </s> add func (s *StatsCtx) initWeb() { if s.httpRegister == nil { </s> remove units = append(units, serialize(cur)) </s> add if cur != nil { units = append(units, cur.serialize()) }
units, _ := s.loadUnits(atomic.LoadUint32(&s.limitHours))
if s.conf.limit == 0 { return nil } units, _ := s.loadUnits(atomic.LoadUint32(&s.limitHours)) if units == nil { return nil } // top clients
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 4358 fix stats Merge in DNS/adguard-home from 4358-fix-stats to master Updates #4358. Updates #4342. Squashed commit of the following: commit 5683cb304688ea639e5ba7f219a7bf12370211a4 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 18:20:54 2022 +0300 stats: rm races test commit 63dd67650ed64eaf9685b955a4fdf3c0067a7f8c Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 17:13:36 2022 +0300 stats: try to imp test commit 59a0f249fc00566872db62e362c87bc0c201b333 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 16:38:57 2022 +0300 stats: fix nil ptr deref commit 7fc3ff18a34a1d0e0fec3ca83a33f499ac752572 Author: Eugene Burkov <[email protected]> Date: Thu Apr 7 16:02:51 2022 +0300 stats: fix races finally, imp tests commit c63f5f4e7929819fe79b3a1e392f6b91cd630846 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:56:49 2022 +0300 aghhttp: add register func commit 61adc7f0e95279c1b7f4a0c0af5ab387ee461411 Merge: edbdb2d4 9b3adac1 Author: Eugene Burkov <[email protected]> Date: Thu Aug 4 00:36:01 2022 +0300 Merge branch 'master' into 4358-fix-stats commit edbdb2d4c6a06dcbf8107a28c4c3a61ba394e907 Merge: a91e4d7a a481ff4c Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 21:00:42 2022 +0300 Merge branch 'master' into 4358-fix-stats commit a91e4d7af13591eeef45cb7980d1ebc1650a5cb7 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:46:19 2022 +0300 stats: imp code, docs commit c5f3814c5c1a734ca8ff6726cc9ffc1177a055cf Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:16:13 2022 +0300 all: log changes commit 5e6caafc771dddc4c6be07c34658de359106fbe5 Merge: 091ba756 eb8e8166 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:09:10 2022 +0300 Merge branch 'master' into 4358-fix-stats commit 091ba75618d3689b9c04f05431283417c8cc52f9 Author: Eugene Burkov <[email protected]> Date: Wed Aug 3 18:07:39 2022 +0300 stats: imp docs, code commit f2b2de77ce5f0448d6df9232a614a3710f1e2e8a Author: Eugene Burkov <[email protected]> Date: Tue Aug 2 17:09:30 2022 +0300 all: refactor stats & add mutexes commit b3f11c455ceaa3738ec20eefc46f866ff36ed046 Author: Eugene Burkov <[email protected]> Date: Wed Apr 27 15:30:09 2022 +0300 WIP
https://github.com/AdguardTeam/AdGuardHome/commit/4293cf5945a9331fd8ce1eb33a88865c6b8713cc
internal/stats/unit.go
"install_devices_android_list_1": "From the Android Menu home screen, tap Settings.", "install_devices_android_list_2": "Tap Wi-Fi on the menu. The screen listing all of the available networks will be shown (it is impossible to set custom DNS for mobile connection).", "install_devices_android_list_3": "Long press the network you're connected to, and tap Modify Network.", "install_devices_android_list_4": "On some devices, you may need to check the box for Advanced to see further settings. To adjust your Android DNS settings, you will need to switch the IP settings from DHCP to Static.", "install_devices_android_list_5": "Change set DNS 1 and DNS 2 values to your AdGuard Home server addresses.", "install_devices_ios_list_1": "From the home screen, tap Settings.", "install_devices_ios_list_2": "Choose Wi-Fi in the left menu (it is impossible to configure DNS for mobile networks).", "install_devices_ios_list_3": "Tap on the name of the currently active network.", "install_devices_ios_list_4": "In the DNS field enter your AdGuard Home server addresses.", "get_started": "Get Started",
</s> remove "client_identifier_desc": "Clients can be identified by the IP address, CIDR, MAC address or a special client ID (can be used for DoT/DoH/DoQ). <0>Here</0> you can learn more about how to identify clients.", </s> add "client_identifier_desc": "Clients can be identified by the IP address, CIDR, MAC address, or a special client ID (can be used for DoT/DoH/DoQ). <0>Here</0> you can learn more about how to identify clients.", </s> remove "filter_category_security_desc": "Lists that specialize on blocking malware, phishing or scam domains", </s> add "filter_category_security_desc": "Lists that specialize on blocking malware, phishing, or scam domains", </s> remove "access_blocked_desc": "Don't confuse this with filters. AdGuard Home will drop DNS queries with these domains in queries' questions. Here you can specify the exact domain names, wildcards and URL filter rules, e.g. \"example.org\", \"*.example.org\" or \"||example.org^\".", </s> add "access_blocked_desc": "Don't confuse this with filters. AdGuard Home will drop DNS queries with these domains in queries' questions. Here you can specify the exact domain names, wildcards, and URL filter rules, e.g. \"example.org\", \"*.example.org\", or \"||example.org^\".",
"install_devices_android_list_5": "Change DNS 1 and DNS 2 values to your AdGuard Home server addresses.",
"install_devices_android_list_1": "From the Android Menu home screen, tap Settings.", "install_devices_android_list_2": "Tap Wi-Fi on the menu. The screen listing all of the available networks will be shown (it is impossible to set custom DNS for mobile connection).", "install_devices_android_list_3": "Long press the network you're connected to, and tap Modify Network.", "install_devices_android_list_4": "On some devices, you may need to check the box for Advanced to see further settings. To adjust your Android DNS settings, you will need to switch the IP settings from DHCP to Static.", "install_devices_android_list_5": "Change DNS 1 and DNS 2 values to your AdGuard Home server addresses.", "install_devices_ios_list_1": "From the home screen, tap Settings.", "install_devices_ios_list_2": "Choose Wi-Fi in the left menu (it is impossible to configure DNS for mobile networks).", "install_devices_ios_list_3": "Tap on the name of the currently active network.", "install_devices_ios_list_4": "In the DNS field enter your AdGuard Home server addresses.", "get_started": "Get Started",
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: client: imp en locale Merge in DNS/adguard-home from imp-i18n-en to master Squashed commit of the following: commit 7d0f46dc0a9b28e709ac9ad1748b17ae9ad4a520 Author: Ainar Garipov <[email protected]> Date: Thu May 13 16:04:22 2021 +0300 client: imp en locale
https://github.com/AdguardTeam/AdGuardHome/commit/42ec9cae76bd747391d670c6a046ec4800ca60f5
client/src/__locales/en.json
"client_new": "New Client", "client_edit": "Edit Client", "client_identifier": "Identifier", "ip_address": "IP address", "client_identifier_desc": "Clients can be identified by the IP address, CIDR, MAC address or a special client ID (can be used for DoT/DoH/DoQ). <0>Here</0> you can learn more about how to identify clients.", "form_enter_ip": "Enter IP", "form_enter_subnet_ip": "Enter an IP address in the subnet \"{{cidr}}\"", "form_enter_mac": "Enter MAC", "form_enter_id": "Enter identifier", "form_add_id": "Add identifier",
</s> remove "install_devices_android_list_5": "Change set DNS 1 and DNS 2 values to your AdGuard Home server addresses.", </s> add "install_devices_android_list_5": "Change DNS 1 and DNS 2 values to your AdGuard Home server addresses.", </s> remove "access_blocked_desc": "Don't confuse this with filters. AdGuard Home will drop DNS queries with these domains in queries' questions. Here you can specify the exact domain names, wildcards and URL filter rules, e.g. \"example.org\", \"*.example.org\" or \"||example.org^\".", </s> add "access_blocked_desc": "Don't confuse this with filters. AdGuard Home will drop DNS queries with these domains in queries' questions. Here you can specify the exact domain names, wildcards, and URL filter rules, e.g. \"example.org\", \"*.example.org\", or \"||example.org^\".", </s> remove "filter_category_security_desc": "Lists that specialize on blocking malware, phishing or scam domains", </s> add "filter_category_security_desc": "Lists that specialize on blocking malware, phishing, or scam domains",
"client_identifier_desc": "Clients can be identified by the IP address, CIDR, MAC address, or a special client ID (can be used for DoT/DoH/DoQ). <0>Here</0> you can learn more about how to identify clients.",
"client_new": "New Client", "client_edit": "Edit Client", "client_identifier": "Identifier", "ip_address": "IP address", "client_identifier_desc": "Clients can be identified by the IP address, CIDR, MAC address, or a special client ID (can be used for DoT/DoH/DoQ). <0>Here</0> you can learn more about how to identify clients.", "form_enter_ip": "Enter IP", "form_enter_subnet_ip": "Enter an IP address in the subnet \"{{cidr}}\"", "form_enter_mac": "Enter MAC", "form_enter_id": "Enter identifier", "form_add_id": "Add identifier",
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: client: imp en locale Merge in DNS/adguard-home from imp-i18n-en to master Squashed commit of the following: commit 7d0f46dc0a9b28e709ac9ad1748b17ae9ad4a520 Author: Ainar Garipov <[email protected]> Date: Thu May 13 16:04:22 2021 +0300 client: imp en locale
https://github.com/AdguardTeam/AdGuardHome/commit/42ec9cae76bd747391d670c6a046ec4800ca60f5
client/src/__locales/en.json
"access_allowed_desc": "A list of CIDR or IP addresses. If configured, AdGuard Home will accept requests from these IP addresses only.", "access_disallowed_title": "Disallowed clients", "access_disallowed_desc": "A list of CIDR or IP addresses. If configured, AdGuard Home will drop requests from these IP addresses.", "access_blocked_title": "Disallowed domains", "access_blocked_desc": "Don't confuse this with filters. AdGuard Home will drop DNS queries with these domains in queries' questions. Here you can specify the exact domain names, wildcards and URL filter rules, e.g. \"example.org\", \"*.example.org\" or \"||example.org^\".", "access_settings_saved": "Access settings successfully saved", "updates_checked": "Updates successfully checked", "updates_version_equal": "AdGuard Home is up-to-date", "check_updates_now": "Check for updates now", "dns_privacy": "DNS Privacy",
</s> remove "client_identifier_desc": "Clients can be identified by the IP address, CIDR, MAC address or a special client ID (can be used for DoT/DoH/DoQ). <0>Here</0> you can learn more about how to identify clients.", </s> add "client_identifier_desc": "Clients can be identified by the IP address, CIDR, MAC address, or a special client ID (can be used for DoT/DoH/DoQ). <0>Here</0> you can learn more about how to identify clients.", </s> remove "install_devices_android_list_5": "Change set DNS 1 and DNS 2 values to your AdGuard Home server addresses.", </s> add "install_devices_android_list_5": "Change DNS 1 and DNS 2 values to your AdGuard Home server addresses.", </s> remove "filter_category_security_desc": "Lists that specialize on blocking malware, phishing or scam domains", </s> add "filter_category_security_desc": "Lists that specialize on blocking malware, phishing, or scam domains",
"access_blocked_desc": "Don't confuse this with filters. AdGuard Home will drop DNS queries with these domains in queries' questions. Here you can specify the exact domain names, wildcards, and URL filter rules, e.g. \"example.org\", \"*.example.org\", or \"||example.org^\".",
"access_allowed_desc": "A list of CIDR or IP addresses. If configured, AdGuard Home will accept requests from these IP addresses only.", "access_disallowed_title": "Disallowed clients", "access_disallowed_desc": "A list of CIDR or IP addresses. If configured, AdGuard Home will drop requests from these IP addresses.", "access_blocked_title": "Disallowed domains", "access_blocked_desc": "Don't confuse this with filters. AdGuard Home will drop DNS queries with these domains in queries' questions. Here you can specify the exact domain names, wildcards, and URL filter rules, e.g. \"example.org\", \"*.example.org\", or \"||example.org^\".", "access_settings_saved": "Access settings successfully saved", "updates_checked": "Updates successfully checked", "updates_version_equal": "AdGuard Home is up-to-date", "check_updates_now": "Check for updates now", "dns_privacy": "DNS Privacy",
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: client: imp en locale Merge in DNS/adguard-home from imp-i18n-en to master Squashed commit of the following: commit 7d0f46dc0a9b28e709ac9ad1748b17ae9ad4a520 Author: Ainar Garipov <[email protected]> Date: Thu May 13 16:04:22 2021 +0300 client: imp en locale
https://github.com/AdguardTeam/AdGuardHome/commit/42ec9cae76bd747391d670c6a046ec4800ca60f5
client/src/__locales/en.json
"filter_category_security": "Security", "filter_category_regional": "Regional", "filter_category_other": "Other", "filter_category_general_desc": "Lists that block tracking and advertising on most of the devices", "filter_category_security_desc": "Lists that specialize on blocking malware, phishing or scam domains", "filter_category_regional_desc": "Lists that focus on regional ads and tracking servers", "filter_category_other_desc": "Other blocklists", "setup_config_to_enable_dhcp_server": "Setup configuration to enable DHCP server", "original_response": "Original response", "click_to_view_queries": "Click to view queries",
</s> remove "install_devices_android_list_5": "Change set DNS 1 and DNS 2 values to your AdGuard Home server addresses.", </s> add "install_devices_android_list_5": "Change DNS 1 and DNS 2 values to your AdGuard Home server addresses.", </s> remove "access_blocked_desc": "Don't confuse this with filters. AdGuard Home will drop DNS queries with these domains in queries' questions. Here you can specify the exact domain names, wildcards and URL filter rules, e.g. \"example.org\", \"*.example.org\" or \"||example.org^\".", </s> add "access_blocked_desc": "Don't confuse this with filters. AdGuard Home will drop DNS queries with these domains in queries' questions. Here you can specify the exact domain names, wildcards, and URL filter rules, e.g. \"example.org\", \"*.example.org\", or \"||example.org^\".", </s> remove "client_identifier_desc": "Clients can be identified by the IP address, CIDR, MAC address or a special client ID (can be used for DoT/DoH/DoQ). <0>Here</0> you can learn more about how to identify clients.", </s> add "client_identifier_desc": "Clients can be identified by the IP address, CIDR, MAC address, or a special client ID (can be used for DoT/DoH/DoQ). <0>Here</0> you can learn more about how to identify clients.",
"filter_category_security_desc": "Lists that specialize on blocking malware, phishing, or scam domains",
"filter_category_security": "Security", "filter_category_regional": "Regional", "filter_category_other": "Other", "filter_category_general_desc": "Lists that block tracking and advertising on most of the devices", "filter_category_security_desc": "Lists that specialize on blocking malware, phishing, or scam domains", "filter_category_regional_desc": "Lists that focus on regional ads and tracking servers", "filter_category_other_desc": "Other blocklists", "setup_config_to_enable_dhcp_server": "Setup configuration to enable DHCP server", "original_response": "Original response", "click_to_view_queries": "Click to view queries",
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: client: imp en locale Merge in DNS/adguard-home from imp-i18n-en to master Squashed commit of the following: commit 7d0f46dc0a9b28e709ac9ad1748b17ae9ad4a520 Author: Ainar Garipov <[email protected]> Date: Thu May 13 16:04:22 2021 +0300 client: imp en locale
https://github.com/AdguardTeam/AdGuardHome/commit/42ec9cae76bd747391d670c6a046ec4800ca60f5
client/src/__locales/en.json
DisableIPv6 bool `json:"disable_ipv6"` UpstreamMode string `json:"upstream_mode"` } func (s *Server) handleGetConfig(w http.ResponseWriter, r *http.Request) { resp := dnsConfigJSON{}
</s>
CacheSize uint32 `json:"cache_size"` CacheMinTTL uint32 `json:"cache_ttl_min"` CacheMaxTTL uint32 `json:"cache_ttl_max"`
DisableIPv6 bool `json:"disable_ipv6"` UpstreamMode string `json:"upstream_mode"` CacheSize uint32 `json:"cache_size"` CacheMinTTL uint32 `json:"cache_ttl_min"` CacheMaxTTL uint32 `json:"cache_ttl_max"` } func (s *Server) handleGetConfig(w http.ResponseWriter, r *http.Request) { resp := dnsConfigJSON{}
[ "keep", "add", "keep", "keep", "keep", "keep" ]
+ dns: new settings for cache Squashed commit of the following: commit e5b488249a4d972efd63c6e96830d9f30829aee1 Author: Simon Zolin <[email protected]> Date: Tue Jun 16 15:38:27 2020 +0300 + dns: new settings for cache
https://github.com/AdguardTeam/AdGuardHome/commit/4303b3dd2f6c4e1f64e8cd8575070de35b3d6df7
dnsforward/dnsforward_http.go
resp.DNSSECEnabled = s.conf.EnableDNSSEC resp.DisableIPv6 = s.conf.AAAADisabled if s.conf.FastestAddr { resp.UpstreamMode = "fastest_addr" } else if s.conf.AllServers { resp.UpstreamMode = "parallel" }
</s>
resp.CacheSize = s.conf.CacheSize resp.CacheMinTTL = s.conf.CacheMinTTL resp.CacheMaxTTL = s.conf.CacheMaxTTL
resp.DNSSECEnabled = s.conf.EnableDNSSEC resp.DisableIPv6 = s.conf.AAAADisabled resp.CacheSize = s.conf.CacheSize resp.CacheMinTTL = s.conf.CacheMinTTL resp.CacheMaxTTL = s.conf.CacheMaxTTL if s.conf.FastestAddr { resp.UpstreamMode = "fastest_addr" } else if s.conf.AllServers { resp.UpstreamMode = "parallel" }
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
+ dns: new settings for cache Squashed commit of the following: commit e5b488249a4d972efd63c6e96830d9f30829aee1 Author: Simon Zolin <[email protected]> Date: Tue Jun 16 15:38:27 2020 +0300 + dns: new settings for cache
https://github.com/AdguardTeam/AdGuardHome/commit/4303b3dd2f6c4e1f64e8cd8575070de35b3d6df7
dnsforward/dnsforward_http.go
return } restart := false s.Lock() if js.Exists("upstream_dns") { s.conf.UpstreamDNS = req.Upstreams restart = true
</s>
if req.CacheMinTTL > req.CacheMaxTTL { httpError(r, w, http.StatusBadRequest, "cache_ttl_min must be less or equal than cache_ttl_max") return }
return } if req.CacheMinTTL > req.CacheMaxTTL { httpError(r, w, http.StatusBadRequest, "cache_ttl_min must be less or equal than cache_ttl_max") return } restart := false s.Lock() if js.Exists("upstream_dns") { s.conf.UpstreamDNS = req.Upstreams restart = true
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
+ dns: new settings for cache Squashed commit of the following: commit e5b488249a4d972efd63c6e96830d9f30829aee1 Author: Simon Zolin <[email protected]> Date: Tue Jun 16 15:38:27 2020 +0300 + dns: new settings for cache
https://github.com/AdguardTeam/AdGuardHome/commit/4303b3dd2f6c4e1f64e8cd8575070de35b3d6df7
dnsforward/dnsforward_http.go
s.conf.AAAADisabled = req.DisableIPv6 } if js.Exists("upstream_mode") { s.conf.FastestAddr = false s.conf.AllServers = false switch req.UpstreamMode { case "": //
</s>
if js.Exists("cache_size") { s.conf.CacheSize = req.CacheSize restart = true } if js.Exists("cache_ttl_min") { s.conf.CacheMinTTL = req.CacheMinTTL restart = true } if js.Exists("cache_ttl_max") { s.conf.CacheMaxTTL = req.CacheMaxTTL restart = true }
s.conf.AAAADisabled = req.DisableIPv6 } if js.Exists("cache_size") { s.conf.CacheSize = req.CacheSize restart = true } if js.Exists("cache_ttl_min") { s.conf.CacheMinTTL = req.CacheMinTTL restart = true } if js.Exists("cache_ttl_max") { s.conf.CacheMaxTTL = req.CacheMaxTTL restart = true } if js.Exists("upstream_mode") { s.conf.FastestAddr = false s.conf.AllServers = false switch req.UpstreamMode { case "": //
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
+ dns: new settings for cache Squashed commit of the following: commit e5b488249a4d972efd63c6e96830d9f30829aee1 Author: Simon Zolin <[email protected]> Date: Tue Jun 16 15:38:27 2020 +0300 + dns: new settings for cache
https://github.com/AdguardTeam/AdGuardHome/commit/4303b3dd2f6c4e1f64e8cd8575070de35b3d6df7
dnsforward/dnsforward_http.go
edns_cs_enabled: type: boolean dnssec_enabled: type: boolean upstream_mode: enum: - "" - parallel - fastest_addr
</s>
cache_size: type: integer cache_ttl_min: type: integer cache_ttl_max: type: integer
edns_cs_enabled: type: boolean dnssec_enabled: type: boolean cache_size: type: integer cache_ttl_min: type: integer cache_ttl_max: type: integer upstream_mode: enum: - "" - parallel - fastest_addr
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
+ dns: new settings for cache Squashed commit of the following: commit e5b488249a4d972efd63c6e96830d9f30829aee1 Author: Simon Zolin <[email protected]> Date: Tue Jun 16 15:38:27 2020 +0300 + dns: new settings for cache
https://github.com/AdguardTeam/AdGuardHome/commit/4303b3dd2f6c4e1f64e8cd8575070de35b3d6df7
openapi/openapi.yaml
} }, "tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", "dev": true, "requires": {
</s> remove font-size: 0.9rem; </s> add font-size: 0.85rem;
"tiny-version-compare": { "version": "0.9.1", "resolved": "https://registry.npmjs.org/tiny-version-compare/-/tiny-version-compare-0.9.1.tgz", "integrity": "sha512-kYim94l7ptSmj9rqxUMkrcMCJ448CS+hwqjA7OFcRi0ISdi0zjgdSUklQ4velVVECCjCo5frU3tNZ3oSgIKzsA==" },
} }, "tiny-version-compare": { "version": "0.9.1", "resolved": "https://registry.npmjs.org/tiny-version-compare/-/tiny-version-compare-0.9.1.tgz", "integrity": "sha512-kYim94l7ptSmj9rqxUMkrcMCJ448CS+hwqjA7OFcRi0ISdi0zjgdSUklQ4velVVECCjCo5frU3tNZ3oSgIKzsA==" }, "tmp": { "version": "0.0.33", "resolved": "https://registry.npmjs.org/tmp/-/tmp-0.0.33.tgz", "integrity": "sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw==", "dev": true, "requires": {
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
Add update check Closes #338
https://github.com/AdguardTeam/AdGuardHome/commit/43fcf4117db0e1e26085a0cc20a574edc8bd6255
client/package-lock.json
"svg-url-loader": "^2.3.2", "tabler-react": "^1.10.0", "whatwg-fetch": "2.0.3" }, "devDependencies": { "autoprefixer": "^8.6.3", "babel-core": "6.26.0", "babel-eslint": "^8.2.3",
</s>
"tiny-version-compare": "^0.9.1",
"svg-url-loader": "^2.3.2", "tabler-react": "^1.10.0", "tiny-version-compare": "^0.9.1", "whatwg-fetch": "2.0.3" }, "devDependencies": { "autoprefixer": "^8.6.3", "babel-core": "6.26.0", "babel-eslint": "^8.2.3",
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
Add update check Closes #338
https://github.com/AdguardTeam/AdGuardHome/commit/43fcf4117db0e1e26085a0cc20a574edc8bd6255
client/package.json
dispatch(getStatsFailure()); } }; export const getTopStatsRequest = createAction('GET_TOP_STATS_REQUEST'); export const getTopStatsFailure = createAction('GET_TOP_STATS_FAILURE'); export const getTopStatsSuccess = createAction('GET_TOP_STATS_SUCCESS'); export const getTopStats = () => async (dispatch, getState) => {
</s> remove version {dnsVersion} / address: {dnsAddress}:{dnsPort} </s> add <div className="nav-version__text"> version: <span className="nav-version__value">{dnsVersion}</span> </div> <div className="nav-version__text"> address: <span className="nav-version__value">{dnsAddress}:{dnsPort}</span> </div>
export const getVersionRequest = createAction('GET_VERSION_REQUEST'); export const getVersionFailure = createAction('GET_VERSION_FAILURE'); export const getVersionSuccess = createAction('GET_VERSION_SUCCESS'); export const getVersion = () => async (dispatch) => { dispatch(getVersionRequest()); try { const newVersion = await apiClient.getGlobalVersion(); dispatch(getVersionSuccess(newVersion)); } catch (error) { dispatch(addErrorToast({ error })); dispatch(getVersionFailure()); } };
dispatch(getStatsFailure()); } }; export const getVersionRequest = createAction('GET_VERSION_REQUEST'); export const getVersionFailure = createAction('GET_VERSION_FAILURE'); export const getVersionSuccess = createAction('GET_VERSION_SUCCESS'); export const getVersion = () => async (dispatch) => { dispatch(getVersionRequest()); try { const newVersion = await apiClient.getGlobalVersion(); dispatch(getVersionSuccess(newVersion)); } catch (error) { dispatch(addErrorToast({ error })); dispatch(getVersionFailure()); } }; export const getTopStatsRequest = createAction('GET_TOP_STATS_REQUEST'); export const getTopStatsFailure = createAction('GET_TOP_STATS_FAILURE'); export const getTopStatsSuccess = createAction('GET_TOP_STATS_SUCCESS'); export const getTopStats = () => async (dispatch, getState) => {
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
Add update check Closes #338
https://github.com/AdguardTeam/AdGuardHome/commit/43fcf4117db0e1e26085a0cc20a574edc8bd6255
client/src/actions/index.js
GLOBAL_QUERY_LOG = { path: 'querylog', method: 'GET' }; GLOBAL_QUERY_LOG_ENABLE = { path: 'querylog_enable', method: 'POST' }; GLOBAL_QUERY_LOG_DISABLE = { path: 'querylog_disable', method: 'POST' }; GLOBAL_SET_UPSTREAM_DNS = { path: 'set_upstream_dns', method: 'POST' }; restartGlobalFiltering() { const { path, method } = this.GLOBAL_RESTART; return this.makeRequest(path, method);
</s> remove version {dnsVersion} / address: {dnsAddress}:{dnsPort} </s> add <div className="nav-version__text"> version: <span className="nav-version__value">{dnsVersion}</span> </div> <div className="nav-version__text"> address: <span className="nav-version__value">{dnsAddress}:{dnsPort}</span> </div>
GLOBAL_VERSION = { path: 'version.json', method: 'GET' };
GLOBAL_QUERY_LOG = { path: 'querylog', method: 'GET' }; GLOBAL_QUERY_LOG_ENABLE = { path: 'querylog_enable', method: 'POST' }; GLOBAL_QUERY_LOG_DISABLE = { path: 'querylog_disable', method: 'POST' }; GLOBAL_SET_UPSTREAM_DNS = { path: 'set_upstream_dns', method: 'POST' }; GLOBAL_VERSION = { path: 'version.json', method: 'GET' }; restartGlobalFiltering() { const { path, method } = this.GLOBAL_RESTART; return this.makeRequest(path, method);
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
Add update check Closes #338
https://github.com/AdguardTeam/AdGuardHome/commit/43fcf4117db0e1e26085a0cc20a574edc8bd6255
client/src/api/Api.js
return this.makeRequest(path, method, config); } // Filtering FILTERING_STATUS = { path: 'filtering/status', method: 'GET' }; FILTERING_ENABLE = { path: 'filtering/enable', method: 'POST' }; FILTERING_DISABLE = { path: 'filtering/disable', method: 'POST' }; FILTERING_ADD_FILTER = { path: 'filtering/add_url', method: 'PUT' };
</s> remove version {dnsVersion} / address: {dnsAddress}:{dnsPort} </s> add <div className="nav-version__text"> version: <span className="nav-version__value">{dnsVersion}</span> </div> <div className="nav-version__text"> address: <span className="nav-version__value">{dnsAddress}:{dnsPort}</span> </div>
getGlobalVersion() { const { path, method } = this.GLOBAL_VERSION; return this.makeRequest(path, method); }
return this.makeRequest(path, method, config); } getGlobalVersion() { const { path, method } = this.GLOBAL_VERSION; return this.makeRequest(path, method); } // Filtering FILTERING_STATUS = { path: 'filtering/status', method: 'GET' }; FILTERING_ENABLE = { path: 'filtering/enable', method: 'POST' }; FILTERING_DISABLE = { path: 'filtering/disable', method: 'POST' }; FILTERING_ADD_FILTER = { path: 'filtering/add_url', method: 'PUT' };
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
Add update check Closes #338
https://github.com/AdguardTeam/AdGuardHome/commit/43fcf4117db0e1e26085a0cc20a574edc8bd6255
client/src/api/Api.js
import Toasts from '../Toasts'; import Status from '../ui/Status'; class App extends Component { componentDidMount() { this.props.getDnsStatus(); this.props.getVersion();
</s>
import Update from '../ui/Update';
import Toasts from '../Toasts'; import Status from '../ui/Status'; import Update from '../ui/Update'; class App extends Component { componentDidMount() { this.props.getDnsStatus(); this.props.getVersion();
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
Add update check Closes #338
https://github.com/AdguardTeam/AdGuardHome/commit/43fcf4117db0e1e26085a0cc20a574edc8bd6255
client/src/components/App/index.js
class App extends Component { componentDidMount() { this.props.getDnsStatus(); } handleStatusChange = () => { this.props.enableDns(); };
</s>
this.props.getVersion();
class App extends Component { componentDidMount() { this.props.getDnsStatus(); this.props.getVersion(); } handleStatusChange = () => { this.props.enableDns(); };
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
Add update check Closes #338
https://github.com/AdguardTeam/AdGuardHome/commit/43fcf4117db0e1e26085a0cc20a574edc8bd6255
client/src/components/App/index.js
}; render() { const { dashboard } = this.props; return ( <HashRouter hashType='noslash'> <Fragment> {updateAvailable && <Update
</s> remove version {dnsVersion} / address: {dnsAddress}:{dnsPort} </s> add <div className="nav-version__text"> version: <span className="nav-version__value">{dnsVersion}</span> </div> <div className="nav-version__text"> address: <span className="nav-version__value">{dnsAddress}:{dnsPort}</span> </div>
const updateAvailable = !dashboard.processingVersions && dashboard.isCoreRunning && dashboard.isUpdateAvailable;
}; render() { const { dashboard } = this.props; const updateAvailable = !dashboard.processingVersions && dashboard.isCoreRunning && dashboard.isUpdateAvailable; return ( <HashRouter hashType='noslash'> <Fragment> {updateAvailable && <Update
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
Add update check Closes #338
https://github.com/AdguardTeam/AdGuardHome/commit/43fcf4117db0e1e26085a0cc20a574edc8bd6255
client/src/components/App/index.js
<HashRouter hashType='noslash'> <Fragment> <LoadingBar className="loading-bar" updateTime={1000} /> <Route component={Header} /> <div className="container container--wrap"> {!dashboard.processing && !dashboard.isCoreRunning && <div className="row row-cards"> <div className="col-lg-12">
</s> remove version {dnsVersion} / address: {dnsAddress}:{dnsPort} </s> add <div className="nav-version__text"> version: <span className="nav-version__value">{dnsVersion}</span> </div> <div className="nav-version__text"> address: <span className="nav-version__value">{dnsAddress}:{dnsPort}</span> </div> </s> remove font-size: 0.9rem; </s> add font-size: 0.85rem;
{updateAvailable && <Update announcement={dashboard.announcement} announcementUrl={dashboard.announcementUrl} /> }
<HashRouter hashType='noslash'> <Fragment> {updateAvailable && <Update announcement={dashboard.announcement} announcementUrl={dashboard.announcementUrl} /> } <LoadingBar className="loading-bar" updateTime={1000} /> <Route component={Header} /> <div className="container container--wrap"> {!dashboard.processing && !dashboard.isCoreRunning && <div className="row row-cards"> <div className="col-lg-12">
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
Add update check Closes #338
https://github.com/AdguardTeam/AdGuardHome/commit/43fcf4117db0e1e26085a0cc20a574edc8bd6255
client/src/components/App/index.js
isCoreRunning: PropTypes.bool, error: PropTypes.string, }; export default App;
</s> remove version {dnsVersion} / address: {dnsAddress}:{dnsPort} </s> add <div className="nav-version__text"> version: <span className="nav-version__value">{dnsVersion}</span> </div> <div className="nav-version__text"> address: <span className="nav-version__value">{dnsAddress}:{dnsPort}</span> </div>
getVersion: PropTypes.func,
isCoreRunning: PropTypes.bool, error: PropTypes.string, getVersion: PropTypes.func, }; export default App;
[ "keep", "add", "keep", "keep", "keep" ]
Add update check Closes #338
https://github.com/AdguardTeam/AdGuardHome/commit/43fcf4117db0e1e26085a0cc20a574edc8bd6255
client/src/components/App/index.js
overflow: hidden; } .nav-version { padding: 16px 0; font-size: 0.85rem; text-align: right; } .header-brand-img { height: 26px;
</s> remove font-size: 0.9rem; </s> add font-size: 0.85rem;
padding: 7px 0; font-size: 0.80rem;
overflow: hidden; } .nav-version { padding: 7px 0; font-size: 0.80rem; padding: 7px 0; font-size: 0.80rem; text-align: right; } .header-brand-img { height: 26px;
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Add update check Closes #338
https://github.com/AdguardTeam/AdGuardHome/commit/43fcf4117db0e1e26085a0cc20a574edc8bd6255
client/src/components/Header/Header.css
font-size: 0.80rem; text-align: right; } .header-brand-img { height: 26px; } @media screen and (min-width: 992px) {
</s> remove padding: 16px 0; font-size: 0.85rem; </s> add padding: 7px 0; font-size: 0.80rem; </s> remove font-size: 0.9rem; </s> add font-size: 0.85rem;
.nav-version__value { font-weight: 600; }
font-size: 0.80rem; text-align: right; } .nav-version__value { font-weight: 600; } .header-brand-img { height: 26px; } @media screen and (min-width: 992px) {
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
Add update check Closes #338
https://github.com/AdguardTeam/AdGuardHome/commit/43fcf4117db0e1e26085a0cc20a574edc8bd6255
client/src/components/Header/Header.css
} .nav-version { padding: 0; font-size: 0.9rem; } } .dns-status { padding: 0.35em 0.5em;
</s> remove padding: 16px 0; font-size: 0.85rem; </s> add padding: 7px 0; font-size: 0.80rem;
font-size: 0.85rem;
} .nav-version { padding: 0; font-size: 0.85rem; } } .dns-status { padding: 0.35em 0.5em;
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Add update check Closes #338
https://github.com/AdguardTeam/AdGuardHome/commit/43fcf4117db0e1e26085a0cc20a574edc8bd6255
client/src/components/Header/Header.css
export default function Version(props) { const { dnsVersion, dnsAddress, dnsPort } = props; return ( <div className="nav-version"> version {dnsVersion} / address: {dnsAddress}:{dnsPort} </div> ); } Version.propTypes = {
</s>
<div className="nav-version__text"> version: <span className="nav-version__value">{dnsVersion}</span> </div> <div className="nav-version__text"> address: <span className="nav-version__value">{dnsAddress}:{dnsPort}</span> </div>
export default function Version(props) { const { dnsVersion, dnsAddress, dnsPort } = props; return ( <div className="nav-version"> <div className="nav-version__text"> version: <span className="nav-version__value">{dnsVersion}</span> </div> <div className="nav-version__text"> address: <span className="nav-version__value">{dnsAddress}:{dnsPort}</span> </div> </div> ); } Version.propTypes = {
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Add update check Closes #338
https://github.com/AdguardTeam/AdGuardHome/commit/43fcf4117db0e1e26085a0cc20a574edc8bd6255
client/src/components/Header/Version.js
import { combineReducers } from 'redux'; import { handleActions } from 'redux-actions'; import { loadingBarReducer } from 'react-redux-loading-bar'; import nanoid from 'nanoid'; import * as actions from '../actions'; const settings = handleActions({ [actions.initSettingsRequest]: state => ({ ...state, processing: true }),
</s>
import versionCompare from 'tiny-version-compare';
import { combineReducers } from 'redux'; import { handleActions } from 'redux-actions'; import { loadingBarReducer } from 'react-redux-loading-bar'; import versionCompare from 'tiny-version-compare'; import nanoid from 'nanoid'; import * as actions from '../actions'; const settings = handleActions({ [actions.initSettingsRequest]: state => ({ ...state, processing: true }),
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
Add update check Closes #338
https://github.com/AdguardTeam/AdGuardHome/commit/43fcf4117db0e1e26085a0cc20a574edc8bd6255
client/src/reducers/index.js
processingTopStats: true, processingStats: true, logStatusProcessing: false, }); const queryLogs = handleActions({ [actions.getLogsRequest]: state => ({ ...state, getLogsProcessing: true }), [actions.getLogsFailure]: state => ({ ...state, getLogsProcessing: false }), [actions.getLogsSuccess]: (state, { payload }) => {
</s>
processingVersion: true,
processingTopStats: true, processingStats: true, logStatusProcessing: false, processingVersion: true, }); const queryLogs = handleActions({ [actions.getLogsRequest]: state => ({ ...state, getLogsProcessing: true }), [actions.getLogsFailure]: state => ({ ...state, getLogsProcessing: false }), [actions.getLogsSuccess]: (state, { payload }) => {
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
Add update check Closes #338
https://github.com/AdguardTeam/AdGuardHome/commit/43fcf4117db0e1e26085a0cc20a574edc8bd6255
client/src/reducers/index.js
"custom_ip": "Custom IP", "blocking_ipv4": "Blocking IPv4", "blocking_ipv6": "Blocking IPv6", "dns_over_https": "DNS-over-HTTPS", "dns_over_tls": "DNS-over-TLS", "dns_over_quic": "DNS-over-QUIC", "client_id": "Client ID", "client_id_placeholder": "Enter client ID", "client_id_desc": "Different clients can be identified by a special client ID. <a>Here</a> you can learn more about how to identify clients.",
</s> remove } </s> add
"dnscrypt": "DNSCrypt",
"custom_ip": "Custom IP", "blocking_ipv4": "Blocking IPv4", "blocking_ipv6": "Blocking IPv6", "dnscrypt": "DNSCrypt", "dns_over_https": "DNS-over-HTTPS", "dns_over_tls": "DNS-over-TLS", "dns_over_quic": "DNS-over-QUIC", "client_id": "Client ID", "client_id_placeholder": "Enter client ID", "client_id_desc": "Different clients can be identified by a special client ID. <a>Here</a> you can learn more about how to identify clients.",
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2662 dnscrypt logs Merge in DNS/adguard-home from 2662-dnscrypt-logs to master Closes #2662. Squashed commit of the following: commit 05f6742b5c73e1d150834965ae3a54ca06ef8e24 Author: Ainar Garipov <[email protected]> Date: Thu Feb 11 12:58:08 2021 +0300 all: imp docs commit ee0b8c574c1cb5302a5ffb62d2fec4126509b2e8 Merge: aaa8c6b8 e64df20e Author: Ainar Garipov <[email protected]> Date: Thu Feb 11 12:56:44 2021 +0300 Merge branch 'master' into 2662-dnscrypt-logs commit aaa8c6b8085679f4acd234527bd03cb0b2520b4f Author: Ainar Garipov <[email protected]> Date: Thu Feb 11 12:38:49 2021 +0300 all: document changes commit 57b6a4d8e95e87d928274d095dc2004f1591d940 Author: Ainar Garipov <[email protected]> Date: Thu Feb 11 12:36:22 2021 +0300 all: fix dnscrypt in logs
https://github.com/AdguardTeam/AdGuardHome/commit/44168292d5f466b9e7cda271987f03363ab6d6a8
client/src/__locales/en.json
"port_53_faq_link": "Port 53 is often occupied by \"DNSStubListener\" or \"systemd-resolved\" services. Please read <0>this instruction</0> on how to resolve this.", "adg_will_drop_dns_queries": "AdGuard Home will be dropping all DNS queries from this client.", "client_not_in_allowed_clients": "The client is not allowed because it is not in the \"Allowed clients\" list.", "experimental": "Experimental" }
</s>
"port_53_faq_link": "Port 53 is often occupied by \"DNSStubListener\" or \"systemd-resolved\" services. Please read <0>this instruction</0> on how to resolve this.", "adg_will_drop_dns_queries": "AdGuard Home will be dropping all DNS queries from this client.", "client_not_in_allowed_clients": "The client is not allowed because it is not in the \"Allowed clients\" list.", "experimental": "Experimental"
[ "keep", "keep", "keep", "keep", "replace" ]
Pull request: 2662 dnscrypt logs Merge in DNS/adguard-home from 2662-dnscrypt-logs to master Closes #2662. Squashed commit of the following: commit 05f6742b5c73e1d150834965ae3a54ca06ef8e24 Author: Ainar Garipov <[email protected]> Date: Thu Feb 11 12:58:08 2021 +0300 all: imp docs commit ee0b8c574c1cb5302a5ffb62d2fec4126509b2e8 Merge: aaa8c6b8 e64df20e Author: Ainar Garipov <[email protected]> Date: Thu Feb 11 12:56:44 2021 +0300 Merge branch 'master' into 2662-dnscrypt-logs commit aaa8c6b8085679f4acd234527bd03cb0b2520b4f Author: Ainar Garipov <[email protected]> Date: Thu Feb 11 12:38:49 2021 +0300 all: document changes commit 57b6a4d8e95e87d928274d095dc2004f1591d940 Author: Ainar Garipov <[email protected]> Date: Thu Feb 11 12:36:22 2021 +0300 all: fix dnscrypt in logs
https://github.com/AdguardTeam/AdGuardHome/commit/44168292d5f466b9e7cda271987f03363ab6d6a8
client/src/__locales/en.json
"adg_will_drop_dns_queries": "AdGuard Home will be dropping all DNS queries from this client.", "client_not_in_allowed_clients": "The client is not allowed because it is not in the \"Allowed clients\" list.", "experimental": "Experimental" }
</s> remove } </s> add
}
"adg_will_drop_dns_queries": "AdGuard Home will be dropping all DNS queries from this client.", "client_not_in_allowed_clients": "The client is not allowed because it is not in the \"Allowed clients\" list.", "experimental": "Experimental" } }
[ "keep", "keep", "keep", "add" ]
Pull request: 2662 dnscrypt logs Merge in DNS/adguard-home from 2662-dnscrypt-logs to master Closes #2662. Squashed commit of the following: commit 05f6742b5c73e1d150834965ae3a54ca06ef8e24 Author: Ainar Garipov <[email protected]> Date: Thu Feb 11 12:58:08 2021 +0300 all: imp docs commit ee0b8c574c1cb5302a5ffb62d2fec4126509b2e8 Merge: aaa8c6b8 e64df20e Author: Ainar Garipov <[email protected]> Date: Thu Feb 11 12:56:44 2021 +0300 Merge branch 'master' into 2662-dnscrypt-logs commit aaa8c6b8085679f4acd234527bd03cb0b2520b4f Author: Ainar Garipov <[email protected]> Date: Thu Feb 11 12:38:49 2021 +0300 all: document changes commit 57b6a4d8e95e87d928274d095dc2004f1591d940 Author: Ainar Garipov <[email protected]> Date: Thu Feb 11 12:36:22 2021 +0300 all: fix dnscrypt in logs
https://github.com/AdguardTeam/AdGuardHome/commit/44168292d5f466b9e7cda271987f03363ab6d6a8
client/src/__locales/en.json
export const SCHEME_TO_PROTOCOL_MAP = { doh: 'dns_over_https', dot: 'dns_over_tls', doq: 'dns_over_quic', '': 'plain_dns', };
</s> remove } </s> add
dnscrypt: 'dnscrypt',
export const SCHEME_TO_PROTOCOL_MAP = { dnscrypt: 'dnscrypt', doh: 'dns_over_https', dot: 'dns_over_tls', doq: 'dns_over_quic', '': 'plain_dns', };
[ "keep", "add", "keep", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2662 dnscrypt logs Merge in DNS/adguard-home from 2662-dnscrypt-logs to master Closes #2662. Squashed commit of the following: commit 05f6742b5c73e1d150834965ae3a54ca06ef8e24 Author: Ainar Garipov <[email protected]> Date: Thu Feb 11 12:58:08 2021 +0300 all: imp docs commit ee0b8c574c1cb5302a5ffb62d2fec4126509b2e8 Merge: aaa8c6b8 e64df20e Author: Ainar Garipov <[email protected]> Date: Thu Feb 11 12:56:44 2021 +0300 Merge branch 'master' into 2662-dnscrypt-logs commit aaa8c6b8085679f4acd234527bd03cb0b2520b4f Author: Ainar Garipov <[email protected]> Date: Thu Feb 11 12:38:49 2021 +0300 all: document changes commit 57b6a4d8e95e87d928274d095dc2004f1591d940 Author: Ainar Garipov <[email protected]> Date: Thu Feb 11 12:36:22 2021 +0300 all: fix dnscrypt in logs
https://github.com/AdguardTeam/AdGuardHome/commit/44168292d5f466b9e7cda271987f03363ab6d6a8
client/src/helpers/constants.js
ClientProtoDOH, ClientProtoDOQ, ClientProtoDOT, ClientProtoPlain: return cp, nil default: return "", fmt.Errorf("invalid client proto: %q", s)
</s> remove } </s> add
ClientProtoDNSCrypt,
ClientProtoDOH, ClientProtoDOQ, ClientProtoDOT, ClientProtoDNSCrypt, ClientProtoPlain: return cp, nil default: return "", fmt.Errorf("invalid client proto: %q", s)
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
Pull request: 2662 dnscrypt logs Merge in DNS/adguard-home from 2662-dnscrypt-logs to master Closes #2662. Squashed commit of the following: commit 05f6742b5c73e1d150834965ae3a54ca06ef8e24 Author: Ainar Garipov <[email protected]> Date: Thu Feb 11 12:58:08 2021 +0300 all: imp docs commit ee0b8c574c1cb5302a5ffb62d2fec4126509b2e8 Merge: aaa8c6b8 e64df20e Author: Ainar Garipov <[email protected]> Date: Thu Feb 11 12:56:44 2021 +0300 Merge branch 'master' into 2662-dnscrypt-logs commit aaa8c6b8085679f4acd234527bd03cb0b2520b4f Author: Ainar Garipov <[email protected]> Date: Thu Feb 11 12:38:49 2021 +0300 all: document changes commit 57b6a4d8e95e87d928274d095dc2004f1591d940 Author: Ainar Garipov <[email protected]> Date: Thu Feb 11 12:36:22 2021 +0300 all: fix dnscrypt in logs
https://github.com/AdguardTeam/AdGuardHome/commit/44168292d5f466b9e7cda271987f03363ab6d6a8
internal/querylog/qlog.go
s.ServeHTTP(w, r) } func (s *Server) registerHandlers() { s.conf.HTTPRegister("GET", "/control/dns_info", s.handleGetConfig) s.conf.HTTPRegister("POST", "/control/dns_config", s.handleSetConfig) s.conf.HTTPRegister("POST", "/control/test_upstream_dns", s.handleTestUpstreamDNS) s.conf.HTTPRegister("GET", "/control/access/list", s.handleAccessList) s.conf.HTTPRegister("POST", "/control/access/set", s.handleAccessSet) s.conf.HTTPRegister("", "/dns-query", s.handleDOH)
</s> remove s.conf.HTTPRegister("GET", "/control/access/list", s.handleAccessList) s.conf.HTTPRegister("POST", "/control/access/set", s.handleAccessSet) </s> add s.conf.HTTPRegister(http.MethodGet, "/control/access/list", s.handleAccessList) s.conf.HTTPRegister(http.MethodPost, "/control/access/set", s.handleAccessSet) </s> remove func handleStatus(w http.ResponseWriter, r *http.Request) { </s> add func handleStatus(w http.ResponseWriter, _ *http.Request) { </s> remove return ensure("POST", handler) </s> add return ensure(http.MethodPost, handler) </s> remove if method == "POST" || method == "PUT" || method == "DELETE" { </s> add if method == http.MethodPost || method == http.MethodPut || method == http.MethodDelete { </s> remove Context.mux.Handle("/control/login", postInstallHandler(ensureHandler("POST", handleLogin))) httpRegister("GET", "/control/logout", handleLogout) </s> add Context.mux.Handle("/control/login", postInstallHandler(ensureHandler(http.MethodPost, handleLogin))) httpRegister(http.MethodGet, "/control/logout", handleLogout)
s.conf.HTTPRegister(http.MethodGet, "/control/dns_info", s.handleGetConfig) s.conf.HTTPRegister(http.MethodPost, "/control/dns_config", s.handleSetConfig) s.conf.HTTPRegister(http.MethodPost, "/control/test_upstream_dns", s.handleTestUpstreamDNS)
s.ServeHTTP(w, r) } func (s *Server) registerHandlers() { s.conf.HTTPRegister(http.MethodGet, "/control/dns_info", s.handleGetConfig) s.conf.HTTPRegister(http.MethodPost, "/control/dns_config", s.handleSetConfig) s.conf.HTTPRegister(http.MethodPost, "/control/test_upstream_dns", s.handleTestUpstreamDNS) s.conf.HTTPRegister(http.MethodGet, "/control/dns_info", s.handleGetConfig) s.conf.HTTPRegister(http.MethodPost, "/control/dns_config", s.handleSetConfig) s.conf.HTTPRegister(http.MethodPost, "/control/test_upstream_dns", s.handleTestUpstreamDNS) s.conf.HTTPRegister(http.MethodGet, "/control/dns_info", s.handleGetConfig) s.conf.HTTPRegister(http.MethodPost, "/control/dns_config", s.handleSetConfig) s.conf.HTTPRegister(http.MethodPost, "/control/test_upstream_dns", s.handleTestUpstreamDNS) s.conf.HTTPRegister("GET", "/control/access/list", s.handleAccessList) s.conf.HTTPRegister("POST", "/control/access/set", s.handleAccessSet) s.conf.HTTPRegister("", "/dns-query", s.handleDOH)
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: all: imp http handlers, imp docs Merge in DNS/adguard-home from fix-openapi to master Squashed commit of the following: commit 0e7530472fb566e5cab73d178c8ec16e5ef11dcb Author: Ainar Garipov <[email protected]> Date: Wed Jan 13 17:02:06 2021 +0300 all: imp http handlers, imp docs
https://github.com/AdguardTeam/AdGuardHome/commit/4474e9fcf9073af593df76b4844f4091c1c7946e
internal/dnsforward/http.go
s.conf.HTTPRegister("GET", "/control/dns_info", s.handleGetConfig) s.conf.HTTPRegister("POST", "/control/dns_config", s.handleSetConfig) s.conf.HTTPRegister("POST", "/control/test_upstream_dns", s.handleTestUpstreamDNS) s.conf.HTTPRegister("GET", "/control/access/list", s.handleAccessList) s.conf.HTTPRegister("POST", "/control/access/set", s.handleAccessSet) s.conf.HTTPRegister("", "/dns-query", s.handleDOH) }
</s> remove s.conf.HTTPRegister("GET", "/control/dns_info", s.handleGetConfig) s.conf.HTTPRegister("POST", "/control/dns_config", s.handleSetConfig) s.conf.HTTPRegister("POST", "/control/test_upstream_dns", s.handleTestUpstreamDNS) </s> add s.conf.HTTPRegister(http.MethodGet, "/control/dns_info", s.handleGetConfig) s.conf.HTTPRegister(http.MethodPost, "/control/dns_config", s.handleSetConfig) s.conf.HTTPRegister(http.MethodPost, "/control/test_upstream_dns", s.handleTestUpstreamDNS) </s> remove return ensure("POST", handler) </s> add return ensure(http.MethodPost, handler) </s> remove func handleStatus(w http.ResponseWriter, r *http.Request) { </s> add func handleStatus(w http.ResponseWriter, _ *http.Request) { </s> remove r, _ := http.NewRequest("GET", "http://localhost/", nil) </s> add r, _ := http.NewRequest(http.MethodGet, "http://localhost/", nil) </s> remove return ensure("GET", handler) </s> add return ensure(http.MethodGet, handler)
s.conf.HTTPRegister(http.MethodGet, "/control/access/list", s.handleAccessList) s.conf.HTTPRegister(http.MethodPost, "/control/access/set", s.handleAccessSet)
s.conf.HTTPRegister("GET", "/control/dns_info", s.handleGetConfig) s.conf.HTTPRegister("POST", "/control/dns_config", s.handleSetConfig) s.conf.HTTPRegister("POST", "/control/test_upstream_dns", s.handleTestUpstreamDNS) s.conf.HTTPRegister(http.MethodGet, "/control/access/list", s.handleAccessList) s.conf.HTTPRegister(http.MethodPost, "/control/access/set", s.handleAccessSet) s.conf.HTTPRegister(http.MethodGet, "/control/access/list", s.handleAccessList) s.conf.HTTPRegister(http.MethodPost, "/control/access/set", s.handleAccessSet) s.conf.HTTPRegister("", "/dns-query", s.handleDOH) }
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep" ]
Pull request: all: imp http handlers, imp docs Merge in DNS/adguard-home from fix-openapi to master Squashed commit of the following: commit 0e7530472fb566e5cab73d178c8ec16e5ef11dcb Author: Ainar Garipov <[email protected]> Date: Wed Jan 13 17:02:06 2021 +0300 all: imp http handlers, imp docs
https://github.com/AdguardTeam/AdGuardHome/commit/4474e9fcf9073af593df76b4844f4091c1c7946e
internal/dnsforward/http.go
} // RegisterAuthHandlers - register handlers func RegisterAuthHandlers() { Context.mux.Handle("/control/login", postInstallHandler(ensureHandler("POST", handleLogin))) httpRegister("GET", "/control/logout", handleLogout) } func parseCookie(cookie string) string { pairs := strings.Split(cookie, ";") for _, pair := range pairs {
</s> remove func handleStatus(w http.ResponseWriter, r *http.Request) { </s> add func handleStatus(w http.ResponseWriter, _ *http.Request) { </s> remove return ensure("POST", handler) </s> add return ensure(http.MethodPost, handler) </s> remove return ensure("GET", handler) </s> add return ensure(http.MethodGet, handler) </s> remove r, _ := http.NewRequest("GET", "http://localhost/", nil) </s> add r, _ := http.NewRequest(http.MethodGet, "http://localhost/", nil) </s> remove r.Method = "GET" </s> add r.Method = http.MethodGet
Context.mux.Handle("/control/login", postInstallHandler(ensureHandler(http.MethodPost, handleLogin))) httpRegister(http.MethodGet, "/control/logout", handleLogout)
} // RegisterAuthHandlers - register handlers func RegisterAuthHandlers() { Context.mux.Handle("/control/login", postInstallHandler(ensureHandler(http.MethodPost, handleLogin))) httpRegister(http.MethodGet, "/control/logout", handleLogout) Context.mux.Handle("/control/login", postInstallHandler(ensureHandler(http.MethodPost, handleLogin))) httpRegister(http.MethodGet, "/control/logout", handleLogout) } func parseCookie(cookie string) string { pairs := strings.Split(cookie, ";") for _, pair := range pairs {
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: all: imp http handlers, imp docs Merge in DNS/adguard-home from fix-openapi to master Squashed commit of the following: commit 0e7530472fb566e5cab73d178c8ec16e5ef11dcb Author: Ainar Garipov <[email protected]> Date: Wed Jan 13 17:02:06 2021 +0300 all: imp http handlers, imp docs
https://github.com/AdguardTeam/AdGuardHome/commit/4474e9fcf9073af593df76b4844f4091c1c7946e
internal/home/auth.go
w := testResponseWriter{} w.hdr = make(http.Header) r := http.Request{} r.Header = make(http.Header) r.Method = "GET" // get / - we're redirected to login page r.URL = &url.URL{Path: "/"} handlerCalled = false handler2(&w, &r)
</s> remove r, _ := http.NewRequest("GET", "http://localhost/", nil) </s> add r, _ := http.NewRequest(http.MethodGet, "http://localhost/", nil) </s> remove func handleStatus(w http.ResponseWriter, r *http.Request) { </s> add func handleStatus(w http.ResponseWriter, _ *http.Request) { </s> remove Context.mux.Handle("/control/login", postInstallHandler(ensureHandler("POST", handleLogin))) httpRegister("GET", "/control/logout", handleLogout) </s> add Context.mux.Handle("/control/login", postInstallHandler(ensureHandler(http.MethodPost, handleLogin))) httpRegister(http.MethodGet, "/control/logout", handleLogout) </s> remove 'example': '' </s> add </s> remove return ensure("GET", handler) </s> add return ensure(http.MethodGet, handler)
r.Method = http.MethodGet
w := testResponseWriter{} w.hdr = make(http.Header) r := http.Request{} r.Header = make(http.Header) r.Method = http.MethodGet // get / - we're redirected to login page r.URL = &url.URL{Path: "/"} handlerCalled = false handler2(&w, &r)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: all: imp http handlers, imp docs Merge in DNS/adguard-home from fix-openapi to master Squashed commit of the following: commit 0e7530472fb566e5cab73d178c8ec16e5ef11dcb Author: Ainar Garipov <[email protected]> Date: Wed Jan 13 17:02:06 2021 +0300 all: imp http handlers, imp docs
https://github.com/AdguardTeam/AdGuardHome/commit/4474e9fcf9073af593df76b4844f4091c1c7946e
internal/home/auth_test.go
} else { binary.BigEndian.PutUint32(data, tval) } assert.Nil(t, ioutil.WriteFile(glFilePrefix+"test", data, 0o644)) r, _ := http.NewRequest("GET", "http://localhost/", nil) r.AddCookie(&http.Cookie{Name: glCookieName, Value: "test"}) assert.True(t, glProcessCookie(r)) GLMode = false }
</s> remove func handleStatus(w http.ResponseWriter, r *http.Request) { </s> add func handleStatus(w http.ResponseWriter, _ *http.Request) { </s> remove r.Method = "GET" </s> add r.Method = http.MethodGet </s> remove Context.mux.Handle("/control/login", postInstallHandler(ensureHandler("POST", handleLogin))) httpRegister("GET", "/control/logout", handleLogout) </s> add Context.mux.Handle("/control/login", postInstallHandler(ensureHandler(http.MethodPost, handleLogin))) httpRegister(http.MethodGet, "/control/logout", handleLogout) </s> remove return ensure("POST", handler) </s> add return ensure(http.MethodPost, handler) </s> remove return ensure("GET", handler) </s> add return ensure(http.MethodGet, handler)
r, _ := http.NewRequest(http.MethodGet, "http://localhost/", nil)
} else { binary.BigEndian.PutUint32(data, tval) } assert.Nil(t, ioutil.WriteFile(glFilePrefix+"test", data, 0o644)) r, _ := http.NewRequest(http.MethodGet, "http://localhost/", nil) r.AddCookie(&http.Cookie{Name: glCookieName, Value: "test"}) assert.True(t, glProcessCookie(r)) GLMode = false }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep" ]
Pull request: all: imp http handlers, imp docs Merge in DNS/adguard-home from fix-openapi to master Squashed commit of the following: commit 0e7530472fb566e5cab73d178c8ec16e5ef11dcb Author: Ainar Garipov <[email protected]> Date: Wed Jan 13 17:02:06 2021 +0300 all: imp http handlers, imp docs
https://github.com/AdguardTeam/AdGuardHome/commit/4474e9fcf9073af593df76b4844f4091c1c7946e
internal/home/authglinet_test.go
} *dnsAddresses = append(*dnsAddresses, addr) } func handleStatus(w http.ResponseWriter, r *http.Request) { c := dnsforward.FilteringConfig{} if Context.dnsServer != nil { Context.dnsServer.WriteDiskConfig(&c) }
</s> remove return ensure("POST", handler) </s> add return ensure(http.MethodPost, handler) </s> remove Context.mux.Handle("/control/login", postInstallHandler(ensureHandler("POST", handleLogin))) httpRegister("GET", "/control/logout", handleLogout) </s> add Context.mux.Handle("/control/login", postInstallHandler(ensureHandler(http.MethodPost, handleLogin))) httpRegister(http.MethodGet, "/control/logout", handleLogout) </s> remove return ensure("GET", handler) </s> add return ensure(http.MethodGet, handler) </s> remove r, _ := http.NewRequest("GET", "http://localhost/", nil) </s> add r, _ := http.NewRequest(http.MethodGet, "http://localhost/", nil) </s> remove r.Method = "GET" </s> add r.Method = http.MethodGet
func handleStatus(w http.ResponseWriter, _ *http.Request) {
} *dnsAddresses = append(*dnsAddresses, addr) } func handleStatus(w http.ResponseWriter, _ *http.Request) { c := dnsforward.FilteringConfig{} if Context.dnsServer != nil { Context.dnsServer.WriteDiskConfig(&c) }
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: all: imp http handlers, imp docs Merge in DNS/adguard-home from fix-openapi to master Squashed commit of the following: commit 0e7530472fb566e5cab73d178c8ec16e5ef11dcb Author: Ainar Garipov <[email protected]> Date: Wed Jan 13 17:02:06 2021 +0300 all: imp http handlers, imp docs
https://github.com/AdguardTeam/AdGuardHome/commit/4474e9fcf9073af593df76b4844f4091c1c7946e
internal/home/control.go
http.Error(w, "This request must be "+method, http.StatusMethodNotAllowed) return } if method == "POST" || method == "PUT" || method == "DELETE" { Context.controlLock.Lock() defer Context.controlLock.Unlock() } handler(w, r)
</s> remove return ensure("POST", handler) </s> add return ensure(http.MethodPost, handler) </s> remove return ensure("GET", handler) </s> add return ensure(http.MethodGet, handler) </s> remove func handleStatus(w http.ResponseWriter, r *http.Request) { </s> add func handleStatus(w http.ResponseWriter, _ *http.Request) { </s> remove s.conf.HTTPRegister("GET", "/control/dns_info", s.handleGetConfig) s.conf.HTTPRegister("POST", "/control/dns_config", s.handleSetConfig) s.conf.HTTPRegister("POST", "/control/test_upstream_dns", s.handleTestUpstreamDNS) </s> add s.conf.HTTPRegister(http.MethodGet, "/control/dns_info", s.handleGetConfig) s.conf.HTTPRegister(http.MethodPost, "/control/dns_config", s.handleSetConfig) s.conf.HTTPRegister(http.MethodPost, "/control/test_upstream_dns", s.handleTestUpstreamDNS) </s> remove 'example': '' </s> add
if method == http.MethodPost || method == http.MethodPut || method == http.MethodDelete {
http.Error(w, "This request must be "+method, http.StatusMethodNotAllowed) return } if method == http.MethodPost || method == http.MethodPut || method == http.MethodDelete { Context.controlLock.Lock() defer Context.controlLock.Unlock() } handler(w, r)
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
Pull request: all: imp http handlers, imp docs Merge in DNS/adguard-home from fix-openapi to master Squashed commit of the following: commit 0e7530472fb566e5cab73d178c8ec16e5ef11dcb Author: Ainar Garipov <[email protected]> Date: Wed Jan 13 17:02:06 2021 +0300 all: imp http handlers, imp docs
https://github.com/AdguardTeam/AdGuardHome/commit/4474e9fcf9073af593df76b4844f4091c1c7946e
internal/home/control.go