From e3253c8fa44990d1c089c4a414ed47cd5cbe7f0f Mon Sep 17 00:00:00 2001 From: marc Date: Sat, 13 Aug 2016 10:11:51 -0700 Subject: [PATCH] Fix check failures. * unused variables in tests * unnamed fields in struct initializer (specified Name everywhere, Help nowhere. Filling it in is still a todo) * rename to metric.MetricMetadata to metric.Metadata to avoid stuttering * rename `CpuXX` to `CPUXX` --- gossip/gossip.go | 12 ++--- gossip/infostore_test.go | 2 +- gossip/node_set.go | 2 +- gossip/node_set_test.go | 12 ++--- kv/txn_coord_sender.go | 12 ++--- rpc/clock_offset.go | 4 +- server/node.go | 6 +-- server/status/recorder_test.go | 12 ++--- server/status/runtime.go | 52 +++++++++---------- sql/executor.go | 24 ++++----- sql/metric_util_test.go | 4 +- sql/pgwire/server.go | 6 +-- sql/pgwire/types_test.go | 4 +- storage/store_metrics.go | 92 +++++++++++++++++----------------- util/metric/metric.go | 52 ++++++++++--------- util/metric/metric_group.go | 10 ++-- util/metric/metric_test.go | 2 +- util/metric/registry.go | 3 +- util/metric/registry_test.go | 37 ++++++++------ 19 files changed, 178 insertions(+), 170 deletions(-) diff --git a/gossip/gossip.go b/gossip/gossip.go index c413a2b6c0d5..59831d7c2cf9 100644 --- a/gossip/gossip.go +++ b/gossip/gossip.go @@ -118,12 +118,12 @@ const ( // Gossip metrics counter names. var ( - MetaConnectionsIncomingGauge = metric.MetricMetadata{"gossip.connections.incoming", ""} - MetaConnectionsOutgoingGauge = metric.MetricMetadata{"gossip.connections.outgoing", ""} - MetaInfosSentRates = metric.MetricMetadata{"gossip.infos.sent", ""} - MetaInfosReceivedRates = metric.MetricMetadata{"gossip.infos.received", ""} - MetaBytesSentRates = metric.MetricMetadata{"gossip.bytes.sent", ""} - MetaBytesReceivedRates = metric.MetricMetadata{"gossip.bytes.received", ""} + MetaConnectionsIncomingGauge = metric.Metadata{Name: "gossip.connections.incoming"} + MetaConnectionsOutgoingGauge = metric.Metadata{Name: "gossip.connections.outgoing"} + MetaInfosSentRates = metric.Metadata{Name: "gossip.infos.sent"} + MetaInfosReceivedRates = metric.Metadata{Name: "gossip.infos.received"} + MetaBytesSentRates = metric.Metadata{Name: "gossip.bytes.sent"} + MetaBytesReceivedRates = metric.Metadata{Name: "gossip.bytes.received"} ) // Storage is an interface which allows the gossip instance diff --git a/gossip/infostore_test.go b/gossip/infostore_test.go index b6b699cef774..6939b2b439ae 100644 --- a/gossip/infostore_test.go +++ b/gossip/infostore_test.go @@ -296,7 +296,7 @@ func TestLeastUseful(t *testing.T) { defer stopper.Stop() is := newInfoStore(1, emptyAddr, stopper) - set := makeNodeSet(3, metric.NewGauge(metric.MetricMetadata{"", ""})) + set := makeNodeSet(3, metric.NewGauge(metric.Metadata{Name: ""})) if is.leastUseful(set) != 0 { t.Error("not expecting a node from an empty set") } diff --git a/gossip/node_set.go b/gossip/node_set.go index fd12d36be992..182554d3f4be 100644 --- a/gossip/node_set.go +++ b/gossip/node_set.go @@ -63,7 +63,7 @@ func (as nodeSet) asSlice() []roachpb.NodeID { // from the parent. func (as nodeSet) filter(filterFn func(node roachpb.NodeID) bool) nodeSet { avail := makeNodeSet(as.maxSize, - metric.NewGauge(metric.MetricMetadata{"TODO(marc)", "TODO(marc)"})) + metric.NewGauge(metric.Metadata{Name: "TODO(marc)", Help: "TODO(marc)"})) for node := range as.nodes { if filterFn(node) { avail.addNode(node) diff --git a/gossip/node_set_test.go b/gossip/node_set_test.go index 90745fde405d..509c330f7206 100644 --- a/gossip/node_set_test.go +++ b/gossip/node_set_test.go @@ -26,7 +26,7 @@ import ( func TestNodeSetMaxSize(t *testing.T) { defer leaktest.AfterTest(t)() - nodes := makeNodeSet(1, metric.NewGauge(metric.MetricMetadata{"", ""})) + nodes := makeNodeSet(1, metric.NewGauge(metric.Metadata{Name: ""})) if !nodes.hasSpace() { t.Error("set should have space") } @@ -38,7 +38,7 @@ func TestNodeSetMaxSize(t *testing.T) { func TestNodeSetHasNode(t *testing.T) { defer leaktest.AfterTest(t)() - nodes := makeNodeSet(2, metric.NewGauge(metric.MetricMetadata{"", ""})) + nodes := makeNodeSet(2, metric.NewGauge(metric.Metadata{Name: ""})) node := roachpb.NodeID(1) if nodes.hasNode(node) { t.Error("node wasn't added and should not be valid") @@ -52,7 +52,7 @@ func TestNodeSetHasNode(t *testing.T) { func TestNodeSetAddAndRemoveNode(t *testing.T) { defer leaktest.AfterTest(t)() - nodes := makeNodeSet(2, metric.NewGauge(metric.MetricMetadata{"", ""})) + nodes := makeNodeSet(2, metric.NewGauge(metric.Metadata{Name: ""})) node0 := roachpb.NodeID(1) node1 := roachpb.NodeID(2) nodes.addNode(node0) @@ -72,13 +72,13 @@ func TestNodeSetAddAndRemoveNode(t *testing.T) { func TestNodeSetFilter(t *testing.T) { defer leaktest.AfterTest(t)() - nodes1 := makeNodeSet(2, metric.NewGauge(metric.MetricMetadata{"", ""})) + nodes1 := makeNodeSet(2, metric.NewGauge(metric.Metadata{Name: ""})) node0 := roachpb.NodeID(1) node1 := roachpb.NodeID(2) nodes1.addNode(node0) nodes1.addNode(node1) - nodes2 := makeNodeSet(1, metric.NewGauge(metric.MetricMetadata{"", ""})) + nodes2 := makeNodeSet(1, metric.NewGauge(metric.Metadata{Name: ""})) nodes2.addNode(node1) filtered := nodes1.filter(func(a roachpb.NodeID) bool { @@ -91,7 +91,7 @@ func TestNodeSetFilter(t *testing.T) { func TestNodeSetAsSlice(t *testing.T) { defer leaktest.AfterTest(t)() - nodes := makeNodeSet(2, metric.NewGauge(metric.MetricMetadata{"", ""})) + nodes := makeNodeSet(2, metric.NewGauge(metric.Metadata{Name: ""})) node0 := roachpb.NodeID(1) node1 := roachpb.NodeID(2) nodes.addNode(node0) diff --git a/kv/txn_coord_sender.go b/kv/txn_coord_sender.go index 3407e3fdee86..121204af2082 100644 --- a/kv/txn_coord_sender.go +++ b/kv/txn_coord_sender.go @@ -115,12 +115,12 @@ type TxnMetrics struct { } var ( - metaAbortsRates = metric.MetricMetadata{"txn.aborts", ""} - metaCommitsRates = metric.MetricMetadata{"txn.commits", ""} - metaCommits1PCRates = metric.MetricMetadata{"txn.commits1PC", ""} - metaAbandonsRates = metric.MetricMetadata{"txn.abandons", ""} - metaDurationsHistograms = metric.MetricMetadata{"txn.durations", ""} - metaRestartsHistogram = metric.MetricMetadata{"txn.restarts", ""} + metaAbortsRates = metric.Metadata{Name: "txn.aborts"} + metaCommitsRates = metric.Metadata{Name: "txn.commits"} + metaCommits1PCRates = metric.Metadata{Name: "txn.commits1PC"} + metaAbandonsRates = metric.Metadata{Name: "txn.abandons"} + metaDurationsHistograms = metric.Metadata{Name: "txn.durations"} + metaRestartsHistogram = metric.Metadata{Name: "txn.restarts"} ) // NewTxnMetrics returns a new instance of txnMetrics that contains metrics which have diff --git a/rpc/clock_offset.go b/rpc/clock_offset.go index 2f9d32fb330e..e0833c36b768 100644 --- a/rpc/clock_offset.go +++ b/rpc/clock_offset.go @@ -34,8 +34,8 @@ type remoteClockMetrics struct { } var ( - metaClusterOffsetLowerBound = metric.MetricMetadata{"clock-offset.lower-bound-nanos", ""} - metaClusterOffsetUpperBound = metric.MetricMetadata{"clock-offset.upper-bound-nanos", ""} + metaClusterOffsetLowerBound = metric.Metadata{Name: "clock-offset.lower-bound-nanos"} + metaClusterOffsetUpperBound = metric.Metadata{Name: "clock-offset.upper-bound-nanos"} ) // RemoteClockMonitor keeps track of the most recent measurements of remote diff --git a/server/node.go b/server/node.go index 3e7f59d2c0b8..55334965bd36 100644 --- a/server/node.go +++ b/server/node.go @@ -67,9 +67,9 @@ const ( // Metric names. var ( - metaExecLatency = metric.MetricMetadata{"exec.latency", ""} - metaExecSuccess = metric.MetricMetadata{"exec.success", ""} - metaExecError = metric.MetricMetadata{"exec.error", ""} + metaExecLatency = metric.Metadata{Name: "exec.latency"} + metaExecSuccess = metric.Metadata{Name: "exec.success"} + metaExecError = metric.Metadata{Name: "exec.error"} ) // errNeedsBootstrap indicates the node should be used as the seed of diff --git a/server/status/recorder_test.go b/server/status/recorder_test.go index 8b240be8bdfe..efaae3f7d706 100644 --- a/server/status/recorder_test.go +++ b/server/status/recorder_test.go @@ -257,22 +257,22 @@ func TestMetricsRecorder(t *testing.T) { for _, data := range metricNames { switch data.typ { case "gauge": - g := metric.NewGauge(metric.MetricMetadata{reg.prefix + data.name, ""}) + g := metric.NewGauge(metric.Metadata{Name: reg.prefix + data.name}) reg.reg.AddMetric(g) g.Update(data.val) addExpected(reg.prefix, data.name, reg.source, 100, data.val, reg.isNode) case "floatgauge": - g := metric.NewGaugeFloat64(metric.MetricMetadata{reg.prefix + data.name, ""}) + g := metric.NewGaugeFloat64(metric.Metadata{Name: reg.prefix + data.name}) reg.reg.AddMetric(g) g.Update(float64(data.val)) addExpected(reg.prefix, data.name, reg.source, 100, data.val, reg.isNode) case "counter": - c := metric.NewCounter(metric.MetricMetadata{reg.prefix + data.name, ""}) + c := metric.NewCounter(metric.Metadata{Name: reg.prefix + data.name}) reg.reg.AddMetric(c) c.Inc((data.val)) addExpected(reg.prefix, data.name, reg.source, 100, data.val, reg.isNode) case "rate": - r := metric.NewRates(metric.MetricMetadata{reg.prefix + data.name, ""}) + r := metric.NewRates(metric.Metadata{Name: reg.prefix + data.name}) reg.reg.AddMetricGroup(r) r.Add(data.val) addExpected(reg.prefix, data.name+"-count", reg.source, 100, data.val, reg.isNode) @@ -282,14 +282,14 @@ func TestMetricsRecorder(t *testing.T) { addExpected(reg.prefix, data.name+sep+scale.Name(), reg.source, 100, 0, reg.isNode) } case "histogram": - h := metric.NewHistogram(metric.MetricMetadata{reg.prefix + data.name, ""}, time.Second, 1000, 2) + h := metric.NewHistogram(metric.Metadata{Name: reg.prefix + data.name}, time.Second, 1000, 2) reg.reg.AddMetric(h) h.RecordValue(data.val) for _, q := range recordHistogramQuantiles { addExpected(reg.prefix, data.name+q.suffix, reg.source, 100, data.val, reg.isNode) } case "latency": - l := metric.NewLatency(metric.MetricMetadata{reg.prefix + data.name, ""}) + l := metric.NewLatency(metric.Metadata{Name: reg.prefix + data.name}) reg.reg.AddMetricGroup(l) l.RecordValue(data.val) // Latency is simply three histograms (at different resolution diff --git a/server/status/runtime.go b/server/status/runtime.go index 8547c25275d9..971048ce032b 100644 --- a/server/status/runtime.go +++ b/server/status/runtime.go @@ -32,20 +32,20 @@ import ( ) var ( - metaCgoCalls = metric.MetricMetadata{"sys.cgocalls", "Number of cgo calls"} - metaGoroutines = metric.MetricMetadata{"sys.goroutines", "Number of goroutines"} - metaGoAllocBytes = metric.MetricMetadata{"sys.go.allocbytes", ""} - metaGoTotalBytes = metric.MetricMetadata{"sys.go.totalbytes", ""} - metaCgoAllocBytes = metric.MetricMetadata{"sys.cgo.allocbytes", ""} - metaCgoTotalBytes = metric.MetricMetadata{"sys.cgo.totalbytes", ""} - metaGCCount = metric.MetricMetadata{"sys.gc.count", ""} - metaGCPauseNS = metric.MetricMetadata{"sys.gc.pause.ns", ""} - metaGCPausePercent = metric.MetricMetadata{"sys.gc.pause.percent", ""} - metaCPUUserNS = metric.MetricMetadata{"sys.cpu.user.ns", ""} - metaCPUUserPercent = metric.MetricMetadata{"sys.cpu.user.percent", ""} - metaCPUSysNS = metric.MetricMetadata{"sys.cpu.sys.ns", ""} - metaCPUSysPercent = metric.MetricMetadata{"sys.cpu.sys.percent", ""} - metaRSS = metric.MetricMetadata{"sys.rss", ""} + metaCgoCalls = metric.Metadata{Name: "sys.cgocalls", Help: "Number of cgo calls"} + metaGoroutines = metric.Metadata{Name: "sys.goroutines", Help: "Number of goroutines"} + metaGoAllocBytes = metric.Metadata{Name: "sys.go.allocbytes"} + metaGoTotalBytes = metric.Metadata{Name: "sys.go.totalbytes"} + metaCgoAllocBytes = metric.Metadata{Name: "sys.cgo.allocbytes"} + metaCgoTotalBytes = metric.Metadata{Name: "sys.cgo.totalbytes"} + metaGCCount = metric.Metadata{Name: "sys.gc.count"} + metaGCPauseNS = metric.Metadata{Name: "sys.gc.pause.ns"} + metaGCPausePercent = metric.Metadata{Name: "sys.gc.pause.percent"} + metaCPUUserNS = metric.Metadata{Name: "sys.cpu.user.ns"} + metaCPUUserPercent = metric.Metadata{Name: "sys.cpu.user.percent"} + metaCPUSysNS = metric.Metadata{Name: "sys.cpu.sys.ns"} + metaCPUSysPercent = metric.Metadata{Name: "sys.cpu.sys.percent"} + metaRSS = metric.Metadata{Name: "sys.rss"} ) // getCgoMemStats is a function that fetches stats for the C++ portion of the code. @@ -82,10 +82,10 @@ type RuntimeStatSampler struct { GcCount *metric.Gauge GcPauseNS *metric.Gauge GcPausePercent *metric.GaugeFloat64 - CpuUserNS *metric.Gauge - CpuUserPercent *metric.GaugeFloat64 - CpuSysNS *metric.Gauge - CpuSysPercent *metric.GaugeFloat64 + CPUUserNS *metric.Gauge + CPUUserPercent *metric.GaugeFloat64 + CPUSysNS *metric.Gauge + CPUSysPercent *metric.GaugeFloat64 Rss *metric.Gauge } @@ -102,10 +102,10 @@ func MakeRuntimeStatSampler(clock *hlc.Clock, reg *metric.Registry) RuntimeStatS GcCount: metric.NewGauge(metaGCCount), GcPauseNS: metric.NewGauge(metaGCPauseNS), GcPausePercent: metric.NewGaugeFloat64(metaGCPausePercent), - CpuUserNS: metric.NewGauge(metaCPUUserNS), - CpuUserPercent: metric.NewGaugeFloat64(metaCPUUserPercent), - CpuSysNS: metric.NewGauge(metaCPUSysNS), - CpuSysPercent: metric.NewGaugeFloat64(metaCPUSysPercent), + CPUUserNS: metric.NewGauge(metaCPUUserNS), + CPUUserPercent: metric.NewGaugeFloat64(metaCPUUserPercent), + CPUSysNS: metric.NewGauge(metaCPUSysNS), + CPUSysPercent: metric.NewGaugeFloat64(metaCPUSysPercent), Rss: metric.NewGauge(metaRSS), } @@ -197,9 +197,9 @@ func (rsr *RuntimeStatSampler) SampleEnvironment() { rsr.GcCount.Update(int64(ms.NumGC)) rsr.GcPauseNS.Update(int64(ms.PauseTotalNs)) rsr.GcPausePercent.Update(pausePerc) - rsr.CpuUserNS.Update(newUtime) - rsr.CpuUserPercent.Update(uPerc) - rsr.CpuSysNS.Update(newStime) - rsr.CpuSysPercent.Update(sPerc) + rsr.CPUUserNS.Update(newUtime) + rsr.CPUUserPercent.Update(uPerc) + rsr.CPUSysNS.Update(newStime) + rsr.CPUSysPercent.Update(sPerc) rsr.Rss.Update(int64(mem.Resident)) } diff --git a/sql/executor.go b/sql/executor.go index d05724a58b67..57b7e0d3da90 100644 --- a/sql/executor.go +++ b/sql/executor.go @@ -54,18 +54,18 @@ const sqlImplicitTxnName string = "sql txn implicit" // Fully-qualified names for metrics. var ( - MetaLatency = metric.MetricMetadata{"sql.latency", ""} - MetaTxnBegin = metric.MetricMetadata{"sql.txn.begin.count", ""} - MetaTxnCommit = metric.MetricMetadata{"sql.txn.commit.count", ""} - MetaTxnAbort = metric.MetricMetadata{"sql.txn.abort.count", ""} - MetaTxnRollback = metric.MetricMetadata{"sql.txn.rollback.count", ""} - MetaSelect = metric.MetricMetadata{"sql.select.count", ""} - MetaUpdate = metric.MetricMetadata{"sql.update.count", ""} - MetaInsert = metric.MetricMetadata{"sql.insert.count", ""} - MetaDelete = metric.MetricMetadata{"sql.delete.count", ""} - MetaDdl = metric.MetricMetadata{"sql.ddl.count", ""} - MetaMisc = metric.MetricMetadata{"sql.misc.count", ""} - MetaQuery = metric.MetricMetadata{"sql.query.count", ""} + MetaLatency = metric.Metadata{Name: "sql.latency"} + MetaTxnBegin = metric.Metadata{Name: "sql.txn.begin.count"} + MetaTxnCommit = metric.Metadata{Name: "sql.txn.commit.count"} + MetaTxnAbort = metric.Metadata{Name: "sql.txn.abort.count"} + MetaTxnRollback = metric.Metadata{Name: "sql.txn.rollback.count"} + MetaSelect = metric.Metadata{Name: "sql.select.count"} + MetaUpdate = metric.Metadata{Name: "sql.update.count"} + MetaInsert = metric.Metadata{Name: "sql.insert.count"} + MetaDelete = metric.Metadata{Name: "sql.delete.count"} + MetaDdl = metric.Metadata{Name: "sql.ddl.count"} + MetaMisc = metric.Metadata{Name: "sql.misc.count"} + MetaQuery = metric.Metadata{Name: "sql.query.count"} ) // TODO(radu): experimental code for testing distSQL flows. diff --git a/sql/metric_util_test.go b/sql/metric_util_test.go index 8a20a5f1dd5e..0fabe9fd3e08 100644 --- a/sql/metric_util_test.go +++ b/sql/metric_util_test.go @@ -27,7 +27,7 @@ import ( ) func checkCounterEQ( - t *testing.T, s serverutils.TestServerInterface, meta metric.MetricMetadata, e int64, + t *testing.T, s serverutils.TestServerInterface, meta metric.Metadata, e int64, ) { if a := s.MustGetSQLCounter(meta.Name); a != e { t.Error(errors.Errorf("stat %s: actual %d != expected %d", meta.Name, a, e)) @@ -35,7 +35,7 @@ func checkCounterEQ( } func checkCounterGE( - t *testing.T, s serverutils.TestServerInterface, meta metric.MetricMetadata, e int64, + t *testing.T, s serverutils.TestServerInterface, meta metric.Metadata, e int64, ) { if a := s.MustGetSQLCounter(meta.Name); a < e { t.Error(errors.Errorf("stat %s: expected: actual %d >= %d", meta.Name, a, e)) diff --git a/sql/pgwire/server.go b/sql/pgwire/server.go index ca9a8530cc9b..edc4c536c7ef 100644 --- a/sql/pgwire/server.go +++ b/sql/pgwire/server.go @@ -44,9 +44,9 @@ const ( // Fully-qualified names for metrics. var ( - MetaConns = metric.MetricMetadata{"sql.conns", ""} - MetaBytesIn = metric.MetricMetadata{"sql.bytesin", ""} - MetaBytesOut = metric.MetricMetadata{"sql.bytesout", ""} + MetaConns = metric.Metadata{Name: "sql.conns"} + MetaBytesIn = metric.Metadata{Name: "sql.bytesin"} + MetaBytesOut = metric.Metadata{Name: "sql.bytesout"} ) const ( diff --git a/sql/pgwire/types_test.go b/sql/pgwire/types_test.go index a20d98645136..b2ca6722c94b 100644 --- a/sql/pgwire/types_test.go +++ b/sql/pgwire/types_test.go @@ -83,7 +83,7 @@ func TestTimestampRoundtrip(t *testing.T) { } func BenchmarkWriteBinaryDecimal(b *testing.B) { - buf := writeBuffer{bytecount: metric.NewCounter(metric.MetricMetadata{"", ""})} + buf := writeBuffer{bytecount: metric.NewCounter(metric.Metadata{Name: ""})} dec := new(parser.DDecimal) dec.SetString("-1728718718271827121233.1212121212") @@ -102,7 +102,7 @@ func BenchmarkWriteBinaryDecimal(b *testing.B) { } func BenchmarkDecodeBinaryDecimal(b *testing.B) { - wbuf := writeBuffer{bytecount: metric.NewCounter(metric.MetricMetadata{"", ""})} + wbuf := writeBuffer{bytecount: metric.NewCounter(metric.Metadata{Name: ""})} expected := new(parser.DDecimal) expected.SetString("-1728718718271827121233.1212121212") diff --git a/storage/store_metrics.go b/storage/store_metrics.go index 66c5d05214f7..75e6d268375b 100644 --- a/storage/store_metrics.go +++ b/storage/store_metrics.go @@ -25,58 +25,58 @@ import ( ) var ( - metaReplicaCount = metric.MetricMetadata{"replicas", ""} - metaReservedReplicaCount = metric.MetricMetadata{"replicas.reserved", ""} - metaLeaderRangeCount = metric.MetricMetadata{"ranges.leader", ""} - metaReplicatedRangeCount = metric.MetricMetadata{"ranges.replicated", ""} - metaReplicationPendingRangeCount = metric.MetricMetadata{"ranges.replication-pending", ""} - metaAvailableRangeCount = metric.MetricMetadata{"ranges.available", ""} - metaLeaseRequestSuccessCount = metric.MetricMetadata{"leases.success", ""} - metaLeaseRequestErrorCount = metric.MetricMetadata{"leases.error", ""} - metaLiveBytes = metric.MetricMetadata{"livebytes", ""} - metaKeyBytes = metric.MetricMetadata{"keybytes", ""} - metaValBytes = metric.MetricMetadata{"valbytes", ""} - metaIntentBytes = metric.MetricMetadata{"intentbytes", ""} - metaLiveCount = metric.MetricMetadata{"livecount", ""} - metaKeyCount = metric.MetricMetadata{"keycount", ""} - metaValCount = metric.MetricMetadata{"valcount", ""} - metaIntentCount = metric.MetricMetadata{"intentcount", ""} - metaIntentAge = metric.MetricMetadata{"intentage", ""} - metaGcBytesAge = metric.MetricMetadata{"gcbytesage", ""} - metaLastUpdateNanos = metric.MetricMetadata{"lastupdatenanos", ""} - metaCapacity = metric.MetricMetadata{"capacity", ""} - metaAvailable = metric.MetricMetadata{"capacity.available", ""} - metaReserved = metric.MetricMetadata{"capacity.reserved", ""} - metaSysBytes = metric.MetricMetadata{"sysbytes", ""} - metaSysCount = metric.MetricMetadata{"syscount", ""} + metaReplicaCount = metric.Metadata{Name: "replicas"} + metaReservedReplicaCount = metric.Metadata{Name: "replicas.reserved"} + metaLeaderRangeCount = metric.Metadata{Name: "ranges.leader"} + metaReplicatedRangeCount = metric.Metadata{Name: "ranges.replicated"} + metaReplicationPendingRangeCount = metric.Metadata{Name: "ranges.replication-pending"} + metaAvailableRangeCount = metric.Metadata{Name: "ranges.available"} + metaLeaseRequestSuccessCount = metric.Metadata{Name: "leases.success"} + metaLeaseRequestErrorCount = metric.Metadata{Name: "leases.error"} + metaLiveBytes = metric.Metadata{Name: "livebytes"} + metaKeyBytes = metric.Metadata{Name: "keybytes"} + metaValBytes = metric.Metadata{Name: "valbytes"} + metaIntentBytes = metric.Metadata{Name: "intentbytes"} + metaLiveCount = metric.Metadata{Name: "livecount"} + metaKeyCount = metric.Metadata{Name: "keycount"} + metaValCount = metric.Metadata{Name: "valcount"} + metaIntentCount = metric.Metadata{Name: "intentcount"} + metaIntentAge = metric.Metadata{Name: "intentage"} + metaGcBytesAge = metric.Metadata{Name: "gcbytesage"} + metaLastUpdateNanos = metric.Metadata{Name: "lastupdatenanos"} + metaCapacity = metric.Metadata{Name: "capacity"} + metaAvailable = metric.Metadata{Name: "capacity.available"} + metaReserved = metric.Metadata{Name: "capacity.reserved"} + metaSysBytes = metric.Metadata{Name: "sysbytes"} + metaSysCount = metric.Metadata{Name: "syscount"} // RocksDB metrics. - metaRdbBlockCacheHits = metric.MetricMetadata{"rocksdb.block.cache.hits", ""} - metaRdbBlockCacheMisses = metric.MetricMetadata{"rocksdb.block.cache.misses", ""} - metaRdbBlockCacheUsage = metric.MetricMetadata{"rocksdb.block.cache.usage", ""} - metaRdbBlockCachePinnedUsage = metric.MetricMetadata{"rocksdb.block.cache.pinned-usage", ""} - metaRdbBloomFilterPrefixChecked = metric.MetricMetadata{"rocksdb.bloom.filter.prefix.checked", ""} - metaRdbBloomFilterPrefixUseful = metric.MetricMetadata{"rocksdb.bloom.filter.prefix.useful", ""} - metaRdbMemtableHits = metric.MetricMetadata{"rocksdb.memtable.hits", ""} - metaRdbMemtableMisses = metric.MetricMetadata{"rocksdb.memtable.misses", ""} - metaRdbMemtableTotalSize = metric.MetricMetadata{"rocksdb.memtable.total-size", ""} - metaRdbFlushes = metric.MetricMetadata{"rocksdb.flushes", ""} - metaRdbCompactions = metric.MetricMetadata{"rocksdb.compactions", ""} - metaRdbTableReadersMemEstimate = metric.MetricMetadata{"rocksdb.table-readers-mem-estimate", ""} - metaRdbReadAmplification = metric.MetricMetadata{"rocksdb.read-amplification", ""} + metaRdbBlockCacheHits = metric.Metadata{Name: "rocksdb.block.cache.hits"} + metaRdbBlockCacheMisses = metric.Metadata{Name: "rocksdb.block.cache.misses"} + metaRdbBlockCacheUsage = metric.Metadata{Name: "rocksdb.block.cache.usage"} + metaRdbBlockCachePinnedUsage = metric.Metadata{Name: "rocksdb.block.cache.pinned-usage"} + metaRdbBloomFilterPrefixChecked = metric.Metadata{Name: "rocksdb.bloom.filter.prefix.checked"} + metaRdbBloomFilterPrefixUseful = metric.Metadata{Name: "rocksdb.bloom.filter.prefix.useful"} + metaRdbMemtableHits = metric.Metadata{Name: "rocksdb.memtable.hits"} + metaRdbMemtableMisses = metric.Metadata{Name: "rocksdb.memtable.misses"} + metaRdbMemtableTotalSize = metric.Metadata{Name: "rocksdb.memtable.total-size"} + metaRdbFlushes = metric.Metadata{Name: "rocksdb.flushes"} + metaRdbCompactions = metric.Metadata{Name: "rocksdb.compactions"} + metaRdbTableReadersMemEstimate = metric.Metadata{Name: "rocksdb.table-readers-mem-estimate"} + metaRdbReadAmplification = metric.Metadata{Name: "rocksdb.read-amplification"} // Range event metrics. - metaRangeSplits = metric.MetricMetadata{"range.splits", ""} - metaRangeAdds = metric.MetricMetadata{"range.adds", ""} - metaRangeRemoves = metric.MetricMetadata{"range.removes", ""} - metaRangeSnapshotsGenerated = metric.MetricMetadata{"range.snapshots.generated", ""} - metaRangeSnapshotsNormalApplied = metric.MetricMetadata{"range.snapshots.normal-applied", ""} - metaRangeSnapshotsPreemptiveApplied = metric.MetricMetadata{"range.snapshots.preemptive-applied", ""} + metaRangeSplits = metric.Metadata{Name: "range.splits"} + metaRangeAdds = metric.Metadata{Name: "range.adds"} + metaRangeRemoves = metric.Metadata{Name: "range.removes"} + metaRangeSnapshotsGenerated = metric.Metadata{Name: "range.snapshots.generated"} + metaRangeSnapshotsNormalApplied = metric.Metadata{Name: "range.snapshots.normal-applied"} + metaRangeSnapshotsPreemptiveApplied = metric.Metadata{Name: "range.snapshots.preemptive-applied"} // Raft processing metrics. - metaRaftSelectDurationNanos = metric.MetricMetadata{"process-raft.waitingnanos", ""} - metaRaftWorkingDurationNanos = metric.MetricMetadata{"process-raft.workingnanos", ""} - metaRaftTickingDurationNanos = metric.MetricMetadata{"process-raft.tickingnanos", ""} + metaRaftSelectDurationNanos = metric.Metadata{Name: "process-raft.waitingnanos"} + metaRaftWorkingDurationNanos = metric.Metadata{Name: "process-raft.workingnanos"} + metaRaftTickingDurationNanos = metric.Metadata{Name: "process-raft.tickingnanos"} ) type storeMetrics struct { diff --git a/util/metric/metric.go b/util/metric/metric.go index 938c3db8b1b3..c2e75c93cff5 100644 --- a/util/metric/metric.go +++ b/util/metric/metric.go @@ -35,9 +35,9 @@ const histWrapNum = 4 // number of histograms to keep in rolling window // Iterable provides a method for synchronized access to interior objects. type Iterable interface { - // Name returns the fully-qualified name of the metric. + // GetName returns the fully-qualified name of the metric. GetName() string - // Help returns the help text for the metric. + // GetHelp returns the help text for the metric. GetHelp() string // Inspect calls the given closure with each contained item. Inspect(func(interface{})) @@ -51,17 +51,19 @@ type PrometheusExportable interface { FillPrometheusMetric(promMetric *prometheusgo.MetricFamily) } -// MetricMetadata holds metadata about a metric. It must be embedded in +// Metadata holds metadata about a metric. It must be embedded in // each metric object. -type MetricMetadata struct { +type Metadata struct { Name, Help string } -func (m *MetricMetadata) GetName() string { +// GetName returns the metric's name. +func (m *Metadata) GetName() string { return m.Name } -func (m *MetricMetadata) GetHelp() string { +// GetHelp returns the metric's help string. +func (m *Metadata) GetHelp() string { return m.Help } @@ -111,7 +113,7 @@ func maybeTick(m periodic) { // A Histogram is a wrapper around an hdrhistogram.WindowedHistogram. type Histogram struct { - MetricMetadata + Metadata maxVal int64 mu syncutil.Mutex @@ -123,14 +125,14 @@ type Histogram struct { // NewHistogram creates a new windowed HDRHistogram with the given parameters. // Data is kept in the active window for approximately the given duration. // See the documentation for hdrhistogram.WindowedHistogram for details. -func NewHistogram(metadata MetricMetadata, duration time.Duration, +func NewHistogram(metadata Metadata, duration time.Duration, maxVal int64, sigFigs int) *Histogram { return &Histogram{ - MetricMetadata: metadata, - maxVal: maxVal, - nextT: now(), - duration: duration, - windowed: hdrhistogram.NewWindowed(histWrapNum, 0, maxVal, sigFigs), + Metadata: metadata, + maxVal: maxVal, + nextT: now(), + duration: duration, + windowed: hdrhistogram.NewWindowed(histWrapNum, 0, maxVal, sigFigs), } } @@ -206,12 +208,12 @@ func (h *Histogram) FillPrometheusMetric(promMetric *prometheusgo.MetricFamily) // A Counter holds a single mutable atomic value. type Counter struct { - MetricMetadata + Metadata metrics.Counter } // NewCounter creates a counter. -func NewCounter(metadata MetricMetadata) *Counter { +func NewCounter(metadata Metadata) *Counter { return &Counter{metadata, metrics.NewCounter()} } @@ -233,12 +235,12 @@ func (c *Counter) FillPrometheusMetric(promMetric *prometheusgo.MetricFamily) { // A Gauge atomically stores a single integer value. type Gauge struct { - MetricMetadata + Metadata metrics.Gauge } // NewGauge creates a Gauge. -func NewGauge(metadata MetricMetadata) *Gauge { +func NewGauge(metadata Metadata) *Gauge { return &Gauge{metadata, metrics.NewGauge()} } @@ -260,12 +262,12 @@ func (g *Gauge) FillPrometheusMetric(promMetric *prometheusgo.MetricFamily) { // A GaugeFloat64 atomically stores a single float64 value. type GaugeFloat64 struct { - MetricMetadata + Metadata metrics.GaugeFloat64 } // NewGaugeFloat64 creates a GaugeFloat64. -func NewGaugeFloat64(metadata MetricMetadata) *GaugeFloat64 { +func NewGaugeFloat64(metadata Metadata) *GaugeFloat64 { return &GaugeFloat64{metadata, metrics.NewGaugeFloat64()} } @@ -287,7 +289,7 @@ func (g *GaugeFloat64) FillPrometheusMetric(promMetric *prometheusgo.MetricFamil // A Rate is a exponential weighted moving average. type Rate struct { - MetricMetadata + Metadata mu syncutil.Mutex // protects fields below curSum float64 wrapped ewma.MovingAverage @@ -297,7 +299,7 @@ type Rate struct { // NewRate creates an EWMA rate on the given timescale. Timescales at // or below 2s are illegal and will cause a panic. -func NewRate(metadata MetricMetadata, timescale time.Duration) *Rate { +func NewRate(metadata Metadata, timescale time.Duration) *Rate { const tickInterval = time.Second if timescale <= 2*time.Second { panic(fmt.Sprintf("EWMA with per-second ticks makes no sense on timescale %s", timescale)) @@ -305,10 +307,10 @@ func NewRate(metadata MetricMetadata, timescale time.Duration) *Rate { avgAge := float64(timescale) / float64(2*tickInterval) return &Rate{ - MetricMetadata: metadata, - interval: tickInterval, - nextT: now(), - wrapped: ewma.NewMovingAverage(avgAge), + Metadata: metadata, + interval: tickInterval, + nextT: now(), + wrapped: ewma.NewMovingAverage(avgAge), } } diff --git a/util/metric/metric_group.go b/util/metric/metric_group.go index d48e047f5be8..f13bc0c4dc5b 100644 --- a/util/metric/metric_group.go +++ b/util/metric/metric_group.go @@ -63,11 +63,11 @@ type metricGroup interface { // // TODO(mrtracy,tschottdorf): need to discuss roll-ups and generally how (and // which) information flows between metrics and time series. -func NewLatency(metadata MetricMetadata) Histograms { +func NewLatency(metadata Metadata) Histograms { windows := DefaultTimeScales hs := make(Histograms) for _, w := range windows { - hs[w] = NewHistogram(MetricMetadata{metadata.Name + sep + w.name, metadata.Help}, + hs[w] = NewHistogram(Metadata{metadata.Name + sep + w.name, metadata.Help}, w.d, int64(time.Minute), 2) } return hs @@ -95,13 +95,13 @@ type Rates struct { // NewRates registers and returns a new Rates instance, which contains a set of EWMA-based rates // with generally useful time scales and a cumulative counter. -func NewRates(metadata MetricMetadata) Rates { +func NewRates(metadata Metadata) Rates { scales := DefaultTimeScales es := make(map[TimeScale]*Rate) for _, scale := range scales { - es[scale] = NewRate(MetricMetadata{metadata.Name + sep + scale.name, metadata.Help}, scale.d) + es[scale] = NewRate(Metadata{metadata.Name + sep + scale.name, metadata.Help}, scale.d) } - c := NewCounter(MetricMetadata{metadata.Name + sep + "count", metadata.Help}) + c := NewCounter(Metadata{metadata.Name + sep + "count", metadata.Help}) return Rates{Counter: c, Rates: es} } diff --git a/util/metric/metric_test.go b/util/metric/metric_test.go index fede18ddc326..16107c05337a 100644 --- a/util/metric/metric_test.go +++ b/util/metric/metric_test.go @@ -31,7 +31,7 @@ func testMarshal(t *testing.T, m json.Marshaler, exp string) { } } -var emptyMetadata = MetricMetadata{"", ""} +var emptyMetadata = Metadata{Name: ""} func TestGauge(t *testing.T) { g := NewGauge(emptyMetadata) diff --git a/util/metric/registry.go b/util/metric/registry.go index 3f7b297f5372..da5573c2f627 100644 --- a/util/metric/registry.go +++ b/util/metric/registry.go @@ -17,12 +17,13 @@ package metric import ( - "context" "encoding/json" "io" "reflect" "regexp" + "golang.org/x/net/context" + "github.com/cockroachdb/cockroach/util/log" "github.com/cockroachdb/cockroach/util/syncutil" "github.com/gogo/protobuf/proto" diff --git a/util/metric/registry_test.go b/util/metric/registry_test.go index 0c67e64dca14..b8f6d45bb67d 100644 --- a/util/metric/registry_test.go +++ b/util/metric/registry_test.go @@ -24,23 +24,23 @@ import ( func TestRegistry(t *testing.T) { r := NewRegistry() - topGauge := NewGauge(MetricMetadata{"top.gauge", ""}) + topGauge := NewGauge(Metadata{Name: "top.gauge"}) r.AddMetric(topGauge) - r.AddMetric(NewGaugeFloat64(MetricMetadata{"top.floatgauge", ""})) + r.AddMetric(NewGaugeFloat64(Metadata{Name: "top.floatgauge"})) - topCounter := NewCounter(MetricMetadata{"top.counter", ""}) + topCounter := NewCounter(Metadata{Name: "top.counter"}) r.AddMetric(topCounter) - topRate := NewRate(MetricMetadata{"top.rate", ""}, time.Minute) + topRate := NewRate(Metadata{Name: "top.rate"}, time.Minute) r.AddMetric(topRate) - r.AddMetricGroup(NewRates(MetricMetadata{"top.rates", ""})) - r.AddMetric(NewHistogram(MetricMetadata{"top.hist", ""}, time.Minute, 1000, 3)) - r.AddMetricGroup(NewLatency(MetricMetadata{"top.latency", ""})) + r.AddMetricGroup(NewRates(Metadata{Name: "top.rates"})) + r.AddMetric(NewHistogram(Metadata{Name: "top.hist"}, time.Minute, 1000, 3)) + r.AddMetricGroup(NewLatency(Metadata{Name: "top.latency"})) - r.AddMetric(NewGauge(MetricMetadata{"bottom.gauge", ""})) - r.AddMetricGroup(NewRates(MetricMetadata{"bottom.rates", ""})) + r.AddMetric(NewGauge(Metadata{Name: "bottom.gauge"})) + r.AddMetricGroup(NewRates(Metadata{Name: "bottom.rates"})) ms := &struct { StructGauge *Gauge StructGauge64 *GaugeFloat64 @@ -56,13 +56,18 @@ func TestRegistry(t *testing.T) { AlsoNotAMetric string ReallyNotAMetric *Registry }{ - StructGauge: NewGauge(MetricMetadata{"struct.gauge", ""}), - StructGauge64: NewGaugeFloat64(MetricMetadata{"struct.gauge64", ""}), - StructCounter: NewCounter(MetricMetadata{"struct.counter", ""}), - StructHistogram: NewHistogram(MetricMetadata{"struct.histogram", ""}, time.Minute, 1000, 3), - StructRate: NewRate(MetricMetadata{"struct.rate", ""}, time.Minute), - StructLatency: NewLatency(MetricMetadata{"struct.latency", ""}), - StructRates: NewRates(MetricMetadata{"struct.rates", ""}), + StructGauge: NewGauge(Metadata{Name: "struct.gauge"}), + StructGauge64: NewGaugeFloat64(Metadata{Name: "struct.gauge64"}), + StructCounter: NewCounter(Metadata{Name: "struct.counter"}), + StructHistogram: NewHistogram(Metadata{Name: "struct.histogram"}, time.Minute, 1000, 3), + StructRate: NewRate(Metadata{Name: "struct.rate"}, time.Minute), + StructLatency: NewLatency(Metadata{Name: "struct.latency"}), + StructRates: NewRates(Metadata{Name: "struct.rates"}), + privateStructGauge: NewGauge(Metadata{Name: "struct.private-gauge"}), + privateStructGauge64: NewGaugeFloat64(Metadata{Name: "struct.private-gauge64"}), + NotAMetric: 0, + AlsoNotAMetric: "foo", + ReallyNotAMetric: NewRegistry(), } r.AddMetricStruct(ms)