mirror of
https://github.com/prometheus-community/json_exporter
synced 2024-12-24 15:33:59 +00:00
Fix lint errors
Signed-off-by: rustyclock <rustyclock@protonmail.com>
This commit is contained in:
parent
f57d3e9429
commit
1e1ba273ed
18
cmd/main.go
18
cmd/main.go
@ -64,28 +64,28 @@ func main(c *cli.Context) {
|
||||
promlogConfig := &promlog.Config{}
|
||||
logger := promlog.New(promlogConfig)
|
||||
|
||||
level.Info(logger).Log("msg", "Starting json_exporter", "version", version.Info())
|
||||
level.Info(logger).Log("msg", "Build context", "build", version.BuildContext())
|
||||
level.Info(logger).Log("msg", "Starting json_exporter", "version", version.Info()) //nolint:errcheck
|
||||
level.Info(logger).Log("msg", "Build context", "build", version.BuildContext()) //nolint:errcheck
|
||||
|
||||
internal.Init(logger, c)
|
||||
|
||||
config, err := config.LoadConfig(c.Args()[0])
|
||||
if err != nil {
|
||||
level.Error(logger).Log("msg", "Error loading config", "err", err)
|
||||
level.Error(logger).Log("msg", "Error loading config", "err", err) //nolint:errcheck
|
||||
os.Exit(1)
|
||||
}
|
||||
configJson, err := json.Marshal(config)
|
||||
if err != nil {
|
||||
level.Error(logger).Log("msg", "Failed to marshal config to JOSN", "err", err)
|
||||
level.Error(logger).Log("msg", "Failed to marshal config to JOSN", "err", err) //nolint:errcheck
|
||||
}
|
||||
level.Info(logger).Log("msg", "Loaded config file", "config", configJson)
|
||||
level.Info(logger).Log("msg", "Loaded config file", "config", configJson) //nolint:errcheck
|
||||
|
||||
http.Handle("/metrics", promhttp.Handler())
|
||||
http.HandleFunc("/probe", func(w http.ResponseWriter, req *http.Request) {
|
||||
probeHandler(w, req, logger, config)
|
||||
})
|
||||
if err := http.ListenAndServe(fmt.Sprintf(":%d", c.Int("port")), nil); err != nil {
|
||||
level.Error(logger).Log("msg", "failed to start the server", "err", err)
|
||||
level.Error(logger).Log("msg", "failed to start the server", "err", err) //nolint:errcheck
|
||||
}
|
||||
}
|
||||
|
||||
@ -99,7 +99,7 @@ func probeHandler(w http.ResponseWriter, r *http.Request, logger log.Logger, con
|
||||
|
||||
metrics, err := internal.CreateMetricsList(registry, config)
|
||||
if err != nil {
|
||||
level.Error(logger).Log("msg", "Failed to create metrics list from config", "err", err)
|
||||
level.Error(logger).Log("msg", "Failed to create metrics list from config", "err", err) //nolint:errcheck
|
||||
}
|
||||
|
||||
probeSuccessGauge := prometheus.NewGauge(prometheus.GaugeOpts{
|
||||
@ -123,9 +123,9 @@ func probeHandler(w http.ResponseWriter, r *http.Request, logger log.Logger, con
|
||||
|
||||
data, err := internal.FetchJson(ctx, logger, target, config.Headers)
|
||||
if err != nil {
|
||||
level.Error(logger).Log("msg", "Failed to fetch JSON response", "err", err)
|
||||
level.Error(logger).Log("msg", "Failed to fetch JSON response", "err", err) //nolint:errcheck
|
||||
duration := time.Since(start).Seconds()
|
||||
level.Error(logger).Log("msg", "Probe failed", "duration_seconds", duration)
|
||||
level.Error(logger).Log("msg", "Probe failed", "duration_seconds", duration) //nolint:errcheck
|
||||
} else {
|
||||
internal.Scrape(logger, metrics, data)
|
||||
|
||||
|
@ -43,7 +43,7 @@ func Scrape(logger log.Logger, collectors []JsonGaugeCollector, json []byte) {
|
||||
// TODO: Better handling/logging for this scenario
|
||||
floatValue, err := extractValue(logger, json, collector.KeyJsonPath)
|
||||
if err != nil {
|
||||
level.Error(logger).Log("msg", "Failed to extract float value for metric", "path", collector.KeyJsonPath, "err", err)
|
||||
level.Error(logger).Log("msg", "Failed to extract float value for metric", "path", collector.KeyJsonPath, "err", err) //nolint:errcheck
|
||||
continue
|
||||
}
|
||||
|
||||
@ -51,20 +51,20 @@ func Scrape(logger log.Logger, collectors []JsonGaugeCollector, json []byte) {
|
||||
} else { // ScrapeType is 'object'
|
||||
path, err := compilePath(collector.KeyJsonPath)
|
||||
if err != nil {
|
||||
level.Error(logger).Log("msg", "Failed to compile path", "path", collector.KeyJsonPath, "err", err)
|
||||
level.Error(logger).Log("msg", "Failed to compile path", "path", collector.KeyJsonPath, "err", err) //nolint:errcheck
|
||||
continue
|
||||
}
|
||||
|
||||
eval, err := jsonpath.EvalPathsInBytes(json, []*jsonpath.Path{path})
|
||||
if err != nil {
|
||||
level.Error(logger).Log("msg", "Failed to create evaluator for json path", "path", collector.KeyJsonPath, "err", err)
|
||||
level.Error(logger).Log("msg", "Failed to create evaluator for json path", "path", collector.KeyJsonPath, "err", err) //nolint:errcheck
|
||||
continue
|
||||
}
|
||||
for {
|
||||
if result, ok := eval.Next(); ok {
|
||||
floatValue, err := extractValue(logger, result.Value, collector.ValueJsonPath)
|
||||
if err != nil {
|
||||
level.Error(logger).Log("msg", "Failed to extract value", "path", collector.ValueJsonPath, "err", err)
|
||||
level.Error(logger).Log("msg", "Failed to extract value", "path", collector.ValueJsonPath, "err", err) //nolint:errcheck
|
||||
continue
|
||||
}
|
||||
|
||||
@ -118,7 +118,7 @@ func extractValue(logger log.Logger, json []byte, path string) (float64, error)
|
||||
if eval.Error != nil {
|
||||
return floatValue, fmt.Errorf("Failed to evaluate json. ERROR: '%s', PATH: '%s', JSON: '%s'", eval.Error, path, string(json))
|
||||
} else {
|
||||
level.Debug(logger).Log("msg", "Path not found", "path", path, "json", string(json))
|
||||
level.Debug(logger).Log("msg", "Path not found", "path", path, "json", string(json)) //nolint:errcheck
|
||||
return floatValue, fmt.Errorf("Could not find path. PATH: '%s'", path)
|
||||
}
|
||||
}
|
||||
@ -139,14 +139,14 @@ func extractLabels(logger log.Logger, json []byte, l map[string]string) map[stri
|
||||
// Dynamic value
|
||||
p, err := compilePath(path)
|
||||
if err != nil {
|
||||
level.Error(logger).Log("msg", "Failed to compile path for label", "path", path, "label", label, "err", err)
|
||||
level.Error(logger).Log("msg", "Failed to compile path for label", "path", path, "label", label, "err", err) //nolint:errcheck
|
||||
labels[label] = ""
|
||||
continue
|
||||
}
|
||||
|
||||
eval, err := jsonpath.EvalPathsInBytes(json, []*jsonpath.Path{p})
|
||||
if err != nil {
|
||||
level.Error(logger).Log("msg", "Failed to create evaluator for json", "path", path, "err", err)
|
||||
level.Error(logger).Log("msg", "Failed to create evaluator for json", "path", path, "err", err) //nolint:errcheck
|
||||
labels[label] = ""
|
||||
continue
|
||||
}
|
||||
@ -154,10 +154,10 @@ func extractLabels(logger log.Logger, json []byte, l map[string]string) map[stri
|
||||
result, ok := eval.Next()
|
||||
if result == nil || !ok {
|
||||
if eval.Error != nil {
|
||||
level.Error(logger).Log("msg", "Failed to evaluate", "label", label, "json", string(json), "err", eval.Error)
|
||||
level.Error(logger).Log("msg", "Failed to evaluate", "label", label, "json", string(json), "err", eval.Error) //nolint:errcheck
|
||||
} else {
|
||||
level.Warn(logger).Log("msg", "Label path not found in json", "path", path, "label", label)
|
||||
level.Debug(logger).Log("msg", "Label path not found in json", "path", path, "label", label, "json", string(json))
|
||||
level.Warn(logger).Log("msg", "Label path not found in json", "path", path, "label", label) //nolint:errcheck
|
||||
level.Debug(logger).Log("msg", "Label path not found in json", "path", path, "label", label, "json", string(json)) //nolint:errcheck
|
||||
}
|
||||
continue
|
||||
}
|
||||
@ -177,7 +177,7 @@ func FetchJson(ctx context.Context, logger log.Logger, endpoint string, headers
|
||||
req, err := http.NewRequest("GET", endpoint, nil)
|
||||
req = req.WithContext(ctx)
|
||||
if err != nil {
|
||||
level.Error(logger).Log("msg", "Failed to create request", "err", err)
|
||||
level.Error(logger).Log("msg", "Failed to create request", "err", err) //nolint:errcheck
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -26,8 +26,8 @@ func Init(logger log.Logger, c *cli.Context) {
|
||||
args := c.Args()
|
||||
|
||||
if len(args) < 1 {
|
||||
cli.ShowAppHelp(c) //nolint:errcheck
|
||||
level.Error(logger).Log("msg", "Not enough arguments")
|
||||
cli.ShowAppHelp(c) //nolint:errcheck
|
||||
level.Error(logger).Log("msg", "Not enough arguments") //nolint:errcheck
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ func Init(logger log.Logger, c *cli.Context) {
|
||||
_, err := config.LoadConfig(configPath)
|
||||
|
||||
if err != nil {
|
||||
level.Error(logger).Log("msg", "Failed to load config")
|
||||
level.Error(logger).Log("msg", "Failed to load config") //nolint:errcheck
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user