Skip to content

Commit

Permalink
cmd/stdiscosrv: Metric for returned retry-after
Browse files Browse the repository at this point in the history
  • Loading branch information
calmh committed Nov 3, 2023
1 parent 5e22584 commit bdd2766
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
8 changes: 5 additions & 3 deletions cmd/stdiscosrv/apisrv.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,9 @@ func (s *apiSrv) handleGET(w http.ResponseWriter, req *http.Request) {
s.db.put(key, rec)
}

w.Header().Set("Retry-After", notFoundRetryAfterString(int(misses)))
afterS := notFoundRetryAfterSeconds(int(misses))
retryAfterHistogram.Observe(float64(afterS))
w.Header().Set("Retry-After", strconv.Itoa(afterS))
http.Error(w, "Not Found", http.StatusNotFound)
return
}
Expand Down Expand Up @@ -476,13 +478,13 @@ func errorRetryAfterString() string {
return strconv.Itoa(errorRetryAfterSeconds + rand.Intn(errorRetryFuzzSeconds))
}

func notFoundRetryAfterString(misses int) string {
func notFoundRetryAfterSeconds(misses int) int {
retryAfterS := notFoundRetryMinSeconds + notFoundRetryIncSeconds*misses
if retryAfterS > notFoundRetryMaxSeconds {
retryAfterS = notFoundRetryMaxSeconds
}
retryAfterS += rand.Intn(notFoundRetryFuzzSeconds)
return strconv.Itoa(retryAfterS)
return retryAfterS
}

func reannounceAfterString() string {
Expand Down
12 changes: 10 additions & 2 deletions cmd/stdiscosrv/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ var (
Help: "Latency of database operations.",
Objectives: map[float64]float64{0.5: 0.05, 0.9: 0.01, 0.99: 0.001},
}, []string{"operation"})

retryAfterHistogram = prometheus.NewHistogram(prometheus.HistogramOpts{
Namespace: "syncthing",
Subsystem: "discovery",
Name: "retry_after_seconds",
Help: "Retry-After header value in seconds.",
Buckets: prometheus.ExponentialBuckets(60, 2, 7), // 60, 120, 240, 480, 960, 1920, 3840
})
)

const (
Expand All @@ -108,7 +116,8 @@ func init() {
lookupRequestsTotal, announceRequestsTotal,
replicationSendsTotal, replicationRecvsTotal,
databaseKeys, databaseStatisticsSeconds,
databaseOperations, databaseOperationSeconds)
databaseOperations, databaseOperationSeconds,
retryAfterHistogram)

processCollectorOpts := collectors.ProcessCollectorOpts{
Namespace: "syncthing_discovery",
Expand All @@ -120,5 +129,4 @@ func init() {
prometheus.MustRegister(
collectors.NewProcessCollector(processCollectorOpts),
)

}

0 comments on commit bdd2766

Please sign in to comment.