Skip to content

Commit

Permalink
feat: add wal write system call metrics observation
Browse files Browse the repository at this point in the history
Signed-off-by: Qiuyu Wu <qiuyu.wu@shopee.com>
  • Loading branch information
Qiuyu Wu committed Mar 25, 2024
1 parent 8383107 commit d9f52b2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions server/wal/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"io"
"os"
"sync"
"time"

"go.etcd.io/etcd/pkg/v3/crc"
"go.etcd.io/etcd/pkg/v3/ioutil"
Expand Down Expand Up @@ -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
}
Expand All @@ -118,7 +121,9 @@ func (e *encoder) flush() error {
func writeUint64(w io.Writer, n uint64, buf []byte) error {
// http://golang.org/src/encoding/binary/binary.go
binary.LittleEndian.PutUint64(buf, n)
start := time.Now()
nv, err := w.Write(buf)
walWriteSec.Observe(time.Since(start).Seconds())
walWriteBytes.Add(float64(nv))
return err
}
9 changes: 9 additions & 0 deletions server/wal/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit d9f52b2

Please sign in to comment.