mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
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:
parent
2846d62573
commit
c3d6abc8e6
|
@ -32,11 +32,11 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
tritonLabel = model.MetaLabelPrefix + "triton_"
|
tritonLabel = model.MetaLabelPrefix + "triton_"
|
||||||
tritonLabelMachineId = tritonLabel + "machine_id"
|
tritonLabelMachineID = tritonLabel + "machine_id"
|
||||||
tritonLabelMachineAlias = tritonLabel + "machine_alias"
|
tritonLabelMachineAlias = tritonLabel + "machine_alias"
|
||||||
tritonLabelMachineBrand = tritonLabel + "machine_brand"
|
tritonLabelMachineBrand = tritonLabel + "machine_brand"
|
||||||
tritonLabelMachineImage = tritonLabel + "machine_image"
|
tritonLabelMachineImage = tritonLabel + "machine_image"
|
||||||
tritonLabelServerId = tritonLabel + "server_id"
|
tritonLabelServerID = tritonLabel + "server_id"
|
||||||
namespace = "prometheus"
|
namespace = "prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -58,6 +58,7 @@ func init() {
|
||||||
prometheus.MustRegister(refreshDuration)
|
prometheus.MustRegister(refreshDuration)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DiscoveryResponse models a JSON response from the Triton discovery.
|
||||||
type DiscoveryResponse struct {
|
type DiscoveryResponse struct {
|
||||||
Containers []struct {
|
Containers []struct {
|
||||||
ServerUUID string `json:"server_uuid"`
|
ServerUUID string `json:"server_uuid"`
|
||||||
|
@ -169,11 +170,11 @@ func (d *Discovery) refresh() (tg *config.TargetGroup, err error) {
|
||||||
|
|
||||||
for _, container := range dr.Containers {
|
for _, container := range dr.Containers {
|
||||||
labels := model.LabelSet{
|
labels := model.LabelSet{
|
||||||
tritonLabelMachineId: model.LabelValue(container.VMUUID),
|
tritonLabelMachineID: model.LabelValue(container.VMUUID),
|
||||||
tritonLabelMachineAlias: model.LabelValue(container.VMAlias),
|
tritonLabelMachineAlias: model.LabelValue(container.VMAlias),
|
||||||
tritonLabelMachineBrand: model.LabelValue(container.VMBrand),
|
tritonLabelMachineBrand: model.LabelValue(container.VMBrand),
|
||||||
tritonLabelMachineImage: model.LabelValue(container.VMImageUUID),
|
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)
|
addr := fmt.Sprintf("%s.%s:%d", container.VMUUID, d.sdConfig.DNSSuffix, d.sdConfig.Port)
|
||||||
labels[model.AddressLabel] = model.LabelValue(addr)
|
labels[model.AddressLabel] = model.LabelValue(addr)
|
||||||
|
|
|
@ -64,10 +64,12 @@ func (ls Labels) String() string {
|
||||||
return b.String()
|
return b.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MarshalJSON implements json.Marshaler.
|
||||||
func (ls Labels) MarshalJSON() ([]byte, error) {
|
func (ls Labels) MarshalJSON() ([]byte, error) {
|
||||||
return json.Marshal(ls.Map())
|
return json.Marshal(ls.Map())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// UnmarshalJSON implements json.Unmarshaler.
|
||||||
func (ls *Labels) UnmarshalJSON(b []byte) error {
|
func (ls *Labels) UnmarshalJSON(b []byte) error {
|
||||||
var m map[string]string
|
var m map[string]string
|
||||||
|
|
||||||
|
@ -187,7 +189,7 @@ func Compare(a, b Labels) int {
|
||||||
return len(a) - len(b)
|
return len(a) - len(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LabelsBuilder allows modifiying Labels.
|
// Builder allows modifiying Labels.
|
||||||
type Builder struct {
|
type Builder struct {
|
||||||
base Labels
|
base Labels
|
||||||
del []string
|
del []string
|
||||||
|
|
|
@ -92,7 +92,7 @@ M [a-zA-Z_:]
|
||||||
l.offsets = append(l.offsets, l.i)
|
l.offsets = append(l.offsets, l.i)
|
||||||
<lstateLValueIn>(\\.|[^\\"])*\" l.state = lstateLabels
|
<lstateLValueIn>(\\.|[^\\"])*\" l.state = lstateLabels
|
||||||
if !utf8.Valid(l.b[l.offsets[len(l.offsets)-1]:l.i-1]) {
|
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
|
return -1
|
||||||
}
|
}
|
||||||
l.offsets = append(l.offsets, l.i-1)
|
l.offsets = append(l.offsets, l.i-1)
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
// CAUTION: Generated file - DO NOT EDIT.
|
// Code generated by golex. DO NOT EDIT.
|
||||||
|
|
||||||
// Copyright 2017 The Prometheus Authors
|
// Copyright 2017 The Prometheus Authors
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
@ -492,7 +492,7 @@ yyrule14: // (\\.|[^\\"])*\"
|
||||||
{
|
{
|
||||||
l.state = lstateLabels
|
l.state = lstateLabels
|
||||||
if !utf8.Valid(l.b[l.offsets[len(l.offsets)-1] : l.i-1]) {
|
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
|
return -1
|
||||||
}
|
}
|
||||||
l.offsets = append(l.offsets, l.i-1)
|
l.offsets = append(l.offsets, l.i-1)
|
||||||
|
|
|
@ -172,7 +172,7 @@ func TestParseErrors(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
input: "a{b=\"\xff\"} 1\n",
|
input: "a{b=\"\xff\"} 1\n",
|
||||||
err: "Invalid UTF-8 label value.",
|
err: "invalid UTF-8 label value",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
input: "a true\n",
|
input: "a true\n",
|
||||||
|
|
|
@ -18,16 +18,17 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// A quiet NaN. This is also math.NaN().
|
// NormalNaN is a quiet NaN. This is also math.NaN().
|
||||||
NormalNaN uint64 = 0x7ff8000000000001
|
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
|
// 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
|
// 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.
|
// it easier to distinguish from the NormalNaN by a human when debugging.
|
||||||
StaleNaN uint64 = 0x7ff0000000000002
|
StaleNaN uint64 = 0x7ff0000000000002
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// IsStaleNaN returns true when the provided NaN value is a stale marker.
|
||||||
func IsStaleNaN(v float64) bool {
|
func IsStaleNaN(v float64) bool {
|
||||||
return math.Float64bits(v) == StaleNaN
|
return math.Float64bits(v) == StaleNaN
|
||||||
}
|
}
|
||||||
|
|
|
@ -207,6 +207,7 @@ func newConcreteSeriersIterator(series *concreteSeries) storage.SeriesIterator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Seek implements storage.SeriesIterator.
|
||||||
func (c *concreteSeriesIterator) Seek(t int64) bool {
|
func (c *concreteSeriesIterator) Seek(t int64) bool {
|
||||||
c.cur = sort.Search(len(c.series.samples), func(n int) bool {
|
c.cur = sort.Search(len(c.series.samples), func(n int) bool {
|
||||||
return c.series.samples[n].Timestamp >= t
|
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)
|
return c.cur < len(c.series.samples)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// At implements storage.SeriesIterator.
|
||||||
func (c *concreteSeriesIterator) At() (t int64, v float64) {
|
func (c *concreteSeriesIterator) At() (t int64, v float64) {
|
||||||
s := c.series.samples[c.cur]
|
s := c.series.samples[c.cur]
|
||||||
return s.Timestamp, s.Value
|
return s.Timestamp, s.Value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Next implements storage.SeriesIterator.
|
||||||
func (c *concreteSeriesIterator) Next() bool {
|
func (c *concreteSeriesIterator) Next() bool {
|
||||||
c.cur++
|
c.cur++
|
||||||
return c.cur < len(c.series.samples)
|
return c.cur < len(c.series.samples)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Err implements storage.SeriesIterator.
|
||||||
func (c *concreteSeriesIterator) Err() error {
|
func (c *concreteSeriesIterator) Err() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,12 @@ import (
|
||||||
"github.com/prometheus/prometheus/storage"
|
"github.com/prometheus/prometheus/storage"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Appender implements retrieval.Appendable.
|
||||||
func (s *Storage) Appender() (storage.Appender, error) {
|
func (s *Storage) Appender() (storage.Appender, error) {
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Add implements storage.Appender.
|
||||||
func (s *Storage) Add(l labels.Labels, t int64, v float64) (uint64, error) {
|
func (s *Storage) Add(l labels.Labels, t int64, v float64) (uint64, error) {
|
||||||
s.mtx.RLock()
|
s.mtx.RLock()
|
||||||
defer s.mtx.RUnlock()
|
defer s.mtx.RUnlock()
|
||||||
|
@ -44,15 +46,18 @@ func labelsToMetric(ls labels.Labels) model.Metric {
|
||||||
return metric
|
return metric
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AddFast implements storage.Appender.
|
||||||
func (s *Storage) AddFast(l labels.Labels, _ uint64, t int64, v float64) error {
|
func (s *Storage) AddFast(l labels.Labels, _ uint64, t int64, v float64) error {
|
||||||
_, err := s.Add(l, t, v)
|
_, err := s.Add(l, t, v)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Commit implements storage.Appender.
|
||||||
func (*Storage) Commit() error {
|
func (*Storage) Commit() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Rollback implements storage.Appender.
|
||||||
func (*Storage) Rollback() error {
|
func (*Storage) Rollback() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,20 +45,23 @@ func init() {
|
||||||
prometheus.MustRegister(numWatchers)
|
prometheus.MustRegister(numWatchers)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ZookeeperLogger wraps a log.Logger into a zk.Logger.
|
||||||
type ZookeeperLogger struct {
|
type ZookeeperLogger struct {
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewZookeeperLogger is a constructor for ZookeeperLogger
|
// NewZookeeperLogger is a constructor for ZookeeperLogger.
|
||||||
func NewZookeeperLogger(logger log.Logger) ZookeeperLogger {
|
func NewZookeeperLogger(logger log.Logger) ZookeeperLogger {
|
||||||
return ZookeeperLogger{logger: logger}
|
return ZookeeperLogger{logger: logger}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implements zk.Logger
|
// Printf implements zk.Logger.
|
||||||
func (zl ZookeeperLogger) Printf(s string, i ...interface{}) {
|
func (zl ZookeeperLogger) Printf(s string, i ...interface{}) {
|
||||||
level.Info(zl.logger).Log("msg", fmt.Sprintf(s, i...))
|
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 {
|
type ZookeeperTreeCache struct {
|
||||||
conn *zk.Conn
|
conn *zk.Conn
|
||||||
prefix string
|
prefix string
|
||||||
|
@ -70,6 +73,7 @@ type ZookeeperTreeCache struct {
|
||||||
logger log.Logger
|
logger log.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A ZookeeperTreeCacheEvent models a Zookeeper event for a path.
|
||||||
type ZookeeperTreeCacheEvent struct {
|
type ZookeeperTreeCacheEvent struct {
|
||||||
Path string
|
Path string
|
||||||
Data *[]byte
|
Data *[]byte
|
||||||
|
@ -83,6 +87,7 @@ type zookeeperTreeCacheNode struct {
|
||||||
children map[string]*zookeeperTreeCacheNode
|
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 {
|
func NewZookeeperTreeCache(conn *zk.Conn, path string, events chan ZookeeperTreeCacheEvent, logger log.Logger) *ZookeeperTreeCache {
|
||||||
tc := &ZookeeperTreeCache{
|
tc := &ZookeeperTreeCache{
|
||||||
conn: conn,
|
conn: conn,
|
||||||
|
@ -101,6 +106,7 @@ func NewZookeeperTreeCache(conn *zk.Conn, path string, events chan ZookeeperTree
|
||||||
return tc
|
return tc
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop stops the tree cache.
|
||||||
func (tc *ZookeeperTreeCache) Stop() {
|
func (tc *ZookeeperTreeCache) Stop() {
|
||||||
tc.stop <- struct{}{}
|
tc.stop <- struct{}{}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue