all: fix fmt
This commit is contained in:
parent
d54022baa6
commit
2f3e25bee5
|
@ -42,7 +42,7 @@ type getConfigResp struct {
|
|||
// Ignored is the list of host names, which should not be written to log.
|
||||
Ignored []string `json:"ignored"`
|
||||
|
||||
// Interval is the querylog rotation interval in milliseconds
|
||||
// Interval is the querylog rotation interval in milliseconds.
|
||||
Interval float64 `json:"interval"`
|
||||
|
||||
// Enabled shows if the querylog is enabled. It is an aghalg.NullBool to
|
||||
|
@ -103,8 +103,7 @@ func (l *queryLog) handleQueryLogInfo(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
ivl := l.conf.RotationIvl
|
||||
|
||||
ok := checkInterval(ivl)
|
||||
if !ok {
|
||||
if !checkInterval(ivl) {
|
||||
// NOTE: If interval is custom we set it to 90 days for compatibility
|
||||
// with old API.
|
||||
ivl = timeutil.Day * 90
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/AdguardTeam/AdGuardHome/internal/aghhttp"
|
||||
"github.com/AdguardTeam/AdGuardHome/internal/aghnet"
|
||||
"github.com/AdguardTeam/golibs/log"
|
||||
"github.com/AdguardTeam/golibs/timeutil"
|
||||
"golang.org/x/exp/slices"
|
||||
)
|
||||
|
||||
|
@ -116,10 +117,7 @@ func (s *StatsCtx) handleGetStatsConfig(w http.ResponseWriter, r *http.Request)
|
|||
Interval: float64(s.limit.Milliseconds()),
|
||||
Ignored: ignored,
|
||||
}
|
||||
err := aghhttp.WriteJSONResponse(w, r, resp)
|
||||
if err != nil {
|
||||
log.Debug("stats: write response: %s", err)
|
||||
}
|
||||
_ = aghhttp.WriteJSONResponse(w, r, resp)
|
||||
}
|
||||
|
||||
// handleStatsConfig handles requests to the POST /control/stats_config
|
||||
|
@ -146,11 +144,12 @@ func (s *StatsCtx) handleStatsConfig(w http.ResponseWriter, r *http.Request) {
|
|||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
|
||||
s.setLimitLocked(int(reqData.IntervalDays))
|
||||
limit := time.Duration(reqData.IntervalDays) * timeutil.Day
|
||||
s.setLimitLocked(limit)
|
||||
}
|
||||
|
||||
// handlePutStatsConfig handles requests to the PUT
|
||||
// /control/stats/config/update endpoint.
|
||||
// handlePutStatsConfig handles requests to the PUT /control/stats/config/update
|
||||
// endpoint.
|
||||
func (s *StatsCtx) handlePutStatsConfig(w http.ResponseWriter, r *http.Request) {
|
||||
reqData := getConfigResp{}
|
||||
err := json.NewDecoder(r.Body).Decode(&reqData)
|
||||
|
@ -171,15 +170,15 @@ func (s *StatsCtx) handlePutStatsConfig(w http.ResponseWriter, r *http.Request)
|
|||
|
||||
defer s.configModified()
|
||||
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
|
||||
if reqData.Enabled == aghalg.NBNull {
|
||||
aghhttp.Error(r, w, http.StatusUnprocessableEntity, "enabled is null")
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
s.lock.Lock()
|
||||
defer s.lock.Unlock()
|
||||
|
||||
s.enabled = reqData.Enabled == aghalg.NBTrue
|
||||
|
||||
s.limit = ivl
|
||||
|
|
|
@ -453,15 +453,14 @@ func (s *StatsCtx) periodicFlush() {
|
|||
log.Debug("periodic flushing finished")
|
||||
}
|
||||
|
||||
// setLimitLocked sets the limit interval without locking. For internal use
|
||||
// only.
|
||||
// setLimitLocked sets the limit without locking. For internal use only.
|
||||
//
|
||||
// TODO(s.chzhen): Remove it when migration to the new API is over.
|
||||
func (s *StatsCtx) setLimitLocked(limitDays int) {
|
||||
if limitDays != 0 {
|
||||
func (s *StatsCtx) setLimitLocked(limit time.Duration) {
|
||||
if limit != 0 {
|
||||
s.enabled = true
|
||||
s.limit = time.Duration(limitDays) * timeutil.Day
|
||||
log.Debug("stats: set limit: %d days", limitDays)
|
||||
s.limit = limit
|
||||
log.Debug("stats: set limit: %d days", int(limit.Hours()/24))
|
||||
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue