Skip to content

Commit

Permalink
Fix check failures.
Browse files Browse the repository at this point in the history
* 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`
  • Loading branch information
marc committed Aug 13, 2016
1 parent 353afee commit e3253c8
Show file tree
Hide file tree
Showing 19 changed files with 178 additions and 170 deletions.
12 changes: 6 additions & 6 deletions gossip/gossip.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion gossip/infostore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion gossip/node_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions gossip/node_set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand All @@ -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")
Expand All @@ -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)
Expand All @@ -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 {
Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions kv/txn_coord_sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions rpc/clock_offset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions server/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions server/status/recorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
52 changes: 26 additions & 26 deletions server/status/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}

Expand All @@ -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),
}

Expand Down Expand Up @@ -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))
}
24 changes: 12 additions & 12 deletions sql/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions sql/metric_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ 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))
}
}

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))
Expand Down
6 changes: 3 additions & 3 deletions sql/pgwire/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
4 changes: 2 additions & 2 deletions sql/pgwire/types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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")
Expand Down
Loading

0 comments on commit e3253c8

Please sign in to comment.