Skip to content

Commit 1e1ba27

Browse files
committed
Fix lint errors
Signed-off-by: rustyclock <rustyclock@protonmail.com>
1 parent f57d3e9 commit 1e1ba27

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

cmd/main.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -64,28 +64,28 @@ func main(c *cli.Context) {
6464
promlogConfig := &promlog.Config{}
6565
logger := promlog.New(promlogConfig)
6666

67-
level.Info(logger).Log("msg", "Starting json_exporter", "version", version.Info())
68-
level.Info(logger).Log("msg", "Build context", "build", version.BuildContext())
67+
level.Info(logger).Log("msg", "Starting json_exporter", "version", version.Info()) //nolint:errcheck
68+
level.Info(logger).Log("msg", "Build context", "build", version.BuildContext()) //nolint:errcheck
6969

7070
internal.Init(logger, c)
7171

7272
config, err := config.LoadConfig(c.Args()[0])
7373
if err != nil {
74-
level.Error(logger).Log("msg", "Error loading config", "err", err)
74+
level.Error(logger).Log("msg", "Error loading config", "err", err) //nolint:errcheck
7575
os.Exit(1)
7676
}
7777
configJson, err := json.Marshal(config)
7878
if err != nil {
79-
level.Error(logger).Log("msg", "Failed to marshal config to JOSN", "err", err)
79+
level.Error(logger).Log("msg", "Failed to marshal config to JOSN", "err", err) //nolint:errcheck
8080
}
81-
level.Info(logger).Log("msg", "Loaded config file", "config", configJson)
81+
level.Info(logger).Log("msg", "Loaded config file", "config", configJson) //nolint:errcheck
8282

8383
http.Handle("/metrics", promhttp.Handler())
8484
http.HandleFunc("/probe", func(w http.ResponseWriter, req *http.Request) {
8585
probeHandler(w, req, logger, config)
8686
})
8787
if err := http.ListenAndServe(fmt.Sprintf(":%d", c.Int("port")), nil); err != nil {
88-
level.Error(logger).Log("msg", "failed to start the server", "err", err)
88+
level.Error(logger).Log("msg", "failed to start the server", "err", err) //nolint:errcheck
8989
}
9090
}
9191

