Skip to content

Commit 84fafff

Browse files
authored
Merge pull request #9819 from gyuho/mmm
*: promote db size metric to "'etcd" namespace
2 parents 25f4d80 + a8d7d5a commit 84fafff

File tree

7 files changed

+66
-11
lines changed

7 files changed

+66
-11
lines changed

Documentation/op-guide/grafana.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@
341341
"steppedLine": false,
342342
"targets": [
343343
{
344-
"expr": "etcd_debugging_mvcc_db_total_size_in_bytes{job=\"$cluster\"}",
344+
"expr": "etcd_mvcc_db_total_size_in_bytes{job=\"$cluster\"}",
345345
"hide": false,
346346
"interval": "",
347347
"intervalFactor": 2,

Documentation/op-guide/maintenance.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ $ ETCDCTL_API=3 etcdctl put newkey 123
149149
OK
150150
```
151151

152-
The metric `etcd_debugging_mvcc_db_total_size_in_use_in_bytes` indicates the actual database usage after a history compaction, while `etcd_debugging_mvcc_db_total_size_in_bytes` shows the database size including free space waiting for defragmentation. The latter increases only when the former is close to it, meaning when both of these metrics are close to the quota, a history compaction is required to avoid triggering the space quota.
152+
The metric `etcd_mvcc_db_total_size_in_use_in_bytes` indicates the actual database usage after a history compaction, while `etcd_debugging_mvcc_db_total_size_in_bytes` shows the database size including free space waiting for defragmentation. The latter increases only when the former is close to it, meaning when both of these metrics are close to the quota, a history compaction is required to avoid triggering the space quota.
153+
154+
`etcd_debugging_mvcc_db_total_size_in_bytes` is renamed to `etcd_mvcc_db_total_size_in_bytes` from v3.4.
153155

154156
## Snapshot backup
155157

Documentation/upgrades/upgrade_3_4.md

+13
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,19 @@ OK
4747
+etcd --peer-trusted-ca-file ca-peer.crt
4848
```
4949

50+
#### Promote `etcd_debugging_mvcc_db_total_size_in_bytes` Prometheus metrics
51+
52+
v3.4 promotes `etcd_debugging_mvcc_db_total_size_in_bytes` Prometheus metrics to `etcd_mvcc_db_total_size_in_bytes`, in order to encourage etcd storage monitoring.
53+
54+
`etcd_debugging_mvcc_db_total_size_in_bytes` is still served in v3.4 for backward compatibilities. It will be completely deprecated in v3.5.
55+
56+
```diff
57+
-etcd_debugging_mvcc_db_total_size_in_bytes
58+
+etcd_mvcc_db_total_size_in_bytes
59+
```
60+
61+
Note that `etcd_debugging_*` namespace metrics have been marked as experimental. As we improve monitoring guide, we will promote more metrics.
62+
5063
#### Deprecating `etcd --log-output` flag (now `--log-outputs`)
5164

5265
Rename [`etcd --log-output` to `--log-outputs`](https://github.com/coreos/etcd/pull/9624) to support multiple log outputs. **`etcd --logger=capnslog` does not support multiple log outputs.**

Documentation/upgrades/upgrade_3_5.md

+11
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,17 @@ Before [starting an upgrade](#upgrade-procedure), read through the rest of this
1414

1515
Highlighted breaking changes in 3.5.
1616

17+
#### Deprecate `etcd_debugging_mvcc_db_total_size_in_bytes` Prometheus metrics
18+
19+
v3.4 promoted `etcd_debugging_mvcc_db_total_size_in_bytes` Prometheus metrics to `etcd_mvcc_db_total_size_in_bytes`, in order to encourage etcd storage monitoring. And v3.5 completely deprcates `etcd_debugging_mvcc_db_total_size_in_bytes`.
20+
21+
```diff
22+
-etcd_debugging_mvcc_db_total_size_in_bytes
23+
+etcd_mvcc_db_total_size_in_bytes
24+
```
25+
26+
Note that `etcd_debugging_*` namespace metrics have been marked as experimental. As we improve monitoring guide, we will promote more metrics.
27+
1728
#### Deprecated in `etcd --logger capnslog`
1829

1930
v3.4 defaults to `--logger=zap` in order to support multiple log outputs and structured logging.

integration/metrics_test.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,16 @@ func TestMetricDbSizeBoot(t *testing.T) {
4040
}
4141
}
4242

43-
// TestMetricDbSizeDefrag checks that the db size metric is set after defrag.
4443
func TestMetricDbSizeDefrag(t *testing.T) {
44+
testMetricDbSizeDefrag(t, "etcd")
45+
}
46+
47+
func TestMetricDbSizeDefragDebugging(t *testing.T) {
48+
testMetricDbSizeDefrag(t, "etcd_debugging")
49+
}
50+
51+
// testMetricDbSizeDefrag checks that the db size metric is set after defrag.
52+
func testMetricDbSizeDefrag(t *testing.T, name string) {
4553
defer testutil.AfterTest(t)
4654
clus := NewClusterV3(t, &ClusterConfig{Size: 1})
4755
defer clus.Terminate(t)
@@ -63,7 +71,7 @@ func TestMetricDbSizeDefrag(t *testing.T) {
6371
time.Sleep(500 * time.Millisecond)
6472

6573
expected := numPuts * len(putreq.Value)
66-
beforeDefrag, err := clus.Members[0].Metric("etcd_debugging_mvcc_db_total_size_in_bytes")
74+
beforeDefrag, err := clus.Members[0].Metric(name + "_mvcc_db_total_size_in_bytes")
6775
if err != nil {
6876
t.Fatal(err)
6977
}
@@ -74,7 +82,7 @@ func TestMetricDbSizeDefrag(t *testing.T) {
7482
if bv < expected {
7583
t.Fatalf("expected db size greater than %d, got %d", expected, bv)
7684
}
77-
beforeDefragInUse, err := clus.Members[0].Metric("etcd_debugging_mvcc_db_total_size_in_use_in_bytes")
85+
beforeDefragInUse, err := clus.Members[0].Metric("etcd_mvcc_db_total_size_in_use_in_bytes")
7886
if err != nil {
7987
t.Fatal(err)
8088
}
@@ -98,7 +106,7 @@ func TestMetricDbSizeDefrag(t *testing.T) {
98106
}
99107
time.Sleep(500 * time.Millisecond)
100108

101-
afterCompactionInUse, err := clus.Members[0].Metric("etcd_debugging_mvcc_db_total_size_in_use_in_bytes")
109+
afterCompactionInUse, err := clus.Members[0].Metric("etcd_mvcc_db_total_size_in_use_in_bytes")
102110
if err != nil {
103111
t.Fatal(err)
104112
}
@@ -113,7 +121,7 @@ func TestMetricDbSizeDefrag(t *testing.T) {
113121
// defrag should give freed space back to fs
114122
mc.Defragment(context.TODO(), &pb.DefragmentRequest{})
115123

116-
afterDefrag, err := clus.Members[0].Metric("etcd_debugging_mvcc_db_total_size_in_bytes")
124+
afterDefrag, err := clus.Members[0].Metric(name + "_mvcc_db_total_size_in_bytes")
117125
if err != nil {
118126
t.Fatal(err)
119127
}
@@ -125,7 +133,7 @@ func TestMetricDbSizeDefrag(t *testing.T) {
125133
t.Fatalf("expected less than %d, got %d after defrag", bv, av)
126134
}
127135

128-
afterDefragInUse, err := clus.Members[0].Metric("etcd_debugging_mvcc_db_total_size_in_use_in_bytes")
136+
afterDefragInUse, err := clus.Members[0].Metric("etcd_mvcc_db_total_size_in_use_in_bytes")
129137
if err != nil {
130138
t.Fatal(err)
131139
}

mvcc/kvstore.go

+3
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,9 @@ func (s *store) restore() error {
323323
reportDbTotalSizeInBytesMu.Lock()
324324
reportDbTotalSizeInBytes = func() float64 { return float64(b.Size()) }
325325
reportDbTotalSizeInBytesMu.Unlock()
326+
reportDbTotalSizeInBytesDebuggingMu.Lock()
327+
reportDbTotalSizeInBytesDebugging = func() float64 { return float64(b.Size()) }
328+
reportDbTotalSizeInBytesDebuggingMu.Unlock()
326329
reportDbTotalSizeInUseInBytesMu.Lock()
327330
reportDbTotalSizeInUseInBytes = func() float64 { return float64(b.SizeInUse()) }
328331
reportDbTotalSizeInUseInBytesMu.Unlock()

mvcc/metrics.go

+21-3
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ var (
146146
})
147147

148148
dbTotalSize = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
149-
Namespace: "etcd_debugging",
149+
Namespace: "etcd",
150150
Subsystem: "mvcc",
151151
Name: "db_total_size_in_bytes",
152152
Help: "Total size of the underlying database physically allocated in bytes.",
@@ -159,11 +159,28 @@ var (
159159
)
160160
// overridden by mvcc initialization
161161
reportDbTotalSizeInBytesMu sync.RWMutex
162-
reportDbTotalSizeInBytes func() float64 = func() float64 { return 0 }
162+
reportDbTotalSizeInBytes = func() float64 { return 0 }
163163

164-
dbTotalSizeInUse = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
164+
// TODO: remove this in v3.5
165+
dbTotalSizeDebugging = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
165166
Namespace: "etcd_debugging",
166167
Subsystem: "mvcc",
168+
Name: "db_total_size_in_bytes",
169+
Help: "Total size of the underlying database physically allocated in bytes.",
170+
},
171+
func() float64 {
172+
reportDbTotalSizeInBytesDebuggingMu.RLock()
173+
defer reportDbTotalSizeInBytesDebuggingMu.RUnlock()
174+
return reportDbTotalSizeInBytesDebugging()
175+
},
176+
)
177+
// overridden by mvcc initialization
178+
reportDbTotalSizeInBytesDebuggingMu sync.RWMutex
179+
reportDbTotalSizeInBytesDebugging = func() float64 { return 0 }
180+
181+
dbTotalSizeInUse = prometheus.NewGaugeFunc(prometheus.GaugeOpts{
182+
Namespace: "etcd",
183+
Subsystem: "mvcc",
167184
Name: "db_total_size_in_use_in_bytes",
168185
Help: "Total size of the underlying database logically in use in bytes.",
169186
},
@@ -218,6 +235,7 @@ func init() {
218235
prometheus.MustRegister(dbCompactionTotalMs)
219236
prometheus.MustRegister(dbCompactionKeysCounter)
220237
prometheus.MustRegister(dbTotalSize)
238+
prometheus.MustRegister(dbTotalSizeDebugging)
221239
prometheus.MustRegister(dbTotalSizeInUse)
222240
prometheus.MustRegister(hashSec)
223241
prometheus.MustRegister(hashRevSec)

0 commit comments

Comments
 (0)