Pull request: 4850 stats: imp logging

Merge in DNS/adguard-home from 4850-imp-stats-logging to master

Updates #4850.

Squashed commit of the following:

commit 3c1ee8dd794fab2b604a0e710a513f75273ed417
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Mon Aug 22 14:17:56 2022 +0300

    all: imp chlog

commit 0c7adc72740114eb7ae0105199ccbdbfabf8f9fe
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Mon Aug 22 14:12:01 2022 +0300

    stats: fix err check

commit d14a5cabecba75e9f0d401e61994d0efd2b324ff
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Mon Aug 22 14:09:15 2022 +0300

    stats: imp logging again

commit 34fc6663484924466171f46dc320382cf02f360b
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Mon Aug 22 12:49:43 2022 +0300

    stats: imp code, logging

commit 09aa857a5e449e62c8c870b7eb5c5ce744d78ae7
Merge: 09a732af eccfbf6a
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Fri Aug 19 19:43:45 2022 +0300

    Merge branch 'master' into 4850-imp-stats-logging

commit 09a732afdc9b6dad4439be83aab7df72c5d68dac
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Fri Aug 19 19:38:51 2022 +0300

    stats: imp logging
This commit is contained in:
Eugene Burkov 2022-08-22 14:21:41 +03:00
parent eccfbf6a6d
commit 970b6cf698
2 changed files with 22 additions and 13 deletions

View File

@ -28,7 +28,12 @@ and this project adheres to
future release.
- Go 1.18 support. v0.109.0 will require at least Go 1.19 to build.
### Fixed
- Unnecessary logging of non-critical statistics errors ([#4850]).
[#2993]: https://github.com/AdguardTeam/AdGuardHome/issues/2993
[#4850]: https://github.com/AdguardTeam/AdGuardHome/issues/4850

View File

@ -385,35 +385,39 @@ func (s *StatsCtx) flush() (cont bool, sleepFor time.Duration) {
return true, 0
}
isCommitable := true
tx, err := db.Begin(true)
if err != nil {
log.Error("stats: opening transaction: %s", err)
return true, 0
}
defer func() {
if err = finishTxn(tx, isCommitable); err != nil {
log.Error("stats: %s", err)
}
}()
s.curr = newUnit(id)
isCommitable := true
ferr := ptr.serialize().flushUnitToDB(tx, ptr.id)
if ferr != nil {
log.Error("stats: flushing unit: %s", ferr)
flushErr := ptr.serialize().flushUnitToDB(tx, ptr.id)
if flushErr != nil {
log.Error("stats: flushing unit: %s", flushErr)
isCommitable = false
}
derr := tx.DeleteBucket(idToUnitName(id - limit))
if derr != nil {
log.Error("stats: deleting unit: %s", derr)
if !errors.Is(derr, bbolt.ErrBucketNotFound) {
delErr := tx.DeleteBucket(idToUnitName(id - limit))
if delErr != nil {
// TODO(e.burkov): Improve the algorithm of deleting the oldest bucket
// to avoid the error.
if errors.Is(delErr, bbolt.ErrBucketNotFound) {
log.Debug("stats: warning: deleting unit: %s", delErr)
} else {
isCommitable = false
log.Error("stats: deleting unit: %s", delErr)
}
}
err = finishTxn(tx, isCommitable)
if err != nil {
log.Error("stats: %s", err)
}
return true, 0
}