@@ -99,7 +99,7 @@ func probeHandler(w http.ResponseWriter, r *http.Request, logger log.Logger, con
9999

100100
metrics, err := internal.CreateMetricsList(registry, config)
101101
if err != nil {
102-
level.Error(logger).Log("msg", "Failed to create metrics list from config", "err", err)
102+
level.Error(logger).Log("msg", "Failed to create metrics list from config", "err", err) //nolint:errcheck
103103
}
104104

105105
probeSuccessGauge := prometheus.NewGauge(prometheus.GaugeOpts{
@@ -123,9 +123,9 @@ func probeHandler(w http.ResponseWriter, r *http.Request, logger log.Logger, con
123123

124124
data, err := internal.FetchJson(ctx, logger, target, config.Headers)
125125
if err != nil {
126-
level.Error(logger).Log("msg", "Failed to fetch JSON response", "err", err)
126+
level.Error(logger).Log("msg", "Failed to fetch JSON response", "err", err) //nolint:errcheck
127127
duration := time.Since(start).Seconds()
128-
level.Error(logger).Log("msg", "Probe failed", "duration_seconds", duration)
128+
level.Error(logger).Log("msg", "Probe failed", "duration_seconds", duration) //nolint:errcheck
129129
} else {
130130
internal.Scrape(logger, metrics, data)
131131

internal/collector.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -43,28 +43,28 @@ func Scrape(logger log.Logger, collectors []JsonGaugeCollector, json []byte) {
4343
// TODO: Better handling/logging for this scenario
4444
floatValue, err := extractValue(logger, json, collector.KeyJsonPath)
4545
if err != nil {
46-
level.Error(logger).Log("msg", "Failed to extract float value for metric", "path", collector.KeyJsonPath, "err", err)
46+
level.Error(logger).Log("msg", "Failed to extract float value for metric", "path", collector.KeyJsonPath, "err", err) //nolint:errcheck
4747
continue
4848
}
4949

5050
collector.With(extractLabels(logger, json, collector.LabelsJsonPath)).Set(floatValue)
5151
} else { // ScrapeType is 'object'
5252
path, err := compilePath(collector.KeyJsonPath)
5353
if err != nil {
54-
level.Error(logger).Log("msg", "Failed to compile path", "path", collector.KeyJsonPath, "err", err)
54+
level.Error(logger).Log("msg", "Failed to compile path", "path", collector.KeyJsonPath, "err", err) //nolint:errcheck
5555
continue
5656
}
5757

5858
eval, err := jsonpath.EvalPathsInBytes(json, []*jsonpath.Path{path})
5959
if err != nil {
60-
level.Error(logger).Log("msg", "Failed to create evaluator for json path", "path", collector.KeyJsonPath, "err", err)
60+
level.Error(logger).Log("msg", "Failed to create evaluator for json path", "path", collector.KeyJsonPath, "err", err) //nolint:errcheck
6161
continue
6262
}
6363
for {
6464
if result, ok := eval.Next(); ok {
6565
floatValue, err := extractValue(logger, result.Value, collector.ValueJsonPath)
6666
if err != nil {
67-
level.Error(logger).Log("msg", "Failed to extract value", "path", collector.ValueJsonPath, "err", err)
67+
level.Error(logger).Log("msg", "Failed to extract value", "path", collector.ValueJsonPath, "err", err) //nolint:errcheck
6868
continue
6969
}
7070

@@ -118,7 +118,7 @@ func extractValue(logger log.Logger, json []byte, path string) (float64, error)
118118
if eval.Error != nil {
119119
return floatValue, fmt.Errorf("Failed to evaluate json. ERROR: '%s', PATH: '%s', JSON: '%s'", eval.Error, path, string(json))
120120
} else {
121-
level.Debug(logger).Log("msg", "Path not found", "path", path, "json", string(json))
121+
level.Debug(logger).Log("msg", "Path not found", "path", path, "json", string(json)) //nolint:errcheck
122122
return floatValue, fmt.Errorf("Could not find path. PATH: '%s'", path)
123123
}
124124
}
@@ -139,25 +139,25 @@ func extractLabels(logger log.Logger, json []byte, l map[string]string) map[stri
139139
// Dynamic value
140140
p, err := compilePath(path)
141141
if err != nil {
142-
level.Error(logger).Log("msg", "Failed to compile path for label", "path", path, "label", label, "err", err)
142+
level.Error(logger).Log("msg", "Failed to compile path for label", "path", path, "label", label, "err", err) //nolint:errcheck
143143
labels[label] = ""
144144
continue
145145
}
146146

147147
eval, err := jsonpath.EvalPathsInBytes(json, []*jsonpath.Path{p})
148148
if err != nil {
149-
level.Error(logger).Log("msg", "Failed to create evaluator for json", "path", path, "err", err)
149+
level.Error(logger).Log("msg", "Failed to create evaluator for json", "path", path, "err", err) //nolint:errcheck
150150
labels[label] = ""
151151
continue
152152
}
153153

154154
result, ok := eval.Next()
155155
if result == nil || !ok {
156156
if eval.Error != nil {
157-
level.Error(logger).Log("msg", "Failed to evaluate", "label", label, "json", string(json), "err", eval.Error)
157+
level.Error(logger).Log("msg", "Failed to evaluate", "label", label, "json", string(json), "err", eval.Error) //nolint:errcheck
158158
} else {
159-
level.Warn(logger).Log("msg", "Label path not found in json", "path", path, "label", label)
160-
level.Debug(logger).Log("msg", "Label path not found in json", "path", path, "label", label, "json", string(json))
159+
level.Warn(logger).Log("msg", "Label path not found in json", "path", path, "label", label) //nolint:errcheck
160+
level.Debug(logger).Log("msg", "Label path not found in json", "path", path, "label", label, "json", string(json)) //nolint:errcheck
161161
}
162162
continue
163163
}
@@ -177,7 +177,7 @@ func FetchJson(ctx context.Context, logger log.Logger, endpoint string, headers
177177
req, err := http.NewRequest("GET", endpoint, nil)
178178
req = req.WithContext(ctx)
179179
if err != nil {
180-
level.Error(logger).Log("msg", "Failed to create request", "err", err)
180+
level.Error(logger).Log("msg", "Failed to create request", "err", err) //nolint:errcheck
181181
return nil, err
182182
}
183183

internal/init.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ func Init(logger log.Logger, c *cli.Context) {
2626
args := c.Args()
2727

2828
if len(args) < 1 {
29-
cli.ShowAppHelp(c) //nolint:errcheck
30-
level.Error(logger).Log("msg", "Not enough arguments")
29+
cli.ShowAppHelp(c) //nolint:errcheck
30+
level.Error(logger).Log("msg", "Not enough arguments") //nolint:errcheck
3131
os.Exit(1)
3232
}
3333

@@ -38,7 +38,7 @@ func Init(logger log.Logger, c *cli.Context) {
3838
_, err := config.LoadConfig(configPath)
3939

4040
if err != nil {
41-
level.Error(logger).Log("msg", "Failed to load config")
41+
level.Error(logger).Log("msg", "Failed to load config") //nolint:errcheck
4242
os.Exit(1)
4343
}
4444
}

0 commit comments

Comments
 (0)