Skip to content

Commit

Permalink
logging: query errors should not use debug level
Browse files Browse the repository at this point in the history
  • Loading branch information
mrlhansen committed Sep 16, 2024
1 parent 740e7ff commit f1a863f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
4 changes: 2 additions & 2 deletions cmd/idrac_exporter/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func MetricsHandler(rsp http.ResponseWriter, req *http.Request) {

c, err := collector.GetCollector(target)
if err != nil {
errorMsg := fmt.Sprintf("Error instantiating metrics collector for host %s: %v\n", target, err)
errorMsg := fmt.Sprintf("Error instantiating metrics collector for host %s: %v", target, err)
log.Error(errorMsg)
http.Error(rsp, errorMsg, http.StatusInternalServerError)
return
Expand All @@ -63,7 +63,7 @@ func MetricsHandler(rsp http.ResponseWriter, req *http.Request) {

metrics, err := c.Gather()
if err != nil {
errorMsg := fmt.Sprintf("Error collecting metrics for host %s: %v\n", target, err)
errorMsg := fmt.Sprintf("Error collecting metrics for host %s: %v", target, err)
log.Error(errorMsg)
http.Error(rsp, errorMsg, http.StatusInternalServerError)
return
Expand Down
8 changes: 4 additions & 4 deletions internal/collector/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -458,25 +458,25 @@ func (client *Client) redfishGet(path string, res interface{}) error {
req.Header.Add("Accept", "application/json")
req.SetBasicAuth(client.username, client.password)

log.Debug("Querying url %q", url)
log.Debug("Querying %q", url)

resp, err := client.httpClient.Do(req)
if resp != nil {
defer resp.Body.Close()
}
if err != nil {
log.Debug("Failed to query url %q: %v", url, err)
log.Error("Failed to query %q: %v", url, err)
return err
}

if resp.StatusCode != 200 {
log.Debug("Query to url %q returned unexpected status code: %d (%s)", url, resp.StatusCode, resp.Status)
log.Error("Query to %q returned unexpected status code: %d (%s)", url, resp.StatusCode, resp.Status)
return fmt.Errorf("%d %s", resp.StatusCode, resp.Status)
}

err = json.NewDecoder(resp.Body).Decode(res)
if err != nil {
log.Debug("Error decoding response from url %q: %v", url, err)
log.Error("Error decoding response from %q: %v", url, err)
return err
}

Expand Down
2 changes: 2 additions & 0 deletions internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ func readConfigFile(filename string) {
if err != nil {
log.Fatal("Invalid configuration file: %s: %s", filename, err.Error())
}

log.Info("Configuration file: %s", filename)
}

func ReadConfig(filename string) {
Expand Down

0 comments on commit f1a863f

Please sign in to comment.