(minor) refactor redis GC and fix TX calls,

add indicator that metrics are running
This commit is contained in:
Lawrence, Rendall
2022-04-17 00:57:30 +03:00
parent 7716aa828a
commit f9c72341c0
12 changed files with 169 additions and 137 deletions
+17 -20
View File
@@ -17,6 +17,7 @@ import (
"github.com/sot-tech/mochi/frontend"
"github.com/sot-tech/mochi/pkg/conf"
"github.com/sot-tech/mochi/pkg/log"
"github.com/sot-tech/mochi/pkg/metrics"
"github.com/sot-tech/mochi/pkg/stop"
)
@@ -285,17 +286,15 @@ func injectRouteParamsToContext(ctx context.Context, ps httprouter.Params) conte
func (f *Frontend) announceRoute(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
var err error
var start time.Time
if f.EnableRequestTiming {
start = time.Now()
}
var addr netip.Addr
defer func() {
if f.EnableRequestTiming {
recordResponseDuration("announce", addr, err, time.Since(start))
} else {
recordResponseDuration("announce", addr, err, time.Duration(0))
}
}()
if f.EnableRequestTiming && metrics.Enabled() {
start = time.Now()
defer func() {
if f.EnableRequestTiming && metrics.Enabled() {
recordResponseDuration("announce", addr, err, time.Since(start))
}
}()
}
req, err := ParseAnnounce(r, f.ParseOptions)
if err != nil {
@@ -325,17 +324,15 @@ func (f *Frontend) announceRoute(w http.ResponseWriter, r *http.Request, ps http
func (f *Frontend) scrapeRoute(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
var err error
var start time.Time
if f.EnableRequestTiming {
start = time.Now()
}
var addr netip.Addr
defer func() {
if f.EnableRequestTiming {
recordResponseDuration("scrape", addr, err, time.Since(start))
} else {
recordResponseDuration("scrape", addr, err, time.Duration(0))
}
}()
if f.EnableRequestTiming && metrics.Enabled() {
start = time.Now()
defer func() {
if f.EnableRequestTiming && metrics.Enabled() {
recordResponseDuration("scrape", addr, err, time.Since(start))
}
}()
}
req, err := ParseScrape(r, f.ParseOptions)
if err != nil {
+1 -1
View File
@@ -79,7 +79,7 @@ func ParseAnnounce(r *http.Request, opts ParseOptions) (*bittorrent.AnnounceRequ
}
request.Peer.ID, err = bittorrent.NewPeerID([]byte(peerID))
if err != nil {
return nil, err
return nil, errInvalidPeerID
}
// Determine the number of remaining bytes for the client.
request.Left, err = qp.Uint("left", 64)