From a8257099406085c261dbafd18df59e4d679804b9 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Fri, 16 Jun 2017 11:27:07 -0700 Subject: [PATCH 1/2] integration: test mvcc db size metric is set on restore --- integration/metrics_test.go | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 integration/metrics_test.go diff --git a/integration/metrics_test.go b/integration/metrics_test.go new file mode 100644 index 00000000000..91d35ebc2a5 --- /dev/null +++ b/integration/metrics_test.go @@ -0,0 +1,37 @@ +// Copyright 2017 The etcd Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package integration + +import ( + "testing" + + "github.com/coreos/etcd/pkg/testutil" +) + +// TestMetricDbSize checks that the db size metric is set on boot. +func TestMetricDbSize(t *testing.T) { + defer testutil.AfterTest(t) + clus := NewClusterV3(t, &ClusterConfig{Size: 1}) + defer clus.Terminate(t) + + v, err := clus.Members[0].Metric("etcd_debugging_mvcc_db_total_size_in_bytes") + if err != nil { + t.Fatal(err) + } + + if v == "0" { + t.Fatalf("expected non-zero, got %q", v) + } +} From 7f149d8fb63d1bc29b3125786d214f10ca1c0f75 Mon Sep 17 00:00:00 2001 From: Anthony Romano Date: Fri, 16 Jun 2017 11:27:34 -0700 Subject: [PATCH 2/2] mvcc: set db size metric on restore Fixes #8080 --- mvcc/kvstore.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mvcc/kvstore.go b/mvcc/kvstore.go index 776371db5d8..d6def51bda3 100644 --- a/mvcc/kvstore.go +++ b/mvcc/kvstore.go @@ -260,6 +260,9 @@ func (s *store) restore() error { // restore index tx := s.b.BatchTx() tx.Lock() + + dbTotalSize.Set(float64(s.b.Size())) + _, finishedCompactBytes := tx.UnsafeRange(metaBucketName, finishedCompactKeyName, nil, 0) if len(finishedCompactBytes) != 0 { s.compactMainRev = bytesToRev(finishedCompactBytes[0]).main