Skip to content

Commit 88feab3

Browse files
authored
Merge pull request #21030 from tjungblu/www_lls
2 parents 7e385a1 + 71a9ffe commit 88feab3

File tree

3 files changed

+67
-1
lines changed

3 files changed

+67
-1
lines changed

server/etcdserver/api/v3rpc/metrics.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,63 @@ var (
5252
},
5353
[]string{"type", "client_api_version"},
5454
)
55+
56+
watchSendLoopWatchStreamDuration = prometheus.NewHistogram(
57+
prometheus.HistogramOpts{
58+
Namespace: "etcd_debugging",
59+
Subsystem: "server",
60+
Name: "watch_send_loop_watch_stream_duration_seconds",
61+
Help: "The total duration in seconds of running through the send loop watch stream response all events.",
62+
// lowest bucket start of upper bound 0.001 sec (1 ms) with factor 2
63+
// highest bucket start of 0.001 sec * 2^13 == 8.192 sec
64+
Buckets: prometheus.ExponentialBuckets(0.001, 2, 14),
65+
},
66+
)
67+
68+
watchSendLoopWatchStreamDurationPerEvent = prometheus.NewHistogram(
69+
prometheus.HistogramOpts{
70+
Namespace: "etcd_debugging",
71+
Subsystem: "server",
72+
Name: "watch_send_loop_watch_stream_duration_per_event_seconds",
73+
Help: "The average duration in seconds of running through the send loop watch stream response, per event.",
74+
// lowest bucket start of upper bound 0.001 sec (1 ms) with factor 2
75+
// highest bucket start of 0.001 sec * 2^13 == 8.192 sec
76+
Buckets: prometheus.ExponentialBuckets(0.001, 2, 14),
77+
},
78+
)
79+
80+
watchSendLoopControlStreamDuration = prometheus.NewHistogram(
81+
prometheus.HistogramOpts{
82+
Namespace: "etcd_debugging",
83+
Subsystem: "server",
84+
Name: "watch_send_loop_control_stream_duration_seconds",
85+
Help: "The total duration in seconds of running through the send loop control stream response.",
86+
// lowest bucket start of upper bound 0.001 sec (1 ms) with factor 2
87+
// highest bucket start of 0.001 sec * 2^13 == 8.192 sec
88+
Buckets: prometheus.ExponentialBuckets(0.001, 2, 14),
89+
},
90+
)
91+
92+
watchSendLoopProgressDuration = prometheus.NewHistogram(
93+
prometheus.HistogramOpts{
94+
Namespace: "etcd_debugging",
95+
Subsystem: "server",
96+
Name: "watch_send_loop_progress_duration_seconds",
97+
Help: "The total duration in seconds of running through the progress loop control stream response.",
98+
// lowest bucket start of upper bound 0.001 sec (1 ms) with factor 2
99+
// highest bucket start of 0.001 sec * 2^13 == 8.192 sec
100+
Buckets: prometheus.ExponentialBuckets(0.001, 2, 14),
101+
},
102+
)
55103
)
56104

57105
func init() {
58106
prometheus.MustRegister(sentBytes)
59107
prometheus.MustRegister(receivedBytes)
60108
prometheus.MustRegister(streamFailures)
61109
prometheus.MustRegister(clientRequests)
110+
prometheus.MustRegister(watchSendLoopWatchStreamDuration)
111+
prometheus.MustRegister(watchSendLoopWatchStreamDurationPerEvent)
112+
prometheus.MustRegister(watchSendLoopControlStreamDuration)
113+
prometheus.MustRegister(watchSendLoopProgressDuration)
62114
}

server/etcdserver/api/v3rpc/watch.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ func (sws *serverWatchStream) sendLoop() {
432432
return
433433
}
434434

435+
start := time.Now()
435436
// TODO: evs is []mvccpb.Event type
436437
// either return []*mvccpb.Event from the mvcc package
437438
// or define protocol buffer with []mvccpb.Event.
@@ -502,11 +503,15 @@ func (sws *serverWatchStream) sendLoop() {
502503
}
503504
sws.mu.Unlock()
504505

506+
totalDur := time.Since(start)
507+
watchSendLoopWatchStreamDuration.Observe(totalDur.Seconds())
508+
watchSendLoopWatchStreamDurationPerEvent.Observe(totalDur.Seconds() / float64(len(evs)))
509+
505510
case c, ok := <-sws.ctrlStream:
506511
if !ok {
507512
return
508513
}
509-
514+
start := time.Now()
510515
if err := sws.gRPCStream.Send(c); err != nil {
511516
if isClientCtxErr(sws.gRPCStream.Context().Err(), err) {
512517
sws.lg.Debug("failed to send watch control response to gRPC stream", zap.Error(err))
@@ -544,7 +549,11 @@ func (sws *serverWatchStream) sendLoop() {
544549
delete(pending, wid)
545550
}
546551

552+
watchSendLoopControlStreamDuration.Observe(time.Since(start).Seconds())
553+
547554
case <-progressTicker.C:
555+
start := time.Now()
556+
548557
sws.mu.Lock()
549558
for id, ok := range sws.progress {
550559
if ok {
@@ -553,6 +562,7 @@ func (sws *serverWatchStream) sendLoop() {
553562
sws.progress[id] = true
554563
}
555564
sws.mu.Unlock()
565+
watchSendLoopProgressDuration.Observe(time.Since(start).Seconds())
556566

557567
case <-sws.closec:
558568
return

tests/e2e/metrics_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ func TestNoMetricsMissing(t *testing.T) {
160160
"etcd_debugging_mvcc_watch_stream_total",
161161
"etcd_debugging_mvcc_watcher_total",
162162
"etcd_debugging_server_lease_expired_total",
163+
"etcd_debugging_server_watch_send_loop_watch_stream_duration_seconds",
164+
"etcd_debugging_server_watch_send_loop_watch_stream_duration_per_event_seconds",
165+
"etcd_debugging_server_watch_send_loop_control_stream_duration_seconds",
166+
"etcd_debugging_server_watch_send_loop_progress_duration_seconds",
163167
"etcd_debugging_snap_save_marshalling_duration_seconds",
164168
"etcd_debugging_snap_save_total_duration_seconds",
165169
"etcd_debugging_store_expires_total",

0 commit comments

Comments
 (0)