Fix some lint errors (#3334)

I left the promql ones and some others untouched as I remember that @fabxc
prefers them that way.
This commit is contained in:
Julius Volz 2017-10-23 06:57:30 -07:00 committed by Brian Brazil
parent 2846d62573
commit c3d6abc8e6
9 changed files with 32 additions and 13 deletions

View file

@ -32,11 +32,11 @@ import (
const (
tritonLabel = model.MetaLabelPrefix + "triton_"
tritonLabelMachineId = tritonLabel + "machine_id"
tritonLabelMachineID = tritonLabel + "machine_id"
tritonLabelMachineAlias = tritonLabel + "machine_alias"
tritonLabelMachineBrand = tritonLabel + "machine_brand"
tritonLabelMachineImage = tritonLabel + "machine_image"
tritonLabelServerId = tritonLabel + "server_id"
tritonLabelServerID = tritonLabel + "server_id"
namespace = "prometheus"
)
@ -58,6 +58,7 @@ func init() {
prometheus.MustRegister(refreshDuration)
}
// DiscoveryResponse models a JSON response from the Triton discovery.
type DiscoveryResponse struct {
Containers []struct {
ServerUUID string `json:"server_uuid"`
@ -169,11 +170,11 @@ func (d *Discovery) refresh() (tg *config.TargetGroup, err error) {
for _, container := range dr.Containers {
labels := model.LabelSet{
tritonLabelMachineId: model.LabelValue(container.VMUUID),
tritonLabelMachineID: model.LabelValue(container.VMUUID),
tritonLabelMachineAlias: model.LabelValue(container.VMAlias),
tritonLabelMachineBrand: model.LabelValue(container.VMBrand),
tritonLabelMachineImage: model.LabelValue(container.VMImageUUID),
tritonLabelServerId: model.LabelValue(container.ServerUUID),
tritonLabelServerID: model.LabelValue(container.ServerUUID),
}
addr := fmt.Sprintf("%s.%s:%d", container.VMUUID, d.sdConfig.DNSSuffix, d.sdConfig.Port)
labels[model.AddressLabel] = model.LabelValue(addr)

View file

@ -64,10 +64,12 @@ func (ls Labels) String() string {
return b.String()
}
// MarshalJSON implements json.Marshaler.
func (ls Labels) MarshalJSON() ([]byte, error) {
return json.Marshal(ls.Map())
}
// UnmarshalJSON implements json.Unmarshaler.
func (ls *Labels) UnmarshalJSON(b []byte) error {
var m map[string]string
@ -187,7 +189,7 @@ func Compare(a, b Labels) int {
return len(a) - len(b)
}
// LabelsBuilder allows modifiying Labels.
// Builder allows modifiying Labels.
type Builder struct {
base Labels
del []string

View file

@ -92,7 +92,7 @@ M [a-zA-Z_:]
l.offsets = append(l.offsets, l.i)
<lstateLValueIn>(\\.|[^\\"])*\" l.state = lstateLabels
if !utf8.Valid(l.b[l.offsets[len(l.offsets)-1]:l.i-1]) {
l.err = fmt.Errorf("Invalid UTF-8 label value.")
l.err = fmt.Errorf("invalid UTF-8 label value")
return -1
}
l.offsets = append(l.offsets, l.i-1)

View file

@ -1,4 +1,4 @@
// CAUTION: Generated file - DO NOT EDIT.
// Code generated by golex. DO NOT EDIT.
// Copyright 2017 The Prometheus Authors
// Licensed under the Apache License, Version 2.0 (the "License");
@ -492,7 +492,7 @@ yyrule14: // (\\.|[^\\"])*\"
{
l.state = lstateLabels
if !utf8.Valid(l.b[l.offsets[len(l.offsets)-1] : l.i-1]) {
l.err = fmt.Errorf("Invalid UTF-8 label value.")
l.err = fmt.Errorf("invalid UTF-8 label value")
return -1
}
l.offsets = append(l.offsets, l.i-1)

View file

@ -172,7 +172,7 @@ func TestParseErrors(t *testing.T) {
},
{
input: "a{b=\"\xff\"} 1\n",
err: "Invalid UTF-8 label value.",
err: "invalid UTF-8 label value",
},
{
input: "a true\n",

View file

@ -18,16 +18,17 @@ import (
)
const (
// A quiet NaN. This is also math.NaN().
// NormalNaN is a quiet NaN. This is also math.NaN().
NormalNaN uint64 = 0x7ff8000000000001
// A signalling NaN, due to the MSB of the mantissa being 0.
// StaleNaN is a signalling NaN, due to the MSB of the mantissa being 0.
// This value is chosen with many leading 0s, so we have scope to store more
// complicated values in the future. It is 2 rather than 1 to make
// it easier to distinguish from the NormalNaN by a human when debugging.
StaleNaN uint64 = 0x7ff0000000000002
)
// IsStaleNaN returns true when the provided NaN value is a stale marker.
func IsStaleNaN(v float64) bool {
return math.Float64bits(v) == StaleNaN
}

View file

@ -207,6 +207,7 @@ func newConcreteSeriersIterator(series *concreteSeries) storage.SeriesIterator {
}
}
// Seek implements storage.SeriesIterator.
func (c *concreteSeriesIterator) Seek(t int64) bool {
c.cur = sort.Search(len(c.series.samples), func(n int) bool {
return c.series.samples[n].Timestamp >= t
@ -214,16 +215,19 @@ func (c *concreteSeriesIterator) Seek(t int64) bool {
return c.cur < len(c.series.samples)
}
// At implements storage.SeriesIterator.
func (c *concreteSeriesIterator) At() (t int64, v float64) {
s := c.series.samples[c.cur]
return s.Timestamp, s.Value
}
// Next implements storage.SeriesIterator.
func (c *concreteSeriesIterator) Next() bool {
c.cur++
return c.cur < len(c.series.samples)
}
// Err implements storage.SeriesIterator.
func (c *concreteSeriesIterator) Err() error {
return nil
}

View file

@ -19,10 +19,12 @@ import (
"github.com/prometheus/prometheus/storage"
)
// Appender implements retrieval.Appendable.
func (s *Storage) Appender() (storage.Appender, error) {
return s, nil
}
// Add implements storage.Appender.
func (s *Storage) Add(l labels.Labels, t int64, v float64) (uint64, error) {
s.mtx.RLock()
defer s.mtx.RUnlock()
@ -44,15 +46,18 @@ func labelsToMetric(ls labels.Labels) model.Metric {
return metric
}
// AddFast implements storage.Appender.
func (s *Storage) AddFast(l labels.Labels, _ uint64, t int64, v float64) error {
_, err := s.Add(l, t, v)
return err
}
// Commit implements storage.Appender.
func (*Storage) Commit() error {
return nil
}
// Rollback implements storage.Appender.
func (*Storage) Rollback() error {
return nil
}

View file

@ -45,20 +45,23 @@ func init() {
prometheus.MustRegister(numWatchers)
}
// ZookeeperLogger wraps a log.Logger into a zk.Logger.
type ZookeeperLogger struct {
logger log.Logger
}
// NewZookeeperLogger is a constructor for ZookeeperLogger
// NewZookeeperLogger is a constructor for ZookeeperLogger.
func NewZookeeperLogger(logger log.Logger) ZookeeperLogger {
return ZookeeperLogger{logger: logger}
}
// Implements zk.Logger
// Printf implements zk.Logger.
func (zl ZookeeperLogger) Printf(s string, i ...interface{}) {
level.Info(zl.logger).Log("msg", fmt.Sprintf(s, i...))
}
// A ZookeeperTreeCache keeps data from all children of a Zookeeper path
// locally cached and updated according to received events.
type ZookeeperTreeCache struct {
conn *zk.Conn
prefix string
@ -70,6 +73,7 @@ type ZookeeperTreeCache struct {
logger log.Logger
}
// A ZookeeperTreeCacheEvent models a Zookeeper event for a path.
type ZookeeperTreeCacheEvent struct {
Path string
Data *[]byte
@ -83,6 +87,7 @@ type zookeeperTreeCacheNode struct {
children map[string]*zookeeperTreeCacheNode
}
// NewZookeeperTreeCache creates a new ZookeeperTreeCache for a given path.
func NewZookeeperTreeCache(conn *zk.Conn, path string, events chan ZookeeperTreeCacheEvent, logger log.Logger) *ZookeeperTreeCache {
tc := &ZookeeperTreeCache{
conn: conn,
@ -101,6 +106,7 @@ func NewZookeeperTreeCache(conn *zk.Conn, path string, events chan ZookeeperTree
return tc
}
// Stop stops the tree cache.
func (tc *ZookeeperTreeCache) Stop() {
tc.stop <- struct{}{}
}