docstring_tokens
stringlengths
0
76.5k
code_tokens
stringlengths
75
1.81M
label_window
listlengths
4
2.12k
html_url
stringlengths
74
116
file_name
stringlengths
3
311
// StatsResp is a response to the GET /control/stats. type StatsResp struct {
<mask> // topAddrs is an alias for the types of the TopFoo fields of statsResponse. <mask> // The key is either a client's address or a requested address. <mask> type topAddrs = map[string]uint64 <mask> <mask> // statsResponse is a response for getting statistics. <mask> type statsResponse struct { <mask> Time...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/http.go
<mask> // statsResponse is a response for getting statistics. <mask> type statsResponse struct { <mask> TimeUnits string `json:"time_units"` <mask> <mask> NumDNSQueries uint64 `json:"num_dns_queries"` <mask> NumBlockedFiltering uint64 `json:"num_blocked_filtering"` <mask> NumReplacedSafebrowsi...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/http.go
NumDNSQueries uint64 `json:"num_dns_queries"` NumBlockedFiltering uint64 `json:"num_blocked_filtering"` NumReplacedSafebrowsing uint64 `json:"num_replaced_safebrowsing"` NumReplacedSafesearch uint64 `json:"num_replaced_safesearch"` NumReplacedParental uint64 `json:"num_replaced_parental"` Avg...
<mask> <mask> BlockedFiltering []uint64 `json:"blocked_filtering"` <mask> ReplacedSafebrowsing []uint64 `json:"replaced_safebrowsing"` <mask> ReplacedParental []uint64 `json:"replaced_parental"` <mask> } <mask> <mask> // handleStats handles requests to the GET /control/stats endpoint. <mask> func (...
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/http.go
// handleStats handles requests to the GET /control/stats endpoint.
<mask> ReplacedSafebrowsing []uint64 `json:"replaced_safebrowsing"` <mask> ReplacedParental []uint64 `json:"replaced_parental"` <mask> } <mask> <mask> // handleStats is a handler for getting statistics. <mask> func (s *StatsCtx) handleStats(w http.ResponseWriter, r *http.Request) { <mask> start := time.N...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/http.go
limit := atomic.LoadUint32(&s.limitHours)
<mask> } <mask> <mask> // handleStats is a handler for getting statistics. <mask> func (s *StatsCtx) handleStats(w http.ResponseWriter, r *http.Request) { <mask> start := time.Now() <mask> <mask> var resp statsResponse <mask> var ok bool <mask> resp, ok = s.getData() <mask> <mask> log.Debug("stats: p...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/http.go
start := time.Now() resp, ok := s.getData(limit)
<mask> // handleStats handles requests to the GET /control/stats endpoint. <mask> func (s *StatsCtx) handleStats(w http.ResponseWriter, r *http.Request) { <mask> limit := atomic.LoadUint32(&s.limitHours) <mask> <mask> log.Debug("stats: prepared data in %v", time.Since(start)) <mask> <mask> if !ok { <mask> ...
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/http.go
<mask> <mask> err := json.NewEncoder(w).Encode(resp) <mask> if err != nil { <mask> aghhttp.Error(r, w, http.StatusInternalServerError, "json encode: %s", err) <mask> <mask> return <mask> } <mask> } <mask> <mask> type config struct { <mask> IntervalDays uint32 `json:"interval"` </s> Pull request: ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/http.go
// configResp is the response to the GET /control/stats_info. type configResp struct {
<mask> return <mask> } <mask> } <mask> <mask> type config struct { <mask> IntervalDays uint32 `json:"interval"` <mask> } <mask> <mask> // Get configuration <mask> func (s *StatsCtx) handleStatsInfo(w http.ResponseWriter, r *http.Request) { </s> Pull request: 4358 stats races Merge in DNS/adguard-home ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/http.go
// handleStatsInfo handles requests to the GET /control/stats_info endpoint.
<mask> type config struct { <mask> IntervalDays uint32 `json:"interval"` <mask> } <mask> <mask> // Get configuration <mask> func (s *StatsCtx) handleStatsInfo(w http.ResponseWriter, r *http.Request) { <mask> resp := config{} <mask> resp.IntervalDays = s.limitHours / 24 <mask> <mask> data, err := json.Ma...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/http.go
resp := configResp{IntervalDays: atomic.LoadUint32(&s.limitHours) / 24}
<mask> } <mask> <mask> // Get configuration <mask> func (s *StatsCtx) handleStatsInfo(w http.ResponseWriter, r *http.Request) { <mask> resp := config{} <mask> resp.IntervalDays = s.limitHours / 24 <mask> <mask> data, err := json.Marshal(resp) <mask> if err != nil { <mask> aghhttp.Error(r, w, http.Stat...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/http.go
<mask> data, err := json.Marshal(resp) <mask> if err != nil { <mask> aghhttp.Error(r, w, http.StatusInternalServerError, "json encode: %s", err) <mask> <mask> return <mask> } <mask> w.Header().Set("Content-Type", "application/json") <mask> _, err = w.Write(data) <mask> if err != nil { <mask> aghh...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/http.go
err := json.NewEncoder(w).Encode(resp)
<mask> <mask> return <mask> } <mask> w.Header().Set("Content-Type", "application/json") <mask> _, err = w.Write(data) <mask> if err != nil { <mask> aghhttp.Error(r, w, http.StatusInternalServerError, "http write: %s", err) <mask> } <mask> } <mask> </s> Pull request: 4358 stats races Merge in DNS/...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/http.go
aghhttp.Error(r, w, http.StatusInternalServerError, "json encode: %s", err)
<mask> } <mask> w.Header().Set("Content-Type", "application/json") <mask> _, err = w.Write(data) <mask> if err != nil { <mask> aghhttp.Error(r, w, http.StatusInternalServerError, "http write: %s", err) <mask> } <mask> } <mask> <mask> // Set configuration <mask> func (s *StatsCtx) handleStatsConfig(w h...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/http.go
// handleStatsConfig handles requests to the POST /control/stats_config // endpoint.
<mask> aghhttp.Error(r, w, http.StatusInternalServerError, "http write: %s", err) <mask> } <mask> } <mask> <mask> // Set configuration <mask> func (s *StatsCtx) handleStatsConfig(w http.ResponseWriter, r *http.Request) { <mask> reqData := config{} <mask> err := json.NewDecoder(r.Body).Decode(&reqData) <m...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/http.go
reqData := configResp{}
<mask> } <mask> <mask> // Set configuration <mask> func (s *StatsCtx) handleStatsConfig(w http.ResponseWriter, r *http.Request) { <mask> reqData := config{} <mask> err := json.NewDecoder(r.Body).Decode(&reqData) <mask> if err != nil { <mask> aghhttp.Error(r, w, http.StatusBadRequest, "json decode: %s", er...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/http.go
// handleStatsReset handles requests to the POST /control/stats_reset endpoint.
<mask> s.setLimit(int(reqData.IntervalDays)) <mask> s.configModified() <mask> } <mask> <mask> // Reset data <mask> func (s *StatsCtx) handleStatsReset(w http.ResponseWriter, r *http.Request) { <mask> s.clear() <mask> } <mask> <mask> // Register web handlers </s> Pull request: 4358 stats races Merge in ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/http.go
err := s.clear() if err != nil { aghhttp.Error(r, w, http.StatusInternalServerError, "stats: %s", err) }
<mask> } <mask> <mask> // Reset data <mask> func (s *StatsCtx) handleStatsReset(w http.ResponseWriter, r *http.Request) { <mask> s.clear() <mask> } <mask> <mask> // Register web handlers <mask> func (s *StatsCtx) initWeb() { <mask> if s.httpRegister == nil { </s> Pull request: 4358 stats races Merge in ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/http.go
// initWeb registers the handlers for web endpoints of statistics module.
<mask> func (s *StatsCtx) handleStatsReset(w http.ResponseWriter, r *http.Request) { <mask> s.clear() <mask> } <mask> <mask> // Register web handlers <mask> func (s *StatsCtx) initWeb() { <mask> if s.httpRegister == nil { <mask> return <mask> } <mask> </s> Pull request: 4358 stats races Merge in DNS/...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/http.go
"fmt" "io"
<mask> package stats <mask> <mask> import ( <mask> "net" <mask> "os" <mask> "sync" <mask> "sync/atomic" </s> Pull request: 4358 stats races Merge in DNS/adguard-home from 4358-stats-races to master Updates #4358 Squashed commit of the following: commit 162d17b04d95adad21fb9b3c5a6fb64df2e037ec Merge: 17...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats.go
"os" "sync" "sync/atomic" "time"
<mask> "fmt" <mask> "io" <mask> "net" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghhttp" <mask> "github.com/AdguardTeam/golibs/errors" <mask> "github.com/AdguardTeam/golibs/log" </s> Pull request: 4358 stats races Merge in DNS/adguard-home from 4358-stats-races to master Updates #4358 ...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats.go
"github.com/AdguardTeam/golibs/errors" "github.com/AdguardTeam/golibs/log" "go.etcd.io/bbolt"
<mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghhttp" <mask> ) <mask> <mask> // DiskConfig is the configuration structure that is stored in file. <mask> type DiskConfig struct { </s> Pull request: 4358 stats races Merge in DNS/adguard-home from 4358-stats-races to master Updates #4358 Squashe...
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats.go
<mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghhttp" <mask> ) <mask> <mask> // UnitIDGenFunc is the signature of a function that generates a unique ID for <mask> // the statistics unit. <mask> type UnitIDGenFunc func() (id uint32) <mask> <mask> // DiskConfig is the configuration structure th...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats.go
// 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 }
<mask> } <mask> <mask> // Config is the configuration structure for the statistics collecting. <mask> type Config struct { <mask> // UnitID is the function to generate the identifier for current unit. If <mask> // nil, the default function is used, see newUnitID. <mask> UnitID UnitIDGenFunc </s> Pull reque...
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats.go
io.Closer
<mask> type Interface interface { <mask> // Start begins the statistics collecting. <mask> Start() <mask> <mask> // Close stops the statistics collecting. <mask> Close() <mask> <mask> // Update collects the incoming statistics data. <mask> Update(e Entry) <mask> <mask> // GetTopClientIP returns at ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats.go
TopClientsIP(limit uint) []net.IP
<mask> Update(e Entry) <mask> <mask> // GetTopClientIP returns at most limit IP addresses corresponding to the <mask> // clients with the most number of requests. <mask> GetTopClientsIP(limit uint) []net.IP <mask> <mask> // WriteDiskConfig puts the Interface's configuration to the dc. <mask> WriteDiskCo...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats.go
// StatsCtx collects the statistics and flushes it to the database. Its default // flushing interval is one hour. // // TODO(e.burkov): Use atomic.Pointer for accessing db in go1.19. type StatsCtx struct { // limitHours is the maximum number of hours to collect statistics into the // current unit. // // It is of ...
<mask> // WriteDiskConfig puts the Interface's configuration to the dc. <mask> WriteDiskConfig(dc *DiskConfig) <mask> } <mask> <mask> // TimeUnit is the unit of measuring time while aggregating the statistics. <mask> type TimeUnit int <mask> <mask> // Supported TimeUnit values. <mask> const ( <mask> Hour...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats.go
// currMu protects curr. currMu *sync.RWMutex // curr is the actual statistics collection result. curr *unit
<mask> <mask> // TimeUnit is the unit of measuring time while aggregating the statistics. <mask> type TimeUnit int <mask> <mask> // Supported TimeUnit values. <mask> const ( <mask> Hours TimeUnit = iota <mask> Days <mask> ) <mask> <mask> // Result is the resulting code of processing the DNS request. <m...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats.go
// dbMu protects db. dbMu *sync.Mutex // db is the opened statistics database, if any. db *bbolt.DB
<mask> Hours TimeUnit = iota <mask> Days <mask> ) <mask> <mask> // Result is the resulting code of processing the DNS request. <mask> type Result int <mask> <mask> // Supported Result values. <mask> // <mask> // TODO(e.burkov): Think about better naming. <mask> const ( </s> Pull request: 4358 stats rac...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats.go
// unitIDGen is the function that generates an identifier for the current // unit. It's here for only testing purposes. unitIDGen UnitIDGenFunc
<mask> <mask> // Result is the resulting code of processing the DNS request. <mask> type Result int <mask> <mask> // Supported Result values. <mask> // <mask> // TODO(e.burkov): Think about better naming. <mask> const ( <mask> RNotFiltered Result = iota + 1 <mask> RFiltered <mask> RSafeBrowsing <mask>...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats.go
// httpRegister is used to set HTTP handlers. httpRegister aghhttp.RegisterFunc // configModified is called whenever the configuration is modified via web // interface. configModified func() // filename is the name of database file. filename string } var _ Interface = &StatsCtx{} // New creates s from conf a...
<mask> <mask> resultLast = RParental + 1 <mask> ) <mask> <mask> // Entry is a statistics data entry. <mask> type Entry struct { <mask> // Clients is the client's primary ID. <mask> // <mask> // TODO(a.garipov): Make this a {net.IP, string} enum? <mask> Client string <mask> <mask> // Domain is the d...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats.go
if cur != nil { units = append(units, cur.serialize()) }
<mask> // <mask> // TODO(a.garipov): Make this a {net.IP, string} enum? <mask> Client string <mask> <mask> // Domain is the domain name requested. <mask> Domain string <mask> <mask> // Result is the result of processing the request. <mask> Result Result <mask> <mask> // Time is the duration of the...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats.go
if unitsLen := len(units); unitsLen != int(limit) { log.Fatalf("loaded %d units whilst the desired number is %d", unitsLen, limit) }
<mask> <mask> // Domain is the domain name requested. <mask> Domain string <mask> <mask> // Result is the result of processing the request. <mask> Result Result <mask> <mask> // Time is the duration of the request processing in milliseconds. <mask> Time uint32 <mask> } </s> Pull request: 4358 stats ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats.go
return units, firstID
<mask> <mask> // Result is the result of processing the request. <mask> Result Result <mask> <mask> // Time is the duration of the request processing in milliseconds. <mask> Time uint32 <mask> } </s> Pull request: 4358 stats races Merge in DNS/adguard-home from 4358-stats-races to master Updates #4358 ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats.go
package stats_test
<mask> package stats <mask> <mask> import ( <mask> "fmt" <mask> "net" <mask> "os" </s> Pull request: 4358 stats races Merge in DNS/adguard-home from 4358-stats-races to master Updates #4358 Squashed commit of the following: commit 162d17b04d95adad21fb9b3c5a6fb64df2e037ec Merge: 17732cfa d4c3a43b Author: ...
[ "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
"encoding/json"
<mask> package stats_test <mask> <mask> import ( <mask> "fmt" <mask> "net" <mask> "net/http" <mask> "net/http/httptest" </s> Pull request: 4358 stats races Merge in DNS/adguard-home from 4358-stats-races to master Updates #4358 Squashed commit of the following: commit 162d17b04d95adad21fb9b3c5a6fb64df2...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
"net/http" "net/http/httptest" "path/filepath"
<mask> <mask> import ( <mask> "fmt" <mask> "net" <mask> "os" <mask> "sync/atomic" <mask> "testing" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghtest" <mask> "github.com/AdguardTeam/golibs/testutil" </s> Pull request: 4358 stats races Merge in DNS/adguard-home from 4358-stats-races ...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
"github.com/AdguardTeam/AdGuardHome/internal/stats"
<mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghtest" <mask> "github.com/AdguardTeam/golibs/testutil" <mask> "github.com/stretchr/testify/assert" <mask> "github.com/stretchr/testify/require" <mask> ) <mask> </s> Pull request: 4358 stats races Merge in DNS/adguard-home from 4358-stats-races ...
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
// constUnitID is the UnitIDGenFunc which always return 0. func constUnitID() (id uint32) { return 0 }
<mask> func TestMain(m *testing.M) { <mask> aghtest.DiscardLogOutput(m) <mask> } <mask> <mask> func UIntArrayEquals(a, b []uint64) bool { <mask> if len(a) != len(b) { <mask> return false <mask> } <mask> <mask> for i := range a { <mask> if a[i] != b[i] { <mask> return false <mask> } </s> Pul...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
func assertSuccessAndUnmarshal(t *testing.T, to any, handler http.Handler, req *http.Request) { t.Helper() require.NotNil(t, handler) rw := httptest.NewRecorder() handler.ServeHTTP(rw, req) require.Equal(t, http.StatusOK, rw.Code) data := rw.Body.Bytes() if to == nil { assert.Empty(t, data) return
<mask> if len(a) != len(b) { <mask> return false <mask> } <mask> <mask> for i := range a { <mask> if a[i] != b[i] { <mask> return false <mask> } <mask> } <mask> <mask> return true <mask> } <mask> </s> Pull request: 4358 stats races Merge in DNS/adguard-home from 4358-stats-races to maste...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
err := json.Unmarshal(data, to) require.NoError(t, err)
<mask> return false <mask> } <mask> } <mask> <mask> return true <mask> } <mask> <mask> func TestStats(t *testing.T) { <mask> conf := Config{ <mask> Filename: "./stats.db", </s> Pull request: 4358 stats races Merge in DNS/adguard-home from 4358-stats-races to master Updates #4358 Squashed comm...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
cliIP := net.IP{127, 0, 0, 1} cliIPStr := cliIP.String() handlers := map[string]http.Handler{} conf := stats.Config{ Filename: filepath.Join(t.TempDir(), "stats.db"),
<mask> return true <mask> } <mask> <mask> func TestStats(t *testing.T) { <mask> conf := Config{ <mask> Filename: "./stats.db", <mask> LimitDays: 1, <mask> } <mask> <mask> s, err := New(conf) <mask> require.NoError(t, err) </s> Pull request: 4358 stats races Merge in DNS/adguard-home from 4358-s...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
UnitID: constUnitID, HTTPRegister: func(_, url string, handler http.HandlerFunc) { handlers[url] = handler },
<mask> Filename: filepath.Join(t.TempDir(), "stats.db"), <mask> LimitDays: 1, <mask> } <mask> <mask> s, err := stats.New(conf) <mask> require.NoError(t, err) </s> Pull request: 4358 stats races Merge in DNS/adguard-home from 4358-stats-races to master Updates #4358 Squashed commit of the following: ...
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
s, err := stats.New(conf)
<mask> Filename: "./stats.db", <mask> LimitDays: 1, <mask> } <mask> <mask> s, err := New(conf) <mask> require.NoError(t, err) <mask> testutil.CleanupAndRequireSuccess(t, func() (err error) { <mask> s.clear() <mask> s.Close() <mask> </s> Pull request: 4358 stats races Merge in DNS/adguard-home...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
<mask> } <mask> <mask> s, err := New(conf) <mask> require.NoError(t, err) <mask> testutil.CleanupAndRequireSuccess(t, func() (err error) { <mask> s.clear() <mask> s.Close() <mask> <mask> return os.Remove(conf.Filename) <mask> }) <mask> <mask> s.Update(Entry{ </s> Pull request: 4358 stats rac...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
s.Start() testutil.CleanupAndRequireSuccess(t, s.Close) t.Run("data", func(t *testing.T) { const reqDomain = "domain" entries := []stats.Entry{{ Domain: reqDomain, Client: cliIPStr, Result: stats.RFiltered, Time: 123456, }, { Domain: reqDomain, Client: cliIPStr, Result: stats.RNotFilte...
<mask> testutil.CleanupAndRequireSuccess(t, func() (err error) { <mask> s.clear() <mask> s.Close() <mask> <mask> return os.Remove(conf.Filename) <mask> }) <mask> <mask> s.Update(Entry{ <mask> Domain: "domain", <mask> Client: "127.0.0.1", <mask> Result: RFiltered, <mask> Time: 123456, <...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "ke...
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
for _, e := range entries { s.Update(e) }
<mask> <mask> a := []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2} <mask> assert.True(t, UIntArrayEquals(d.DNSQueries, a)) <mask> <mask> a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1} <mask> assert.True(t, UIntArrayEquals(d.BlockedFilter...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
data := &stats.StatsResp{} req := httptest.NewRequest(http.MethodGet, "/control/stats", nil) assertSuccessAndUnmarshal(t, data, handlers["/control/stats"], req)
<mask> <mask> a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1} <mask> assert.True(t, UIntArrayEquals(d.BlockedFiltering, a)) <mask> <mask> a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} <mask> assert.True(t, UIntArrayEquals(d.Replaced...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
assert.Equal(t, wantData, data) })
<mask> <mask> a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} <mask> assert.True(t, UIntArrayEquals(d.ReplacedSafebrowsing, a)) <mask> <mask> a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} <mask> assert.True(t, UIntArrayEquals(d.Repl...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
t.Run("tops", func(t *testing.T) { topClients := s.TopClientsIP(2) require.NotEmpty(t, topClients)
<mask> <mask> a = []uint64{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0} <mask> assert.True(t, UIntArrayEquals(d.ReplacedParental, a)) <mask> <mask> m := d.TopQueried <mask> require.NotEmpty(t, m) <mask> assert.EqualValues(t, 1, m[0]["domain"]) <mask> <mask> m = d.TopBlocked ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
assert.True(t, cliIP.Equal(topClients[0])) })
<mask> m := d.TopQueried <mask> require.NotEmpty(t, m) <mask> assert.EqualValues(t, 1, m[0]["domain"]) <mask> <mask> m = d.TopBlocked <mask> require.NotEmpty(t, m) <mask> assert.EqualValues(t, 1, m[0]["domain"]) <mask> <mask> m = d.TopClients <mask> require.NotEmpty(t, m) <mask> assert.EqualValues...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
t.Run("reset", func(t *testing.T) { req := httptest.NewRequest(http.MethodPost, "/control/stats_reset", nil) assertSuccessAndUnmarshal(t, nil, handlers["/control/stats_reset"], req) _24zeroes := [24]uint64{} emptyData := &stats.StatsResp{ TimeUnits: "hours", TopQueried: []map[string...
<mask> m = d.TopBlocked <mask> require.NotEmpty(t, m) <mask> assert.EqualValues(t, 1, m[0]["domain"]) <mask> <mask> m = d.TopClients <mask> require.NotEmpty(t, m) <mask> assert.EqualValues(t, 2, m[0]["127.0.0.1"]) <mask> <mask> assert.EqualValues(t, 2, d.NumDNSQueries) <mask> assert.EqualValues(t, 1...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
req = httptest.NewRequest(http.MethodGet, "/control/stats", nil) data := &stats.StatsResp{}
<mask> m = d.TopClients <mask> require.NotEmpty(t, m) <mask> assert.EqualValues(t, 2, m[0]["127.0.0.1"]) <mask> <mask> assert.EqualValues(t, 2, d.NumDNSQueries) <mask> assert.EqualValues(t, 1, d.NumBlockedFiltering) <mask> assert.EqualValues(t, 0, d.NumReplacedSafebrowsing) <mask> assert.EqualValues(t, ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
assertSuccessAndUnmarshal(t, data, handlers["/control/stats"], req) assert.Equal(t, emptyData, data) })
<mask> assert.EqualValues(t, 0, d.NumReplacedSafesearch) <mask> assert.EqualValues(t, 0, d.NumReplacedParental) <mask> assert.EqualValues(t, 0.123456, d.AvgProcessingTime) <mask> <mask> topClients := s.GetTopClientsIP(2) <mask> require.NotEmpty(t, topClients) <mask> assert.True(t, net.IP{127, 0, 0, 1}.Equ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
var curHour uint32 = 1 handlers := map[string]http.Handler{} conf := stats.Config{ Filename: filepath.Join(t.TempDir(), "stats.db"), LimitDays: 1, UnitID: func() (id uint32) { return atomic.LoadUint32(&curHour) }, HTTPRegister: func(_, url string, handler http.HandlerFunc) { handlers[url] = han...
<mask> assert.True(t, net.IP{127, 0, 0, 1}.Equal(topClients[0])) <mask> } <mask> <mask> func TestLargeNumbers(t *testing.T) { <mask> var hour int32 = 0 <mask> newID := func() uint32 { <mask> // Use "atomic" to make go race detector happy. <mask> return uint32(atomic.LoadInt32(&hour)) <mask> } <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
s, err := stats.New(conf)
<mask> // Use "atomic" to make go race detector happy. <mask> return uint32(atomic.LoadInt32(&hour)) <mask> } <mask> <mask> conf := Config{ <mask> Filename: "./stats.db", <mask> LimitDays: 1, <mask> UnitID: newID, <mask> } <mask> s, err := New(conf) <mask> require.NoError(t, err) <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
<mask> UnitID: newID, <mask> } <mask> s, err := New(conf) <mask> require.NoError(t, err) <mask> testutil.CleanupAndRequireSuccess(t, func() (err error) { <mask> s.Close() <mask> <mask> return os.Remove(conf.Filename) <mask> }) <mask> <mask> // Number of distinct clients and domains every hou...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
s.Start() testutil.CleanupAndRequireSuccess(t, s.Close)
<mask> require.NoError(t, err) <mask> testutil.CleanupAndRequireSuccess(t, func() (err error) { <mask> s.Close() <mask> <mask> return os.Remove(conf.Filename) <mask> }) <mask> <mask> // Number of distinct clients and domains every hour. <mask> const n = 1000 <mask> <mask> for h := 0; h < 12; h++...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
const ( hoursNum = 12 cliNumPerHour = 1000 )
<mask> <mask> return os.Remove(conf.Filename) <mask> }) <mask> <mask> // Number of distinct clients and domains every hour. <mask> const n = 1000 <mask> <mask> for h := 0; h < 12; h++ { <mask> atomic.AddInt32(&hour, 1) <mask> for i := 0; i < n; i++ { <mask> s.Update(Entry{ <mask> Domain:...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", ...
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
req := httptest.NewRequest(http.MethodGet, "/control/stats", nil)
<mask> }) <mask> } <mask> } <mask> <mask> d, ok := s.getData() <mask> require.True(t, ok) <mask> assert.EqualValues(t, hour*n, d.NumDNSQueries) <mask> } <mask> <mask> func TestStatsCollector(t *testing.T) { <mask> ng := func(_ *unitDB) uint64 { <mask> return 0 <mask> } <mask> units := make...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
for h := 0; h < hoursNum; h++ { atomic.AddUint32(&curHour, 1)
<mask> return 0 <mask> } <mask> units := make([]*unitDB, 720) <mask> <mask> t.Run("hours", func(t *testing.T) { <mask> statsData := statsCollector(units, 0, Hours, ng) <mask> assert.Len(t, statsData, 720) <mask> }) <mask> <mask> t.Run("days", func(t *testing.T) { <mask> for i := 0; i != 25; i+...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
for i := 0; i < cliNumPerHour; i++ { ip := net.IP{127, 0, byte((i & 0xff00) >> 8), byte(i & 0xff)} e := stats.Entry{ Domain: fmt.Sprintf("domain%d.hour%d", i, h), Client: ip.String(), Result: stats.RNotFiltered, Time: 123456, } s.Update(e)
<mask> statsData := statsCollector(units, 0, Hours, ng) <mask> assert.Len(t, statsData, 720) <mask> }) <mask> <mask> t.Run("days", func(t *testing.T) { <mask> for i := 0; i != 25; i++ { <mask> statsData := statsCollector(units, uint32(i), Days, ng) <mask> require.Lenf(t, statsData, 30, "i=%d", i)...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
} data := &stats.StatsResp{} assertSuccessAndUnmarshal(t, data, handlers["/control/stats"], req) assert.Equal(t, hoursNum*cliNumPerHour, int(data.NumDNSQueries))
<mask> for i := 0; i != 25; i++ { <mask> statsData := statsCollector(units, uint32(i), Days, ng) <mask> require.Lenf(t, statsData, 30, "i=%d", i) <mask> } <mask> }) <mask> } </s> Pull request: 4358 stats races Merge in DNS/adguard-home from 4358-stats-races to master Updates #4358 Squashed commit o...
[ "keep", "keep", "keep", "keep", "replace", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/stats_test.go
<mask> "bytes" <mask> "encoding/binary" <mask> "encoding/gob" <mask> "fmt" <mask> "net" <mask> "os" <mask> "sort" <mask> "sync" <mask> "sync/atomic" <mask> "time" <mask> </s> Pull request: 4358 stats races Merge in DNS/adguard-home from 4358-stats-races to master Updates #4358 Squashed commit ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
<mask> "fmt" <mask> "net" <mask> "os" <mask> "sort" <mask> "sync" <mask> "sync/atomic" <mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghhttp" <mask> "github.com/AdguardTeam/golibs/errors" <mask> "github.com/AdguardTeam/golibs/log" </s> Pull request: 4358 stats races Me...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
<mask> "sync" <mask> "sync/atomic" <mask> "time" <mask> <mask> "github.com/AdguardTeam/AdGuardHome/internal/aghhttp" <mask> "github.com/AdguardTeam/golibs/errors" <mask> "github.com/AdguardTeam/golibs/log" <mask> "go.etcd.io/bbolt" <mask> ) <mask> </s> Pull request: 4358 stats races Merge in DNS/ad...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
// maxDomains is the max number of top domains to return. maxDomains = 100 // maxClients is the max number of top clients to return. maxClients = 100
<mask> // TODO(a.garipov): Rewrite all of this. Add proper error handling and <mask> // inspection. Improve logging. Decrease complexity. <mask> <mask> const ( <mask> maxDomains = 100 // max number of top domains to store in file or return via Get() <mask> maxClients = 100 // max number of top clients to st...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
// UnitIDGenFunc is the signature of a function that generates a unique ID for // the statistics unit. type UnitIDGenFunc func() (id uint32) // TimeUnit is the unit of measuring time while aggregating the statistics. type TimeUnit int // Supported TimeUnit values. const ( Hours TimeUnit = iota Days ) // Result is ...
<mask> maxDomains = 100 // max number of top domains to store in file or return via Get() <mask> maxClients = 100 // max number of top clients to store in file or return via Get() <mask> ) <mask> <mask> // StatsCtx collects the statistics and flushes it to the database. Its default <mask> // flushing interval...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
// TODO(e.burkov): Think about better naming. const ( RNotFiltered Result = iota + 1 RFiltered RSafeBrowsing RSafeSearch RParental resultLast = RParental + 1 ) // Entry is a statistics data entry. type Entry struct { // Clients is the client's primary ID. // // TODO(a.garipov): Make this a {net.IP, string} ...
<mask> <mask> // StatsCtx collects the statistics and flushes it to the database. Its default <mask> // flushing interval is one hour. <mask> // <mask> // TODO(e.burkov): Use atomic.Pointer for accessing curr and db in go1.19. <mask> type StatsCtx struct { <mask> // currMu protects the current unit. <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "re...
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
<mask> } <mask> <mask> // unit collects the statistics data for a specific period of time. <mask> type unit struct { <mask> // mu protects all the fields of a unit. <mask> mu *sync.RWMutex <mask> <mask> // id is the unique unit's identifier. It's set to an absolute hour number <mask> // since the beginn...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
// // Must not be rewritten after creating to be accessed concurrently without // using mu.
<mask> type unit struct { <mask> // id is the unique unit's identifier. It's set to an absolute hour number <mask> // since the beginning of UNIX time by the default ID generating function. <mask> id uint32 <mask> <mask> // nTotal stores the total number of requests. <mask> nTotal uint64 </s> Pull reques...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
// newUnit allocates the new *unit. func newUnit(id uint32) (u *unit) { return &unit{ id: id, nResult: make([]uint64, resultLast), domains: make(map[string]uint64), blockedDomains: make(map[string]uint64), clients: make(map[string]uint64), }
<mask> // clients stores the number of requests from each client. <mask> clients map[string]uint64 <mask> } <mask> <mask> // ongoing returns the current unit. It's safe for concurrent use. <mask> // <mask> // Note that the unit itself should be locked before accessing. <mask> func (s *StatsCtx) ongoing() (u...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "re...
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
// unitDB is the structure for serializing statistics data into the database.
<mask> Name string <mask> Count uint64 <mask> } <mask> <mask> // unitDB is the structure for deserializing statistics data into the database. <mask> type unitDB struct { <mask> // NTotal is the total number of requests. <mask> NTotal uint64 <mask> // NResult is the number of requests by the result's kin...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
<mask> // requests in the unit. <mask> TimeAvg uint32 <mask> } <mask> <mask> // withRecovered turns the value recovered from panic if any into an error and <mask> // combines it with the one pointed by orig. orig must be non-nil. <mask> func withRecovered(orig *error) { <mask> p := recover() <mask> if p ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "re...
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
func finishTxn(tx *bbolt.Tx, commit bool) (err error) { if commit { err = errors.Annotate(tx.Commit(), "committing: %w") } else { err = errors.Annotate(tx.Rollback(), "rolling back: %w")
<mask> <mask> return uint32(time.Now().Unix() / secsInHour) <mask> } <mask> <mask> // newUnit allocates the new *unit. <mask> func newUnit(id uint32) (u *unit) { <mask> return &unit{ <mask> mu: &sync.RWMutex{}, <mask> id: id, <mask> nResult: make([]uint64, resultLast),...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "re...
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
return err
<mask> <mask> return <mask> } <mask> <mask> log.Tracef("transaction has been committed") <mask> } <mask> <mask> // bucketNameLen is the length of a bucket, a 64-bit unsigned integer. <mask> // <mask> // TODO(a.garipov): Find out why a 64-bit integer is used when IDs seem to </s> Pull request: 4358 sta...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
func convertMapToSlice(m map[string]uint64, max int) (s []countPair) { s = make([]countPair, 0, len(m)) for k, v := range m { s = append(s, countPair{Name: k, Count: v})
<mask> <mask> return uint32(binary.BigEndian.Uint64(name)), true <mask> } <mask> <mask> // Flush the current unit to DB and delete an old unit when a new hour is started <mask> // If a unit must be flushed: <mask> // . lock DB <mask> // . atomically set a new empty unit as the current one and get the old uni...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "re...
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
sort.Slice(s, func(i, j int) bool { return s[j].Count < s[i].Count }) if max > len(s) { max = len(s)
<mask> _ = tx.Rollback() <mask> } <mask> } <mask> <mask> log.Tracef("periodicFlush() exited") <mask> } <mask> <mask> // deleteUnit removes the unit by it's id from the database the tx belongs to. <mask> func (s *StatsCtx) deleteUnit(tx *bbolt.Tx, id uint32) bool { <mask> err := tx.DeleteBucket(idToU...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
return s[:max]
<mask> <mask> return false <mask> } <mask> <mask> log.Debug("stats: deleted unit %d", id) <mask> <mask> return true <mask> } <mask> <mask> func convertMapToSlice(m map[string]uint64, max int) []countPair { <mask> a := []countPair{} <mask> for k, v := range m { <mask> a = append(a, countPair{Na...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "k...
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
func convertSliceToMap(a []countPair) (m map[string]uint64) { m = map[string]uint64{}
<mask> } <mask> return a[:max] <mask> } <mask> <mask> func convertSliceToMap(a []countPair) map[string]uint64 { <mask> m := map[string]uint64{} <mask> for _, it := range a { <mask> m[it.Name] = it.Count <mask> } <mask> return m <mask> } </s> Pull request: 4358 stats races Merge in DNS/adguard-home...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
// serialize converts u to the *unitDB. It's safe for concurrent use. u must // not be nil.
<mask> } <mask> return m <mask> } <mask> <mask> // serialize converts u to the *unitDB. It's safe for concurrent use. <mask> func (u *unit) serialize() (udb *unitDB) { <mask> u.mu.RLock() <mask> defer u.mu.RUnlock() <mask> <mask> var timeAvg uint32 = 0 </s> Pull request: 4358 stats races Merge in DN...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
<mask> } <mask> <mask> // serialize converts u to the *unitDB. It's safe for concurrent use. <mask> func (u *unit) serialize() (udb *unitDB) { <mask> u.mu.RLock() <mask> defer u.mu.RUnlock() <mask> <mask> var timeAvg uint32 = 0 <mask> if u.nTotal != 0 { <mask> timeAvg = uint32(u.timeSum / u.nTotal) ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
<mask> if udb == nil { <mask> return <mask> } <mask> <mask> u.mu.Lock() <mask> defer u.mu.Unlock() <mask> <mask> u.nTotal = udb.NTotal <mask> u.nResult = make([]uint64, resultLast) <mask> copy(u.nResult, udb.NResult) <mask> u.domains = convertSliceToMap(udb.Domains) <mask> u.blockedDomains = co...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
// add adds new data to u. It's safe for concurrent use. func (u *unit) add(res Result, domain, cli string, dur uint64) { u.nResult[res]++ if res == RNotFiltered { u.domains[domain]++ } else { u.blockedDomains[domain]++ } u.clients[cli]++ u.timeSum += dur u.nTotal++ } // flushUnitToDB puts udb to the data...
<mask> u.clients = convertSliceToMap(udb.Clients) <mask> u.timeSum = uint64(udb.TimeAvg) * udb.NTotal <mask> } <mask> <mask> func flushUnitToDB(tx *bbolt.Tx, id uint32, udb *unitDB) bool { <mask> log.Tracef("Flushing unit %d", id) <mask> <mask> bkt, err := tx.CreateBucketIfNotExists(idToUnitName(id)) <ma...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
return fmt.Errorf("creating bucket: %w", err)
<mask> log.Tracef("Flushing unit %d", id) <mask> <mask> bkt, err := tx.CreateBucketIfNotExists(idToUnitName(id)) <mask> if err != nil { <mask> log.Error("tx.CreateBucketIfNotExists: %s", err) <mask> return false <mask> } <mask> <mask> var buf bytes.Buffer <mask> enc := gob.NewEncoder(&buf) <mask>...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
buf := &bytes.Buffer{} err = gob.NewEncoder(buf).Encode(udb)
<mask> log.Error("tx.CreateBucketIfNotExists: %s", err) <mask> return false <mask> } <mask> <mask> var buf bytes.Buffer <mask> enc := gob.NewEncoder(&buf) <mask> err = enc.Encode(udb) <mask> if err != nil { <mask> log.Error("gob.Encode: %s", err) <mask> return false <mask> } <mask> </s> Pul...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
return fmt.Errorf("encoding unit: %w", err)
<mask> var buf bytes.Buffer <mask> enc := gob.NewEncoder(&buf) <mask> err = enc.Encode(udb) <mask> if err != nil { <mask> log.Error("gob.Encode: %s", err) <mask> return false <mask> } <mask> <mask> err = bkt.Put([]byte{0}, buf.Bytes()) <mask> if err != nil { <mask> log.Error("bkt.Put: %s", err)...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
return fmt.Errorf("putting unit to database: %w", err)
<mask> } <mask> <mask> err = bkt.Put([]byte{0}, buf.Bytes()) <mask> if err != nil { <mask> log.Error("bkt.Put: %s", err) <mask> return false <mask> } <mask> <mask> return true <mask> } <mask> <mask> func (s *StatsCtx) loadUnitFromDB(tx *bbolt.Tx, id uint32) *unitDB { <mask> bkt := tx.Bucket(id...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
return nil
<mask> if bkt == nil { <mask> return nil <mask> } <mask> <mask> // log.Tracef("Loading unit %d", id) <mask> <mask> var buf bytes.Buffer <mask> buf.Write(bkt.Get([]byte{0})) <mask> dec := gob.NewDecoder(&buf) <mask> udb := unitDB{} <mask> err := dec.Decode(&udb) <mask> if err != nil { <mask> ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
<mask> <mask> return m <mask> } <mask> <mask> func (s *StatsCtx) setLimit(limitDays int) { <mask> atomic.StoreUint32(&s.limitHours, uint32(24*limitDays)) <mask> if limitDays == 0 { <mask> s.clear() <mask> } <mask> <mask> log.Debug("stats: set limit: %d days", limitDays) <mask> } <mask> <mask> f...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "re...
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
nums = make([]uint64, 0, len(units))
<mask> func statsCollector(units []*unitDB, firstID uint32, timeUnit TimeUnit, ng numsGetter) (nums []uint64) { <mask> if timeUnit == Hours { <mask> for _, u := range units { <mask> nums = append(nums, ng(u)) <mask> } <mask> } else { </s> Pull request: 4358 stats races Merge in DNS/adguard-home from 43...
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
func (s *StatsCtx) getData(limit uint32) (StatsResp, bool) {
<mask> * safesearch-blocked <mask> * parental-blocked <mask> These values are just the sum of data for all units. <mask> */ <mask> func (s *StatsCtx) getData() (statsResponse, bool) { <mask> limit := atomic.LoadUint32(&s.limitHours) <mask> if limit == 0 { <mask> return statsResponse{ <mask> TimeUn...
[ "keep", "keep", "keep", "keep", "replace", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
return StatsResp{
<mask> */ <mask> func (s *StatsCtx) getData() (statsResponse, bool) { <mask> limit := atomic.LoadUint32(&s.limitHours) <mask> if limit == 0 { <mask> return statsResponse{ <mask> TimeUnits: "days", <mask> <mask> TopBlocked: []topAddrs{}, <mask> TopClients: []topAddrs{}, <mask> TopQueried: []to...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
return StatsResp{}, false
<mask> } <mask> <mask> units, firstID := s.loadUnits(limit) <mask> if units == nil { <mask> return statsResponse{}, false <mask> } <mask> <mask> dnsQueries := statsCollector(units, firstID, timeUnit, func(u *unitDB) (num uint64) { return u.NTotal }) <mask> if timeUnit != Hours && len(dnsQueries) != i...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
data := StatsResp{
<mask> if timeUnit != Hours && len(dnsQueries) != int(limit/24) { <mask> log.Fatalf("len(dnsQueries) != limit: %d %d", len(dnsQueries), limit) <mask> } <mask> <mask> data := statsResponse{ <mask> DNSQueries: dnsQueries, <mask> BlockedFiltering: statsCollector(units, firstID, timeUnit, fun...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
<mask> } <mask> <mask> return data, true <mask> } <mask> <mask> func (s *StatsCtx) GetTopClientsIP(maxCount uint) []net.IP { <mask> if !s.isEnabled() { <mask> return nil <mask> } <mask> <mask> units, _ := s.loadUnits(atomic.LoadUint32(&s.limitHours)) <mask> if units == nil { <mask> return nil ...
[ "keep", "keep", "keep", "keep", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "replace", "re...
https://github.com/AdguardTeam/AdGuardHome/commit/72098d22551313c3a76b7dcf36594bc09188db86
internal/stats/unit.go
http.HandleFunc("/control/dhcp/add_static_lease", postInstall(optionalAuth(ensurePOST(handleDHCPAddStaticLease)))) http.HandleFunc("/control/dhcp/remove_static_lease", postInstall(optionalAuth(ensurePOST(handleDHCPRemoveStaticLease))))
<mask> http.HandleFunc("/control/dhcp/status", postInstall(optionalAuth(ensureGET(handleDHCPStatus)))) <mask> http.HandleFunc("/control/dhcp/interfaces", postInstall(optionalAuth(ensureGET(handleDHCPInterfaces)))) <mask> http.HandleFunc("/control/dhcp/set_config", postInstall(optionalAuth(ensurePOST(handleDHCPSet...
[ "keep", "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/725aeeb910eeb69fc7463cd2492eaf97e4863868
control.go
type leaseJSON struct { HWAddr string `json:"mac"` IP string `json:"ip"` Hostname string `json:"hostname"` }
<mask> } <mask> <mask> type dhcpServerConfigJSON struct { <mask> dhcpd.ServerConfig `json:",inline"` <mask> StaticLeases []leaseJSON `json:"static_leases"` <mask> } </s> + dhcp: /dhcp/add_static_lease, /dhcp/remove_static_lease: control static lease table </s> remove Expiry time.Time `json:"ex...
[ "keep", "add", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/725aeeb910eeb69fc7463cd2492eaf97e4863868
dhcp.go
StaticLeases []leaseJSON `json:"static_leases"`
<mask> type dhcpServerConfigJSON struct { <mask> dhcpd.ServerConfig `json:",inline"` <mask> } <mask> <mask> func handleDHCPSetConfig(w http.ResponseWriter, r *http.Request) { <mask> log.Tracef("%s %v", r.Method, r.URL) <mask> newconfig := dhcpServerConfigJSON{} </s> + dhcp: /dhcp/add_static_lease, /dhcp/rem...
[ "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/725aeeb910eeb69fc7463cd2492eaf97e4863868
dhcp.go
const leaseExpireStatic = 1
<mask> ) <mask> <mask> const defaultDiscoverTime = time.Second * 3 <mask> <mask> // Lease contains the necessary information about a DHCP lease <mask> // field ordering is important -- yaml fields will mirror ordering from here <mask> type Lease struct { <mask> HWAddr net.HardwareAddr `json:"mac" yaml:"hwa...
[ "keep", "keep", "add", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/725aeeb910eeb69fc7463cd2492eaf97e4863868
dhcpd/dhcpd.go
// Lease expiration time // 1: static lease Expiry time.Time `json:"expires"`
<mask> type Lease struct { <mask> HWAddr net.HardwareAddr `json:"mac" yaml:"hwaddr"` <mask> IP net.IP `json:"ip"` <mask> Hostname string `json:"hostname"` <mask> Expiry time.Time `json:"expires"` <mask> } <mask> <mask> // ServerConfig - DHCP server configuration <mask>...
[ "keep", "keep", "keep", "keep", "replace", "keep", "keep", "keep", "keep", "keep" ]
https://github.com/AdguardTeam/AdGuardHome/commit/725aeeb910eeb69fc7463cd2492eaf97e4863868
dhcpd/dhcpd.go