Skip to content

Commit

Permalink
Merge pull request prometheus-community#210 from tjhop/chore/adopt-slog
Browse files Browse the repository at this point in the history
chore!: adopt slog, drop go-kit/log
  • Loading branch information
bitfehler authored Oct 18, 2024
2 parents 90d956b + 3db8be8 commit b08f887
Show file tree
Hide file tree
Showing 17 changed files with 96 additions and 101 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ executors:
# also be updated.
golang:
docker:
- image: cimg/go:1.21
- image: cimg/go:1.23
jobs:
test:
executor: golang
Expand Down
8 changes: 5 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
---
linters:
enable:
- sloglint

issues:
exclude-rules:
- path: _test.go
Expand All @@ -7,6 +11,4 @@ issues:

linters-settings:
errcheck:
exclude-functions:
# Never check for logger errors.
- (github.com/go-kit/log.Logger).Log
exclude-functions: []
2 changes: 1 addition & 1 deletion .promu.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
go:
# Whenever the Go version is updated here,
# .circleci/config.yml should also be updated.
version: 1.21
version: 1.23

repository:
path: github.com/prometheus-community/ipmi_exporter
Expand Down
5 changes: 2 additions & 3 deletions collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"path"
"time"

"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"

"github.com/prometheus-community/ipmi_exporter/freeipmi"
Expand Down Expand Up @@ -81,7 +80,7 @@ func (c metaCollector) Collect(ch chan<- prometheus.Metric) {
start := time.Now()
defer func() {
duration := time.Since(start).Seconds()
level.Debug(logger).Log("msg", "Scrape duration", "target", targetName(c.target), "duration", duration)
logger.Debug("Scrape duration", "target", targetName(c.target), "duration", duration)
ch <- prometheus.MustNewConstMetric(
durationDesc,
prometheus.GaugeValue,
Expand All @@ -97,7 +96,7 @@ func (c metaCollector) Collect(ch chan<- prometheus.Metric) {

for _, collector := range config.GetCollectors() {
var up int
level.Debug(logger).Log("msg", "Running collector", "target", target.host, "collector", collector.Name())
logger.Debug("Running collector", "target", target.host, "collector", collector.Name())

fqcmd := collector.Cmd()
if !path.IsAbs(fqcmd) {
Expand Down
7 changes: 3 additions & 4 deletions collector_bmc.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package main

import (
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"

"github.com/prometheus-community/ipmi_exporter/freeipmi"
Expand Down Expand Up @@ -50,18 +49,18 @@ func (c BMCCollector) Args() []string {
func (c BMCCollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metric, target ipmiTarget) (int, error) {
firmwareRevision, err := freeipmi.GetBMCInfoFirmwareRevision(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect BMC data", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect BMC data", "target", targetName(target.host), "error", err)
return 0, err
}
manufacturerID, err := freeipmi.GetBMCInfoManufacturerID(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect BMC data", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect BMC data", "target", targetName(target.host), "error", err)
return 0, err
}
systemFirmwareVersion, err := freeipmi.GetBMCInfoSystemFirmwareVersion(result)
if err != nil {
// This one is not always available.
level.Debug(logger).Log("msg", "Failed to parse bmc-info data", "target", targetName(target.host), "error", err)
logger.Debug("Failed to parse bmc-info data", "target", targetName(target.host), "error", err)
systemFirmwareVersion = "N/A"
}
ch <- prometheus.MustNewConstMetric(
Expand Down
17 changes: 8 additions & 9 deletions collector_bmc_watchdog.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package main

import (
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"

"github.com/prometheus-community/ipmi_exporter/freeipmi"
Expand Down Expand Up @@ -95,42 +94,42 @@ func (c BMCWatchdogCollector) Args() []string {
func (c BMCWatchdogCollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metric, target ipmiTarget) (int, error) {
timerState, err := freeipmi.GetBMCWatchdogTimerState(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect BMC watchdog timer", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect BMC watchdog timer", "target", targetName(target.host), "error", err)
return 0, err
}
currentTimerUse, err := freeipmi.GetBMCWatchdogTimerUse(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect BMC watchdog timer use", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect BMC watchdog timer use", "target", targetName(target.host), "error", err)
return 0, err
}
loggingState, err := freeipmi.GetBMCWatchdogLoggingState(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect BMC watchdog logging", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect BMC watchdog logging", "target", targetName(target.host), "error", err)
return 0, err
}
currentTimeoutAction, err := freeipmi.GetBMCWatchdogTimeoutAction(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect BMC watchdog timeout action", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect BMC watchdog timeout action", "target", targetName(target.host), "error", err)
return 0, err
}
currentPretimeoutInterrupt, err := freeipmi.GetBMCWatchdogPretimeoutInterrupt(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect BMC watchdog pretimeout interrupt", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect BMC watchdog pretimeout interrupt", "target", targetName(target.host), "error", err)
return 0, err
}
pretimeoutInterval, err := freeipmi.GetBMCWatchdogPretimeoutInterval(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect BMC watchdog pretimeout interval", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect BMC watchdog pretimeout interval", "target", targetName(target.host), "error", err)
return 0, err
}
initialCountdown, err := freeipmi.GetBMCWatchdogInitialCountdown(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect BMC watchdog initial countdown", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect BMC watchdog initial countdown", "target", targetName(target.host), "error", err)
return 0, err
}
currentCountdown, err := freeipmi.GetBMCWatchdogCurrentCountdown(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect BMC watchdog current countdown", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect BMC watchdog current countdown", "target", targetName(target.host), "error", err)
return 0, err
}

Expand Down
7 changes: 3 additions & 4 deletions collector_chassis.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package main

import (
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"

"github.com/prometheus-community/ipmi_exporter/freeipmi"
Expand Down Expand Up @@ -62,17 +61,17 @@ func (c ChassisCollector) Args() []string {
func (c ChassisCollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metric, target ipmiTarget) (int, error) {
currentChassisPowerState, err := freeipmi.GetChassisPowerState(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect chassis data", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect chassis data", "target", targetName(target.host), "error", err)
return 0, err
}
currentChassisDriveFault, err := freeipmi.GetChassisDriveFault(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect chassis data", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect chassis data", "target", targetName(target.host), "error", err)
return 0, err
}
currentChassisCoolingFault, err := freeipmi.GetChassisCoolingFault(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect chassis data", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect chassis data", "target", targetName(target.host), "error", err)
return 0, err
}
ch <- prometheus.MustNewConstMetric(
Expand Down
3 changes: 1 addition & 2 deletions collector_dcmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package main

import (
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"

"github.com/prometheus-community/ipmi_exporter/freeipmi"
Expand Down Expand Up @@ -50,7 +49,7 @@ func (c DCMICollector) Args() []string {
func (c DCMICollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metric, target ipmiTarget) (int, error) {
currentPowerConsumption, err := freeipmi.GetCurrentPowerConsumption(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect DCMI data", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect DCMI data", "target", targetName(target.host), "error", err)
return 0, err
}
// Returned value negative == Power Measurement is not avail
Expand Down
7 changes: 3 additions & 4 deletions collector_ipmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"math"
"strconv"

"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"

"github.com/prometheus-community/ipmi_exporter/freeipmi"
Expand Down Expand Up @@ -148,7 +147,7 @@ func (c IPMICollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metr
targetHost := targetName(target.host)
results, err := freeipmi.GetSensorData(result, excludeIds)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect sensor data", "target", targetHost, "error", err)
logger.Error("Failed to collect sensor data", "target", targetHost, "error", err)
return 0, err
}
for _, data := range results {
Expand All @@ -164,11 +163,11 @@ func (c IPMICollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metr
case "N/A":
state = math.NaN()
default:
level.Error(logger).Log("msg", "Unknown sensor state", "target", targetHost, "state", data.State)
logger.Error("Unknown sensor state", "target", targetHost, "state", data.State)
state = math.NaN()
}

level.Debug(logger).Log("msg", "Got values", "target", targetHost, "data", fmt.Sprintf("%+v", data))
logger.Debug("Got values", "target", targetHost, "data", fmt.Sprintf("%+v", data))

switch data.Unit {
case "RPM":
Expand Down
5 changes: 2 additions & 3 deletions collector_sel.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
package main

import (
"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"

"github.com/prometheus-community/ipmi_exporter/freeipmi"
Expand Down Expand Up @@ -57,12 +56,12 @@ func (c SELCollector) Args() []string {
func (c SELCollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metric, target ipmiTarget) (int, error) {
entriesCount, err := freeipmi.GetSELInfoEntriesCount(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect SEL data", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect SEL data", "target", targetName(target.host), "error", err)
return 0, err
}
freeSpace, err := freeipmi.GetSELInfoFreeSpace(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect SEL data", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect SEL data", "target", targetName(target.host), "error", err)
return 0, err
}
ch <- prometheus.MustNewConstMetric(
Expand Down
5 changes: 2 additions & 3 deletions collector_sel_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package main
import (
"time"

"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"

"github.com/prometheus-community/ipmi_exporter/freeipmi"
Expand Down Expand Up @@ -75,7 +74,7 @@ func (c SELEventsCollector) Collect(result freeipmi.Result, ch chan<- prometheus

events, err := freeipmi.GetSELEvents(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect SEL events", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect SEL events", "target", targetName(target.host), "error", err)
return 0, err
}

Expand Down Expand Up @@ -103,7 +102,7 @@ func (c SELEventsCollector) Collect(result freeipmi.Result, ch chan<- prometheus
// ID,Date,Time,Name,Type,State,Event
// 3,PostInit,PostInit,Sensor #211,Memory,Warning,Correctable memory error ; Event Data3 = 34h
if err != nil {
level.Debug(logger).Log("msg", "Failed to parse time", "target", targetName(target.host), "error", err)
logger.Debug("Failed to parse time", "target", targetName(target.host), "error", err)
} else {
newTimestamp = float64(t.Unix())
}
Expand Down
7 changes: 3 additions & 4 deletions collector_sm_lan_mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"fmt"
"strconv"

"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"

"github.com/prometheus-community/ipmi_exporter/freeipmi"
Expand Down Expand Up @@ -53,11 +52,11 @@ func (c SMLANModeCollector) Args() []string {
func (c SMLANModeCollector) Collect(result freeipmi.Result, ch chan<- prometheus.Metric, target ipmiTarget) (int, error) {
octets, err := freeipmi.GetRawOctets(result)
if err != nil {
level.Error(logger).Log("msg", "Failed to collect LAN mode data", "target", targetName(target.host), "error", err)
logger.Error("Failed to collect LAN mode data", "target", targetName(target.host), "error", err)
return 0, err
}
if len(octets) != 3 {
level.Error(logger).Log("msg", "Unexpected number of octets", "target", targetName(target.host), "octets", octets)
logger.Error("Unexpected number of octets", "target", targetName(target.host), "octets", octets)
return 0, fmt.Errorf("unexpected number of octets in raw response: %d", len(octets))
}

Expand All @@ -66,7 +65,7 @@ func (c SMLANModeCollector) Collect(result freeipmi.Result, ch chan<- prometheus
value, _ := strconv.Atoi(octets[2])
ch <- prometheus.MustNewConstMetric(lanModeDesc, prometheus.GaugeValue, float64(value))
default:
level.Error(logger).Log("msg", "Unexpected lan mode status (ipmi-raw)", "target", targetName(target.host), "sgatus", octets[2])
logger.Error("Unexpected lan mode status (ipmi-raw)", "target", targetName(target.host), "sgatus", octets[2])
return 0, fmt.Errorf("unexpected lan mode status: %s", octets[2])
}

Expand Down
9 changes: 4 additions & 5 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"strings"
"sync"

"github.com/go-kit/log/level"
"github.com/prometheus/client_golang/prometheus"

"github.com/prometheus-community/ipmi_exporter/freeipmi"
Expand Down Expand Up @@ -239,7 +238,7 @@ func (sc *SafeConfig) ReloadConfig(configFile string) error {
if configFile != "" {
config, err = os.ReadFile(configFile)
if err != nil {
level.Error(logger).Log("msg", "Error reading config file", "error", err)
logger.Error("Error reading config file", "error", err)
return err
}
} else {
Expand All @@ -255,7 +254,7 @@ func (sc *SafeConfig) ReloadConfig(configFile string) error {
sc.Unlock()

if configFile != "" {
level.Info(logger).Log("msg", "Loaded config file", "path", configFile)
logger.Info("Loaded config file", "path", configFile)
}
return nil
}
Expand All @@ -281,7 +280,7 @@ func (sc *SafeConfig) ConfigForTarget(target, module string) IPMIConfig {
if module != "default" {
config, ok = sc.C.Modules[module]
if !ok {
level.Error(logger).Log("msg", "Requested module not found, using default", "module", module, "target", targetName(target))
logger.Error("Requested module not found, using default", "module", module, "target", targetName(target))
}
}

Expand All @@ -290,7 +289,7 @@ func (sc *SafeConfig) ConfigForTarget(target, module string) IPMIConfig {
config, ok = sc.C.Modules["default"]
if !ok {
// This is probably fine for running locally, so not making this a warning
level.Debug(logger).Log("msg", "Needed default config for, but none configured, using FreeIPMI defaults", "target", targetName(target))
logger.Debug("Needed default config for, but none configured, using FreeIPMI defaults", "target", targetName(target))
config = defaultConfig
}
}
Expand Down
Loading

0 comments on commit b08f887

Please sign in to comment.