Fix lint issues.
Signed-off-by: Ben Kochie <superq@gmail.com>
This commit is contained in:
parent
429000ac5e
commit
bfa58a640c
|
@ -85,7 +85,7 @@ func (exp *exporter) main(c *cli.Context) {
|
||||||
collector.Collect(registry)
|
collector.Collect(registry)
|
||||||
interval := c.Int("interval")
|
interval := c.Int("interval")
|
||||||
go func() {
|
go func() {
|
||||||
for _ = range time.Tick(time.Duration(interval) * time.Second) {
|
for range time.Tick(time.Duration(interval) * time.Second) {
|
||||||
if exp.ResetOnTick {
|
if exp.ResetOnTick {
|
||||||
registry.Reset()
|
registry.Reset()
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,12 +20,12 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
Name string `yaml:name`
|
Name string `yaml:"name"`
|
||||||
Path string `yaml:path`
|
Path string `yaml:"path"`
|
||||||
Labels map[string]string `yaml:labels`
|
Labels map[string]string `yaml:"labels"`
|
||||||
Type string `yaml:type`
|
Type string `yaml:"type"`
|
||||||
Help string `yaml:help`
|
Help string `yaml:"help"`
|
||||||
Values map[string]string `yaml:values`
|
Values map[string]string `yaml:"values"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (config *Config) labelNames() []string {
|
func (config *Config) labelNames() []string {
|
||||||
|
|
|
@ -62,7 +62,7 @@ func Init(c *cli.Context, reg *harness.MetricRegistry) (harness.Collector, error
|
||||||
args := c.Args()
|
args := c.Args()
|
||||||
|
|
||||||
if len(args) < 2 {
|
if len(args) < 2 {
|
||||||
cli.ShowAppHelp(c)
|
cli.ShowAppHelp(c) //nolint:errcheck
|
||||||
return nil, fmt.Errorf("not enough arguments")
|
return nil, fmt.Errorf("not enough arguments")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,7 @@ func (vs *ValueScraper) parseValue(bytes []byte) (float64, error) {
|
||||||
func (vs *ValueScraper) forTargetValue(data []byte, handle func(*jsonpath.Result)) error {
|
func (vs *ValueScraper) forTargetValue(data []byte, handle func(*jsonpath.Result)) error {
|
||||||
eval, err := jsonpath.EvalPathsInBytes(data, []*jsonpath.Path{vs.valueJsonPath})
|
eval, err := jsonpath.EvalPathsInBytes(data, []*jsonpath.Path{vs.valueJsonPath})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to eval jsonpath;path:<%s>,json:<%s>", vs.valueJsonPath, data)
|
return fmt.Errorf("failed to eval jsonpath;path:<%v>,json:<%s>", vs.valueJsonPath, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
@ -74,7 +74,7 @@ func (vs *ValueScraper) Scrape(data []byte, reg *harness.MetricRegistry) error {
|
||||||
isFirst := true
|
isFirst := true
|
||||||
return vs.forTargetValue(data, func(result *jsonpath.Result) {
|
return vs.forTargetValue(data, func(result *jsonpath.Result) {
|
||||||
if !isFirst {
|
if !isFirst {
|
||||||
log.Infof("ignoring non-first value;path:<%s>", vs.valueJsonPath)
|
log.Infof("ignoring non-first value;path:<%v>", vs.valueJsonPath)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
isFirst = false
|
isFirst = false
|
||||||
|
@ -90,13 +90,13 @@ func (vs *ValueScraper) Scrape(data []byte, reg *harness.MetricRegistry) error {
|
||||||
case jsonpath.JsonNull:
|
case jsonpath.JsonNull:
|
||||||
value = math.NaN()
|
value = math.NaN()
|
||||||
default:
|
default:
|
||||||
log.Warnf("skipping not numerical result;path:<%s>,value:<%s>",
|
log.Warnf("skipping not numerical result;path:<%v>,value:<%s>",
|
||||||
vs.valueJsonPath, result.Value)
|
vs.valueJsonPath, result.Value)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Should never happen.
|
// Should never happen.
|
||||||
log.Errorf("could not parse numerical value as float;path:<%s>,value:<%s>",
|
log.Errorf("could not parse numerical value as float;path:<%v>,value:<%s>",
|
||||||
vs.valueJsonPath, result.Value)
|
vs.valueJsonPath, result.Value)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -161,7 +161,7 @@ func (obsc *ObjectScraper) extractFirstValue(data []byte, path *jsonpath.Path) (
|
||||||
func (obsc *ObjectScraper) Scrape(data []byte, reg *harness.MetricRegistry) error {
|
func (obsc *ObjectScraper) Scrape(data []byte, reg *harness.MetricRegistry) error {
|
||||||
return obsc.forTargetValue(data, func(result *jsonpath.Result) {
|
return obsc.forTargetValue(data, func(result *jsonpath.Result) {
|
||||||
if result.Type != jsonpath.JsonObject && result.Type != jsonpath.JsonArray {
|
if result.Type != jsonpath.JsonObject && result.Type != jsonpath.JsonArray {
|
||||||
log.Warnf("skipping not structual result;path:<%s>,value:<%s>",
|
log.Warnf("skipping not structual result;path:<%v>,value:<%s>",
|
||||||
obsc.valueJsonPath, result.Value)
|
obsc.valueJsonPath, result.Value)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,7 @@ func (obsc *ObjectScraper) Scrape(data []byte, reg *harness.MetricRegistry) erro
|
||||||
for name, path := range obsc.labelJsonPaths {
|
for name, path := range obsc.labelJsonPaths {
|
||||||
firstResult, err := obsc.extractFirstValue(result.Value, path)
|
firstResult, err := obsc.extractFirstValue(result.Value, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("could not find value for label path;path:<%s>,json:<%s>,err:<%s>", path, result.Value, err)
|
log.Warnf("could not find value for label path;path:<%v>,json:<%s>,err:<%s>", path, result.Value, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
value := firstResult.Value
|
value := firstResult.Value
|
||||||
|
@ -189,7 +189,7 @@ func (obsc *ObjectScraper) Scrape(data []byte, reg *harness.MetricRegistry) erro
|
||||||
// Static value
|
// Static value
|
||||||
value, err := obsc.parseValue([]byte(configValue))
|
value, err := obsc.parseValue([]byte(configValue))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("could not use configured value as float number;name:<%s>,err:<%s>", err)
|
log.Errorf("could not use configured value as float number;err:<%s>", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
metricValue = value
|
metricValue = value
|
||||||
|
@ -197,7 +197,7 @@ func (obsc *ObjectScraper) Scrape(data []byte, reg *harness.MetricRegistry) erro
|
||||||
// Dynamic value
|
// Dynamic value
|
||||||
firstResult, err := obsc.extractFirstValue(result.Value, path)
|
firstResult, err := obsc.extractFirstValue(result.Value, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("could not find value for value path;path:<%s>,json:<%s>,err:<%s>", path, result.Value, err)
|
log.Warnf("could not find value for value path;path:<%v>,json:<%s>,err:<%s>", path, result.Value, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,13 +211,13 @@ func (obsc *ObjectScraper) Scrape(data []byte, reg *harness.MetricRegistry) erro
|
||||||
case jsonpath.JsonNull:
|
case jsonpath.JsonNull:
|
||||||
value = math.NaN()
|
value = math.NaN()
|
||||||
default:
|
default:
|
||||||
log.Warnf("skipping not numerical result;path:<%s>,value:<%s>",
|
log.Warnf("skipping not numerical result;path:<%v>,value:<%s>",
|
||||||
obsc.valueJsonPath, result.Value)
|
obsc.valueJsonPath, result.Value)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
// Should never happen.
|
// Should never happen.
|
||||||
log.Errorf("could not parse numerical value as float;path:<%s>,value:<%s>",
|
log.Errorf("could not parse numerical value as float;path:<%v>,value:<%s>",
|
||||||
obsc.valueJsonPath, firstResult.Value)
|
obsc.valueJsonPath, firstResult.Value)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue