8 "github.com/bytom/metrics"
13 latencies = map[string]*metrics.RotatingLatency{}
15 latencyRange = map[string]time.Duration{
16 crosscoreRPCPrefix + "get-block": 20 * time.Second,
17 crosscoreRPCPrefix + "signer/sign-block": 5 * time.Second,
18 crosscoreRPCPrefix + "get-snapshot": 30 * time.Second,
19 // the rest have a default range
23 // latency returns a rotating latency histogram for the given request.
24 func latency(tab *http.ServeMux, req *http.Request) *metrics.RotatingLatency {
26 defer latencyMu.Unlock()
27 if l := latencies[req.URL.Path]; l != nil {
30 // Create a histogram only if the path is legit.
31 if _, pat := tab.Handler(req); pat == req.URL.Path {
32 d, ok := latencyRange[req.URL.Path]
34 d = 100 * time.Millisecond
36 l := metrics.NewRotatingLatency(5, d)
37 latencies[req.URL.Path] = l
38 metrics.PublishLatency(req.URL.Path, l)