Skip to content

Commit d8e99e9

Browse files
committed
DF-23700 fix scale of latency for beholder + cleanups
Default buckets are good for milliseconds.
1 parent 5a427a1 commit d8e99e9

1 file changed

Lines changed: 13 additions & 11 deletions

File tree

metrics/client.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
var (
1818
RPCCallLatency = promauto.NewHistogramVec(prometheus.HistogramOpts{
19-
Name: rpcCallLatencyBeholder,
19+
Name: rpcCallLatencyMetricName,
2020
Help: "The duration of an RPC call in nanoseconds",
2121
Buckets: []float64{
2222
float64(50 * time.Millisecond),
@@ -31,7 +31,7 @@ var (
3131
}, []string{"chainFamily", "chainID", "rpcUrl", "isSendOnly", "success", "rpcCallName"})
3232
)
3333

34-
const rpcCallLatencyBeholder = "rpc_call_latency"
34+
const rpcCallLatencyMetricName = "rpc_call_latency"
3535

3636
// RPCClientMetrics records RPC call latency to Prometheus and Beholder (failures: success="false"; same pattern as multinode metrics).
3737
// Construct once per chain (or process) with ChainFamily and ChainID; pass rpcUrl and isSendOnly on each call
@@ -59,7 +59,11 @@ type RPCClientMetricsConfig struct {
5959

6060
// NewRPCClientMetrics creates RPC client metrics that publish to Prometheus and Beholder.
6161
func NewRPCClientMetrics(cfg RPCClientMetricsConfig) (RPCClientMetrics, error) {
62-
latency, err := beholder.GetMeter().Float64Histogram(rpcCallLatencyBeholder)
62+
latency, err := beholder.GetMeter().Float64Histogram(
63+
rpcCallLatencyMetricName,
64+
metric.WithUnit("ms"),
65+
metric.WithDescription("The duration of an RPC call in milliseconds"),
66+
)
6367
if err != nil {
6468
return nil, fmt.Errorf("failed to register RPC call latency metric: %w", err)
6569
}
@@ -71,25 +75,23 @@ func NewRPCClientMetrics(cfg RPCClientMetricsConfig) (RPCClientMetrics, error) {
7175
}
7276

7377
func (m *rpcClientMetrics) RecordRequest(ctx context.Context, rpcURL string, isSendOnly bool, callName string, latency time.Duration, err error) {
74-
successStr := "true"
75-
if err != nil {
76-
successStr = "false"
77-
}
78+
successStr := strconv.FormatBool(err != nil)
7879
sendStr := strconv.FormatBool(isSendOnly)
7980
latencyNs := float64(latency)
8081
safeRPCURL := SanitizeRPCURL(rpcURL)
8182

82-
RPCCallLatency.WithLabelValues(m.chainFamily, m.chainID, safeRPCURL, sendStr, successStr, callName).Observe(latencyNs)
83+
RPCCallLatency.WithLabelValues(
84+
m.chainFamily, m.chainID, safeRPCURL, sendStr, successStr, callName,
85+
).Observe(latencyNs)
8386

84-
latAttrs := metric.WithAttributes(
87+
m.latencyHis.Record(ctx, latencyNs/float64(time.Millisecond), metric.WithAttributes(
8588
attribute.String("chainFamily", m.chainFamily),
8689
attribute.String("chainID", m.chainID),
8790
attribute.String("rpcUrl", safeRPCURL),
8891
attribute.String("isSendOnly", sendStr),
8992
attribute.String("success", successStr),
9093
attribute.String("rpcCallName", callName),
91-
)
92-
m.latencyHis.Record(ctx, latencyNs, latAttrs)
94+
))
9395
}
9496

9597
// NoopRPCClientMetrics is a no-op implementation for when metrics are disabled.

0 commit comments

Comments
 (0)