From 2f64140c30fbc090e9cd89f6fc9f6fc03ccda016 Mon Sep 17 00:00:00 2001 From: Qiuyu Wu Date: Wed, 20 Mar 2024 15:38:01 +0800 Subject: [PATCH] feat: add wal write system call metrics observation Signed-off-by: Qiuyu Wu --- server/storage/wal/encoder.go | 3 +++ server/storage/wal/metrics.go | 9 +++++++++ 2 files changed, 12 insertions(+) diff --git a/server/storage/wal/encoder.go b/server/storage/wal/encoder.go index 6d1f97ad6478..32375eb2bbc8 100644 --- a/server/storage/wal/encoder.go +++ b/server/storage/wal/encoder.go @@ -20,6 +20,7 @@ import ( "io" "os" "sync" + "time" "go.etcd.io/etcd/pkg/v3/crc" "go.etcd.io/etcd/pkg/v3/ioutil" @@ -92,7 +93,9 @@ func (e *encoder) encode(rec *walpb.Record) error { if padBytes != 0 { data = append(data, make([]byte, padBytes)...) } + start := time.Now() n, err = e.bw.Write(data) + walWriteSec.Observe(time.Since(start).Seconds()) walWriteBytes.Add(float64(n)) return err } diff --git a/server/storage/wal/metrics.go b/server/storage/wal/metrics.go index 814d654cdd30..65e3c34a7bd4 100644 --- a/server/storage/wal/metrics.go +++ b/server/storage/wal/metrics.go @@ -28,6 +28,15 @@ var ( Buckets: prometheus.ExponentialBuckets(0.001, 2, 14), }) + walWriteSec = prometheus.NewHistogram(prometheus.HistogramOpts{ + Namespace: "etcd", + Subsystem: "disk", + Name: "wal_write_duration_seconds", + Help: "The latency distributions of write called by WAL.", + + Buckets: prometheus.ExponentialBuckets(0.001, 2, 14), + }) + walWriteBytes = prometheus.NewGauge(prometheus.GaugeOpts{ Namespace: "etcd", Subsystem: "disk",