From 881d882f67ec270bb579c367b7bb542727774066 Mon Sep 17 00:00:00 2001 From: Ben Kochie Date: Wed, 11 Sep 2024 10:51:28 +0200 Subject: [PATCH] Update logging (#3097) Switch from promlog/go-kit to promslog/slog for logging. * Update Go build to 1.23. Signed-off-by: Ben Kochie Signed-off-by: Vitaly Zhuravlev --- .golangci.yml | 2 - collector/arp_linux.go | 6 +-- collector/bcache_linux.go | 6 +-- collector/bonding_linux.go | 9 ++-- collector/boot_time_bsd.go | 6 +-- collector/boot_time_solaris.go | 6 +-- collector/btrfs_linux.go | 23 +++++---- collector/buddyinfo.go | 9 ++-- collector/cgroups_linux.go | 6 +-- collector/collector.go | 21 ++++----- collector/conntrack_linux.go | 9 ++-- collector/cpu_darwin.go | 6 +-- collector/cpu_dragonfly.go | 6 +-- collector/cpu_freebsd.go | 11 ++--- collector/cpu_linux.go | 43 +++++++++-------- collector/cpu_linux_test.go | 5 +- collector/cpu_netbsd.go | 9 ++-- collector/cpu_openbsd.go | 6 +-- collector/cpu_solaris.go | 6 +-- collector/cpu_vulnerabilities_linux.go | 4 +- collector/cpufreq_linux.go | 6 +-- collector/cpufreq_solaris.go | 6 +-- collector/devstat_dragonfly.go | 6 +-- collector/devstat_freebsd.go | 6 +-- collector/diskstats_common.go | 11 ++--- collector/diskstats_darwin.go | 6 +-- collector/diskstats_linux.go | 15 +++--- collector/diskstats_linux_test.go | 8 ++-- collector/diskstats_openbsd.go | 6 +-- collector/diskstats_openbsd_amd64.go | 6 +-- collector/dmi.go | 7 ++- collector/drbd_linux.go | 13 +++--- collector/drm_linux.go | 6 +-- collector/edac_linux.go | 6 +-- collector/entropy_linux.go | 6 +-- collector/ethtool_linux.go | 37 +++++++-------- collector/ethtool_linux_test.go | 9 ++-- collector/exec_bsd.go | 6 +-- collector/fibrechannel_linux.go | 9 ++-- collector/filefd_linux.go | 6 +-- collector/filesystem_bsd.go | 6 +-- collector/filesystem_common.go | 15 +++--- collector/filesystem_freebsd.go | 7 ++- collector/filesystem_linux.go | 21 ++++----- collector/filesystem_linux_test.go | 9 ++-- collector/filesystem_openbsd.go | 5 +- collector/hwmon_linux.go | 13 +++--- collector/infiniband_linux.go | 9 ++-- collector/interrupts_common.go | 6 +-- collector/interrupts_linux.go | 5 +- collector/interrupts_openbsd.go | 5 +- collector/interrupts_openbsd_amd64.go | 5 +- collector/ipvs_linux.go | 11 ++--- collector/ipvs_linux_test.go | 8 ++-- collector/ksmd_linux.go | 6 +-- collector/lnstat_linux.go | 6 +-- collector/loadavg.go | 9 ++-- collector/logind_linux.go | 6 +-- collector/mdadm_linux.go | 11 ++--- collector/meminfo.go | 3 +- collector/meminfo_darwin.go | 6 +-- collector/meminfo_linux.go | 6 +-- collector/meminfo_linux_test.go | 7 ++- collector/meminfo_netbsd.go | 6 +-- collector/meminfo_numa_linux.go | 6 +-- collector/meminfo_openbsd.go | 7 ++- collector/meminfo_openbsd_amd64.go | 6 +-- collector/memory_bsd.go | 6 +-- collector/mountstats_linux.go | 9 ++-- collector/netclass_linux.go | 9 ++-- collector/netclass_rtnl_linux.go | 3 +- collector/netdev_bsd.go | 8 ++-- collector/netdev_common.go | 15 +++--- collector/netdev_darwin.go | 9 ++-- collector/netdev_linux.go | 19 ++++---- collector/netdev_linux_test.go | 14 +++--- collector/netdev_openbsd.go | 8 ++-- collector/netdev_openbsd_amd64.go | 7 ++- collector/netisr_freebsd.go | 6 +-- collector/netstat_linux.go | 6 +-- collector/network_route_linux.go | 6 +-- collector/nfs_linux.go | 9 ++-- collector/nfsd_linux.go | 9 ++-- collector/ntp.go | 9 ++-- collector/nvme_linux.go | 9 ++-- collector/os_release.go | 9 ++-- collector/os_release_test.go | 6 +-- collector/perf_linux.go | 13 +++--- collector/perf_linux_test.go | 7 +-- collector/powersupplyclass.go | 6 +-- collector/pressure_linux.go | 19 ++++---- collector/processes_linux.go | 21 ++++----- collector/processes_linux_test.go | 5 +- collector/qdisc_linux.go | 11 ++--- collector/rapl_linux.go | 13 +++--- collector/runit.go | 13 +++--- collector/schedstat_linux.go | 9 ++-- collector/selinux_linux.go | 6 +-- collector/slabinfo_linux.go | 6 +-- collector/sockstat_linux.go | 11 ++--- collector/softirqs_common.go | 6 +-- collector/softnet_linux.go | 6 +-- collector/stat_linux.go | 6 +-- collector/supervisord.go | 11 ++--- collector/sysctl_linux.go | 6 +-- collector/systemd_linux.go | 65 +++++++++++++------------- collector/systemd_linux_test.go | 7 +-- collector/tapestats_linux.go | 11 ++--- collector/tcpstat_linux.go | 6 +-- collector/textfile.go | 17 ++++--- collector/textfile_test.go | 13 +++--- collector/thermal_darwin.go | 6 +-- collector/thermal_zone_linux.go | 9 ++-- collector/time.go | 11 ++--- collector/time_linux.go | 3 +- collector/timex.go | 9 ++-- collector/udp_queues_linux.go | 11 ++--- collector/uname.go | 6 +-- collector/vmstat_linux.go | 6 +-- collector/watchdog.go | 9 ++-- collector/watchdog_test.go | 6 +-- collector/wifi_linux.go | 17 ++++--- collector/xfrm.go | 6 +-- collector/xfrm_test.go | 6 +-- collector/xfs_linux.go | 6 +-- collector/zfs.go | 11 ++--- collector/zfs_freebsd.go | 9 ++-- collector/zfs_linux.go | 11 ++--- collector/zfs_solaris.go | 6 +-- collector/zoneinfo_linux.go | 7 ++- go.mod | 5 +- go.sum | 10 ++-- node_exporter.go | 42 ++++++++--------- 133 files changed, 601 insertions(+), 671 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 472b3a5e13..1f1b0f633a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -32,8 +32,6 @@ linters-settings: exclude-functions: # Used in HTTP handlers, any error is handled by the server itself. - (net/http.ResponseWriter).Write - # Never check for logger errors. - - (github.com/go-kit/log.Logger).Log revive: rules: # https://github.com/mgechev/revive/blob/master/RULES_DESCRIPTIONS.md#unused-parameter diff --git a/collector/arp_linux.go b/collector/arp_linux.go index c7861156f3..4b5ac65e7d 100644 --- a/collector/arp_linux.go +++ b/collector/arp_linux.go @@ -19,10 +19,10 @@ package collector import ( "errors" "fmt" + "log/slog" "net" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" "github.com/jsimonetti/rtnetlink" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" @@ -39,7 +39,7 @@ type arpCollector struct { fs procfs.FS deviceFilter deviceFilter entries *prometheus.Desc - logger log.Logger + logger *slog.Logger } func init() { @@ -47,7 +47,7 @@ func init() { } // NewARPCollector returns a new Collector exposing ARP stats. -func NewARPCollector(logger log.Logger) (Collector, error) { +func NewARPCollector(logger *slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) diff --git a/collector/bcache_linux.go b/collector/bcache_linux.go index 1d402d3ff5..97064e2197 100644 --- a/collector/bcache_linux.go +++ b/collector/bcache_linux.go @@ -18,9 +18,9 @@ package collector import ( "fmt" + "log/slog" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs/bcache" ) @@ -36,12 +36,12 @@ func init() { // A bcacheCollector is a Collector which gathers metrics from Linux bcache. type bcacheCollector struct { fs bcache.FS - logger log.Logger + logger *slog.Logger } // NewBcacheCollector returns a newly allocated bcacheCollector. // It exposes a number of Linux bcache statistics. -func NewBcacheCollector(logger log.Logger) (Collector, error) { +func NewBcacheCollector(logger *slog.Logger) (Collector, error) { fs, err := bcache.NewFS(*sysPath) if err != nil { return nil, fmt.Errorf("failed to open sysfs: %w", err) diff --git a/collector/bonding_linux.go b/collector/bonding_linux.go index d9d04e222c..bfec32fd70 100644 --- a/collector/bonding_linux.go +++ b/collector/bonding_linux.go @@ -19,18 +19,17 @@ package collector import ( "errors" "fmt" + "log/slog" "os" "path/filepath" "strings" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" ) type bondingCollector struct { slaves, active typedDesc - logger log.Logger + logger *slog.Logger } func init() { @@ -39,7 +38,7 @@ func init() { // NewBondingCollector returns a newly allocated bondingCollector. // It exposes the number of configured and active slave of linux bonding interfaces. -func NewBondingCollector(logger log.Logger) (Collector, error) { +func NewBondingCollector(logger *slog.Logger) (Collector, error) { return &bondingCollector{ slaves: typedDesc{prometheus.NewDesc( prometheus.BuildFQName(namespace, "bonding", "slaves"), @@ -61,7 +60,7 @@ func (c *bondingCollector) Update(ch chan<- prometheus.Metric) error { bondingStats, err := readBondingStats(statusfile) if err != nil { if errors.Is(err, os.ErrNotExist) { - level.Debug(c.logger).Log("msg", "Not collecting bonding, file does not exist", "file", statusfile) + c.logger.Debug("Not collecting bonding, file does not exist", "file", statusfile) return ErrNoData } return err diff --git a/collector/boot_time_bsd.go b/collector/boot_time_bsd.go index 8a9c17b31a..d632fef094 100644 --- a/collector/boot_time_bsd.go +++ b/collector/boot_time_bsd.go @@ -18,13 +18,13 @@ package collector import ( - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "golang.org/x/sys/unix" + "log/slog" ) type bootTimeCollector struct { - logger log.Logger + logger *slog.Logger } func init() { @@ -32,7 +32,7 @@ func init() { } // newBootTimeCollector returns a new Collector exposing system boot time on BSD systems. -func newBootTimeCollector(logger log.Logger) (Collector, error) { +func newBootTimeCollector(logger *slog.Logger) (Collector, error) { return &bootTimeCollector{ logger: logger, }, nil diff --git a/collector/boot_time_solaris.go b/collector/boot_time_solaris.go index 15955121f7..4c336fb3c9 100644 --- a/collector/boot_time_solaris.go +++ b/collector/boot_time_solaris.go @@ -17,21 +17,21 @@ package collector import ( - "github.com/go-kit/log" "github.com/illumos/go-kstat" "github.com/prometheus/client_golang/prometheus" + "log/slog" ) type bootTimeCollector struct { boottime typedDesc - logger log.Logger + logger *slog.Logger } func init() { registerCollector("boottime", defaultEnabled, newBootTimeCollector) } -func newBootTimeCollector(logger log.Logger) (Collector, error) { +func newBootTimeCollector(logger *slog.Logger) (Collector, error) { return &bootTimeCollector{ boottime: typedDesc{ prometheus.NewDesc( diff --git a/collector/btrfs_linux.go b/collector/btrfs_linux.go index 1e5ef2933f..2dbdf5aa35 100644 --- a/collector/btrfs_linux.go +++ b/collector/btrfs_linux.go @@ -18,13 +18,12 @@ package collector import ( "fmt" + "log/slog" "path" "strings" "syscall" dennwc "github.com/dennwc/btrfs" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs/btrfs" ) @@ -32,7 +31,7 @@ import ( // A btrfsCollector is a Collector which gathers metrics from Btrfs filesystems. type btrfsCollector struct { fs btrfs.FS - logger log.Logger + logger *slog.Logger } func init() { @@ -40,7 +39,7 @@ func init() { } // NewBtrfsCollector returns a new Collector exposing Btrfs statistics. -func NewBtrfsCollector(logger log.Logger) (Collector, error) { +func NewBtrfsCollector(logger *slog.Logger) (Collector, error) { fs, err := btrfs.NewFS(*sysPath) if err != nil { return nil, fmt.Errorf("failed to open sysfs: %w", err) @@ -62,8 +61,8 @@ func (c *btrfsCollector) Update(ch chan<- prometheus.Metric) error { ioctlStatsMap, err := c.getIoctlStats() if err != nil { - level.Debug(c.logger).Log( - "msg", "Error querying btrfs device stats with ioctl", + c.logger.Debug( + "Error querying btrfs device stats with ioctl", "err", err) ioctlStatsMap = make(map[string]*btrfsIoctlFsStats) } @@ -129,8 +128,8 @@ func (c *btrfsCollector) getIoctlStats() (map[string]*btrfsIoctlFsStats, error) if err != nil { // Failed to open this mount point, maybe we didn't have permission // maybe we'll find another mount point for this FS later. - level.Debug(c.logger).Log( - "msg", "Error inspecting btrfs mountpoint", + c.logger.Debug( + "Error inspecting btrfs mountpoint", "mountPoint", mountPath, "err", err) continue @@ -141,8 +140,8 @@ func (c *btrfsCollector) getIoctlStats() (map[string]*btrfsIoctlFsStats, error) if err != nil { // Failed to get the FS info for some reason, // perhaps it'll work with a different mount point - level.Debug(c.logger).Log( - "msg", "Error querying btrfs filesystem", + c.logger.Debug( + "Error querying btrfs filesystem", "mountPoint", mountPath, "err", err) continue @@ -156,8 +155,8 @@ func (c *btrfsCollector) getIoctlStats() (map[string]*btrfsIoctlFsStats, error) deviceStats, err := c.getIoctlDeviceStats(fs, &fsInfo) if err != nil { - level.Debug(c.logger).Log( - "msg", "Error querying btrfs device stats", + c.logger.Debug( + "Error querying btrfs device stats", "mountPoint", mountPath, "err", err) continue diff --git a/collector/buddyinfo.go b/collector/buddyinfo.go index c3cc5e046d..62392b9624 100644 --- a/collector/buddyinfo.go +++ b/collector/buddyinfo.go @@ -18,10 +18,9 @@ package collector import ( "fmt" + "log/slog" "strconv" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" ) @@ -33,7 +32,7 @@ const ( type buddyinfoCollector struct { fs procfs.FS desc *prometheus.Desc - logger log.Logger + logger *slog.Logger } func init() { @@ -41,7 +40,7 @@ func init() { } // NewBuddyinfoCollector returns a new Collector exposing buddyinfo stats. -func NewBuddyinfoCollector(logger log.Logger) (Collector, error) { +func NewBuddyinfoCollector(logger *slog.Logger) (Collector, error) { desc := prometheus.NewDesc( prometheus.BuildFQName(namespace, buddyInfoSubsystem, "blocks"), "Count of free blocks according to size.", @@ -62,7 +61,7 @@ func (c *buddyinfoCollector) Update(ch chan<- prometheus.Metric) error { return fmt.Errorf("couldn't get buddyinfo: %w", err) } - level.Debug(c.logger).Log("msg", "Set node_buddy", "buddyInfo", buddyInfo) + c.logger.Debug("Set node_buddy", "buddyInfo", buddyInfo) for _, entry := range buddyInfo { for size, value := range entry.Sizes { ch <- prometheus.MustNewConstMetric( diff --git a/collector/cgroups_linux.go b/collector/cgroups_linux.go index 9f6d01a465..2a4e288e18 100644 --- a/collector/cgroups_linux.go +++ b/collector/cgroups_linux.go @@ -18,8 +18,8 @@ package collector import ( "fmt" + "log/slog" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" ) @@ -30,7 +30,7 @@ type cgroupSummaryCollector struct { fs procfs.FS cgroups *prometheus.Desc enabled *prometheus.Desc - logger log.Logger + logger *slog.Logger } func init() { @@ -38,7 +38,7 @@ func init() { } // NewCgroupSummaryCollector returns a new Collector exposing a summary of cgroups. -func NewCgroupSummaryCollector(logger log.Logger) (Collector, error) { +func NewCgroupSummaryCollector(logger *slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) diff --git a/collector/collector.go b/collector/collector.go index 3112c78970..9768fb6a1c 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -17,12 +17,11 @@ package collector import ( "errors" "fmt" + "log/slog" "sync" "time" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" ) @@ -50,14 +49,14 @@ const ( ) var ( - factories = make(map[string]func(logger log.Logger) (Collector, error)) + factories = make(map[string]func(logger *slog.Logger) (Collector, error)) initiatedCollectorsMtx = sync.Mutex{} initiatedCollectors = make(map[string]Collector) collectorState = make(map[string]*bool) forcedCollectors = map[string]bool{} // collectors which have been explicitly enabled or disabled ) -func registerCollector(collector string, isDefaultEnabled bool, factory func(logger log.Logger) (Collector, error)) { +func registerCollector(collector string, isDefaultEnabled bool, factory func(logger *slog.Logger) (Collector, error)) { var helpDefaultState string if isDefaultEnabled { helpDefaultState = "enabled" @@ -78,7 +77,7 @@ func registerCollector(collector string, isDefaultEnabled bool, factory func(log // NodeCollector implements the prometheus.Collector interface. type NodeCollector struct { Collectors map[string]Collector - logger log.Logger + logger *slog.Logger } // DisableDefaultCollectors sets the collector state to false for all collectors which @@ -104,7 +103,7 @@ func collectorFlagAction(collector string) func(ctx *kingpin.ParseContext) error } // NewNodeCollector creates a new NodeCollector. -func NewNodeCollector(logger log.Logger, filters ...string) (*NodeCollector, error) { +func NewNodeCollector(logger *slog.Logger, filters ...string) (*NodeCollector, error) { f := make(map[string]bool) for _, filter := range filters { enabled, exist := collectorState[filter] @@ -126,7 +125,7 @@ func NewNodeCollector(logger log.Logger, filters ...string) (*NodeCollector, err if collector, ok := initiatedCollectors[key]; ok { collectors[key] = collector } else { - collector, err := factories[key](log.With(logger, "collector", key)) + collector, err := factories[key](logger.With("collector", key)) if err != nil { return nil, err } @@ -156,7 +155,7 @@ func (n NodeCollector) Collect(ch chan<- prometheus.Metric) { wg.Wait() } -func execute(name string, c Collector, ch chan<- prometheus.Metric, logger log.Logger) { +func execute(name string, c Collector, ch chan<- prometheus.Metric, logger *slog.Logger) { begin := time.Now() err := c.Update(ch) duration := time.Since(begin) @@ -164,13 +163,13 @@ func execute(name string, c Collector, ch chan<- prometheus.Metric, logger log.L if err != nil { if IsNoDataError(err) { - level.Debug(logger).Log("msg", "collector returned no data", "name", name, "duration_seconds", duration.Seconds(), "err", err) + logger.Debug("collector returned no data", "name", name, "duration_seconds", duration.Seconds(), "err", err) } else { - level.Error(logger).Log("msg", "collector failed", "name", name, "duration_seconds", duration.Seconds(), "err", err) + logger.Error("collector failed", "name", name, "duration_seconds", duration.Seconds(), "err", err) } success = 0 } else { - level.Debug(logger).Log("msg", "collector succeeded", "name", name, "duration_seconds", duration.Seconds()) + logger.Debug("collector succeeded", "name", name, "duration_seconds", duration.Seconds()) success = 1 } ch <- prometheus.MustNewConstMetric(scrapeDurationDesc, prometheus.GaugeValue, duration.Seconds(), name) diff --git a/collector/conntrack_linux.go b/collector/conntrack_linux.go index e4ea954900..309857c767 100644 --- a/collector/conntrack_linux.go +++ b/collector/conntrack_linux.go @@ -19,10 +19,9 @@ package collector import ( "errors" "fmt" + "log/slog" "os" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" ) @@ -38,7 +37,7 @@ type conntrackCollector struct { drop *prometheus.Desc earlyDrop *prometheus.Desc searchRestart *prometheus.Desc - logger log.Logger + logger *slog.Logger } type conntrackStatistics struct { @@ -57,7 +56,7 @@ func init() { } // NewConntrackCollector returns a new Collector exposing conntrack stats. -func NewConntrackCollector(logger log.Logger) (Collector, error) { +func NewConntrackCollector(logger *slog.Logger) (Collector, error) { return &conntrackCollector{ current: prometheus.NewDesc( prometheus.BuildFQName(namespace, "", "nf_conntrack_entries"), @@ -154,7 +153,7 @@ func (c *conntrackCollector) Update(ch chan<- prometheus.Metric) error { func (c *conntrackCollector) handleErr(err error) error { if errors.Is(err, os.ErrNotExist) { - level.Debug(c.logger).Log("msg", "conntrack probably not loaded") + c.logger.Debug("conntrack probably not loaded") return ErrNoData } return fmt.Errorf("failed to retrieve conntrack stats: %w", err) diff --git a/collector/cpu_darwin.go b/collector/cpu_darwin.go index 6c461cc348..31b11702b0 100644 --- a/collector/cpu_darwin.go +++ b/collector/cpu_darwin.go @@ -23,10 +23,10 @@ import ( "bytes" "encoding/binary" "fmt" + "log/slog" "strconv" "unsafe" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) @@ -53,7 +53,7 @@ const ClocksPerSec = float64(C.CLK_TCK) type statCollector struct { cpu *prometheus.Desc - logger log.Logger + logger *slog.Logger } func init() { @@ -61,7 +61,7 @@ func init() { } // NewCPUCollector returns a new Collector exposing CPU stats. -func NewCPUCollector(logger log.Logger) (Collector, error) { +func NewCPUCollector(logger *slog.Logger) (Collector, error) { return &statCollector{ cpu: nodeCPUSecondsDesc, logger: logger, diff --git a/collector/cpu_dragonfly.go b/collector/cpu_dragonfly.go index 61cba1eee4..c53aaef00a 100644 --- a/collector/cpu_dragonfly.go +++ b/collector/cpu_dragonfly.go @@ -18,10 +18,10 @@ package collector import ( "errors" + "log/slog" "strconv" "unsafe" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) @@ -78,7 +78,7 @@ const maxCPUTimesLen = C.MAXCPU * C.CPUSTATES type statCollector struct { cpu *prometheus.Desc - logger log.Logger + logger *slog.Logger } func init() { @@ -86,7 +86,7 @@ func init() { } // NewStatCollector returns a new Collector exposing CPU stats. -func NewStatCollector(logger log.Logger) (Collector, error) { +func NewStatCollector(logger *slog.Logger) (Collector, error) { return &statCollector{ cpu: nodeCPUSecondsDesc, logger: logger, diff --git a/collector/cpu_freebsd.go b/collector/cpu_freebsd.go index 96b0f033cb..39b0118567 100644 --- a/collector/cpu_freebsd.go +++ b/collector/cpu_freebsd.go @@ -18,12 +18,11 @@ package collector import ( "fmt" + "log/slog" "math" "strconv" "unsafe" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "golang.org/x/sys/unix" ) @@ -85,7 +84,7 @@ func getCPUTimes() ([]cputime, error) { type statCollector struct { cpu typedDesc temp typedDesc - logger log.Logger + logger *slog.Logger } func init() { @@ -93,7 +92,7 @@ func init() { } // NewStatCollector returns a new Collector exposing CPU stats. -func NewStatCollector(logger log.Logger) (Collector, error) { +func NewStatCollector(logger *slog.Logger) (Collector, error) { return &statCollector{ cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue}, temp: typedDesc{prometheus.NewDesc( @@ -134,11 +133,11 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) error { if err != nil { if err == unix.ENOENT { // No temperature information for this CPU - level.Debug(c.logger).Log("msg", "no temperature information for CPU", "cpu", cpu) + c.logger.Debug("no temperature information for CPU", "cpu", cpu) } else { // Unexpected error ch <- c.temp.mustNewConstMetric(math.NaN(), lcpu) - level.Error(c.logger).Log("msg", "failed to query CPU temperature for CPU", "cpu", cpu, "err", err) + c.logger.Error("failed to query CPU temperature for CPU", "cpu", cpu, "err", err) } continue } diff --git a/collector/cpu_linux.go b/collector/cpu_linux.go index 75d2a795b2..1ee7b94d52 100644 --- a/collector/cpu_linux.go +++ b/collector/cpu_linux.go @@ -18,6 +18,7 @@ package collector import ( "fmt" + "log/slog" "os" "path/filepath" "regexp" @@ -26,8 +27,6 @@ import ( "sync" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" "github.com/prometheus/procfs/sysfs" @@ -45,7 +44,7 @@ type cpuCollector struct { cpuCoreThrottle *prometheus.Desc cpuPackageThrottle *prometheus.Desc cpuIsolated *prometheus.Desc - logger log.Logger + logger *slog.Logger cpuStats map[int64]procfs.CPUStat cpuStatsMutex sync.Mutex isolatedCpus []uint16 @@ -70,7 +69,7 @@ func init() { } // NewCPUCollector returns a new Collector exposing kernel/system statistics. -func NewCPUCollector(logger log.Logger) (Collector, error) { +func NewCPUCollector(logger *slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) @@ -86,7 +85,7 @@ func NewCPUCollector(logger log.Logger) (Collector, error) { if !os.IsNotExist(err) { return nil, fmt.Errorf("Unable to get isolated cpus: %w", err) } - level.Debug(logger).Log("msg", "Could not open isolated file", "error", err) + logger.Debug("Could not open isolated file", "error", err) } c := &cpuCollector{ @@ -146,7 +145,7 @@ func NewCPUCollector(logger log.Logger) (Collector, error) { func (c *cpuCollector) compileIncludeFlags(flagsIncludeFlag, bugsIncludeFlag *string) error { if (*flagsIncludeFlag != "" || *bugsIncludeFlag != "") && !*enableCPUInfo { *enableCPUInfo = true - level.Info(c.logger).Log("msg", "--collector.cpu.info has been set to `true` because you set the following flags, like --collector.cpu.info.flags-include and --collector.cpu.info.bugs-include") + c.logger.Info("--collector.cpu.info has been set to `true` because you set the following flags, like --collector.cpu.info.flags-include and --collector.cpu.info.bugs-include") } var err error @@ -205,7 +204,7 @@ func (c *cpuCollector) updateInfo(ch chan<- prometheus.Metric) error { cpuFreqEnabled, ok := collectorState["cpufreq"] if !ok || cpuFreqEnabled == nil { - level.Debug(c.logger).Log("msg", "cpufreq key missing or nil value in collectorState map") + c.logger.Debug("cpufreq key missing or nil value in collectorState map") } else if !*cpuFreqEnabled { for _, cpu := range info { ch <- prometheus.MustNewConstMetric(c.cpuFrequencyHz, @@ -269,12 +268,12 @@ func (c *cpuCollector) updateThermalThrottle(ch chan<- prometheus.Metric) error // topology/physical_package_id if physicalPackageID, err = readUintFromFile(filepath.Join(cpu, "topology", "physical_package_id")); err != nil { - level.Debug(c.logger).Log("msg", "CPU is missing physical_package_id", "cpu", cpu) + c.logger.Debug("CPU is missing physical_package_id", "cpu", cpu) continue } // topology/core_id if coreID, err = readUintFromFile(filepath.Join(cpu, "topology", "core_id")); err != nil { - level.Debug(c.logger).Log("msg", "CPU is missing core_id", "cpu", cpu) + c.logger.Debug("CPU is missing core_id", "cpu", cpu) continue } @@ -292,7 +291,7 @@ func (c *cpuCollector) updateThermalThrottle(ch chan<- prometheus.Metric) error if coreThrottleCount, err := readUintFromFile(filepath.Join(cpu, "thermal_throttle", "core_throttle_count")); err == nil { packageCoreThrottles[physicalPackageID][coreID] = coreThrottleCount } else { - level.Debug(c.logger).Log("msg", "CPU is missing core_throttle_count", "cpu", cpu) + c.logger.Debug("CPU is missing core_throttle_count", "cpu", cpu) } } @@ -302,7 +301,7 @@ func (c *cpuCollector) updateThermalThrottle(ch chan<- prometheus.Metric) error if packageThrottleCount, err := readUintFromFile(filepath.Join(cpu, "thermal_throttle", "package_throttle_count")); err == nil { packageThrottles[physicalPackageID] = packageThrottleCount } else { - level.Debug(c.logger).Log("msg", "CPU is missing package_throttle_count", "cpu", cpu) + c.logger.Debug("CPU is missing package_throttle_count", "cpu", cpu) } } } @@ -380,68 +379,68 @@ func (c *cpuCollector) updateCPUStats(newStats map[int64]procfs.CPUStat) { // If idle jumps backwards by more than X seconds, assume we had a hotplug event and reset the stats for this CPU. if (cpuStats.Idle - n.Idle) >= jumpBackSeconds { - level.Debug(c.logger).Log("msg", jumpBackDebugMessage, "cpu", i, "old_value", cpuStats.Idle, "new_value", n.Idle) + c.logger.Debug(jumpBackDebugMessage, "cpu", i, "old_value", cpuStats.Idle, "new_value", n.Idle) cpuStats = procfs.CPUStat{} } if n.Idle >= cpuStats.Idle { cpuStats.Idle = n.Idle } else { - level.Debug(c.logger).Log("msg", "CPU Idle counter jumped backwards", "cpu", i, "old_value", cpuStats.Idle, "new_value", n.Idle) + c.logger.Debug("CPU Idle counter jumped backwards", "cpu", i, "old_value", cpuStats.Idle, "new_value", n.Idle) } if n.User >= cpuStats.User { cpuStats.User = n.User } else { - level.Debug(c.logger).Log("msg", "CPU User counter jumped backwards", "cpu", i, "old_value", cpuStats.User, "new_value", n.User) + c.logger.Debug("CPU User counter jumped backwards", "cpu", i, "old_value", cpuStats.User, "new_value", n.User) } if n.Nice >= cpuStats.Nice { cpuStats.Nice = n.Nice } else { - level.Debug(c.logger).Log("msg", "CPU Nice counter jumped backwards", "cpu", i, "old_value", cpuStats.Nice, "new_value", n.Nice) + c.logger.Debug("CPU Nice counter jumped backwards", "cpu", i, "old_value", cpuStats.Nice, "new_value", n.Nice) } if n.System >= cpuStats.System { cpuStats.System = n.System } else { - level.Debug(c.logger).Log("msg", "CPU System counter jumped backwards", "cpu", i, "old_value", cpuStats.System, "new_value", n.System) + c.logger.Debug("CPU System counter jumped backwards", "cpu", i, "old_value", cpuStats.System, "new_value", n.System) } if n.Iowait >= cpuStats.Iowait { cpuStats.Iowait = n.Iowait } else { - level.Debug(c.logger).Log("msg", "CPU Iowait counter jumped backwards", "cpu", i, "old_value", cpuStats.Iowait, "new_value", n.Iowait) + c.logger.Debug("CPU Iowait counter jumped backwards", "cpu", i, "old_value", cpuStats.Iowait, "new_value", n.Iowait) } if n.IRQ >= cpuStats.IRQ { cpuStats.IRQ = n.IRQ } else { - level.Debug(c.logger).Log("msg", "CPU IRQ counter jumped backwards", "cpu", i, "old_value", cpuStats.IRQ, "new_value", n.IRQ) + c.logger.Debug("CPU IRQ counter jumped backwards", "cpu", i, "old_value", cpuStats.IRQ, "new_value", n.IRQ) } if n.SoftIRQ >= cpuStats.SoftIRQ { cpuStats.SoftIRQ = n.SoftIRQ } else { - level.Debug(c.logger).Log("msg", "CPU SoftIRQ counter jumped backwards", "cpu", i, "old_value", cpuStats.SoftIRQ, "new_value", n.SoftIRQ) + c.logger.Debug("CPU SoftIRQ counter jumped backwards", "cpu", i, "old_value", cpuStats.SoftIRQ, "new_value", n.SoftIRQ) } if n.Steal >= cpuStats.Steal { cpuStats.Steal = n.Steal } else { - level.Debug(c.logger).Log("msg", "CPU Steal counter jumped backwards", "cpu", i, "old_value", cpuStats.Steal, "new_value", n.Steal) + c.logger.Debug("CPU Steal counter jumped backwards", "cpu", i, "old_value", cpuStats.Steal, "new_value", n.Steal) } if n.Guest >= cpuStats.Guest { cpuStats.Guest = n.Guest } else { - level.Debug(c.logger).Log("msg", "CPU Guest counter jumped backwards", "cpu", i, "old_value", cpuStats.Guest, "new_value", n.Guest) + c.logger.Debug("CPU Guest counter jumped backwards", "cpu", i, "old_value", cpuStats.Guest, "new_value", n.Guest) } if n.GuestNice >= cpuStats.GuestNice { cpuStats.GuestNice = n.GuestNice } else { - level.Debug(c.logger).Log("msg", "CPU GuestNice counter jumped backwards", "cpu", i, "old_value", cpuStats.GuestNice, "new_value", n.GuestNice) + c.logger.Debug("CPU GuestNice counter jumped backwards", "cpu", i, "old_value", cpuStats.GuestNice, "new_value", n.GuestNice) } c.cpuStats[i] = cpuStats diff --git a/collector/cpu_linux_test.go b/collector/cpu_linux_test.go index b148ffcd93..158ae8ff40 100644 --- a/collector/cpu_linux_test.go +++ b/collector/cpu_linux_test.go @@ -17,10 +17,11 @@ package collector import ( + "io" + "log/slog" "reflect" "testing" - "github.com/go-kit/log" "github.com/prometheus/procfs" ) @@ -35,7 +36,7 @@ func makeTestCPUCollector(s map[int64]procfs.CPUStat) *cpuCollector { dup := make(map[int64]procfs.CPUStat, len(s)) copyStats(dup, s) return &cpuCollector{ - logger: log.NewNopLogger(), + logger: slog.New(slog.NewTextHandler(io.Discard, nil)), cpuStats: dup, } } diff --git a/collector/cpu_netbsd.go b/collector/cpu_netbsd.go index 7fc95c8081..e7c8b1cece 100644 --- a/collector/cpu_netbsd.go +++ b/collector/cpu_netbsd.go @@ -18,6 +18,7 @@ package collector import ( "errors" + "log/slog" "math" "regexp" "sort" @@ -25,8 +26,6 @@ import ( "strings" "unsafe" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "golang.org/x/sys/unix" @@ -214,7 +213,7 @@ func getCPUTimes() ([]cputime, error) { type statCollector struct { cpu typedDesc temp typedDesc - logger log.Logger + logger *slog.Logger } func init() { @@ -222,7 +221,7 @@ func init() { } // NewStatCollector returns a new Collector exposing CPU stats. -func NewStatCollector(logger log.Logger) (Collector, error) { +func NewStatCollector(logger *slog.Logger) (Collector, error) { return &statCollector{ cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue}, temp: typedDesc{prometheus.NewDesc( @@ -269,7 +268,7 @@ func (c *statCollector) Update(ch chan<- prometheus.Metric) error { if temp, ok := cpuTemperatures[cpu]; ok { ch <- c.temp.mustNewConstMetric(temp, lcpu) } else { - level.Debug(c.logger).Log("msg", "no temperature information for CPU", "cpu", cpu) + c.logger.Debug("no temperature information for CPU", "cpu", cpu) ch <- c.temp.mustNewConstMetric(math.NaN(), lcpu) } } diff --git a/collector/cpu_openbsd.go b/collector/cpu_openbsd.go index 8715ff9885..2d59f5476c 100644 --- a/collector/cpu_openbsd.go +++ b/collector/cpu_openbsd.go @@ -17,10 +17,10 @@ package collector import ( + "log/slog" "strconv" "unsafe" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "golang.org/x/sys/unix" ) @@ -45,14 +45,14 @@ const ( type cpuCollector struct { cpu typedDesc - logger log.Logger + logger *slog.Logger } func init() { registerCollector("cpu", defaultEnabled, NewCPUCollector) } -func NewCPUCollector(logger log.Logger) (Collector, error) { +func NewCPUCollector(logger *slog.Logger) (Collector, error) { return &cpuCollector{ cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue}, logger: logger, diff --git a/collector/cpu_solaris.go b/collector/cpu_solaris.go index c78845423f..550ba37462 100644 --- a/collector/cpu_solaris.go +++ b/collector/cpu_solaris.go @@ -17,9 +17,9 @@ package collector import ( + "log/slog" "strconv" - "github.com/go-kit/log" "github.com/illumos/go-kstat" "github.com/prometheus/client_golang/prometheus" ) @@ -29,14 +29,14 @@ import "C" type cpuCollector struct { cpu typedDesc - logger log.Logger + logger *slog.Logger } func init() { registerCollector("cpu", defaultEnabled, NewCpuCollector) } -func NewCpuCollector(logger log.Logger) (Collector, error) { +func NewCpuCollector(logger *slog.Logger) (Collector, error) { return &cpuCollector{ cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue}, logger: logger, diff --git a/collector/cpu_vulnerabilities_linux.go b/collector/cpu_vulnerabilities_linux.go index 69a2c587e3..180d56d6c3 100644 --- a/collector/cpu_vulnerabilities_linux.go +++ b/collector/cpu_vulnerabilities_linux.go @@ -15,8 +15,8 @@ package collector import ( "fmt" + "log/slog" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs/sysfs" ) @@ -40,7 +40,7 @@ func init() { registerCollector(cpuVulerabilitiesCollector, defaultDisabled, NewVulnerabilitySysfsCollector) } -func NewVulnerabilitySysfsCollector(logger log.Logger) (Collector, error) { +func NewVulnerabilitySysfsCollector(logger *slog.Logger) (Collector, error) { return &cpuVulnerabilitiesCollector{}, nil } diff --git a/collector/cpufreq_linux.go b/collector/cpufreq_linux.go index 3372be1ab6..d6b3e42dd5 100644 --- a/collector/cpufreq_linux.go +++ b/collector/cpufreq_linux.go @@ -18,15 +18,15 @@ package collector import ( "fmt" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs/sysfs" + "log/slog" "strings" ) type cpuFreqCollector struct { fs sysfs.FS - logger log.Logger + logger *slog.Logger } func init() { @@ -34,7 +34,7 @@ func init() { } // NewCPUFreqCollector returns a new Collector exposing kernel/system statistics. -func NewCPUFreqCollector(logger log.Logger) (Collector, error) { +func NewCPUFreqCollector(logger *slog.Logger) (Collector, error) { fs, err := sysfs.NewFS(*sysPath) if err != nil { return nil, fmt.Errorf("failed to open sysfs: %w", err) diff --git a/collector/cpufreq_solaris.go b/collector/cpufreq_solaris.go index c3fb9ee687..c13703e14f 100644 --- a/collector/cpufreq_solaris.go +++ b/collector/cpufreq_solaris.go @@ -18,9 +18,9 @@ package collector import ( "fmt" + "log/slog" "strconv" - "github.com/go-kit/log" "github.com/illumos/go-kstat" "github.com/prometheus/client_golang/prometheus" ) @@ -29,14 +29,14 @@ import ( import "C" type cpuFreqCollector struct { - logger log.Logger + logger *slog.Logger } func init() { registerCollector("cpufreq", defaultEnabled, NewCpuFreqCollector) } -func NewCpuFreqCollector(logger log.Logger) (Collector, error) { +func NewCpuFreqCollector(logger *slog.Logger) (Collector, error) { return &cpuFreqCollector{ logger: logger, }, nil diff --git a/collector/devstat_dragonfly.go b/collector/devstat_dragonfly.go index 11678054f7..b1796860fa 100644 --- a/collector/devstat_dragonfly.go +++ b/collector/devstat_dragonfly.go @@ -19,8 +19,8 @@ package collector import ( "errors" "fmt" + "log/slog" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) @@ -98,7 +98,7 @@ type devstatCollector struct { bytesDesc *prometheus.Desc transfersDesc *prometheus.Desc blocksDesc *prometheus.Desc - logger log.Logger + logger *slog.Logger } func init() { @@ -106,7 +106,7 @@ func init() { } // NewDevstatCollector returns a new Collector exposing Device stats. -func NewDevstatCollector(logger log.Logger) (Collector, error) { +func NewDevstatCollector(logger *slog.Logger) (Collector, error) { return &devstatCollector{ bytesDesc: prometheus.NewDesc( prometheus.BuildFQName(namespace, devstatSubsystem, "bytes_total"), diff --git a/collector/devstat_freebsd.go b/collector/devstat_freebsd.go index 20cdc27674..a9d4272003 100644 --- a/collector/devstat_freebsd.go +++ b/collector/devstat_freebsd.go @@ -19,10 +19,10 @@ package collector import ( "errors" "fmt" + "log/slog" "sync" "unsafe" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) @@ -43,7 +43,7 @@ type devstatCollector struct { duration typedDesc busyTime typedDesc blocks typedDesc - logger log.Logger + logger *slog.Logger } func init() { @@ -51,7 +51,7 @@ func init() { } // NewDevstatCollector returns a new Collector exposing Device stats. -func NewDevstatCollector(logger log.Logger) (Collector, error) { +func NewDevstatCollector(logger *slog.Logger) (Collector, error) { return &devstatCollector{ devinfo: &C.struct_devinfo{}, bytes: typedDesc{prometheus.NewDesc( diff --git a/collector/diskstats_common.go b/collector/diskstats_common.go index 2ab84438e7..dc1df4d792 100644 --- a/collector/diskstats_common.go +++ b/collector/diskstats_common.go @@ -19,10 +19,9 @@ package collector import ( "errors" + "log/slog" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" ) @@ -93,10 +92,10 @@ var ( ) ) -func newDiskstatsDeviceFilter(logger log.Logger) (deviceFilter, error) { +func newDiskstatsDeviceFilter(logger *slog.Logger) (deviceFilter, error) { if *oldDiskstatsDeviceExclude != "" { if !diskstatsDeviceExcludeSet { - level.Warn(logger).Log("msg", "--collector.diskstats.ignored-devices is DEPRECATED and will be removed in 2.0.0, use --collector.diskstats.device-exclude") + logger.Warn("--collector.diskstats.ignored-devices is DEPRECATED and will be removed in 2.0.0, use --collector.diskstats.device-exclude") *diskstatsDeviceExclude = *oldDiskstatsDeviceExclude } else { return deviceFilter{}, errors.New("--collector.diskstats.ignored-devices and --collector.diskstats.device-exclude are mutually exclusive") @@ -108,11 +107,11 @@ func newDiskstatsDeviceFilter(logger log.Logger) (deviceFilter, error) { } if *diskstatsDeviceExclude != "" { - level.Info(logger).Log("msg", "Parsed flag --collector.diskstats.device-exclude", "flag", *diskstatsDeviceExclude) + logger.Info("Parsed flag --collector.diskstats.device-exclude", "flag", *diskstatsDeviceExclude) } if *diskstatsDeviceInclude != "" { - level.Info(logger).Log("msg", "Parsed Flag --collector.diskstats.device-include", "flag", *diskstatsDeviceInclude) + logger.Info("Parsed Flag --collector.diskstats.device-include", "flag", *diskstatsDeviceInclude) } return newDeviceFilter(*diskstatsDeviceExclude, *diskstatsDeviceInclude), nil diff --git a/collector/diskstats_darwin.go b/collector/diskstats_darwin.go index b5f6c53844..98052fe7db 100644 --- a/collector/diskstats_darwin.go +++ b/collector/diskstats_darwin.go @@ -18,8 +18,8 @@ package collector import ( "fmt" + "log/slog" - "github.com/go-kit/log" "github.com/lufia/iostat" "github.com/prometheus/client_golang/prometheus" ) @@ -35,7 +35,7 @@ type diskstatsCollector struct { descs []typedDescFunc deviceFilter deviceFilter - logger log.Logger + logger *slog.Logger } func init() { @@ -43,7 +43,7 @@ func init() { } // NewDiskstatsCollector returns a new Collector exposing disk device stats. -func NewDiskstatsCollector(logger log.Logger) (Collector, error) { +func NewDiskstatsCollector(logger *slog.Logger) (Collector, error) { var diskLabelNames = []string{"device"} deviceFilter, err := newDiskstatsDeviceFilter(logger) diff --git a/collector/diskstats_linux.go b/collector/diskstats_linux.go index ed5d044a61..134c19e299 100644 --- a/collector/diskstats_linux.go +++ b/collector/diskstats_linux.go @@ -19,12 +19,11 @@ package collector import ( "bufio" "fmt" + "log/slog" "os" "strconv" "strings" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs/blockdevice" ) @@ -85,7 +84,7 @@ type diskstatsCollector struct { filesystemInfoDesc typedFactorDesc deviceMapperInfoDesc typedFactorDesc ataDescs map[string]typedFactorDesc - logger log.Logger + logger *slog.Logger getUdevDeviceProperties func(uint32, uint32) (udevInfo, error) } @@ -95,7 +94,7 @@ func init() { // NewDiskstatsCollector returns a new Collector exposing disk device stats. // Docs from https://www.kernel.org/doc/Documentation/iostats.txt -func NewDiskstatsCollector(logger log.Logger) (Collector, error) { +func NewDiskstatsCollector(logger *slog.Logger) (Collector, error) { var diskLabelNames = []string{"device"} fs, err := blockdevice.NewFS(*procPath, *sysPath) if err != nil { @@ -262,7 +261,7 @@ func NewDiskstatsCollector(logger log.Logger) (Collector, error) { // Only enable getting device properties from udev if the directory is readable. if stat, err := os.Stat(*udevDataPath); err != nil || !stat.IsDir() { - level.Error(logger).Log("msg", "Failed to open directory, disabling udev device properties", "path", *udevDataPath) + logger.Error("Failed to open directory, disabling udev device properties", "path", *udevDataPath) } else { collector.getUdevDeviceProperties = getUdevDeviceProperties } @@ -284,7 +283,7 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error { info, err := getUdevDeviceProperties(stats.MajorNumber, stats.MinorNumber) if err != nil { - level.Debug(c.logger).Log("msg", "Failed to parse udev info", "err", err) + c.logger.Debug("Failed to parse udev info", "err", err) } // This is usually the serial printed on the disk label. @@ -355,14 +354,14 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error { for attr, desc := range c.ataDescs { str, ok := info[attr] if !ok { - level.Debug(c.logger).Log("msg", "Udev attribute does not exist", "attribute", attr) + c.logger.Debug("Udev attribute does not exist", "attribute", attr) continue } if value, err := strconv.ParseFloat(str, 64); err == nil { ch <- desc.mustNewConstMetric(value, dev) } else { - level.Error(c.logger).Log("msg", "Failed to parse ATA value", "err", err) + c.logger.Error("Failed to parse ATA value", "err", err) } } } diff --git a/collector/diskstats_linux_test.go b/collector/diskstats_linux_test.go index 88d8c8265e..8c45d1c37f 100644 --- a/collector/diskstats_linux_test.go +++ b/collector/diskstats_linux_test.go @@ -18,11 +18,11 @@ package collector import ( "fmt" - "os" + "io" + "log/slog" "strings" "testing" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/testutil" ) @@ -39,7 +39,7 @@ func (c testDiskStatsCollector) Describe(ch chan<- *prometheus.Desc) { prometheus.DescribeByCollect(c, ch) } -func NewTestDiskStatsCollector(logger log.Logger) (prometheus.Collector, error) { +func NewTestDiskStatsCollector(logger *slog.Logger) (prometheus.Collector, error) { dsc, err := NewDiskstatsCollector(logger) if err != nil { return testDiskStatsCollector{}, err @@ -317,7 +317,7 @@ node_disk_written_bytes_total{device="sr0"} 0 node_disk_written_bytes_total{device="vda"} 1.0938236928e+11 ` - logger := log.NewLogfmtLogger(os.Stderr) + logger := slog.New(slog.NewTextHandler(io.Discard, nil)) collector, err := NewDiskstatsCollector(logger) if err != nil { t.Fatal(err) diff --git a/collector/diskstats_openbsd.go b/collector/diskstats_openbsd.go index 2a69042aac..49415c17f4 100644 --- a/collector/diskstats_openbsd.go +++ b/collector/diskstats_openbsd.go @@ -18,9 +18,9 @@ package collector import ( "fmt" + "log/slog" "unsafe" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "golang.org/x/sys/unix" ) @@ -41,7 +41,7 @@ type diskstatsCollector struct { time typedDesc deviceFilter deviceFilter - logger log.Logger + logger *slog.Logger } func init() { @@ -49,7 +49,7 @@ func init() { } // NewDiskstatsCollector returns a new Collector exposing disk device stats. -func NewDiskstatsCollector(logger log.Logger) (Collector, error) { +func NewDiskstatsCollector(logger *slog.Logger) (Collector, error) { deviceFilter, err := newDiskstatsDeviceFilter(logger) if err != nil { return nil, fmt.Errorf("failed to parse device filter flags: %w", err) diff --git a/collector/diskstats_openbsd_amd64.go b/collector/diskstats_openbsd_amd64.go index a39cabb538..b290d88920 100644 --- a/collector/diskstats_openbsd_amd64.go +++ b/collector/diskstats_openbsd_amd64.go @@ -18,9 +18,9 @@ package collector import ( "fmt" + "log/slog" "unsafe" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "golang.org/x/sys/unix" ) @@ -52,7 +52,7 @@ type diskstatsCollector struct { time typedDesc deviceFilter deviceFilter - logger log.Logger + logger *slog.Logger } func init() { @@ -60,7 +60,7 @@ func init() { } // NewDiskstatsCollector returns a new Collector exposing disk device stats. -func NewDiskstatsCollector(logger log.Logger) (Collector, error) { +func NewDiskstatsCollector(logger *slog.Logger) (Collector, error) { deviceFilter, err := newDiskstatsDeviceFilter(logger) if err != nil { return nil, fmt.Errorf("failed to parse device filter flags: %w", err) diff --git a/collector/dmi.go b/collector/dmi.go index 794755076a..2282d7bd00 100644 --- a/collector/dmi.go +++ b/collector/dmi.go @@ -19,11 +19,10 @@ package collector import ( "errors" "fmt" + "log/slog" "os" "strings" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs/sysfs" ) @@ -38,7 +37,7 @@ func init() { } // NewDMICollector returns a new Collector exposing DMI information. -func NewDMICollector(logger log.Logger) (Collector, error) { +func NewDMICollector(logger *slog.Logger) (Collector, error) { fs, err := sysfs.NewFS(*sysPath) if err != nil { return nil, fmt.Errorf("failed to open sysfs: %w", err) @@ -47,7 +46,7 @@ func NewDMICollector(logger log.Logger) (Collector, error) { dmi, err := fs.DMIClass() if err != nil { if errors.Is(err, os.ErrNotExist) { - level.Debug(logger).Log("msg", "Platform does not support Desktop Management Interface (DMI) information", "err", err) + logger.Debug("Platform does not support Desktop Management Interface (DMI) information", "err", err) dmi = &sysfs.DMIClass{} } else { return nil, fmt.Errorf("failed to read Desktop Management Interface (DMI) information: %w", err) diff --git a/collector/drbd_linux.go b/collector/drbd_linux.go index f192a24c6f..cbaf816193 100644 --- a/collector/drbd_linux.go +++ b/collector/drbd_linux.go @@ -20,12 +20,11 @@ import ( "bufio" "errors" "fmt" + "log/slog" "os" "strconv" "strings" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" ) @@ -79,14 +78,14 @@ type drbdCollector struct { numerical map[string]drbdNumericalMetric stringPair map[string]drbdStringPairMetric connected *prometheus.Desc - logger log.Logger + logger *slog.Logger } func init() { registerCollector("drbd", defaultDisabled, newDRBDCollector) } -func newDRBDCollector(logger log.Logger) (Collector, error) { +func newDRBDCollector(logger *slog.Logger) (Collector, error) { return &drbdCollector{ numerical: map[string]drbdNumericalMetric{ "ns": newDRBDNumericalMetric( @@ -191,7 +190,7 @@ func (c *drbdCollector) Update(ch chan<- prometheus.Metric) error { file, err := os.Open(statsFile) if err != nil { if errors.Is(err, os.ErrNotExist) { - level.Debug(c.logger).Log("msg", "stats file does not exist, skipping", "file", statsFile, "err", err) + c.logger.Debug("stats file does not exist, skipping", "file", statsFile, "err", err) return ErrNoData } @@ -208,7 +207,7 @@ func (c *drbdCollector) Update(ch chan<- prometheus.Metric) error { kv := strings.Split(field, ":") if len(kv) != 2 { - level.Debug(c.logger).Log("msg", "skipping invalid key:value pair", "field", field) + c.logger.Debug("skipping invalid key:value pair", "field", field) continue } @@ -274,7 +273,7 @@ func (c *drbdCollector) Update(ch chan<- prometheus.Metric) error { continue } - level.Debug(c.logger).Log("msg", "unhandled key-value pair", "key", kv[0], "value", kv[1]) + c.logger.Debug("unhandled key-value pair", "key", kv[0], "value", kv[1]) } return scanner.Err() diff --git a/collector/drm_linux.go b/collector/drm_linux.go index 11b8c6283b..61bb59ac77 100644 --- a/collector/drm_linux.go +++ b/collector/drm_linux.go @@ -18,8 +18,8 @@ package collector import ( "fmt" + "log/slog" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs/sysfs" ) @@ -30,7 +30,7 @@ const ( type drmCollector struct { fs sysfs.FS - logger log.Logger + logger *slog.Logger CardInfo *prometheus.Desc GPUBusyPercent *prometheus.Desc MemoryGTTSize *prometheus.Desc @@ -46,7 +46,7 @@ func init() { } // NewDrmCollector returns a new Collector exposing /sys/class/drm/card?/device stats. -func NewDrmCollector(logger log.Logger) (Collector, error) { +func NewDrmCollector(logger *slog.Logger) (Collector, error) { fs, err := sysfs.NewFS(*sysPath) if err != nil { return nil, fmt.Errorf("failed to open sysfs: %w", err) diff --git a/collector/edac_linux.go b/collector/edac_linux.go index c7719b7a64..c14c96c36e 100644 --- a/collector/edac_linux.go +++ b/collector/edac_linux.go @@ -18,10 +18,10 @@ package collector import ( "fmt" + "log/slog" "path/filepath" "regexp" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) @@ -39,7 +39,7 @@ type edacCollector struct { ueCount *prometheus.Desc csRowCECount *prometheus.Desc csRowUECount *prometheus.Desc - logger log.Logger + logger *slog.Logger } func init() { @@ -47,7 +47,7 @@ func init() { } // NewEdacCollector returns a new Collector exposing edac stats. -func NewEdacCollector(logger log.Logger) (Collector, error) { +func NewEdacCollector(logger *slog.Logger) (Collector, error) { return &edacCollector{ ceCount: prometheus.NewDesc( prometheus.BuildFQName(namespace, edacSubsystem, "correctable_errors_total"), diff --git a/collector/entropy_linux.go b/collector/entropy_linux.go index 909d2ff4c2..6da61125c6 100644 --- a/collector/entropy_linux.go +++ b/collector/entropy_linux.go @@ -18,8 +18,8 @@ package collector import ( "fmt" + "log/slog" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" ) @@ -28,7 +28,7 @@ type entropyCollector struct { fs procfs.FS entropyAvail *prometheus.Desc entropyPoolSize *prometheus.Desc - logger log.Logger + logger *slog.Logger } func init() { @@ -36,7 +36,7 @@ func init() { } // NewEntropyCollector returns a new Collector exposing entropy stats. -func NewEntropyCollector(logger log.Logger) (Collector, error) { +func NewEntropyCollector(logger *slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) diff --git a/collector/ethtool_linux.go b/collector/ethtool_linux.go index 45c35851d6..da6be30bd1 100644 --- a/collector/ethtool_linux.go +++ b/collector/ethtool_linux.go @@ -23,6 +23,7 @@ package collector import ( "errors" "fmt" + "log/slog" "os" "regexp" "sort" @@ -31,8 +32,6 @@ import ( "syscall" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs/sysfs" "github.com/safchain/ethtool" @@ -79,13 +78,13 @@ type ethtoolCollector struct { deviceFilter deviceFilter infoDesc *prometheus.Desc metricsPattern *regexp.Regexp - logger log.Logger + logger *slog.Logger } // makeEthtoolCollector is the internal constructor for EthtoolCollector. // This allows NewEthtoolTestCollector to override its .ethtool interface // for testing. -func makeEthtoolCollector(logger log.Logger) (*ethtoolCollector, error) { +func makeEthtoolCollector(logger *slog.Logger) (*ethtoolCollector, error) { fs, err := sysfs.NewFS(*sysPath) if err != nil { return nil, fmt.Errorf("failed to open sysfs: %w", err) @@ -97,13 +96,13 @@ func makeEthtoolCollector(logger log.Logger) (*ethtoolCollector, error) { } if *ethtoolDeviceInclude != "" { - level.Info(logger).Log("msg", "Parsed flag --collector.ethtool.device-include", "flag", *ethtoolDeviceInclude) + logger.Info("Parsed flag --collector.ethtool.device-include", "flag", *ethtoolDeviceInclude) } if *ethtoolDeviceExclude != "" { - level.Info(logger).Log("msg", "Parsed flag --collector.ethtool.device-exclude", "flag", *ethtoolDeviceExclude) + logger.Info("Parsed flag --collector.ethtool.device-exclude", "flag", *ethtoolDeviceExclude) } if *ethtoolIncludedMetrics != "" { - level.Info(logger).Log("msg", "Parsed flag --collector.ethtool.metrics-include", "flag", *ethtoolIncludedMetrics) + logger.Info("Parsed flag --collector.ethtool.metrics-include", "flag", *ethtoolIncludedMetrics) } // Pre-populate some common ethtool metrics. @@ -223,7 +222,7 @@ func buildEthtoolFQName(metric string) string { } // NewEthtoolCollector returns a new Collector exposing ethtool stats. -func NewEthtoolCollector(logger log.Logger) (Collector, error) { +func NewEthtoolCollector(logger *slog.Logger) (Collector, error) { return makeEthtoolCollector(logger) } @@ -376,7 +375,7 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error { netClass, err := c.fs.NetClass() if err != nil { if errors.Is(err, os.ErrNotExist) || errors.Is(err, os.ErrPermission) { - level.Debug(c.logger).Log("msg", "Could not read netclass file", "err", err) + c.logger.Debug("Could not read netclass file", "err", err) return ErrNoData } return fmt.Errorf("could not get net class info: %w", err) @@ -405,12 +404,12 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error { } else { if errno, ok := err.(syscall.Errno); ok { if err == unix.EOPNOTSUPP { - level.Debug(c.logger).Log("msg", "ethtool link info error", "err", err, "device", device, "errno", uint(errno)) + c.logger.Debug("ethtool link info error", "err", err, "device", device, "errno", uint(errno)) } else if errno != 0 { - level.Error(c.logger).Log("msg", "ethtool link info error", "err", err, "device", device, "errno", uint(errno)) + c.logger.Error("ethtool link info error", "err", err, "device", device, "errno", uint(errno)) } } else { - level.Error(c.logger).Log("msg", "ethtool link info error", "err", err, "device", device) + c.logger.Error("ethtool link info error", "err", err, "device", device) } } @@ -422,12 +421,12 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error { } else { if errno, ok := err.(syscall.Errno); ok { if err == unix.EOPNOTSUPP { - level.Debug(c.logger).Log("msg", "ethtool driver info error", "err", err, "device", device, "errno", uint(errno)) + c.logger.Debug("ethtool driver info error", "err", err, "device", device, "errno", uint(errno)) } else if errno != 0 { - level.Error(c.logger).Log("msg", "ethtool driver info error", "err", err, "device", device, "errno", uint(errno)) + c.logger.Error("ethtool driver info error", "err", err, "device", device, "errno", uint(errno)) } } else { - level.Error(c.logger).Log("msg", "ethtool driver info error", "err", err, "device", device) + c.logger.Error("ethtool driver info error", "err", err, "device", device) } } @@ -438,12 +437,12 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error { if err != nil { if errno, ok := err.(syscall.Errno); ok { if err == unix.EOPNOTSUPP { - level.Debug(c.logger).Log("msg", "ethtool stats error", "err", err, "device", device, "errno", uint(errno)) + c.logger.Debug("ethtool stats error", "err", err, "device", device, "errno", uint(errno)) } else if errno != 0 { - level.Error(c.logger).Log("msg", "ethtool stats error", "err", err, "device", device, "errno", uint(errno)) + c.logger.Error("ethtool stats error", "err", err, "device", device, "errno", uint(errno)) } } else { - level.Error(c.logger).Log("msg", "ethtool stats error", "err", err, "device", device) + c.logger.Error("ethtool stats error", "err", err, "device", device) } } @@ -462,7 +461,7 @@ func (c *ethtoolCollector) Update(ch chan<- prometheus.Metric) error { metricFQName := buildEthtoolFQName(metricName) existingMetric, exists := metricFQNames[metricFQName] if exists { - level.Debug(c.logger).Log("msg", "dropping duplicate metric name", "device", device, + c.logger.Debug("dropping duplicate metric name", "device", device, "metricFQName", metricFQName, "metric1", existingMetric, "metric2", metricName) // Keep the metricName as "deleted" in the dict in case there are 3 duplicates. metricFQNames[metricFQName] = "" diff --git a/collector/ethtool_linux_test.go b/collector/ethtool_linux_test.go index ae7df0ddff..98e66dbc20 100644 --- a/collector/ethtool_linux_test.go +++ b/collector/ethtool_linux_test.go @@ -19,6 +19,8 @@ package collector import ( "bufio" "fmt" + "io" + "log/slog" "os" "path/filepath" "strconv" @@ -26,7 +28,6 @@ import ( "syscall" "testing" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/testutil" "github.com/safchain/ethtool" @@ -49,7 +50,7 @@ func (c testEthtoolCollector) Describe(ch chan<- *prometheus.Desc) { prometheus.DescribeByCollect(c, ch) } -func NewTestEthtoolCollector(logger log.Logger) (prometheus.Collector, error) { +func NewTestEthtoolCollector(logger *slog.Logger) (prometheus.Collector, error) { dsc, err := NewEthtoolTestCollector(logger) if err != nil { return testEthtoolCollector{}, err @@ -255,7 +256,7 @@ func (e *EthtoolFixture) LinkInfo(intf string) (ethtool.EthtoolCmd, error) { return res, err } -func NewEthtoolTestCollector(logger log.Logger) (Collector, error) { +func NewEthtoolTestCollector(logger *slog.Logger) (Collector, error) { collector, err := makeEthtoolCollector(logger) if err != nil { return nil, err @@ -370,7 +371,7 @@ node_network_supported_speed_bytes{device="eth0",duplex="half",mode="10baseT"} 1 ` *sysPath = "fixtures/sys" - logger := log.NewLogfmtLogger(os.Stderr) + logger := slog.New(slog.NewTextHandler(io.Discard, nil)) collector, err := NewEthtoolTestCollector(logger) if err != nil { t.Fatal(err) diff --git a/collector/exec_bsd.go b/collector/exec_bsd.go index 87cb3ceeb4..07de879ee0 100644 --- a/collector/exec_bsd.go +++ b/collector/exec_bsd.go @@ -18,13 +18,13 @@ package collector import ( - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" + "log/slog" ) type execCollector struct { sysctls []bsdSysctl - logger log.Logger + logger *slog.Logger } func init() { @@ -32,7 +32,7 @@ func init() { } // NewExecCollector returns a new Collector exposing system execution statistics. -func NewExecCollector(logger log.Logger) (Collector, error) { +func NewExecCollector(logger *slog.Logger) (Collector, error) { // From sys/vm/vm_meter.c: // All are of type CTLTYPE_UINT. // diff --git a/collector/fibrechannel_linux.go b/collector/fibrechannel_linux.go index 782ad33ee0..cb8be9db1d 100644 --- a/collector/fibrechannel_linux.go +++ b/collector/fibrechannel_linux.go @@ -18,10 +18,9 @@ package collector import ( "fmt" + "log/slog" "os" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/node_exporter/collector/utils" "github.com/prometheus/procfs/sysfs" @@ -32,7 +31,7 @@ const maxUint64 = ^uint64(0) type fibrechannelCollector struct { fs sysfs.FS metricDescs map[string]*prometheus.Desc - logger log.Logger + logger *slog.Logger subsystem string } @@ -41,7 +40,7 @@ func init() { } // NewFibreChannelCollector returns a new Collector exposing FibreChannel stats. -func NewFibreChannelCollector(logger log.Logger) (Collector, error) { +func NewFibreChannelCollector(logger *slog.Logger) (Collector, error) { var i fibrechannelCollector var err error @@ -99,7 +98,7 @@ func (c *fibrechannelCollector) Update(ch chan<- prometheus.Metric) error { hosts, err := c.fs.FibreChannelClass() if err != nil { if os.IsNotExist(err) { - level.Debug(c.logger).Log("msg", "fibrechannel statistics not found, skipping") + c.logger.Debug("fibrechannel statistics not found, skipping") return ErrNoData } return fmt.Errorf("error obtaining FibreChannel class info: %s", err) diff --git a/collector/filefd_linux.go b/collector/filefd_linux.go index 55069d6c5d..39a72fcd43 100644 --- a/collector/filefd_linux.go +++ b/collector/filefd_linux.go @@ -20,10 +20,10 @@ import ( "bytes" "fmt" "io" + "log/slog" "os" "strconv" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) @@ -32,7 +32,7 @@ const ( ) type fileFDStatCollector struct { - logger log.Logger + logger *slog.Logger } func init() { @@ -40,7 +40,7 @@ func init() { } // NewFileFDStatCollector returns a new Collector exposing file-nr stats. -func NewFileFDStatCollector(logger log.Logger) (Collector, error) { +func NewFileFDStatCollector(logger *slog.Logger) (Collector, error) { return &fileFDStatCollector{logger}, nil } diff --git a/collector/filesystem_bsd.go b/collector/filesystem_bsd.go index d3025a0171..2db3fb8ff3 100644 --- a/collector/filesystem_bsd.go +++ b/collector/filesystem_bsd.go @@ -20,8 +20,6 @@ package collector import ( "errors" "unsafe" - - "github.com/go-kit/log/level" ) /* @@ -51,14 +49,14 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) { for i := 0; i < int(count); i++ { mountpoint := C.GoString(&mnt[i].f_mntonname[0]) if c.excludedMountPointsPattern.MatchString(mountpoint) { - level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", mountpoint) + c.logger.Debug("Ignoring mount point", "mountpoint", mountpoint) continue } device := C.GoString(&mnt[i].f_mntfromname[0]) fstype := C.GoString(&mnt[i].f_fstypename[0]) if c.excludedFSTypesPattern.MatchString(fstype) { - level.Debug(c.logger).Log("msg", "Ignoring fs type", "type", fstype) + c.logger.Debug("Ignoring fs type", "type", fstype) continue } diff --git a/collector/filesystem_common.go b/collector/filesystem_common.go index d224e2c20f..ee61aba8ec 100644 --- a/collector/filesystem_common.go +++ b/collector/filesystem_common.go @@ -19,11 +19,10 @@ package collector import ( "errors" + "log/slog" "regexp" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" ) @@ -70,7 +69,7 @@ type filesystemCollector struct { filesDesc, filesFreeDesc *prometheus.Desc roDesc, deviceErrorDesc *prometheus.Desc mountInfoDesc *prometheus.Desc - logger log.Logger + logger *slog.Logger } type filesystemLabels struct { @@ -89,10 +88,10 @@ func init() { } // NewFilesystemCollector returns a new Collector exposing filesystems stats. -func NewFilesystemCollector(logger log.Logger) (Collector, error) { +func NewFilesystemCollector(logger *slog.Logger) (Collector, error) { if *oldMountPointsExcluded != "" { if !mountPointsExcludeSet { - level.Warn(logger).Log("msg", "--collector.filesystem.ignored-mount-points is DEPRECATED and will be removed in 2.0.0, use --collector.filesystem.mount-points-exclude") + logger.Warn("--collector.filesystem.ignored-mount-points is DEPRECATED and will be removed in 2.0.0, use --collector.filesystem.mount-points-exclude") *mountPointsExclude = *oldMountPointsExcluded } else { return nil, errors.New("--collector.filesystem.ignored-mount-points and --collector.filesystem.mount-points-exclude are mutually exclusive") @@ -101,7 +100,7 @@ func NewFilesystemCollector(logger log.Logger) (Collector, error) { if *oldFSTypesExcluded != "" { if !fsTypesExcludeSet { - level.Warn(logger).Log("msg", "--collector.filesystem.ignored-fs-types is DEPRECATED and will be removed in 2.0.0, use --collector.filesystem.fs-types-exclude") + logger.Warn("--collector.filesystem.ignored-fs-types is DEPRECATED and will be removed in 2.0.0, use --collector.filesystem.fs-types-exclude") *fsTypesExclude = *oldFSTypesExcluded } else { return nil, errors.New("--collector.filesystem.ignored-fs-types and --collector.filesystem.fs-types-exclude are mutually exclusive") @@ -109,9 +108,9 @@ func NewFilesystemCollector(logger log.Logger) (Collector, error) { } subsystem := "filesystem" - level.Info(logger).Log("msg", "Parsed flag --collector.filesystem.mount-points-exclude", "flag", *mountPointsExclude) + logger.Info("Parsed flag --collector.filesystem.mount-points-exclude", "flag", *mountPointsExclude) mountPointPattern := regexp.MustCompile(*mountPointsExclude) - level.Info(logger).Log("msg", "Parsed flag --collector.filesystem.fs-types-exclude", "flag", *fsTypesExclude) + logger.Info("Parsed flag --collector.filesystem.fs-types-exclude", "flag", *fsTypesExclude) filesystemsTypesPattern := regexp.MustCompile(*fsTypesExclude) sizeDesc := prometheus.NewDesc( diff --git a/collector/filesystem_freebsd.go b/collector/filesystem_freebsd.go index f05702d14f..2a6026d3a2 100644 --- a/collector/filesystem_freebsd.go +++ b/collector/filesystem_freebsd.go @@ -17,7 +17,6 @@ package collector import ( - "github.com/go-kit/log/level" "golang.org/x/sys/unix" ) @@ -41,19 +40,19 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) { for _, fs := range buf { mountpoint := unix.ByteSliceToString(fs.Mntonname[:]) if c.excludedMountPointsPattern.MatchString(mountpoint) { - level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", mountpoint) + c.logger.Debug("Ignoring mount point", "mountpoint", mountpoint) continue } device := unix.ByteSliceToString(fs.Mntfromname[:]) fstype := unix.ByteSliceToString(fs.Fstypename[:]) if c.excludedFSTypesPattern.MatchString(fstype) { - level.Debug(c.logger).Log("msg", "Ignoring fs type", "type", fstype) + c.logger.Debug("Ignoring fs type", "type", fstype) continue } if (fs.Flags & unix.MNT_IGNORE) != 0 { - level.Debug(c.logger).Log("msg", "Ignoring mount flagged as ignore", "mountpoint", mountpoint) + c.logger.Debug("Ignoring mount flagged as ignore", "mountpoint", mountpoint) continue } diff --git a/collector/filesystem_linux.go b/collector/filesystem_linux.go index 728e8cca43..19c3971760 100644 --- a/collector/filesystem_linux.go +++ b/collector/filesystem_linux.go @@ -21,14 +21,13 @@ import ( "errors" "fmt" "io" + "log/slog" "os" "strings" "sync" "time" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "golang.org/x/sys/unix" ) @@ -75,11 +74,11 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) { go func() { for _, labels := range mps { if c.excludedMountPointsPattern.MatchString(labels.mountPoint) { - level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", labels.mountPoint) + c.logger.Debug("Ignoring mount point", "mountpoint", labels.mountPoint) continue } if c.excludedFSTypesPattern.MatchString(labels.fsType) { - level.Debug(c.logger).Log("msg", "Ignoring fs", "type", labels.fsType) + c.logger.Debug("Ignoring fs", "type", labels.fsType) continue } @@ -90,7 +89,7 @@ func (c *filesystemCollector) GetStats() ([]filesystemStats, error) { labels: labels, deviceError: 1, }) - level.Debug(c.logger).Log("msg", "Mount point is in an unresponsive state", "mountpoint", labels.mountPoint) + c.logger.Debug("Mount point is in an unresponsive state", "mountpoint", labels.mountPoint) stuckMountsMtx.Unlock() continue } @@ -128,14 +127,14 @@ func (c *filesystemCollector) processStat(labels filesystemLabels) filesystemSta // If the mount has been marked as stuck, unmark it and log it's recovery. if _, ok := stuckMounts[labels.mountPoint]; ok { - level.Debug(c.logger).Log("msg", "Mount point has recovered, monitoring will resume", "mountpoint", labels.mountPoint) + c.logger.Debug("Mount point has recovered, monitoring will resume", "mountpoint", labels.mountPoint) delete(stuckMounts, labels.mountPoint) } stuckMountsMtx.Unlock() if err != nil { labels.deviceError = err.Error() - level.Debug(c.logger).Log("msg", "Error on statfs() system call", "rootfs", rootfsFilePath(labels.mountPoint), "err", err) + c.logger.Debug("Error on statfs() system call", "rootfs", rootfsFilePath(labels.mountPoint), "err", err) return filesystemStats{ labels: labels, deviceError: 1, @@ -157,7 +156,7 @@ func (c *filesystemCollector) processStat(labels filesystemLabels) filesystemSta // stuckMountWatcher listens on the given success channel and if the channel closes // then the watcher does nothing. If instead the timeout is reached, the // mount point that is being watched is marked as stuck. -func stuckMountWatcher(mountPoint string, success chan struct{}, logger log.Logger) { +func stuckMountWatcher(mountPoint string, success chan struct{}, logger *slog.Logger) { mountCheckTimer := time.NewTimer(*mountTimeout) defer mountCheckTimer.Stop() select { @@ -170,18 +169,18 @@ func stuckMountWatcher(mountPoint string, success chan struct{}, logger log.Logg case <-success: // Success came in just after the timeout was reached, don't label the mount as stuck default: - level.Debug(logger).Log("msg", "Mount point timed out, it is being labeled as stuck and will not be monitored", "mountpoint", mountPoint) + logger.Debug("Mount point timed out, it is being labeled as stuck and will not be monitored", "mountpoint", mountPoint) stuckMounts[mountPoint] = struct{}{} } stuckMountsMtx.Unlock() } } -func mountPointDetails(logger log.Logger) ([]filesystemLabels, error) { +func mountPointDetails(logger *slog.Logger) ([]filesystemLabels, error) { file, err := os.Open(procFilePath("1/mountinfo")) if errors.Is(err, os.ErrNotExist) { // Fallback to `/proc/self/mountinfo` if `/proc/1/mountinfo` is missing due hidepid. - level.Debug(logger).Log("msg", "Reading root mounts failed, falling back to self mounts", "err", err) + logger.Debug("Reading root mounts failed, falling back to self mounts", "err", err) file, err = os.Open(procFilePath("self/mountinfo")) } if err != nil { diff --git a/collector/filesystem_linux_test.go b/collector/filesystem_linux_test.go index e29385527c..d088598f3c 100644 --- a/collector/filesystem_linux_test.go +++ b/collector/filesystem_linux_test.go @@ -17,11 +17,12 @@ package collector import ( + "io" + "log/slog" "strings" "testing" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" ) func Test_parseFilesystemLabelsError(t *testing.T) { @@ -82,7 +83,7 @@ func TestMountPointDetails(t *testing.T) { "/var/lib/kubelet/plugins/kubernetes.io/vsphere-volume/mounts/[vsanDatastore] bafb9e5a-8856-7e6c-699c-801844e77a4a/kubernetes-dynamic-pvc-3eba5bba-48a3-11e8-89ab-005056b92113.vmdk": "", } - filesystems, err := mountPointDetails(log.NewNopLogger()) + filesystems, err := mountPointDetails(slog.New(slog.NewTextHandler(io.Discard, nil))) if err != nil { t.Log(err) } @@ -111,7 +112,7 @@ func TestMountsFallback(t *testing.T) { "/": "", } - filesystems, err := mountPointDetails(log.NewNopLogger()) + filesystems, err := mountPointDetails(slog.New(slog.NewTextHandler(io.Discard, nil))) if err != nil { t.Log(err) } @@ -139,7 +140,7 @@ func TestPathRootfs(t *testing.T) { "/sys/fs/cgroup": "", } - filesystems, err := mountPointDetails(log.NewNopLogger()) + filesystems, err := mountPointDetails(slog.New(slog.NewTextHandler(io.Discard, nil))) if err != nil { t.Log(err) } diff --git a/collector/filesystem_openbsd.go b/collector/filesystem_openbsd.go index 1c1e479e1f..d7489364f9 100644 --- a/collector/filesystem_openbsd.go +++ b/collector/filesystem_openbsd.go @@ -17,7 +17,6 @@ package collector import ( - "github.com/go-kit/log/level" "golang.org/x/sys/unix" ) @@ -43,14 +42,14 @@ func (c *filesystemCollector) GetStats() (stats []filesystemStats, err error) { for _, v := range mnt { mountpoint := unix.ByteSliceToString(v.F_mntonname[:]) if c.excludedMountPointsPattern.MatchString(mountpoint) { - level.Debug(c.logger).Log("msg", "Ignoring mount point", "mountpoint", mountpoint) + c.logger.Debug("Ignoring mount point", "mountpoint", mountpoint) continue } device := unix.ByteSliceToString(v.F_mntfromname[:]) fstype := unix.ByteSliceToString(v.F_fstypename[:]) if c.excludedFSTypesPattern.MatchString(fstype) { - level.Debug(c.logger).Log("msg", "Ignoring fs type", "type", fstype) + c.logger.Debug("Ignoring fs type", "type", fstype) continue } diff --git a/collector/hwmon_linux.go b/collector/hwmon_linux.go index ed46f0f808..3d53995c8d 100644 --- a/collector/hwmon_linux.go +++ b/collector/hwmon_linux.go @@ -18,6 +18,7 @@ package collector import ( "errors" + "log/slog" "os" "path/filepath" "regexp" @@ -25,8 +26,6 @@ import ( "strings" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "golang.org/x/sys/unix" ) @@ -55,12 +54,12 @@ func init() { type hwMonCollector struct { deviceFilter deviceFilter sensorFilter deviceFilter - logger log.Logger + logger *slog.Logger } // NewHwMonCollector returns a new Collector exposing /sys/class/hwmon stats // (similar to lm-sensors). -func NewHwMonCollector(logger log.Logger) (Collector, error) { +func NewHwMonCollector(logger *slog.Logger) (Collector, error) { return &hwMonCollector{ logger: logger, @@ -168,7 +167,7 @@ func (c *hwMonCollector) updateHwmon(ch chan<- prometheus.Metric, dir string) er } if c.deviceFilter.ignored(hwmonName) { - level.Debug(c.logger).Log("msg", "ignoring hwmon chip", "chip", hwmonName) + c.logger.Debug("ignoring hwmon chip", "chip", hwmonName) return nil } @@ -211,7 +210,7 @@ func (c *hwMonCollector) updateHwmon(ch chan<- prometheus.Metric, dir string) er // sensors on specific devices. For example, to exclude the sensor "temp3" on // the device "platform_coretemp_0", use "platform_coretemp_0;temp3" if c.sensorFilter.ignored(hwmonName + ";" + sensor) { - level.Debug(c.logger).Log("msg", "ignoring sensor", "sensor", sensor) + c.logger.Debug("ignoring sensor", "sensor", sensor) continue } @@ -450,7 +449,7 @@ func (c *hwMonCollector) Update(ch chan<- prometheus.Metric) error { hwmonFiles, err := os.ReadDir(hwmonPathName) if err != nil { if errors.Is(err, os.ErrNotExist) { - level.Debug(c.logger).Log("msg", "hwmon collector metrics are not available for this system") + c.logger.Debug("hwmon collector metrics are not available for this system") return ErrNoData } diff --git a/collector/infiniband_linux.go b/collector/infiniband_linux.go index b0928da3cf..7b1c438157 100644 --- a/collector/infiniband_linux.go +++ b/collector/infiniband_linux.go @@ -19,11 +19,10 @@ package collector import ( "errors" "fmt" + "log/slog" "os" "strconv" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs/sysfs" ) @@ -31,7 +30,7 @@ import ( type infinibandCollector struct { fs sysfs.FS metricDescs map[string]*prometheus.Desc - logger log.Logger + logger *slog.Logger subsystem string } @@ -40,7 +39,7 @@ func init() { } // NewInfiniBandCollector returns a new Collector exposing InfiniBand stats. -func NewInfiniBandCollector(logger log.Logger) (Collector, error) { +func NewInfiniBandCollector(logger *slog.Logger) (Collector, error) { var i infinibandCollector var err error @@ -116,7 +115,7 @@ func (c *infinibandCollector) Update(ch chan<- prometheus.Metric) error { devices, err := c.fs.InfiniBandClass() if err != nil { if errors.Is(err, os.ErrNotExist) { - level.Debug(c.logger).Log("msg", "infiniband statistics not found, skipping") + c.logger.Debug("infiniband statistics not found, skipping") return ErrNoData } return fmt.Errorf("error obtaining InfiniBand class info: %w", err) diff --git a/collector/interrupts_common.go b/collector/interrupts_common.go index a0996e91f4..08baa1060d 100644 --- a/collector/interrupts_common.go +++ b/collector/interrupts_common.go @@ -19,13 +19,13 @@ package collector import ( "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" + "log/slog" ) type interruptsCollector struct { desc typedDesc - logger log.Logger + logger *slog.Logger nameFilter deviceFilter includeZeros bool } @@ -41,7 +41,7 @@ var ( ) // NewInterruptsCollector returns a new Collector exposing interrupts stats. -func NewInterruptsCollector(logger log.Logger) (Collector, error) { +func NewInterruptsCollector(logger *slog.Logger) (Collector, error) { return &interruptsCollector{ desc: typedDesc{prometheus.NewDesc( namespace+"_interrupts_total", diff --git a/collector/interrupts_linux.go b/collector/interrupts_linux.go index 3d3bd03762..77caf423c0 100644 --- a/collector/interrupts_linux.go +++ b/collector/interrupts_linux.go @@ -25,7 +25,6 @@ import ( "strconv" "strings" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" ) @@ -42,7 +41,7 @@ func (c *interruptsCollector) Update(ch chan<- prometheus.Metric) (err error) { for cpuNo, value := range interrupt.values { filterName := name + ";" + interrupt.info + ";" + interrupt.devices if c.nameFilter.ignored(filterName) { - level.Debug(c.logger).Log("msg", "ignoring interrupt name", "filter_name", filterName) + c.logger.Debug("ignoring interrupt name", "filter_name", filterName) continue } fv, err := strconv.ParseFloat(value, 64) @@ -50,7 +49,7 @@ func (c *interruptsCollector) Update(ch chan<- prometheus.Metric) (err error) { return fmt.Errorf("invalid value %s in interrupts: %w", value, err) } if !c.includeZeros && fv == 0.0 { - level.Debug(c.logger).Log("msg", "ignoring interrupt with zero value", "filter_name", filterName, "cpu", cpuNo) + c.logger.Debug("ignoring interrupt with zero value", "filter_name", filterName, "cpu", cpuNo) continue } ch <- c.desc.mustNewConstMetric(fv, strconv.Itoa(cpuNo), name, interrupt.info, interrupt.devices) diff --git a/collector/interrupts_openbsd.go b/collector/interrupts_openbsd.go index 049f640764..60fcbf1d74 100644 --- a/collector/interrupts_openbsd.go +++ b/collector/interrupts_openbsd.go @@ -20,7 +20,6 @@ import ( "fmt" "strconv" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" ) @@ -110,11 +109,11 @@ func (c *interruptsCollector) Update(ch chan<- prometheus.Metric) error { interruptType := fmt.Sprintf("%d", interrupt.vector) filterName := interruptType + ";" + dev if c.nameFilter.ignored(filterName) { - level.Debug(c.logger).Log("msg", "ignoring interrupt name", "filter_name", filterName) + c.logger.Debug("ignoring interrupt name", "filter_name", filterName) continue } if !c.includeZeros && value == 0.0 { - level.Debug(c.logger).Log("msg", "ignoring interrupt with zero value", "filter_name", filterName, "cpu", cpuNo) + c.logger.Debug("ignoring interrupt with zero value", "filter_name", filterName, "cpu", cpuNo) continue } ch <- c.desc.mustNewConstMetric( diff --git a/collector/interrupts_openbsd_amd64.go b/collector/interrupts_openbsd_amd64.go index 4ce4edfdba..69851a222f 100644 --- a/collector/interrupts_openbsd_amd64.go +++ b/collector/interrupts_openbsd_amd64.go @@ -21,7 +21,6 @@ import ( "strconv" "unsafe" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "golang.org/x/sys/unix" ) @@ -81,11 +80,11 @@ func (c *interruptsCollector) Update(ch chan<- prometheus.Metric) error { interruptType := fmt.Sprintf("%d", interrupt.vector) filterName := interruptType + ";" + dev if c.nameFilter.ignored(filterName) { - level.Debug(c.logger).Log("msg", "ignoring interrupt name", "filter_name", filterName) + c.logger.Debug("ignoring interrupt name", "filter_name", filterName) continue } if !c.includeZeros && value == 0.0 { - level.Debug(c.logger).Log("msg", "ignoring interrupt with zero value", "filter_name", filterName, "cpu", cpuNo) + c.logger.Debug("ignoring interrupt with zero value", "filter_name", filterName, "cpu", cpuNo) continue } ch <- c.desc.mustNewConstMetric( diff --git a/collector/ipvs_linux.go b/collector/ipvs_linux.go index 63a3a1a8a8..7d7bae54a6 100644 --- a/collector/ipvs_linux.go +++ b/collector/ipvs_linux.go @@ -19,14 +19,13 @@ package collector import ( "errors" "fmt" + "log/slog" "os" "sort" "strconv" "strings" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" ) @@ -37,7 +36,7 @@ type ipvsCollector struct { backendLabels []string backendConnectionsActive, backendConnectionsInact, backendWeight typedDesc connections, incomingPackets, outgoingPackets, incomingBytes, outgoingBytes typedDesc - logger log.Logger + logger *slog.Logger } type ipvsBackendStatus struct { @@ -73,11 +72,11 @@ func init() { // NewIPVSCollector sets up a new collector for IPVS metrics. It accepts the // "procfs" config parameter to override the default proc location (/proc). -func NewIPVSCollector(logger log.Logger) (Collector, error) { +func NewIPVSCollector(logger *slog.Logger) (Collector, error) { return newIPVSCollector(logger) } -func newIPVSCollector(logger log.Logger) (*ipvsCollector, error) { +func newIPVSCollector(logger *slog.Logger) (*ipvsCollector, error) { var ( c ipvsCollector err error @@ -143,7 +142,7 @@ func (c *ipvsCollector) Update(ch chan<- prometheus.Metric) error { if err != nil { // Cannot access ipvs metrics, report no error. if errors.Is(err, os.ErrNotExist) { - level.Debug(c.logger).Log("msg", "ipvs collector metrics are not available for this system") + c.logger.Debug("ipvs collector metrics are not available for this system") return ErrNoData } return fmt.Errorf("could not get IPVS stats: %w", err) diff --git a/collector/ipvs_linux_test.go b/collector/ipvs_linux_test.go index 6ee41b299b..bc3e40f975 100644 --- a/collector/ipvs_linux_test.go +++ b/collector/ipvs_linux_test.go @@ -19,14 +19,14 @@ package collector import ( "errors" "fmt" + "io" + "log/slog" "net/http" "net/http/httptest" "os" "strings" "testing" - "github.com/go-kit/log" - "github.com/alecthomas/kingpin/v2" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" @@ -114,7 +114,7 @@ func TestIPVSCollector(t *testing.T) { if _, err := kingpin.CommandLine.Parse(args); err != nil { t.Fatal(err) } - collector, err := newIPVSCollector(log.NewNopLogger()) + collector, err := newIPVSCollector(slog.New(slog.NewTextHandler(io.Discard, nil))) if err != nil { if test.err == nil { t.Fatal(err) @@ -182,7 +182,7 @@ func TestIPVSCollectorResponse(t *testing.T) { if _, err := kingpin.CommandLine.Parse(args); err != nil { t.Fatal(err) } - collector, err := NewIPVSCollector(log.NewNopLogger()) + collector, err := NewIPVSCollector(slog.New(slog.NewTextHandler(io.Discard, nil))) if err != nil { t.Fatal(err) } diff --git a/collector/ksmd_linux.go b/collector/ksmd_linux.go index 6d4142ae9a..d504fe300d 100644 --- a/collector/ksmd_linux.go +++ b/collector/ksmd_linux.go @@ -18,9 +18,9 @@ package collector import ( "fmt" + "log/slog" "path/filepath" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) @@ -31,7 +31,7 @@ var ( type ksmdCollector struct { metricDescs map[string]*prometheus.Desc - logger log.Logger + logger *slog.Logger } func init() { @@ -50,7 +50,7 @@ func getCanonicalMetricName(filename string) string { } // NewKsmdCollector returns a new Collector exposing kernel/system statistics. -func NewKsmdCollector(logger log.Logger) (Collector, error) { +func NewKsmdCollector(logger *slog.Logger) (Collector, error) { subsystem := "ksmd" descs := make(map[string]*prometheus.Desc) diff --git a/collector/lnstat_linux.go b/collector/lnstat_linux.go index b3c90dc06e..43bd7e0590 100644 --- a/collector/lnstat_linux.go +++ b/collector/lnstat_linux.go @@ -18,22 +18,22 @@ package collector import ( "fmt" + "log/slog" "strconv" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" ) type lnstatCollector struct { - logger log.Logger + logger *slog.Logger } func init() { registerCollector("lnstat", defaultDisabled, NewLnstatCollector) } -func NewLnstatCollector(logger log.Logger) (Collector, error) { +func NewLnstatCollector(logger *slog.Logger) (Collector, error) { return &lnstatCollector{logger}, nil } diff --git a/collector/loadavg.go b/collector/loadavg.go index cb7b2cb142..09280ebfd6 100644 --- a/collector/loadavg.go +++ b/collector/loadavg.go @@ -19,15 +19,14 @@ package collector import ( "fmt" + "log/slog" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" ) type loadavgCollector struct { metric []typedDesc - logger log.Logger + logger *slog.Logger } func init() { @@ -35,7 +34,7 @@ func init() { } // NewLoadavgCollector returns a new Collector exposing load average stats. -func NewLoadavgCollector(logger log.Logger) (Collector, error) { +func NewLoadavgCollector(logger *slog.Logger) (Collector, error) { return &loadavgCollector{ metric: []typedDesc{ {prometheus.NewDesc(namespace+"_load1", "1m load average.", nil, nil), prometheus.GaugeValue}, @@ -52,7 +51,7 @@ func (c *loadavgCollector) Update(ch chan<- prometheus.Metric) error { return fmt.Errorf("couldn't get load: %w", err) } for i, load := range loads { - level.Debug(c.logger).Log("msg", "return load", "index", i, "load", load) + c.logger.Debug("return load", "index", i, "load", load) ch <- c.metric[i].mustNewConstMetric(load) } return err diff --git a/collector/logind_linux.go b/collector/logind_linux.go index de5b0d18ad..f5606ee123 100644 --- a/collector/logind_linux.go +++ b/collector/logind_linux.go @@ -18,10 +18,10 @@ package collector import ( "fmt" + "log/slog" "os" "strconv" - "github.com/go-kit/log" "github.com/godbus/dbus/v5" "github.com/prometheus/client_golang/prometheus" ) @@ -46,7 +46,7 @@ var ( ) type logindCollector struct { - logger log.Logger + logger *slog.Logger } type logindDbus struct { @@ -86,7 +86,7 @@ func init() { } // NewLogindCollector returns a new Collector exposing logind statistics. -func NewLogindCollector(logger log.Logger) (Collector, error) { +func NewLogindCollector(logger *slog.Logger) (Collector, error) { return &logindCollector{logger}, nil } diff --git a/collector/mdadm_linux.go b/collector/mdadm_linux.go index 89c56b75d0..5f274ca2a2 100644 --- a/collector/mdadm_linux.go +++ b/collector/mdadm_linux.go @@ -19,16 +19,15 @@ package collector import ( "errors" "fmt" + "log/slog" "os" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" ) type mdadmCollector struct { - logger log.Logger + logger *slog.Logger } func init() { @@ -36,7 +35,7 @@ func init() { } // NewMdadmCollector returns a new Collector exposing raid statistics. -func NewMdadmCollector(logger log.Logger) (Collector, error) { +func NewMdadmCollector(logger *slog.Logger) (Collector, error) { return &mdadmCollector{logger}, nil } @@ -112,7 +111,7 @@ func (c *mdadmCollector) Update(ch chan<- prometheus.Metric) error { if err != nil { if errors.Is(err, os.ErrNotExist) { - level.Debug(c.logger).Log("msg", "Not collecting mdstat, file does not exist", "file", *procPath) + c.logger.Debug("Not collecting mdstat, file does not exist", "file", *procPath) return ErrNoData } @@ -120,7 +119,7 @@ func (c *mdadmCollector) Update(ch chan<- prometheus.Metric) error { } for _, mdStat := range mdStats { - level.Debug(c.logger).Log("msg", "collecting metrics for device", "device", mdStat.Name) + c.logger.Debug("collecting metrics for device", "device", mdStat.Name) stateVals := make(map[string]float64) stateVals[mdStat.ActivityState] = 1 diff --git a/collector/meminfo.go b/collector/meminfo.go index 0a6390d828..55e1360460 100644 --- a/collector/meminfo.go +++ b/collector/meminfo.go @@ -21,7 +21,6 @@ import ( "fmt" "strings" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" ) @@ -41,7 +40,7 @@ func (c *meminfoCollector) Update(ch chan<- prometheus.Metric) error { if err != nil { return fmt.Errorf("couldn't get meminfo: %w", err) } - level.Debug(c.logger).Log("msg", "Set node_mem", "memInfo", fmt.Sprintf("%v", memInfo)) + c.logger.Debug("Set node_mem", "memInfo", fmt.Sprintf("%v", memInfo)) for k, v := range memInfo { if strings.HasSuffix(k, "_total") { metricType = prometheus.CounterValue diff --git a/collector/meminfo_darwin.go b/collector/meminfo_darwin.go index 21316fb57e..b5b10b4b92 100644 --- a/collector/meminfo_darwin.go +++ b/collector/meminfo_darwin.go @@ -24,18 +24,18 @@ import "C" import ( "encoding/binary" "fmt" + "log/slog" "unsafe" - "github.com/go-kit/log" "golang.org/x/sys/unix" ) type meminfoCollector struct { - logger log.Logger + logger *slog.Logger } // NewMeminfoCollector returns a new Collector exposing memory stats. -func NewMeminfoCollector(logger log.Logger) (Collector, error) { +func NewMeminfoCollector(logger *slog.Logger) (Collector, error) { return &meminfoCollector{ logger: logger, }, nil diff --git a/collector/meminfo_linux.go b/collector/meminfo_linux.go index 40e0699055..98d5a5c06b 100644 --- a/collector/meminfo_linux.go +++ b/collector/meminfo_linux.go @@ -18,18 +18,18 @@ package collector import ( "fmt" + "log/slog" - "github.com/go-kit/log" "github.com/prometheus/procfs" ) type meminfoCollector struct { fs procfs.FS - logger log.Logger + logger *slog.Logger } // NewMeminfoCollector returns a new Collector exposing memory stats. -func NewMeminfoCollector(logger log.Logger) (Collector, error) { +func NewMeminfoCollector(logger *slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) diff --git a/collector/meminfo_linux_test.go b/collector/meminfo_linux_test.go index 523426d0d0..41a0133fe5 100644 --- a/collector/meminfo_linux_test.go +++ b/collector/meminfo_linux_test.go @@ -17,15 +17,14 @@ package collector import ( - "os" + "io" + "log/slog" "testing" - - "github.com/go-kit/log" ) func TestMemInfo(t *testing.T) { *procPath = "fixtures/proc" - logger := log.NewLogfmtLogger(os.Stderr) + logger := slog.New(slog.NewTextHandler(io.Discard, nil)) collector, err := NewMeminfoCollector(logger) if err != nil { diff --git a/collector/meminfo_netbsd.go b/collector/meminfo_netbsd.go index f8b131e51f..54d23a128e 100644 --- a/collector/meminfo_netbsd.go +++ b/collector/meminfo_netbsd.go @@ -17,16 +17,16 @@ package collector import ( - "github.com/go-kit/log" "golang.org/x/sys/unix" + "log/slog" ) type meminfoCollector struct { - logger log.Logger + logger *slog.Logger } // NewMeminfoCollector returns a new Collector exposing memory stats. -func NewMeminfoCollector(logger log.Logger) (Collector, error) { +func NewMeminfoCollector(logger *slog.Logger) (Collector, error) { return &meminfoCollector{ logger: logger, }, nil diff --git a/collector/meminfo_numa_linux.go b/collector/meminfo_numa_linux.go index 5ce08e99d9..fc26eba499 100644 --- a/collector/meminfo_numa_linux.go +++ b/collector/meminfo_numa_linux.go @@ -20,13 +20,13 @@ import ( "bufio" "fmt" "io" + "log/slog" "os" "path/filepath" "regexp" "strconv" "strings" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) @@ -45,7 +45,7 @@ type meminfoMetric struct { type meminfoNumaCollector struct { metricDescs map[string]*prometheus.Desc - logger log.Logger + logger *slog.Logger } func init() { @@ -53,7 +53,7 @@ func init() { } // NewMeminfoNumaCollector returns a new Collector exposing memory stats. -func NewMeminfoNumaCollector(logger log.Logger) (Collector, error) { +func NewMeminfoNumaCollector(logger *slog.Logger) (Collector, error) { return &meminfoNumaCollector{ metricDescs: map[string]*prometheus.Desc{}, logger: logger, diff --git a/collector/meminfo_openbsd.go b/collector/meminfo_openbsd.go index 4a4682a325..ca9f46ad8e 100644 --- a/collector/meminfo_openbsd.go +++ b/collector/meminfo_openbsd.go @@ -18,8 +18,7 @@ package collector import ( "fmt" - - "github.com/go-kit/log" + "log/slog" ) /* @@ -56,11 +55,11 @@ sysctl_bcstats(struct bcachestats *bcstats) import "C" type meminfoCollector struct { - logger log.Logger + logger *slog.Logger } // NewMeminfoCollector returns a new Collector exposing memory stats. -func NewMeminfoCollector(logger log.Logger) (Collector, error) { +func NewMeminfoCollector(logger *slog.Logger) (Collector, error) { return &meminfoCollector{ logger: logger, }, nil diff --git a/collector/meminfo_openbsd_amd64.go b/collector/meminfo_openbsd_amd64.go index 2f81c79ed4..906a36e41f 100644 --- a/collector/meminfo_openbsd_amd64.go +++ b/collector/meminfo_openbsd_amd64.go @@ -17,9 +17,9 @@ package collector import ( + "log/slog" "unsafe" - "github.com/go-kit/log" "golang.org/x/sys/unix" ) @@ -51,11 +51,11 @@ type bcachestats struct { } type meminfoCollector struct { - logger log.Logger + logger *slog.Logger } // NewMeminfoCollector returns a new Collector exposing memory stats. -func NewMeminfoCollector(logger log.Logger) (Collector, error) { +func NewMeminfoCollector(logger *slog.Logger) (Collector, error) { return &meminfoCollector{ logger: logger, }, nil diff --git a/collector/memory_bsd.go b/collector/memory_bsd.go index 6af9d8aaa4..1c3710523d 100644 --- a/collector/memory_bsd.go +++ b/collector/memory_bsd.go @@ -19,8 +19,8 @@ package collector import ( "fmt" + "log/slog" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "golang.org/x/sys/unix" ) @@ -33,7 +33,7 @@ type memoryCollector struct { pageSize uint64 sysctls []bsdSysctl kvm kvm - logger log.Logger + logger *slog.Logger } func init() { @@ -41,7 +41,7 @@ func init() { } // NewMemoryCollector returns a new Collector exposing memory stats. -func NewMemoryCollector(logger log.Logger) (Collector, error) { +func NewMemoryCollector(logger *slog.Logger) (Collector, error) { tmp32, err := unix.SysctlUint32("vm.stats.vm.v_page_size") if err != nil { return nil, fmt.Errorf("sysctl(vm.stats.vm.v_page_size) failed: %w", err) diff --git a/collector/mountstats_linux.go b/collector/mountstats_linux.go index cdd84ea16c..03f1a9b676 100644 --- a/collector/mountstats_linux.go +++ b/collector/mountstats_linux.go @@ -18,9 +18,8 @@ package collector import ( "fmt" + "log/slog" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" ) @@ -96,7 +95,7 @@ type mountStatsCollector struct { proc procfs.Proc - logger log.Logger + logger *slog.Logger } // used to uniquely identify an NFS mount to prevent duplicates @@ -111,7 +110,7 @@ func init() { } // NewMountStatsCollector returns a new Collector exposing NFS statistics. -func NewMountStatsCollector(logger log.Logger) (Collector, error) { +func NewMountStatsCollector(logger *slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) @@ -542,7 +541,7 @@ func (c *mountStatsCollector) Update(ch chan<- prometheus.Metric) error { deviceIdentifier := nfsDeviceIdentifier{m.Device, stats.Transport[k].Protocol, mountAddress} i := deviceList[deviceIdentifier] if i { - level.Debug(c.logger).Log("msg", "Skipping duplicate device entry", "device", deviceIdentifier) + c.logger.Debug("Skipping duplicate device entry", "device", deviceIdentifier) break } deviceList[deviceIdentifier] = true diff --git a/collector/netclass_linux.go b/collector/netclass_linux.go index 327c89aaf4..87763c3b6e 100644 --- a/collector/netclass_linux.go +++ b/collector/netclass_linux.go @@ -19,14 +19,13 @@ package collector import ( "errors" "fmt" + "log/slog" "net" "os" "regexp" "sync" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs/sysfs" ) @@ -43,7 +42,7 @@ type netClassCollector struct { ignoredDevicesPattern *regexp.Regexp metricDescs map[string]*prometheus.Desc metricDescsMu sync.Mutex - logger log.Logger + logger *slog.Logger } func init() { @@ -51,7 +50,7 @@ func init() { } // NewNetClassCollector returns a new Collector exposing network class stats. -func NewNetClassCollector(logger log.Logger) (Collector, error) { +func NewNetClassCollector(logger *slog.Logger) (Collector, error) { fs, err := sysfs.NewFS(*sysPath) if err != nil { return nil, fmt.Errorf("failed to open sysfs: %w", err) @@ -77,7 +76,7 @@ func (c *netClassCollector) netClassSysfsUpdate(ch chan<- prometheus.Metric) err netClass, err := c.getNetClassInfo() if err != nil { if errors.Is(err, os.ErrNotExist) || errors.Is(err, os.ErrPermission) { - level.Debug(c.logger).Log("msg", "Could not read netclass file", "err", err) + c.logger.Debug("Could not read netclass file", "err", err) return ErrNoData } return fmt.Errorf("could not get net class info: %w", err) diff --git a/collector/netclass_rtnl_linux.go b/collector/netclass_rtnl_linux.go index ef963715e5..96feb8bc68 100644 --- a/collector/netclass_rtnl_linux.go +++ b/collector/netclass_rtnl_linux.go @@ -23,7 +23,6 @@ import ( "path/filepath" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log/level" "github.com/jsimonetti/rtnetlink" "github.com/mdlayher/ethtool" "github.com/prometheus/client_golang/prometheus" @@ -45,7 +44,7 @@ func (c *netClassCollector) netClassRTNLUpdate(ch chan<- prometheus.Metric) erro if !errors.Is(errors.Unwrap(err), fs.ErrNotExist) { return fmt.Errorf("could not get link modes: %w", err) } - level.Info(c.logger).Log("msg", "ETHTOOL netlink interface unavailable, duplex and linkspeed are not scraped.") + c.logger.Info("ETHTOOL netlink interface unavailable, duplex and linkspeed are not scraped.") } else { for _, lm := range lms { if c.ignoredDevicesPattern.MatchString(lm.Interface.Name) { diff --git a/collector/netdev_bsd.go b/collector/netdev_bsd.go index 691bbec4ad..2c3e7f4cd0 100644 --- a/collector/netdev_bsd.go +++ b/collector/netdev_bsd.go @@ -19,9 +19,7 @@ package collector import ( "errors" - - "github.com/go-kit/log" - "github.com/go-kit/log/level" + "log/slog" ) /* @@ -34,7 +32,7 @@ import ( */ import "C" -func getNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, error) { +func getNetDevStats(filter *deviceFilter, logger *slog.Logger) (netDevStats, error) { netDev := netDevStats{} var ifap, ifa *C.struct_ifaddrs @@ -50,7 +48,7 @@ func getNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, error dev := C.GoString(ifa.ifa_name) if filter.ignored(dev) { - level.Debug(logger).Log("msg", "Ignoring device", "device", dev) + logger.Debug("Ignoring device", "device", dev) continue } diff --git a/collector/netdev_common.go b/collector/netdev_common.go index c6abd7ac0a..893f6afa89 100644 --- a/collector/netdev_common.go +++ b/collector/netdev_common.go @@ -20,13 +20,12 @@ package collector import ( "errors" "fmt" + "log/slog" "net" "strconv" "sync" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" ) @@ -44,7 +43,7 @@ type netDevCollector struct { deviceFilter deviceFilter metricDescsMutex sync.Mutex metricDescs map[string]*prometheus.Desc - logger log.Logger + logger *slog.Logger } type netDevStats map[string]map[string]uint64 @@ -54,10 +53,10 @@ func init() { } // NewNetDevCollector returns a new Collector exposing network device stats. -func NewNetDevCollector(logger log.Logger) (Collector, error) { +func NewNetDevCollector(logger *slog.Logger) (Collector, error) { if *oldNetdevDeviceInclude != "" { if *netdevDeviceInclude == "" { - level.Warn(logger).Log("msg", "--collector.netdev.device-whitelist is DEPRECATED and will be removed in 2.0.0, use --collector.netdev.device-include") + logger.Warn("--collector.netdev.device-whitelist is DEPRECATED and will be removed in 2.0.0, use --collector.netdev.device-include") *netdevDeviceInclude = *oldNetdevDeviceInclude } else { return nil, errors.New("--collector.netdev.device-whitelist and --collector.netdev.device-include are mutually exclusive") @@ -66,7 +65,7 @@ func NewNetDevCollector(logger log.Logger) (Collector, error) { if *oldNetdevDeviceExclude != "" { if *netdevDeviceExclude == "" { - level.Warn(logger).Log("msg", "--collector.netdev.device-blacklist is DEPRECATED and will be removed in 2.0.0, use --collector.netdev.device-exclude") + logger.Warn("--collector.netdev.device-blacklist is DEPRECATED and will be removed in 2.0.0, use --collector.netdev.device-exclude") *netdevDeviceExclude = *oldNetdevDeviceExclude } else { return nil, errors.New("--collector.netdev.device-blacklist and --collector.netdev.device-exclude are mutually exclusive") @@ -78,11 +77,11 @@ func NewNetDevCollector(logger log.Logger) (Collector, error) { } if *netdevDeviceExclude != "" { - level.Info(logger).Log("msg", "Parsed flag --collector.netdev.device-exclude", "flag", *netdevDeviceExclude) + logger.Info("Parsed flag --collector.netdev.device-exclude", "flag", *netdevDeviceExclude) } if *netdevDeviceInclude != "" { - level.Info(logger).Log("msg", "Parsed Flag --collector.netdev.device-include", "flag", *netdevDeviceInclude) + logger.Info("Parsed Flag --collector.netdev.device-include", "flag", *netdevDeviceInclude) } return &netDevCollector{ diff --git a/collector/netdev_darwin.go b/collector/netdev_darwin.go index e3d50e2692..2367ebe5c6 100644 --- a/collector/netdev_darwin.go +++ b/collector/netdev_darwin.go @@ -20,14 +20,13 @@ import ( "bytes" "encoding/binary" "fmt" + "log/slog" "net" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "golang.org/x/sys/unix" ) -func getNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, error) { +func getNetDevStats(filter *deviceFilter, logger *slog.Logger) (netDevStats, error) { netDev := netDevStats{} ifs, err := net.Interfaces() @@ -37,13 +36,13 @@ func getNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, error for _, iface := range ifs { if filter.ignored(iface.Name) { - level.Debug(logger).Log("msg", "Ignoring device", "device", iface.Name) + logger.Debug("Ignoring device", "device", iface.Name) continue } ifaceData, err := getIfaceData(iface.Index) if err != nil { - level.Debug(logger).Log("msg", "failed to load data for interface", "device", iface.Name, "err", err) + logger.Debug("failed to load data for interface", "device", iface.Name, "err", err) continue } diff --git a/collector/netdev_linux.go b/collector/netdev_linux.go index 0767c70615..f449980a1d 100644 --- a/collector/netdev_linux.go +++ b/collector/netdev_linux.go @@ -18,10 +18,9 @@ package collector import ( "fmt" + "log/slog" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/jsimonetti/rtnetlink" "github.com/prometheus/procfs" "github.com/prometheus/procfs/sysfs" @@ -32,14 +31,14 @@ var ( netdevLabelIfAlias = kingpin.Flag("collector.netdev.label-ifalias", "Add ifAlias label").Default("false").Bool() ) -func getNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, error) { +func getNetDevStats(filter *deviceFilter, logger *slog.Logger) (netDevStats, error) { if *netDevNetlink { return netlinkStats(filter, logger) } return procNetDevStats(filter, logger) } -func netlinkStats(filter *deviceFilter, logger log.Logger) (netDevStats, error) { +func netlinkStats(filter *deviceFilter, logger *slog.Logger) (netDevStats, error) { conn, err := rtnetlink.Dial(nil) if err != nil { return nil, err @@ -54,12 +53,12 @@ func netlinkStats(filter *deviceFilter, logger log.Logger) (netDevStats, error) return parseNetlinkStats(links, filter, logger), nil } -func parseNetlinkStats(links []rtnetlink.LinkMessage, filter *deviceFilter, logger log.Logger) netDevStats { +func parseNetlinkStats(links []rtnetlink.LinkMessage, filter *deviceFilter, logger *slog.Logger) netDevStats { metrics := netDevStats{} for _, msg := range links { if msg.Attributes == nil { - level.Debug(logger).Log("msg", "No netlink attributes, skipping") + logger.Debug("No netlink attributes, skipping") continue } name := msg.Attributes.Name @@ -95,13 +94,13 @@ func parseNetlinkStats(links []rtnetlink.LinkMessage, filter *deviceFilter, logg } if filter.ignored(name) { - level.Debug(logger).Log("msg", "Ignoring device", "device", name) + logger.Debug("Ignoring device", "device", name) continue } // Make sure we don't panic when accessing `stats` attributes below. if stats == nil { - level.Debug(logger).Log("msg", "No netlink stats, skipping") + logger.Debug("No netlink stats, skipping") continue } @@ -143,7 +142,7 @@ func parseNetlinkStats(links []rtnetlink.LinkMessage, filter *deviceFilter, logg return metrics } -func procNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, error) { +func procNetDevStats(filter *deviceFilter, logger *slog.Logger) (netDevStats, error) { metrics := netDevStats{} fs, err := procfs.NewFS(*procPath) @@ -160,7 +159,7 @@ func procNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, erro name := stats.Name if filter.ignored(name) { - level.Debug(logger).Log("msg", "Ignoring device", "device", name) + logger.Debug("Ignoring device", "device", name) continue } diff --git a/collector/netdev_linux_test.go b/collector/netdev_linux_test.go index 7909d01821..cb27a81b0a 100644 --- a/collector/netdev_linux_test.go +++ b/collector/netdev_linux_test.go @@ -17,10 +17,10 @@ package collector import ( + "io" + "log/slog" "testing" - "github.com/go-kit/log" - "github.com/jsimonetti/rtnetlink" ) @@ -166,7 +166,7 @@ var links = []rtnetlink.LinkMessage{ func TestNetDevStatsIgnore(t *testing.T) { filter := newDeviceFilter("^veth", "") - netStats := parseNetlinkStats(links, &filter, log.NewNopLogger()) + netStats := parseNetlinkStats(links, &filter, slog.New(slog.NewTextHandler(io.Discard, nil))) if want, got := uint64(10437182923), netStats["wlan0"]["receive_bytes"]; want != got { t.Errorf("want netstat wlan0 bytes %v, got %v", want, got) @@ -199,7 +199,7 @@ func TestNetDevStatsIgnore(t *testing.T) { func TestNetDevStatsAccept(t *testing.T) { filter := newDeviceFilter("", "^💩0$") - netStats := parseNetlinkStats(links, &filter, log.NewNopLogger()) + netStats := parseNetlinkStats(links, &filter, slog.New(slog.NewTextHandler(io.Discard, nil))) if want, got := 1, len(netStats); want != got { t.Errorf("want count of devices to be %d, got %d", want, got) @@ -230,7 +230,7 @@ func TestNetDevLegacyMetricNames(t *testing.T) { } filter := newDeviceFilter("", "") - netStats := parseNetlinkStats(links, &filter, log.NewNopLogger()) + netStats := parseNetlinkStats(links, &filter, slog.New(slog.NewTextHandler(io.Discard, nil))) for dev, devStats := range netStats { legacy(devStats) @@ -263,7 +263,7 @@ func TestNetDevLegacyMetricValues(t *testing.T) { } filter := newDeviceFilter("", "^enp0s0f0$") - netStats := parseNetlinkStats(links, &filter, log.NewNopLogger()) + netStats := parseNetlinkStats(links, &filter, slog.New(slog.NewTextHandler(io.Discard, nil))) metrics, ok := netStats["enp0s0f0"] if !ok { t.Error("expected stats for interface enp0s0f0") @@ -285,7 +285,7 @@ func TestNetDevLegacyMetricValues(t *testing.T) { func TestNetDevMetricValues(t *testing.T) { filter := newDeviceFilter("", "") - netStats := parseNetlinkStats(links, &filter, log.NewNopLogger()) + netStats := parseNetlinkStats(links, &filter, slog.New(slog.NewTextHandler(io.Discard, nil))) for _, msg := range links { device := msg.Attributes.Name diff --git a/collector/netdev_openbsd.go b/collector/netdev_openbsd.go index 177309fd54..31c2640bb6 100644 --- a/collector/netdev_openbsd.go +++ b/collector/netdev_openbsd.go @@ -18,9 +18,7 @@ package collector import ( "errors" - - "github.com/go-kit/log" - "github.com/go-kit/log/level" + "log/slog" ) /* @@ -31,7 +29,7 @@ import ( */ import "C" -func getNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, error) { +func getNetDevStats(filter *deviceFilter, logger *slog.Logger) (netDevStats, error) { netDev := netDevStats{} var ifap, ifa *C.struct_ifaddrs @@ -47,7 +45,7 @@ func getNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, error dev := C.GoString(ifa.ifa_name) if filter.ignored(dev) { - level.Debug(logger).Log("msg", "Ignoring device", "device", dev) + logger.Debug("Ignoring device", "device", dev) continue } diff --git a/collector/netdev_openbsd_amd64.go b/collector/netdev_openbsd_amd64.go index 25702c12d1..e98571648e 100644 --- a/collector/netdev_openbsd_amd64.go +++ b/collector/netdev_openbsd_amd64.go @@ -17,15 +17,14 @@ package collector import ( - "github.com/go-kit/log" - "github.com/go-kit/log/level" + "log/slog" "unsafe" "golang.org/x/sys/unix" ) -func getNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, error) { +func getNetDevStats(filter *deviceFilter, logger *slog.Logger) (netDevStats, error) { netDev := netDevStats{} mib := [6]_C_int{unix.CTL_NET, unix.AF_ROUTE, 0, 0, unix.NET_RT_IFLIST, 0} @@ -55,7 +54,7 @@ func getNetDevStats(filter *deviceFilter, logger log.Logger) (netDevStats, error data := ifm.Data dev := int8ToString(dl.Data[:dl.Nlen]) if filter.ignored(dev) { - level.Debug(logger).Log("msg", "Ignoring device", "device", dev) + logger.Debug("Ignoring device", "device", dev) continue } diff --git a/collector/netisr_freebsd.go b/collector/netisr_freebsd.go index 442bcdc6a7..b3a4451c5c 100644 --- a/collector/netisr_freebsd.go +++ b/collector/netisr_freebsd.go @@ -18,14 +18,14 @@ package collector import ( "fmt" + "log/slog" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) type netisrCollector struct { sysctls []bsdSysctl - logger log.Logger + logger *slog.Logger } const ( @@ -36,7 +36,7 @@ func init() { registerCollector("netisr", defaultEnabled, NewNetisrCollector) } -func NewNetisrCollector(logger log.Logger) (Collector, error) { +func NewNetisrCollector(logger *slog.Logger) (Collector, error) { return &netisrCollector{ sysctls: []bsdSysctl{ { diff --git a/collector/netstat_linux.go b/collector/netstat_linux.go index afbf8d5835..1aa9234004 100644 --- a/collector/netstat_linux.go +++ b/collector/netstat_linux.go @@ -21,13 +21,13 @@ import ( "errors" "fmt" "io" + "log/slog" "os" "regexp" "strconv" "strings" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) @@ -41,7 +41,7 @@ var ( type netStatCollector struct { fieldPattern *regexp.Regexp - logger log.Logger + logger *slog.Logger } func init() { @@ -50,7 +50,7 @@ func init() { // NewNetStatCollector takes and returns // a new Collector exposing network stats. -func NewNetStatCollector(logger log.Logger) (Collector, error) { +func NewNetStatCollector(logger *slog.Logger) (Collector, error) { pattern := regexp.MustCompile(*netStatFields) return &netStatCollector{ fieldPattern: pattern, diff --git a/collector/network_route_linux.go b/collector/network_route_linux.go index c77e175109..8eb141d633 100644 --- a/collector/network_route_linux.go +++ b/collector/network_route_linux.go @@ -19,10 +19,10 @@ package collector import ( "fmt" "golang.org/x/sys/unix" + "log/slog" "net" "strconv" - "github.com/go-kit/log" "github.com/jsimonetti/rtnetlink" "github.com/prometheus/client_golang/prometheus" ) @@ -30,7 +30,7 @@ import ( type networkRouteCollector struct { routeInfoDesc *prometheus.Desc routesDesc *prometheus.Desc - logger log.Logger + logger *slog.Logger } func init() { @@ -38,7 +38,7 @@ func init() { } // NewNetworkRouteCollector returns a new Collector exposing systemd statistics. -func NewNetworkRouteCollector(logger log.Logger) (Collector, error) { +func NewNetworkRouteCollector(logger *slog.Logger) (Collector, error) { const subsystem = "network" routeInfoDesc := prometheus.NewDesc( diff --git a/collector/nfs_linux.go b/collector/nfs_linux.go index e08acdbad7..ea2a1b5259 100644 --- a/collector/nfs_linux.go +++ b/collector/nfs_linux.go @@ -19,11 +19,10 @@ package collector import ( "errors" "fmt" + "log/slog" "os" "reflect" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs/nfs" ) @@ -40,7 +39,7 @@ type nfsCollector struct { nfsRPCRetransmissionsDesc *prometheus.Desc nfsRPCAuthenticationRefreshesDesc *prometheus.Desc nfsProceduresDesc *prometheus.Desc - logger log.Logger + logger *slog.Logger } func init() { @@ -48,7 +47,7 @@ func init() { } // NewNfsCollector returns a new Collector exposing NFS statistics. -func NewNfsCollector(logger log.Logger) (Collector, error) { +func NewNfsCollector(logger *slog.Logger) (Collector, error) { fs, err := nfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) @@ -100,7 +99,7 @@ func (c *nfsCollector) Update(ch chan<- prometheus.Metric) error { stats, err := c.fs.ClientRPCStats() if err != nil { if errors.Is(err, os.ErrNotExist) { - level.Debug(c.logger).Log("msg", "Not collecting NFS metrics", "err", err) + c.logger.Debug("Not collecting NFS metrics", "err", err) return ErrNoData } return fmt.Errorf("failed to retrieve nfs stats: %w", err) diff --git a/collector/nfsd_linux.go b/collector/nfsd_linux.go index 8b310ea23c..7f1bc24072 100644 --- a/collector/nfsd_linux.go +++ b/collector/nfsd_linux.go @@ -19,10 +19,9 @@ package collector import ( "errors" "fmt" + "log/slog" "os" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs/nfs" ) @@ -32,7 +31,7 @@ import ( type nfsdCollector struct { fs nfs.FS requestsDesc *prometheus.Desc - logger log.Logger + logger *slog.Logger } func init() { @@ -44,7 +43,7 @@ const ( ) // NewNFSdCollector returns a new Collector exposing /proc/net/rpc/nfsd statistics. -func NewNFSdCollector(logger log.Logger) (Collector, error) { +func NewNFSdCollector(logger *slog.Logger) (Collector, error) { fs, err := nfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) @@ -66,7 +65,7 @@ func (c *nfsdCollector) Update(ch chan<- prometheus.Metric) error { stats, err := c.fs.ServerRPCStats() if err != nil { if errors.Is(err, os.ErrNotExist) { - level.Debug(c.logger).Log("msg", "Not collecting NFSd metrics", "err", err) + c.logger.Debug("Not collecting NFSd metrics", "err", err) return ErrNoData } return fmt.Errorf("failed to retrieve nfsd stats: %w", err) diff --git a/collector/ntp.go b/collector/ntp.go index 8b8db8a950..10e639b1d9 100644 --- a/collector/ntp.go +++ b/collector/ntp.go @@ -18,14 +18,13 @@ package collector import ( "fmt" + "log/slog" "net" "sync" "time" "github.com/alecthomas/kingpin/v2" "github.com/beevik/ntp" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" ) @@ -51,7 +50,7 @@ var ( type ntpCollector struct { stratum, leap, rtt, offset, reftime, rootDelay, rootDispersion, sanity typedDesc - logger log.Logger + logger *slog.Logger } func init() { @@ -62,7 +61,7 @@ func init() { // Default definition of "local" is: // - collector.ntp.server address is a loopback address (or collector.ntp.server-is-mine flag is turned on) // - the server is reachable with outgoin IP_TTL = 1 -func NewNtpCollector(logger log.Logger) (Collector, error) { +func NewNtpCollector(logger *slog.Logger) (Collector, error) { ipaddr := net.ParseIP(*ntpServer) if !*ntpServerIsLocal && (ipaddr == nil || !ipaddr.IsLoopback()) { return nil, fmt.Errorf("only IP address of local NTP server is valid for --collector.ntp.server") @@ -80,7 +79,7 @@ func NewNtpCollector(logger log.Logger) (Collector, error) { return nil, fmt.Errorf("invalid NTP port number %d; must be between 1 and 65535 inclusive", *ntpServerPort) } - level.Warn(logger).Log("msg", "This collector is deprecated and will be removed in the next major version release.") + logger.Warn("This collector is deprecated and will be removed in the next major version release.") return &ntpCollector{ stratum: typedDesc{prometheus.NewDesc( prometheus.BuildFQName(namespace, ntpSubsystem, "stratum"), diff --git a/collector/nvme_linux.go b/collector/nvme_linux.go index 81d4ab2985..d1a9a87b55 100644 --- a/collector/nvme_linux.go +++ b/collector/nvme_linux.go @@ -19,17 +19,16 @@ package collector import ( "errors" "fmt" + "log/slog" "os" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs/sysfs" ) type nvmeCollector struct { fs sysfs.FS - logger log.Logger + logger *slog.Logger } func init() { @@ -37,7 +36,7 @@ func init() { } // NewNVMeCollector returns a new Collector exposing NVMe stats. -func NewNVMeCollector(logger log.Logger) (Collector, error) { +func NewNVMeCollector(logger *slog.Logger) (Collector, error) { fs, err := sysfs.NewFS(*sysPath) if err != nil { return nil, fmt.Errorf("failed to open sysfs: %w", err) @@ -53,7 +52,7 @@ func (c *nvmeCollector) Update(ch chan<- prometheus.Metric) error { devices, err := c.fs.NVMeClass() if err != nil { if errors.Is(err, os.ErrNotExist) { - level.Debug(c.logger).Log("msg", "nvme statistics not found, skipping") + c.logger.Debug("nvme statistics not found, skipping") return ErrNoData } return fmt.Errorf("error obtaining NVMe class info: %w", err) diff --git a/collector/os_release.go b/collector/os_release.go index 4c86740e61..06bba6ab7c 100644 --- a/collector/os_release.go +++ b/collector/os_release.go @@ -17,6 +17,7 @@ import ( "encoding/xml" "errors" "io" + "log/slog" "os" "regexp" "strconv" @@ -24,8 +25,6 @@ import ( "sync" "time" - "github.com/go-kit/log" - "github.com/go-kit/log/level" envparse "github.com/hashicorp/go-envparse" "github.com/prometheus/client_golang/prometheus" ) @@ -58,7 +57,7 @@ type osRelease struct { type osReleaseCollector struct { infoDesc *prometheus.Desc - logger log.Logger + logger *slog.Logger os *osRelease osMutex sync.RWMutex osReleaseFilenames []string // all os-release file names to check @@ -82,7 +81,7 @@ func init() { } // NewOSCollector returns a new Collector exposing os-release information. -func NewOSCollector(logger log.Logger) (Collector, error) { +func NewOSCollector(logger *slog.Logger) (Collector, error) { return &osReleaseCollector{ logger: logger, infoDesc: prometheus.NewDesc( @@ -178,7 +177,7 @@ func (c *osReleaseCollector) Update(ch chan<- prometheus.Metric) error { } if errors.Is(err, os.ErrNotExist) { if i >= (len(c.osReleaseFilenames) - 1) { - level.Debug(c.logger).Log("msg", "no os-release file found", "files", strings.Join(c.osReleaseFilenames, ",")) + c.logger.Debug("no os-release file found", "files", strings.Join(c.osReleaseFilenames, ",")) return ErrNoData } continue diff --git a/collector/os_release_test.go b/collector/os_release_test.go index b45ee0edfa..e5d6b501f0 100644 --- a/collector/os_release_test.go +++ b/collector/os_release_test.go @@ -14,12 +14,12 @@ package collector import ( + "io" + "log/slog" "os" "reflect" "strings" "testing" - - "github.com/go-kit/log" ) const debianBullseye string = `PRETTY_NAME="Debian GNU/Linux 11 (bullseye)" @@ -129,7 +129,7 @@ func TestUpdateStruct(t *testing.T) { } wantedVersion := 20.04 - collector, err := NewOSCollector(log.NewNopLogger()) + collector, err := NewOSCollector(slog.New(slog.NewTextHandler(io.Discard, nil))) if err != nil { t.Fatal(err) } diff --git a/collector/perf_linux.go b/collector/perf_linux.go index 8934371ad0..b62d9b8016 100644 --- a/collector/perf_linux.go +++ b/collector/perf_linux.go @@ -18,13 +18,12 @@ package collector import ( "fmt" + "log/slog" "runtime" "strconv" "strings" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/hodgesds/perf-utils" "github.com/prometheus/client_golang/prometheus" "golang.org/x/sys/unix" @@ -189,7 +188,7 @@ type perfCollector struct { perfSwProfilers map[int]*perf.SoftwareProfiler perfCacheProfilers map[int]*perf.CacheProfiler desc map[string]*prometheus.Desc - logger log.Logger + logger *slog.Logger tracepointCollector *perfTracepointCollector } @@ -199,7 +198,7 @@ type perfTracepointCollector struct { // collection order is the sorted configured collection order of the profiler. collectionOrder []string - logger log.Logger + logger *slog.Logger profilers map[int]perf.GroupProfiler } @@ -218,7 +217,7 @@ func (c *perfTracepointCollector) updateCPU(cpu int, ch chan<- prometheus.Metric profiler := c.profilers[cpu] p := &perf.GroupProfileValue{} if err := profiler.Profile(p); err != nil { - level.Error(c.logger).Log("msg", "Failed to collect tracepoint profile", "err", err) + c.logger.Error("Failed to collect tracepoint profile", "err", err) return err } @@ -240,7 +239,7 @@ func (c *perfTracepointCollector) updateCPU(cpu int, ch chan<- prometheus.Metric // newPerfTracepointCollector returns a configured perfTracepointCollector. func newPerfTracepointCollector( - logger log.Logger, + logger *slog.Logger, tracepointsFlag []string, cpus []int, ) (*perfTracepointCollector, error) { @@ -301,7 +300,7 @@ func newPerfTracepointCollector( // NewPerfCollector returns a new perf based collector, it creates a profiler // per CPU. -func NewPerfCollector(logger log.Logger) (Collector, error) { +func NewPerfCollector(logger *slog.Logger) (Collector, error) { collector := &perfCollector{ perfHwProfilers: map[int]*perf.HardwareProfiler{}, perfSwProfilers: map[int]*perf.SoftwareProfiler{}, diff --git a/collector/perf_linux_test.go b/collector/perf_linux_test.go index fc557ffd32..e385851153 100644 --- a/collector/perf_linux_test.go +++ b/collector/perf_linux_test.go @@ -17,13 +17,14 @@ package collector import ( + "io" + "log/slog" "os" "runtime" "strconv" "strings" "testing" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) @@ -44,7 +45,7 @@ func canTestPerf(t *testing.T) { func TestPerfCollector(t *testing.T) { canTestPerf(t) - collector, err := NewPerfCollector(log.NewNopLogger()) + collector, err := NewPerfCollector(slog.New(slog.NewTextHandler(io.Discard, nil))) if err != nil { t.Fatal(err) } @@ -97,7 +98,7 @@ func TestPerfCollectorStride(t *testing.T) { } } perfCPUsFlag = &test.flag - collector, err := NewPerfCollector(log.NewNopLogger()) + collector, err := NewPerfCollector(slog.New(slog.NewTextHandler(io.Discard, nil))) if err != nil { t.Fatal(err) } diff --git a/collector/powersupplyclass.go b/collector/powersupplyclass.go index 7f231dac47..a5e648c098 100644 --- a/collector/powersupplyclass.go +++ b/collector/powersupplyclass.go @@ -18,10 +18,10 @@ package collector import ( + "log/slog" "regexp" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) @@ -33,14 +33,14 @@ type powerSupplyClassCollector struct { subsystem string ignoredPattern *regexp.Regexp metricDescs map[string]*prometheus.Desc - logger log.Logger + logger *slog.Logger } func init() { registerCollector("powersupplyclass", defaultEnabled, NewPowerSupplyClassCollector) } -func NewPowerSupplyClassCollector(logger log.Logger) (Collector, error) { +func NewPowerSupplyClassCollector(logger *slog.Logger) (Collector, error) { pattern := regexp.MustCompile(*powerSupplyClassIgnoredPowerSupplies) return &powerSupplyClassCollector{ subsystem: "power_supply", diff --git a/collector/pressure_linux.go b/collector/pressure_linux.go index 36e0650562..7338b7e650 100644 --- a/collector/pressure_linux.go +++ b/collector/pressure_linux.go @@ -19,11 +19,10 @@ package collector import ( "errors" "fmt" + "log/slog" "os" "syscall" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" ) @@ -42,7 +41,7 @@ type pressureStatsCollector struct { fs procfs.FS - logger log.Logger + logger *slog.Logger } func init() { @@ -50,7 +49,7 @@ func init() { } // NewPressureStatsCollector returns a Collector exposing pressure stall information -func NewPressureStatsCollector(logger log.Logger) (Collector, error) { +func NewPressureStatsCollector(logger *slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) @@ -95,15 +94,15 @@ func NewPressureStatsCollector(logger log.Logger) (Collector, error) { // Update calls procfs.NewPSIStatsForResource for the different resources and updates the values func (c *pressureStatsCollector) Update(ch chan<- prometheus.Metric) error { for _, res := range psiResources { - level.Debug(c.logger).Log("msg", "collecting statistics for resource", "resource", res) + c.logger.Debug("collecting statistics for resource", "resource", res) vals, err := c.fs.PSIStatsForResource(res) if err != nil { if errors.Is(err, os.ErrNotExist) { - level.Debug(c.logger).Log("msg", "pressure information is unavailable, you need a Linux kernel >= 4.20 and/or CONFIG_PSI enabled for your kernel") + c.logger.Debug("pressure information is unavailable, you need a Linux kernel >= 4.20 and/or CONFIG_PSI enabled for your kernel") return ErrNoData } if errors.Is(err, syscall.ENOTSUP) { - level.Debug(c.logger).Log("msg", "pressure information is disabled, add psi=1 kernel command line to enable it") + c.logger.Debug("pressure information is disabled, add psi=1 kernel command line to enable it") return ErrNoData } return fmt.Errorf("failed to retrieve pressure stats: %w", err) @@ -111,11 +110,11 @@ func (c *pressureStatsCollector) Update(ch chan<- prometheus.Metric) error { // IRQ pressure does not have 'some' data. // See https://github.com/torvalds/linux/blob/v6.9/include/linux/psi_types.h#L65 if vals.Some == nil && res != "irq" { - level.Debug(c.logger).Log("msg", "pressure information returned no 'some' data") + c.logger.Debug("pressure information returned no 'some' data") return ErrNoData } if vals.Full == nil && res != "cpu" { - level.Debug(c.logger).Log("msg", "pressure information returned no 'full' data") + c.logger.Debug("pressure information returned no 'full' data") return ErrNoData } switch res { @@ -130,7 +129,7 @@ func (c *pressureStatsCollector) Update(ch chan<- prometheus.Metric) error { case "irq": ch <- prometheus.MustNewConstMetric(c.irqFull, prometheus.CounterValue, float64(vals.Full.Total)/1000.0/1000.0) default: - level.Debug(c.logger).Log("msg", "did not account for resource", "resource", res) + c.logger.Debug("did not account for resource", "resource", res) } } diff --git a/collector/processes_linux.go b/collector/processes_linux.go index 798aeaeb30..653045e553 100644 --- a/collector/processes_linux.go +++ b/collector/processes_linux.go @@ -19,14 +19,13 @@ package collector import ( "errors" "fmt" + "log/slog" "os" "path" "strconv" "strings" "syscall" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" ) @@ -39,7 +38,7 @@ type processCollector struct { procsState *prometheus.Desc pidUsed *prometheus.Desc pidMax *prometheus.Desc - logger log.Logger + logger *slog.Logger } func init() { @@ -47,7 +46,7 @@ func init() { } // NewProcessStatCollector returns a new Collector exposing process data read from the proc filesystem. -func NewProcessStatCollector(logger log.Logger) (Collector, error) { +func NewProcessStatCollector(logger *slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) @@ -130,10 +129,10 @@ func (c *processCollector) getAllocatedThreads() (int, map[string]int32, int, ma if err != nil { // PIDs can vanish between getting the list and getting stats. if c.isIgnoredError(err) { - level.Debug(c.logger).Log("msg", "file not found when retrieving stats for pid", "pid", pid.PID, "err", err) + c.logger.Debug("file not found when retrieving stats for pid", "pid", pid.PID, "err", err) continue } - level.Debug(c.logger).Log("msg", "error reading stat for pid", "pid", pid.PID, "err", err) + c.logger.Debug("error reading stat for pid", "pid", pid.PID, "err", err) return 0, nil, 0, nil, fmt.Errorf("error reading stat for pid %d: %w", pid.PID, err) } pids++ @@ -151,17 +150,17 @@ func (c *processCollector) getThreadStates(pid int, pidStat procfs.ProcStat, thr fs, err := procfs.NewFS(procFilePath(path.Join(strconv.Itoa(pid), "task"))) if err != nil { if c.isIgnoredError(err) { - level.Debug(c.logger).Log("msg", "file not found when retrieving tasks for pid", "pid", pid, "err", err) + c.logger.Debug("file not found when retrieving tasks for pid", "pid", pid, "err", err) return nil } - level.Debug(c.logger).Log("msg", "error reading tasks for pid", "pid", pid, "err", err) + c.logger.Debug("error reading tasks for pid", "pid", pid, "err", err) return fmt.Errorf("error reading task for pid %d: %w", pid, err) } t, err := fs.AllProcs() if err != nil { if c.isIgnoredError(err) { - level.Debug(c.logger).Log("msg", "file not found when retrieving tasks for pid", "pid", pid, "err", err) + c.logger.Debug("file not found when retrieving tasks for pid", "pid", pid, "err", err) return nil } return fmt.Errorf("unable to list all threads for pid: %d %w", pid, err) @@ -175,10 +174,10 @@ func (c *processCollector) getThreadStates(pid int, pidStat procfs.ProcStat, thr threadStat, err := thread.Stat() if err != nil { if c.isIgnoredError(err) { - level.Debug(c.logger).Log("msg", "file not found when retrieving stats for thread", "pid", pid, "threadId", thread.PID, "err", err) + c.logger.Debug("file not found when retrieving stats for thread", "pid", pid, "threadId", thread.PID, "err", err) continue } - level.Debug(c.logger).Log("msg", "error reading stat for thread", "pid", pid, "threadId", thread.PID, "err", err) + c.logger.Debug("error reading stat for thread", "pid", pid, "threadId", thread.PID, "err", err) return fmt.Errorf("error reading stat for pid:%d thread:%d err:%w", pid, thread.PID, err) } threadStates[threadStat.State]++ diff --git a/collector/processes_linux_test.go b/collector/processes_linux_test.go index e2814a0104..c50d16c8db 100644 --- a/collector/processes_linux_test.go +++ b/collector/processes_linux_test.go @@ -17,10 +17,11 @@ package collector import ( + "io" + "log/slog" "testing" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" "github.com/prometheus/procfs" ) @@ -33,7 +34,7 @@ func TestReadProcessStatus(t *testing.T) { if err != nil { t.Errorf("failed to open procfs: %v", err) } - c := processCollector{fs: fs, logger: log.NewNopLogger()} + c := processCollector{fs: fs, logger: slog.New(slog.NewTextHandler(io.Discard, nil))} pids, states, threads, _, err := c.getAllocatedThreads() if err != nil { t.Fatalf("Cannot retrieve data from procfs getAllocatedThreads function: %v ", err) diff --git a/collector/qdisc_linux.go b/collector/qdisc_linux.go index 06ab6a88d6..93a78e3b19 100644 --- a/collector/qdisc_linux.go +++ b/collector/qdisc_linux.go @@ -19,18 +19,17 @@ package collector import ( "encoding/json" "fmt" + "log/slog" "os" "path/filepath" "github.com/alecthomas/kingpin/v2" "github.com/ema/qdisc" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" ) type qdiscStatCollector struct { - logger log.Logger + logger *slog.Logger deviceFilter deviceFilter bytes typedDesc packets typedDesc @@ -54,10 +53,10 @@ func init() { } // NewQdiscStatCollector returns a new Collector exposing queuing discipline statistics. -func NewQdiscStatCollector(logger log.Logger) (Collector, error) { +func NewQdiscStatCollector(logger *slog.Logger) (Collector, error) { if *oldCollectorQdiskDeviceInclude != "" { if *collectorQdiscDeviceInclude == "" { - level.Warn(logger).Log("msg", "--collector.qdisk.device-include is DEPRECATED and will be removed in 2.0.0, use --collector.qdisc.device-include") + logger.Warn("--collector.qdisk.device-include is DEPRECATED and will be removed in 2.0.0, use --collector.qdisc.device-include") *collectorQdiscDeviceInclude = *oldCollectorQdiskDeviceInclude } else { return nil, fmt.Errorf("--collector.qdisk.device-include and --collector.qdisc.device-include are mutually exclusive") @@ -66,7 +65,7 @@ func NewQdiscStatCollector(logger log.Logger) (Collector, error) { if *oldCollectorQdiskDeviceExclude != "" { if *collectorQdiscDeviceExclude == "" { - level.Warn(logger).Log("msg", "--collector.qdisk.device-exclude is DEPRECATED and will be removed in 2.0.0, use --collector.qdisc.device-exclude") + logger.Warn("--collector.qdisk.device-exclude is DEPRECATED and will be removed in 2.0.0, use --collector.qdisc.device-exclude") *collectorQdiscDeviceExclude = *oldCollectorQdiskDeviceExclude } else { return nil, fmt.Errorf("--collector.qdisk.device-exclude and --collector.qdisc.device-exclude are mutually exclusive") diff --git a/collector/rapl_linux.go b/collector/rapl_linux.go index 642de6c146..25d78f295c 100644 --- a/collector/rapl_linux.go +++ b/collector/rapl_linux.go @@ -19,12 +19,11 @@ package collector import ( "errors" "fmt" + "log/slog" "os" "strconv" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs/sysfs" ) @@ -33,7 +32,7 @@ const raplCollectorSubsystem = "rapl" type raplCollector struct { fs sysfs.FS - logger log.Logger + logger *slog.Logger joulesMetricDesc *prometheus.Desc } @@ -47,7 +46,7 @@ var ( ) // NewRaplCollector returns a new Collector exposing RAPL metrics. -func NewRaplCollector(logger log.Logger) (Collector, error) { +func NewRaplCollector(logger *slog.Logger) (Collector, error) { fs, err := sysfs.NewFS(*sysPath) if err != nil { @@ -74,11 +73,11 @@ func (c *raplCollector) Update(ch chan<- prometheus.Metric) error { zones, err := sysfs.GetRaplZones(c.fs) if err != nil { if errors.Is(err, os.ErrNotExist) { - level.Debug(c.logger).Log("msg", "Platform doesn't have powercap files present", "err", err) + c.logger.Debug("Platform doesn't have powercap files present", "err", err) return ErrNoData } if errors.Is(err, os.ErrPermission) { - level.Debug(c.logger).Log("msg", "Can't access powercap files", "err", err) + c.logger.Debug("Can't access powercap files", "err", err) return ErrNoData } return fmt.Errorf("failed to retrieve rapl stats: %w", err) @@ -88,7 +87,7 @@ func (c *raplCollector) Update(ch chan<- prometheus.Metric) error { microJoules, err := rz.GetEnergyMicrojoules() if err != nil { if errors.Is(err, os.ErrPermission) { - level.Debug(c.logger).Log("msg", "Can't access energy_uj file", "zone", rz, "err", err) + c.logger.Debug("Can't access energy_uj file", "zone", rz, "err", err) return ErrNoData } return err diff --git a/collector/runit.go b/collector/runit.go index 3cae657c33..8065d90c0c 100644 --- a/collector/runit.go +++ b/collector/runit.go @@ -18,10 +18,9 @@ package collector import ( "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus-community/go-runit/runit" "github.com/prometheus/client_golang/prometheus" + "log/slog" ) var runitServiceDir = kingpin.Flag("collector.runit.servicedir", "Path to runit service directory.").Default("/etc/service").String() @@ -31,7 +30,7 @@ type runitCollector struct { stateDesired typedDesc stateNormal typedDesc stateTimestamp typedDesc - logger log.Logger + logger *slog.Logger } func init() { @@ -39,14 +38,14 @@ func init() { } // NewRunitCollector returns a new Collector exposing runit statistics. -func NewRunitCollector(logger log.Logger) (Collector, error) { +func NewRunitCollector(logger *slog.Logger) (Collector, error) { var ( subsystem = "service" constLabels = prometheus.Labels{"supervisor": "runit"} labelNames = []string{"service"} ) - level.Warn(logger).Log("msg", "This collector is deprecated and will be removed in the next major version release.") + logger.Warn("This collector is deprecated and will be removed in the next major version release.") return &runitCollector{ state: typedDesc{prometheus.NewDesc( @@ -82,11 +81,11 @@ func (c *runitCollector) Update(ch chan<- prometheus.Metric) error { for _, service := range services { status, err := service.Status() if err != nil { - level.Debug(c.logger).Log("msg", "Couldn't get status", "service", service.Name, "err", err) + c.logger.Debug("Couldn't get status", "service", service.Name, "err", err) continue } - level.Debug(c.logger).Log("msg", "duration", "service", service.Name, "status", status.State, "pid", status.Pid, "duration_seconds", status.Duration) + c.logger.Debug("duration", "service", service.Name, "status", status.State, "pid", status.Pid, "duration_seconds", status.Duration) ch <- c.state.mustNewConstMetric(float64(status.State), service.Name) ch <- c.stateDesired.mustNewConstMetric(float64(status.Want), service.Name) ch <- c.stateTimestamp.mustNewConstMetric(float64(status.Timestamp.Unix()), service.Name) diff --git a/collector/schedstat_linux.go b/collector/schedstat_linux.go index e5016561da..59b2bd8e1e 100644 --- a/collector/schedstat_linux.go +++ b/collector/schedstat_linux.go @@ -19,10 +19,9 @@ package collector import ( "errors" "fmt" + "log/slog" "os" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" ) @@ -53,7 +52,7 @@ var ( ) // NewSchedstatCollector returns a new Collector exposing task scheduler statistics -func NewSchedstatCollector(logger log.Logger) (Collector, error) { +func NewSchedstatCollector(logger *slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) @@ -64,7 +63,7 @@ func NewSchedstatCollector(logger log.Logger) (Collector, error) { type schedstatCollector struct { fs procfs.FS - logger log.Logger + logger *slog.Logger } func init() { @@ -75,7 +74,7 @@ func (c *schedstatCollector) Update(ch chan<- prometheus.Metric) error { stats, err := c.fs.Schedstat() if err != nil { if errors.Is(err, os.ErrNotExist) { - level.Debug(c.logger).Log("msg", "schedstat file does not exist") + c.logger.Debug("schedstat file does not exist") return ErrNoData } return err diff --git a/collector/selinux_linux.go b/collector/selinux_linux.go index 79316362fe..9000fe0d66 100644 --- a/collector/selinux_linux.go +++ b/collector/selinux_linux.go @@ -17,16 +17,16 @@ package collector import ( - "github.com/go-kit/log" "github.com/opencontainers/selinux/go-selinux" "github.com/prometheus/client_golang/prometheus" + "log/slog" ) type selinuxCollector struct { configMode *prometheus.Desc currentMode *prometheus.Desc enabled *prometheus.Desc - logger log.Logger + logger *slog.Logger } func init() { @@ -34,7 +34,7 @@ func init() { } // NewSelinuxCollector returns a new Collector exposing SELinux statistics. -func NewSelinuxCollector(logger log.Logger) (Collector, error) { +func NewSelinuxCollector(logger *slog.Logger) (Collector, error) { const subsystem = "selinux" return &selinuxCollector{ diff --git a/collector/slabinfo_linux.go b/collector/slabinfo_linux.go index 70241a08e8..aa871548f0 100644 --- a/collector/slabinfo_linux.go +++ b/collector/slabinfo_linux.go @@ -18,9 +18,9 @@ package collector import ( "fmt" + "log/slog" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" ) @@ -32,7 +32,7 @@ var ( type slabinfoCollector struct { fs procfs.FS - logger log.Logger + logger *slog.Logger subsystem string labels []string slabNameFilter deviceFilter @@ -42,7 +42,7 @@ func init() { registerCollector("slabinfo", defaultDisabled, NewSlabinfoCollector) } -func NewSlabinfoCollector(logger log.Logger) (Collector, error) { +func NewSlabinfoCollector(logger *slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) diff --git a/collector/sockstat_linux.go b/collector/sockstat_linux.go index 480c83b1da..73a3bf6836 100644 --- a/collector/sockstat_linux.go +++ b/collector/sockstat_linux.go @@ -19,10 +19,9 @@ package collector import ( "errors" "fmt" + "log/slog" "os" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" ) @@ -35,7 +34,7 @@ const ( var pageSize = os.Getpagesize() type sockStatCollector struct { - logger log.Logger + logger *slog.Logger } func init() { @@ -43,7 +42,7 @@ func init() { } // NewSockStatCollector returns a new Collector exposing socket stats. -func NewSockStatCollector(logger log.Logger) (Collector, error) { +func NewSockStatCollector(logger *slog.Logger) (Collector, error) { return &sockStatCollector{logger}, nil } @@ -58,7 +57,7 @@ func (c *sockStatCollector) Update(ch chan<- prometheus.Metric) error { switch { case err == nil: case errors.Is(err, os.ErrNotExist): - level.Debug(c.logger).Log("msg", "IPv4 sockstat statistics not found, skipping") + c.logger.Debug("IPv4 sockstat statistics not found, skipping") default: return fmt.Errorf("failed to get IPv4 sockstat data: %w", err) } @@ -67,7 +66,7 @@ func (c *sockStatCollector) Update(ch chan<- prometheus.Metric) error { switch { case err == nil: case errors.Is(err, os.ErrNotExist): - level.Debug(c.logger).Log("msg", "IPv6 sockstat statistics not found, skipping") + c.logger.Debug("IPv6 sockstat statistics not found, skipping") default: return fmt.Errorf("failed to get IPv6 sockstat data: %w", err) } diff --git a/collector/softirqs_common.go b/collector/softirqs_common.go index 08ef780f26..cd9ccb9457 100644 --- a/collector/softirqs_common.go +++ b/collector/softirqs_common.go @@ -18,15 +18,15 @@ package collector import ( "fmt" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" + "log/slog" ) type softirqsCollector struct { fs procfs.FS desc typedDesc - logger log.Logger + logger *slog.Logger } func init() { @@ -34,7 +34,7 @@ func init() { } // NewSoftirqsCollector returns a new Collector exposing softirq stats. -func NewSoftirqsCollector(logger log.Logger) (Collector, error) { +func NewSoftirqsCollector(logger *slog.Logger) (Collector, error) { desc := typedDesc{prometheus.NewDesc( namespace+"_softirqs_functions_total", "Softirq counts per CPU.", diff --git a/collector/softnet_linux.go b/collector/softnet_linux.go index 42d47780e3..296e587587 100644 --- a/collector/softnet_linux.go +++ b/collector/softnet_linux.go @@ -18,9 +18,9 @@ package collector import ( "fmt" + "log/slog" "strconv" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" ) @@ -34,7 +34,7 @@ type softnetCollector struct { receivedRps *prometheus.Desc flowLimitCount *prometheus.Desc softnetBacklogLen *prometheus.Desc - logger log.Logger + logger *slog.Logger } const ( @@ -46,7 +46,7 @@ func init() { } // NewSoftnetCollector returns a new Collector exposing softnet metrics. -func NewSoftnetCollector(logger log.Logger) (Collector, error) { +func NewSoftnetCollector(logger *slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) diff --git a/collector/stat_linux.go b/collector/stat_linux.go index 9974ae7aa7..0b99cc3236 100644 --- a/collector/stat_linux.go +++ b/collector/stat_linux.go @@ -18,9 +18,9 @@ package collector import ( "fmt" + "log/slog" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" ) @@ -34,7 +34,7 @@ type statCollector struct { procsRunning *prometheus.Desc procsBlocked *prometheus.Desc softIRQ *prometheus.Desc - logger log.Logger + logger *slog.Logger } var statSoftirqFlag = kingpin.Flag("collector.stat.softirq", "Export softirq calls per vector").Default("false").Bool() @@ -44,7 +44,7 @@ func init() { } // NewStatCollector returns a new Collector exposing kernel/system statistics. -func NewStatCollector(logger log.Logger) (Collector, error) { +func NewStatCollector(logger *slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) diff --git a/collector/supervisord.go b/collector/supervisord.go index 9b517f0a42..ae5e2297a0 100644 --- a/collector/supervisord.go +++ b/collector/supervisord.go @@ -19,14 +19,13 @@ package collector import ( "context" "fmt" + "log/slog" "net" "net/http" "net/url" "time" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/mattn/go-xmlrpc" "github.com/prometheus/client_golang/prometheus" ) @@ -41,7 +40,7 @@ type supervisordCollector struct { stateDesc *prometheus.Desc exitStatusDesc *prometheus.Desc startTimeDesc *prometheus.Desc - logger log.Logger + logger *slog.Logger } func init() { @@ -49,7 +48,7 @@ func init() { } // NewSupervisordCollector returns a new Collector exposing supervisord statistics. -func NewSupervisordCollector(logger log.Logger) (Collector, error) { +func NewSupervisordCollector(logger *slog.Logger) (Collector, error) { var ( subsystem = "supervisord" labelNames = []string{"name", "group"} @@ -69,7 +68,7 @@ func NewSupervisordCollector(logger log.Logger) (Collector, error) { xrpc = xmlrpc.NewClient(*supervisordURL) } - level.Warn(logger).Log("msg", "This collector is deprecated and will be removed in the next major version release.") + logger.Warn("This collector is deprecated and will be removed in the next major version release.") return &supervisordCollector{ upDesc: prometheus.NewDesc( @@ -174,7 +173,7 @@ func (c *supervisordCollector) Update(ch chan<- prometheus.Metric) error { } else { ch <- prometheus.MustNewConstMetric(c.upDesc, prometheus.GaugeValue, 0, labels...) } - level.Debug(c.logger).Log("msg", "process info", "group", info.Group, "name", info.Name, "state", info.StateName, "pid", info.PID) + c.logger.Debug("process info", "group", info.Group, "name", info.Name, "state", info.StateName, "pid", info.PID) } return nil diff --git a/collector/sysctl_linux.go b/collector/sysctl_linux.go index c14341db85..ac7022fbdd 100644 --- a/collector/sysctl_linux.go +++ b/collector/sysctl_linux.go @@ -15,11 +15,11 @@ package collector import ( "fmt" + "log/slog" "strconv" "strings" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" ) @@ -33,7 +33,7 @@ var ( type sysctlCollector struct { fs procfs.FS - logger log.Logger + logger *slog.Logger sysctls []*sysctl } @@ -41,7 +41,7 @@ func init() { registerCollector("sysctl", defaultDisabled, NewSysctlCollector) } -func NewSysctlCollector(logger log.Logger) (Collector, error) { +func NewSysctlCollector(logger *slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open sysfs: %w", err) diff --git a/collector/systemd_linux.go b/collector/systemd_linux.go index e0d35bcde6..ee2ded8d4a 100644 --- a/collector/systemd_linux.go +++ b/collector/systemd_linux.go @@ -20,6 +20,7 @@ import ( "context" "errors" "fmt" + "log/slog" "math" "regexp" "strconv" @@ -29,8 +30,6 @@ import ( "github.com/alecthomas/kingpin/v2" "github.com/coreos/go-systemd/v22/dbus" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" ) @@ -78,7 +77,7 @@ type systemdCollector struct { // Use regexps for more flexibility than device_filter.go allows systemdUnitIncludePattern *regexp.Regexp systemdUnitExcludePattern *regexp.Regexp - logger log.Logger + logger *slog.Logger } var unitStatesName = []string{"active", "activating", "deactivating", "inactive", "failed"} @@ -88,7 +87,7 @@ func init() { } // NewSystemdCollector returns a new Collector exposing systemd statistics. -func NewSystemdCollector(logger log.Logger) (Collector, error) { +func NewSystemdCollector(logger *slog.Logger) (Collector, error) { const subsystem = "systemd" unitDesc := prometheus.NewDesc( @@ -136,7 +135,7 @@ func NewSystemdCollector(logger log.Logger) (Collector, error) { if *oldSystemdUnitExclude != "" { if !systemdUnitExcludeSet { - level.Warn(logger).Log("msg", "--collector.systemd.unit-blacklist is DEPRECATED and will be removed in 2.0.0, use --collector.systemd.unit-exclude") + logger.Warn("--collector.systemd.unit-blacklist is DEPRECATED and will be removed in 2.0.0, use --collector.systemd.unit-exclude") *systemdUnitExclude = *oldSystemdUnitExclude } else { return nil, errors.New("--collector.systemd.unit-blacklist and --collector.systemd.unit-exclude are mutually exclusive") @@ -144,15 +143,15 @@ func NewSystemdCollector(logger log.Logger) (Collector, error) { } if *oldSystemdUnitInclude != "" { if !systemdUnitIncludeSet { - level.Warn(logger).Log("msg", "--collector.systemd.unit-whitelist is DEPRECATED and will be removed in 2.0.0, use --collector.systemd.unit-include") + logger.Warn("--collector.systemd.unit-whitelist is DEPRECATED and will be removed in 2.0.0, use --collector.systemd.unit-include") *systemdUnitInclude = *oldSystemdUnitInclude } else { return nil, errors.New("--collector.systemd.unit-whitelist and --collector.systemd.unit-include are mutually exclusive") } } - level.Info(logger).Log("msg", "Parsed flag --collector.systemd.unit-include", "flag", *systemdUnitInclude) + logger.Info("Parsed flag --collector.systemd.unit-include", "flag", *systemdUnitInclude) systemdUnitIncludePattern := regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *systemdUnitInclude)) - level.Info(logger).Log("msg", "Parsed flag --collector.systemd.unit-exclude", "flag", *systemdUnitExclude) + logger.Info("Parsed flag --collector.systemd.unit-exclude", "flag", *systemdUnitExclude) systemdUnitExcludePattern := regexp.MustCompile(fmt.Sprintf("^(?:%s)$", *systemdUnitExclude)) return &systemdCollector{ @@ -186,7 +185,7 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error { systemdVersion, systemdVersionFull := c.getSystemdVersion(conn) if systemdVersion < minSystemdVersionSystemState { - level.Debug(c.logger).Log("msg", "Detected systemd version is lower than minimum, some systemd state and timer metrics will not be available", "current", systemdVersion, "minimum", minSystemdVersionSystemState) + c.logger.Debug("Detected systemd version is lower than minimum, some systemd state and timer metrics will not be available", "current", systemdVersion, "minimum", minSystemdVersionSystemState) } ch <- prometheus.MustNewConstMetric( c.systemdVersionDesc, @@ -199,16 +198,16 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error { if err != nil { return fmt.Errorf("couldn't get units: %w", err) } - level.Debug(c.logger).Log("msg", "getAllUnits took", "duration_seconds", time.Since(begin).Seconds()) + c.logger.Debug("getAllUnits took", "duration_seconds", time.Since(begin).Seconds()) begin = time.Now() summary := summarizeUnits(allUnits) c.collectSummaryMetrics(ch, summary) - level.Debug(c.logger).Log("msg", "collectSummaryMetrics took", "duration_seconds", time.Since(begin).Seconds()) + c.logger.Debug("collectSummaryMetrics took", "duration_seconds", time.Since(begin).Seconds()) begin = time.Now() units := filterUnits(allUnits, c.systemdUnitIncludePattern, c.systemdUnitExcludePattern, c.logger) - level.Debug(c.logger).Log("msg", "filterUnits took", "duration_seconds", time.Since(begin).Seconds()) + c.logger.Debug("filterUnits took", "duration_seconds", time.Since(begin).Seconds()) var wg sync.WaitGroup defer wg.Wait() @@ -218,7 +217,7 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error { defer wg.Done() begin = time.Now() c.collectUnitStatusMetrics(conn, ch, units) - level.Debug(c.logger).Log("msg", "collectUnitStatusMetrics took", "duration_seconds", time.Since(begin).Seconds()) + c.logger.Debug("collectUnitStatusMetrics took", "duration_seconds", time.Since(begin).Seconds()) }() if *enableStartTimeMetrics { @@ -227,7 +226,7 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error { defer wg.Done() begin = time.Now() c.collectUnitStartTimeMetrics(conn, ch, units) - level.Debug(c.logger).Log("msg", "collectUnitStartTimeMetrics took", "duration_seconds", time.Since(begin).Seconds()) + c.logger.Debug("collectUnitStartTimeMetrics took", "duration_seconds", time.Since(begin).Seconds()) }() } @@ -237,7 +236,7 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error { defer wg.Done() begin = time.Now() c.collectUnitTasksMetrics(conn, ch, units) - level.Debug(c.logger).Log("msg", "collectUnitTasksMetrics took", "duration_seconds", time.Since(begin).Seconds()) + c.logger.Debug("collectUnitTasksMetrics took", "duration_seconds", time.Since(begin).Seconds()) }() } @@ -247,7 +246,7 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error { defer wg.Done() begin = time.Now() c.collectTimers(conn, ch, units) - level.Debug(c.logger).Log("msg", "collectTimers took", "duration_seconds", time.Since(begin).Seconds()) + c.logger.Debug("collectTimers took", "duration_seconds", time.Since(begin).Seconds()) }() } @@ -256,13 +255,13 @@ func (c *systemdCollector) Update(ch chan<- prometheus.Metric) error { defer wg.Done() begin = time.Now() c.collectSockets(conn, ch, units) - level.Debug(c.logger).Log("msg", "collectSockets took", "duration_seconds", time.Since(begin).Seconds()) + c.logger.Debug("collectSockets took", "duration_seconds", time.Since(begin).Seconds()) }() if systemdVersion >= minSystemdVersionSystemState { begin = time.Now() err = c.collectSystemState(conn, ch) - level.Debug(c.logger).Log("msg", "collectSystemState took", "duration_seconds", time.Since(begin).Seconds()) + c.logger.Debug("collectSystemState took", "duration_seconds", time.Since(begin).Seconds()) } return err @@ -274,14 +273,14 @@ func (c *systemdCollector) collectUnitStatusMetrics(conn *dbus.Conn, ch chan<- p if strings.HasSuffix(unit.Name, ".service") { serviceTypeProperty, err := conn.GetUnitTypePropertyContext(context.TODO(), unit.Name, "Service", "Type") if err != nil { - level.Debug(c.logger).Log("msg", "couldn't get unit type", "unit", unit.Name, "err", err) + c.logger.Debug("couldn't get unit type", "unit", unit.Name, "err", err) } else { serviceType = serviceTypeProperty.Value.Value().(string) } } else if strings.HasSuffix(unit.Name, ".mount") { serviceTypeProperty, err := conn.GetUnitTypePropertyContext(context.TODO(), unit.Name, "Mount", "Type") if err != nil { - level.Debug(c.logger).Log("msg", "couldn't get unit type", "unit", unit.Name, "err", err) + c.logger.Debug("couldn't get unit type", "unit", unit.Name, "err", err) } else { serviceType = serviceTypeProperty.Value.Value().(string) } @@ -299,7 +298,7 @@ func (c *systemdCollector) collectUnitStatusMetrics(conn *dbus.Conn, ch chan<- p // NRestarts wasn't added until systemd 235. restartsCount, err := conn.GetUnitTypePropertyContext(context.TODO(), unit.Name, "Service", "NRestarts") if err != nil { - level.Debug(c.logger).Log("msg", "couldn't get unit NRestarts", "unit", unit.Name, "err", err) + c.logger.Debug("couldn't get unit NRestarts", "unit", unit.Name, "err", err) } else { ch <- prometheus.MustNewConstMetric( c.nRestartsDesc, prometheus.CounterValue, @@ -317,7 +316,7 @@ func (c *systemdCollector) collectSockets(conn *dbus.Conn, ch chan<- prometheus. acceptedConnectionCount, err := conn.GetUnitTypePropertyContext(context.TODO(), unit.Name, "Socket", "NAccepted") if err != nil { - level.Debug(c.logger).Log("msg", "couldn't get unit NAccepted", "unit", unit.Name, "err", err) + c.logger.Debug("couldn't get unit NAccepted", "unit", unit.Name, "err", err) continue } ch <- prometheus.MustNewConstMetric( @@ -326,7 +325,7 @@ func (c *systemdCollector) collectSockets(conn *dbus.Conn, ch chan<- prometheus. currentConnectionCount, err := conn.GetUnitTypePropertyContext(context.TODO(), unit.Name, "Socket", "NConnections") if err != nil { - level.Debug(c.logger).Log("msg", "couldn't get unit NConnections", "unit", unit.Name, "err", err) + c.logger.Debug("couldn't get unit NConnections", "unit", unit.Name, "err", err) continue } ch <- prometheus.MustNewConstMetric( @@ -352,7 +351,7 @@ func (c *systemdCollector) collectUnitStartTimeMetrics(conn *dbus.Conn, ch chan< } else { timestampValue, err := conn.GetUnitPropertyContext(context.TODO(), unit.Name, "ActiveEnterTimestamp") if err != nil { - level.Debug(c.logger).Log("msg", "couldn't get unit StartTimeUsec", "unit", unit.Name, "err", err) + c.logger.Debug("couldn't get unit StartTimeUsec", "unit", unit.Name, "err", err) continue } startTimeUsec = timestampValue.Value.Value().(uint64) @@ -370,7 +369,7 @@ func (c *systemdCollector) collectUnitTasksMetrics(conn *dbus.Conn, ch chan<- pr if strings.HasSuffix(unit.Name, ".service") { tasksCurrentCount, err := conn.GetUnitTypePropertyContext(context.TODO(), unit.Name, "Service", "TasksCurrent") if err != nil { - level.Debug(c.logger).Log("msg", "couldn't get unit TasksCurrent", "unit", unit.Name, "err", err) + c.logger.Debug("couldn't get unit TasksCurrent", "unit", unit.Name, "err", err) } else { val = tasksCurrentCount.Value.Value().(uint64) // Don't set if tasksCurrent if dbus reports MaxUint64. @@ -382,7 +381,7 @@ func (c *systemdCollector) collectUnitTasksMetrics(conn *dbus.Conn, ch chan<- pr } tasksMaxCount, err := conn.GetUnitTypePropertyContext(context.TODO(), unit.Name, "Service", "TasksMax") if err != nil { - level.Debug(c.logger).Log("msg", "couldn't get unit TasksMax", "unit", unit.Name, "err", err) + c.logger.Debug("couldn't get unit TasksMax", "unit", unit.Name, "err", err) } else { val = tasksMaxCount.Value.Value().(uint64) // Don't set if tasksMax if dbus reports MaxUint64. @@ -404,7 +403,7 @@ func (c *systemdCollector) collectTimers(conn *dbus.Conn, ch chan<- prometheus.M lastTriggerValue, err := conn.GetUnitTypePropertyContext(context.TODO(), unit.Name, "Timer", "LastTriggerUSec") if err != nil { - level.Debug(c.logger).Log("msg", "couldn't get unit LastTriggerUSec", "unit", unit.Name, "err", err) + c.logger.Debug("couldn't get unit LastTriggerUSec", "unit", unit.Name, "err", err) continue } @@ -476,14 +475,14 @@ func summarizeUnits(units []unit) map[string]float64 { return summarized } -func filterUnits(units []unit, includePattern, excludePattern *regexp.Regexp, logger log.Logger) []unit { +func filterUnits(units []unit, includePattern, excludePattern *regexp.Regexp, logger *slog.Logger) []unit { filtered := make([]unit, 0, len(units)) for _, unit := range units { if includePattern.MatchString(unit.Name) && !excludePattern.MatchString(unit.Name) && unit.LoadState == "loaded" { - level.Debug(logger).Log("msg", "Adding unit", "unit", unit.Name) + logger.Debug("Adding unit", "unit", unit.Name) filtered = append(filtered, unit) } else { - level.Debug(logger).Log("msg", "Ignoring unit", "unit", unit.Name) + logger.Debug("Ignoring unit", "unit", unit.Name) } } @@ -493,15 +492,15 @@ func filterUnits(units []unit, includePattern, excludePattern *regexp.Regexp, lo func (c *systemdCollector) getSystemdVersion(conn *dbus.Conn) (float64, string) { version, err := conn.GetManagerProperty("Version") if err != nil { - level.Debug(c.logger).Log("msg", "Unable to get systemd version property, defaulting to 0") + c.logger.Debug("Unable to get systemd version property, defaulting to 0") return 0, "" } version = strings.TrimPrefix(strings.TrimSuffix(version, `"`), `"`) - level.Debug(c.logger).Log("msg", "Got systemd version", "version", version) + c.logger.Debug("Got systemd version", "version", version) parsedVersion := systemdVersionRE.FindString(version) v, err := strconv.ParseFloat(parsedVersion, 64) if err != nil { - level.Debug(c.logger).Log("msg", "Got invalid systemd version", "version", version) + c.logger.Debug("Got invalid systemd version", "version", version) return 0, "" } return v, version diff --git a/collector/systemd_linux_test.go b/collector/systemd_linux_test.go index d4e300d1d2..1c290377e6 100644 --- a/collector/systemd_linux_test.go +++ b/collector/systemd_linux_test.go @@ -17,11 +17,12 @@ package collector import ( + "io" + "log/slog" "regexp" "testing" "github.com/coreos/go-systemd/v22/dbus" - "github.com/go-kit/log" ) // Creates mock UnitLists @@ -94,7 +95,7 @@ func TestSystemdIgnoreFilter(t *testing.T) { fixtures := getUnitListFixtures() includePattern := regexp.MustCompile("^foo$") excludePattern := regexp.MustCompile("^bar$") - filtered := filterUnits(fixtures[0], includePattern, excludePattern, log.NewNopLogger()) + filtered := filterUnits(fixtures[0], includePattern, excludePattern, slog.New(slog.NewTextHandler(io.Discard, nil))) for _, unit := range filtered { if excludePattern.MatchString(unit.Name) || !includePattern.MatchString(unit.Name) { t.Error(unit.Name, "should not be in the filtered list") @@ -102,7 +103,7 @@ func TestSystemdIgnoreFilter(t *testing.T) { } } func TestSystemdIgnoreFilterDefaultKeepsAll(t *testing.T) { - logger := log.NewNopLogger() + logger := slog.New(slog.NewTextHandler(io.Discard, nil)) c, err := NewSystemdCollector(logger) if err != nil { t.Fatal(err) diff --git a/collector/tapestats_linux.go b/collector/tapestats_linux.go index 264c2210f1..c74c11d04c 100644 --- a/collector/tapestats_linux.go +++ b/collector/tapestats_linux.go @@ -18,12 +18,11 @@ package collector import ( "fmt" + "log/slog" "os" "regexp" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs/sysfs" ) @@ -45,7 +44,7 @@ type tapestatsCollector struct { writeTimeSeconds *prometheus.Desc residualTotal *prometheus.Desc fs sysfs.FS - logger log.Logger + logger *slog.Logger } func init() { @@ -54,7 +53,7 @@ func init() { // NewTapestatsCollector returns a new Collector exposing tape device stats. // Docs from https://www.kernel.org/doc/html/latest/scsi/st.html#sysfs-and-statistics-for-tape-devices -func NewTapestatsCollector(logger log.Logger) (Collector, error) { +func NewTapestatsCollector(logger *slog.Logger) (Collector, error) { var tapeLabelNames = []string{"device"} fs, err := sysfs.NewFS(*sysPath) @@ -126,7 +125,7 @@ func (c *tapestatsCollector) Update(ch chan<- prometheus.Metric) error { tapes, err := c.fs.SCSITapeClass() if err != nil { if os.IsNotExist(err) { - level.Debug(c.logger).Log("msg", "scsi_tape stats not found, skipping") + c.logger.Debug("scsi_tape stats not found, skipping") return ErrNoData } return fmt.Errorf("error obtaining SCSITape class info: %s", err) @@ -134,7 +133,7 @@ func (c *tapestatsCollector) Update(ch chan<- prometheus.Metric) error { for _, tape := range tapes { if c.ignoredDevicesPattern.MatchString(tape.Name) { - level.Debug(c.logger).Log("msg", "Ignoring device", "device", tape.Name) + c.logger.Debug("Ignoring device", "device", tape.Name) continue } ch <- prometheus.MustNewConstMetric(c.ioNow, prometheus.GaugeValue, float64(tape.Counters.InFlight), tape.Name) diff --git a/collector/tcpstat_linux.go b/collector/tcpstat_linux.go index 99e33bc6a3..476a9b47bf 100644 --- a/collector/tcpstat_linux.go +++ b/collector/tcpstat_linux.go @@ -18,11 +18,11 @@ package collector import ( "fmt" + "log/slog" "os" "syscall" "unsafe" - "github.com/go-kit/log" "github.com/mdlayher/netlink" "github.com/prometheus/client_golang/prometheus" ) @@ -60,7 +60,7 @@ const ( type tcpStatCollector struct { desc typedDesc - logger log.Logger + logger *slog.Logger } func init() { @@ -68,7 +68,7 @@ func init() { } // NewTCPStatCollector returns a new Collector exposing network stats. -func NewTCPStatCollector(logger log.Logger) (Collector, error) { +func NewTCPStatCollector(logger *slog.Logger) (Collector, error) { return &tcpStatCollector{ desc: typedDesc{prometheus.NewDesc( prometheus.BuildFQName(namespace, "tcp", "connection_states"), diff --git a/collector/textfile.go b/collector/textfile.go index 4f1fd0b8c7..6c831489b0 100644 --- a/collector/textfile.go +++ b/collector/textfile.go @@ -18,6 +18,7 @@ package collector import ( "fmt" + "log/slog" "os" "path/filepath" "sort" @@ -25,8 +26,6 @@ import ( "time" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" dto "github.com/prometheus/client_model/go" "github.com/prometheus/common/expfmt" @@ -46,7 +45,7 @@ type textFileCollector struct { path string // Only set for testing to get predictable output. mtime *float64 - logger log.Logger + logger *slog.Logger } func init() { @@ -55,7 +54,7 @@ func init() { // NewTextFileCollector returns a new Collector exposing metrics read from files // in the given textfile directory. -func NewTextFileCollector(logger log.Logger) (Collector, error) { +func NewTextFileCollector(logger *slog.Logger) (Collector, error) { c := &textFileCollector{ path: *textFileDirectory, logger: logger, @@ -63,7 +62,7 @@ func NewTextFileCollector(logger log.Logger) (Collector, error) { return c, nil } -func convertMetricFamily(metricFamily *dto.MetricFamily, ch chan<- prometheus.Metric, logger log.Logger) { +func convertMetricFamily(metricFamily *dto.MetricFamily, ch chan<- prometheus.Metric, logger *slog.Logger) { var valType prometheus.ValueType var val float64 @@ -79,7 +78,7 @@ func convertMetricFamily(metricFamily *dto.MetricFamily, ch chan<- prometheus.Me for _, metric := range metricFamily.Metric { if metric.TimestampMs != nil { - level.Warn(logger).Log("msg", "Ignoring unsupported custom timestamp on textfile collector metric", "metric", metric) + logger.Warn("Ignoring unsupported custom timestamp on textfile collector metric", "metric", metric) } labels := metric.GetLabel() @@ -207,7 +206,7 @@ func (c *textFileCollector) Update(ch chan<- prometheus.Metric) error { files, err := os.ReadDir(path) if err != nil && path != "" { errored = true - level.Error(c.logger).Log("msg", "failed to read textfile collector directory", "path", path, "err", err) + c.logger.Error("failed to read textfile collector directory", "path", path, "err", err) } for _, f := range files { @@ -224,7 +223,7 @@ func (c *textFileCollector) Update(ch chan<- prometheus.Metric) error { if mf.Help != nil && helpTexts[0] != *mf.Help || helpTexts[1] != "" { metricsNamesToHelpTexts[*mf.Name] = [2]string{helpTexts[0], *mf.Help} errored = true - level.Error(c.logger).Log("msg", "inconsistent metric help text", + c.logger.Error("inconsistent metric help text", "metric", *mf.Name, "original_help_text", helpTexts[0], "new_help_text", *mf.Help, @@ -242,7 +241,7 @@ func (c *textFileCollector) Update(ch chan<- prometheus.Metric) error { if err != nil { errored = true - level.Error(c.logger).Log("msg", "failed to collect textfile data", "file", f.Name(), "err", err) + c.logger.Error("failed to collect textfile data", "file", f.Name(), "err", err) continue } diff --git a/collector/textfile_test.go b/collector/textfile_test.go index 95e5966f3e..cd08c64fe9 100644 --- a/collector/textfile_test.go +++ b/collector/textfile_test.go @@ -18,17 +18,18 @@ package collector import ( "fmt" + "io" + "log/slog" "net/http" "net/http/httptest" "os" "testing" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/promhttp" - "github.com/prometheus/common/promlog" - "github.com/prometheus/common/promlog/flag" + "github.com/prometheus/common/promslog" + "github.com/prometheus/common/promslog/flag" ) type collectorAdapter struct { @@ -121,13 +122,13 @@ func TestTextfileCollector(t *testing.T) { c := &textFileCollector{ path: test.path, mtime: &mtime, - logger: log.NewNopLogger(), + logger: slog.New(slog.NewTextHandler(io.Discard, nil)), } // Suppress a log message about `nonexistent_path` not existing, this is // expected and clutters the test output. - promlogConfig := &promlog.Config{} - flag.AddFlags(kingpin.CommandLine, promlogConfig) + promslogConfig := &promslog.Config{} + flag.AddFlags(kingpin.CommandLine, promslogConfig) if _, err := kingpin.CommandLine.Parse([]string{"--log.level", "debug"}); err != nil { t.Fatal(err) } diff --git a/collector/thermal_darwin.go b/collector/thermal_darwin.go index 25673dcc4d..0a3b8981f4 100644 --- a/collector/thermal_darwin.go +++ b/collector/thermal_darwin.go @@ -47,9 +47,9 @@ import "C" import ( "errors" "fmt" + "log/slog" "unsafe" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) @@ -57,7 +57,7 @@ type thermCollector struct { cpuSchedulerLimit typedDesc cpuAvailableCPU typedDesc cpuSpeedLimit typedDesc - logger log.Logger + logger *slog.Logger } const thermal = "thermal" @@ -67,7 +67,7 @@ func init() { } // NewThermCollector returns a new Collector exposing current CPU power levels. -func NewThermCollector(logger log.Logger) (Collector, error) { +func NewThermCollector(logger *slog.Logger) (Collector, error) { return &thermCollector{ cpuSchedulerLimit: typedDesc{ desc: prometheus.NewDesc( diff --git a/collector/thermal_zone_linux.go b/collector/thermal_zone_linux.go index 6eff27321a..95db272340 100644 --- a/collector/thermal_zone_linux.go +++ b/collector/thermal_zone_linux.go @@ -19,10 +19,9 @@ package collector import ( "errors" "fmt" + "log/slog" "os" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs/sysfs" ) @@ -35,7 +34,7 @@ type thermalZoneCollector struct { coolingDeviceCurState *prometheus.Desc coolingDeviceMaxState *prometheus.Desc zoneTemp *prometheus.Desc - logger log.Logger + logger *slog.Logger } func init() { @@ -43,7 +42,7 @@ func init() { } // NewThermalZoneCollector returns a new Collector exposing kernel/system statistics. -func NewThermalZoneCollector(logger log.Logger) (Collector, error) { +func NewThermalZoneCollector(logger *slog.Logger) (Collector, error) { fs, err := sysfs.NewFS(*sysPath) if err != nil { return nil, fmt.Errorf("failed to open sysfs: %w", err) @@ -74,7 +73,7 @@ func (c *thermalZoneCollector) Update(ch chan<- prometheus.Metric) error { thermalZones, err := c.fs.ClassThermalZoneStats() if err != nil { if errors.Is(err, os.ErrNotExist) || errors.Is(err, os.ErrPermission) || errors.Is(err, os.ErrInvalid) { - level.Debug(c.logger).Log("msg", "Could not read thermal zone stats", "err", err) + c.logger.Debug("Could not read thermal zone stats", "err", err) return ErrNoData } return err diff --git a/collector/time.go b/collector/time.go index 31a6e74e24..a4a81687b4 100644 --- a/collector/time.go +++ b/collector/time.go @@ -17,10 +17,9 @@ package collector import ( + "log/slog" "time" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" ) @@ -29,7 +28,7 @@ type timeCollector struct { zone typedDesc clocksourcesAvailable typedDesc clocksourceCurrent typedDesc - logger log.Logger + logger *slog.Logger } func init() { @@ -38,7 +37,7 @@ func init() { // NewTimeCollector returns a new Collector exposing the current system time in // seconds since epoch. -func NewTimeCollector(logger log.Logger) (Collector, error) { +func NewTimeCollector(logger *slog.Logger) (Collector, error) { const subsystem = "time" return &timeCollector{ now: typedDesc{prometheus.NewDesc( @@ -70,9 +69,9 @@ func (c *timeCollector) Update(ch chan<- prometheus.Metric) error { nowSec := float64(now.UnixNano()) / 1e9 zone, zoneOffset := now.Zone() - level.Debug(c.logger).Log("msg", "Return time", "now", nowSec) + c.logger.Debug("Return time", "now", nowSec) ch <- c.now.mustNewConstMetric(nowSec) - level.Debug(c.logger).Log("msg", "Zone offset", "offset", zoneOffset, "time_zone", zone) + c.logger.Debug("Zone offset", "offset", zoneOffset, "time_zone", zone) ch <- c.zone.mustNewConstMetric(float64(zoneOffset), zone) return c.update(ch) } diff --git a/collector/time_linux.go b/collector/time_linux.go index dd4afe7592..212ba2280a 100644 --- a/collector/time_linux.go +++ b/collector/time_linux.go @@ -20,7 +20,6 @@ import ( "fmt" "strconv" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs/sysfs" ) @@ -35,7 +34,7 @@ func (c *timeCollector) update(ch chan<- prometheus.Metric) error { if err != nil { return fmt.Errorf("couldn't get clocksources: %w", err) } - level.Debug(c.logger).Log("msg", "in Update", "clocksources", fmt.Sprintf("%v", clocksources)) + c.logger.Debug("in Update", "clocksources", fmt.Sprintf("%v", clocksources)) for i, clocksource := range clocksources { is := strconv.Itoa(i) diff --git a/collector/timex.go b/collector/timex.go index 69cbc1a1d0..eb21f7c370 100644 --- a/collector/timex.go +++ b/collector/timex.go @@ -19,10 +19,9 @@ package collector import ( "errors" "fmt" + "log/slog" "os" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "golang.org/x/sys/unix" ) @@ -61,7 +60,7 @@ type timexCollector struct { stbcnt, tai, syncStatus typedDesc - logger log.Logger + logger *slog.Logger } func init() { @@ -69,7 +68,7 @@ func init() { } // NewTimexCollector returns a new Collector exposing adjtime(3) stats. -func NewTimexCollector(logger log.Logger) (Collector, error) { +func NewTimexCollector(logger *slog.Logger) (Collector, error) { const subsystem = "timex" return &timexCollector{ @@ -170,7 +169,7 @@ func (c *timexCollector) Update(ch chan<- prometheus.Metric) error { status, err := unix.Adjtimex(timex) if err != nil { if errors.Is(err, os.ErrPermission) { - level.Debug(c.logger).Log("msg", "Not collecting timex metrics", "err", err) + c.logger.Debug("Not collecting timex metrics", "err", err) return ErrNoData } return fmt.Errorf("failed to retrieve adjtimex stats: %w", err) diff --git a/collector/udp_queues_linux.go b/collector/udp_queues_linux.go index 3fac869198..2923936e38 100644 --- a/collector/udp_queues_linux.go +++ b/collector/udp_queues_linux.go @@ -19,10 +19,9 @@ package collector import ( "errors" "fmt" + "log/slog" "os" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" ) @@ -31,7 +30,7 @@ type ( udpQueuesCollector struct { fs procfs.FS desc *prometheus.Desc - logger log.Logger + logger *slog.Logger } ) @@ -40,7 +39,7 @@ func init() { } // NewUDPqueuesCollector returns a new Collector exposing network udp queued bytes. -func NewUDPqueuesCollector(logger log.Logger) (Collector, error) { +func NewUDPqueuesCollector(logger *slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) @@ -64,7 +63,7 @@ func (c *udpQueuesCollector) Update(ch chan<- prometheus.Metric) error { ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s4.RxQueueLength), "rx", "v4") } else { if errors.Is(errIPv4, os.ErrNotExist) { - level.Debug(c.logger).Log("msg", "not collecting ipv4 based metrics") + c.logger.Debug("not collecting ipv4 based metrics") } else { return fmt.Errorf("couldn't get udp queued bytes: %w", errIPv4) } @@ -76,7 +75,7 @@ func (c *udpQueuesCollector) Update(ch chan<- prometheus.Metric) error { ch <- prometheus.MustNewConstMetric(c.desc, prometheus.GaugeValue, float64(s6.RxQueueLength), "rx", "v6") } else { if errors.Is(errIPv6, os.ErrNotExist) { - level.Debug(c.logger).Log("msg", "not collecting ipv6 based metrics") + c.logger.Debug("not collecting ipv6 based metrics") } else { return fmt.Errorf("couldn't get udp6 queued bytes: %w", errIPv6) } diff --git a/collector/uname.go b/collector/uname.go index 76e66b7e33..a333fd487d 100644 --- a/collector/uname.go +++ b/collector/uname.go @@ -18,8 +18,8 @@ package collector import ( - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" + "log/slog" ) var unameDesc = prometheus.NewDesc( @@ -37,7 +37,7 @@ var unameDesc = prometheus.NewDesc( ) type unameCollector struct { - logger log.Logger + logger *slog.Logger } type uname struct { SysName string @@ -53,7 +53,7 @@ func init() { } // NewUnameCollector returns new unameCollector. -func newUnameCollector(logger log.Logger) (Collector, error) { +func newUnameCollector(logger *slog.Logger) (Collector, error) { return &unameCollector{logger}, nil } diff --git a/collector/vmstat_linux.go b/collector/vmstat_linux.go index cde2df5da5..e31be0f7b8 100644 --- a/collector/vmstat_linux.go +++ b/collector/vmstat_linux.go @@ -19,13 +19,13 @@ package collector import ( "bufio" "fmt" + "log/slog" "os" "regexp" "strconv" "strings" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" ) @@ -39,7 +39,7 @@ var ( type vmStatCollector struct { fieldPattern *regexp.Regexp - logger log.Logger + logger *slog.Logger } func init() { @@ -47,7 +47,7 @@ func init() { } // NewvmStatCollector returns a new Collector exposing vmstat stats. -func NewvmStatCollector(logger log.Logger) (Collector, error) { +func NewvmStatCollector(logger *slog.Logger) (Collector, error) { pattern := regexp.MustCompile(*vmStatFields) return &vmStatCollector{ fieldPattern: pattern, diff --git a/collector/watchdog.go b/collector/watchdog.go index 01351be9b5..77fb792ea7 100644 --- a/collector/watchdog.go +++ b/collector/watchdog.go @@ -19,17 +19,16 @@ package collector import ( "errors" "fmt" + "log/slog" "os" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs/sysfs" ) type watchdogCollector struct { fs sysfs.FS - logger log.Logger + logger *slog.Logger } func init() { @@ -37,7 +36,7 @@ func init() { } // NewWatchdogCollector returns a new Collector exposing watchdog stats. -func NewWatchdogCollector(logger log.Logger) (Collector, error) { +func NewWatchdogCollector(logger *slog.Logger) (Collector, error) { fs, err := sysfs.NewFS(*sysPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) @@ -103,7 +102,7 @@ func (c *watchdogCollector) Update(ch chan<- prometheus.Metric) error { watchdogClass, err := c.fs.WatchdogClass() if err != nil { if errors.Is(err, os.ErrNotExist) || errors.Is(err, os.ErrPermission) || errors.Is(err, os.ErrInvalid) { - level.Debug(c.logger).Log("msg", "Could not read watchdog stats", "err", err) + c.logger.Debug("Could not read watchdog stats", "err", err) return ErrNoData } return err diff --git a/collector/watchdog_test.go b/collector/watchdog_test.go index e59382b4c9..baf08995ce 100644 --- a/collector/watchdog_test.go +++ b/collector/watchdog_test.go @@ -18,11 +18,11 @@ package collector import ( "fmt" - "os" + "io" + "log/slog" "strings" "testing" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/testutil" ) @@ -68,7 +68,7 @@ func TestWatchdogStats(t *testing.T) { ` *sysPath = "fixtures/sys" - logger := log.NewLogfmtLogger(os.Stderr) + logger := slog.New(slog.NewTextHandler(io.Discard, nil)) c, err := NewWatchdogCollector(logger) if err != nil { t.Fatal(err) diff --git a/collector/wifi_linux.go b/collector/wifi_linux.go index aff8eb2d36..c84cdd71d4 100644 --- a/collector/wifi_linux.go +++ b/collector/wifi_linux.go @@ -20,12 +20,11 @@ import ( "encoding/json" "errors" "fmt" + "log/slog" "os" "path/filepath" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/mdlayher/wifi" "github.com/prometheus/client_golang/prometheus" ) @@ -45,7 +44,7 @@ type wifiCollector struct { stationTransmitFailedTotal *prometheus.Desc stationBeaconLossTotal *prometheus.Desc - logger log.Logger + logger *slog.Logger } var ( @@ -67,7 +66,7 @@ type wifiStater interface { } // NewWifiCollector returns a new Collector exposing Wifi statistics. -func NewWifiCollector(logger log.Logger) (Collector, error) { +func NewWifiCollector(logger *slog.Logger) (Collector, error) { const ( subsystem = "wifi" ) @@ -169,11 +168,11 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error { if err != nil { // Cannot access wifi metrics, report no error. if errors.Is(err, os.ErrNotExist) { - level.Debug(c.logger).Log("msg", "wifi collector metrics are not available for this system") + c.logger.Debug("wifi collector metrics are not available for this system") return ErrNoData } if errors.Is(err, os.ErrPermission) { - level.Debug(c.logger).Log("msg", "wifi collector got permission denied when accessing metrics") + c.logger.Debug("wifi collector got permission denied when accessing metrics") return ErrNoData } @@ -192,7 +191,7 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error { continue } - level.Debug(c.logger).Log("msg", "probing wifi device with type", "wifi", ifi.Name, "type", ifi.Type) + c.logger.Debug("probing wifi device with type", "wifi", ifi.Name, "type", ifi.Type) ch <- prometheus.MustNewConstMetric( c.interfaceFrequencyHertz, @@ -210,7 +209,7 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error { case err == nil: c.updateBSSStats(ch, ifi.Name, bss) case errors.Is(err, os.ErrNotExist): - level.Debug(c.logger).Log("msg", "BSS information not found for wifi device", "name", ifi.Name) + c.logger.Debug("BSS information not found for wifi device", "name", ifi.Name) default: return fmt.Errorf("failed to retrieve BSS for device %s: %v", ifi.Name, err) @@ -223,7 +222,7 @@ func (c *wifiCollector) Update(ch chan<- prometheus.Metric) error { c.updateStationStats(ch, ifi.Name, station) } case errors.Is(err, os.ErrNotExist): - level.Debug(c.logger).Log("msg", "station information not found for wifi device", "name", ifi.Name) + c.logger.Debug("station information not found for wifi device", "name", ifi.Name) default: return fmt.Errorf("failed to retrieve station info for device %q: %v", ifi.Name, err) diff --git a/collector/xfrm.go b/collector/xfrm.go index cbdcc97f1f..d96ee8aa74 100644 --- a/collector/xfrm.go +++ b/collector/xfrm.go @@ -18,15 +18,15 @@ package collector import ( "fmt" + "log/slog" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" ) type xfrmCollector struct { fs procfs.FS - logger log.Logger + logger *slog.Logger } func init() { @@ -34,7 +34,7 @@ func init() { } // NewXfrmCollector returns a new Collector exposing XFRM stats. -func NewXfrmCollector(logger log.Logger) (Collector, error) { +func NewXfrmCollector(logger *slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) diff --git a/collector/xfrm_test.go b/collector/xfrm_test.go index 2e1ac02899..e009fc40f5 100644 --- a/collector/xfrm_test.go +++ b/collector/xfrm_test.go @@ -18,11 +18,11 @@ package collector import ( "fmt" - "os" + "io" + "log/slog" "strings" "testing" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus/testutil" ) @@ -127,7 +127,7 @@ func TestXfrmStats(t *testing.T) { ` *procPath = "fixtures/proc" - logger := log.NewLogfmtLogger(os.Stderr) + logger := slog.New(slog.NewTextHandler(io.Discard, nil)) c, err := NewXfrmCollector(logger) if err != nil { t.Fatal(err) diff --git a/collector/xfs_linux.go b/collector/xfs_linux.go index bb25acab9f..3eac1d0e84 100644 --- a/collector/xfs_linux.go +++ b/collector/xfs_linux.go @@ -18,8 +18,8 @@ package collector import ( "fmt" + "log/slog" - "github.com/go-kit/log" "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs/xfs" ) @@ -27,7 +27,7 @@ import ( // An xfsCollector is a Collector which gathers metrics from XFS filesystems. type xfsCollector struct { fs xfs.FS - logger log.Logger + logger *slog.Logger } func init() { @@ -35,7 +35,7 @@ func init() { } // NewXFSCollector returns a new Collector exposing XFS statistics. -func NewXFSCollector(logger log.Logger) (Collector, error) { +func NewXFSCollector(logger *slog.Logger) (Collector, error) { fs, err := xfs.NewFS(*procPath, *sysPath) if err != nil { return nil, fmt.Errorf("failed to open sysfs: %w", err) diff --git a/collector/zfs.go b/collector/zfs.go index 0abb13327d..8581e0a24b 100644 --- a/collector/zfs.go +++ b/collector/zfs.go @@ -18,10 +18,9 @@ package collector import ( "errors" + "log/slog" "strings" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" ) @@ -39,11 +38,11 @@ type zfsCollector struct { linuxZpoolObjsetPath string linuxZpoolStatePath string linuxPathMap map[string]string - logger log.Logger + logger *slog.Logger } // NewZFSCollector returns a new Collector exposing ZFS statistics. -func NewZFSCollector(logger log.Logger) (Collector, error) { +func NewZFSCollector(logger *slog.Logger) (Collector, error) { return &zfsCollector{ linuxProcpathBase: "spl/kstat/zfs", linuxZpoolIoPath: "/*/io", @@ -70,7 +69,7 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error { if _, err := c.openProcFile(c.linuxProcpathBase); err != nil { if err == errZFSNotAvailable { - level.Debug(c.logger).Log("err", err) + c.logger.Debug(err.Error()) return ErrNoData } } @@ -78,7 +77,7 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error { for subsystem := range c.linuxPathMap { if err := c.updateZfsStats(subsystem, ch); err != nil { if err == errZFSNotAvailable { - level.Debug(c.logger).Log("err", err) + c.logger.Debug(err.Error()) // ZFS /proc files are added as new features to ZFS arrive, it is ok to continue continue } diff --git a/collector/zfs_freebsd.go b/collector/zfs_freebsd.go index 804d4f58a9..654957811c 100644 --- a/collector/zfs_freebsd.go +++ b/collector/zfs_freebsd.go @@ -17,14 +17,13 @@ package collector import ( - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" + "log/slog" ) type zfsCollector struct { sysctls []bsdSysctl - logger log.Logger + logger *slog.Logger } const ( @@ -35,7 +34,7 @@ func init() { registerCollector("zfs", defaultEnabled, NewZfsCollector) } -func NewZfsCollector(logger log.Logger) (Collector, error) { +func NewZfsCollector(logger *slog.Logger) (Collector, error) { return &zfsCollector{ sysctls: []bsdSysctl{ { @@ -273,7 +272,7 @@ func (c *zfsCollector) Update(ch chan<- prometheus.Metric) error { v, err := m.Value() if err != nil { // debug logging - level.Debug(c.logger).Log("name", m.name, "mib", m.mib, "couldn't get sysctl:", err) + c.logger.Debug(m.name, "mib", m.mib, "couldn't get sysctl:", err) continue } diff --git a/collector/zfs_linux.go b/collector/zfs_linux.go index e1bf2c97c0..31e610d52d 100644 --- a/collector/zfs_linux.go +++ b/collector/zfs_linux.go @@ -25,7 +25,6 @@ import ( "strconv" "strings" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" ) @@ -50,7 +49,7 @@ func (c *zfsCollector) openProcFile(path string) (*os.File, error) { // file not found error can occur if: // 1. zfs module is not loaded // 2. zfs version does not have the feature with metrics -- ok to ignore - level.Debug(c.logger).Log("msg", "Cannot open file for reading", "path", procFilePath(path)) + c.logger.Debug("Cannot open file for reading", "path", procFilePath(path)) return nil, errZFSNotAvailable } return file, nil @@ -85,7 +84,7 @@ func (c *zfsCollector) updatePoolStats(ch chan<- prometheus.Metric) error { file, err := os.Open(zpoolPath) if err != nil { // this file should exist, but there is a race where an exporting pool can remove the files -- ok to ignore - level.Debug(c.logger).Log("msg", "Cannot open file for reading", "path", zpoolPath) + c.logger.Debug("Cannot open file for reading", "path", zpoolPath) return errZFSNotAvailable } @@ -107,7 +106,7 @@ func (c *zfsCollector) updatePoolStats(ch chan<- prometheus.Metric) error { file, err := os.Open(zpoolPath) if err != nil { // This file should exist, but there is a race where an exporting pool can remove the files. Ok to ignore. - level.Debug(c.logger).Log("msg", "Cannot open file for reading", "path", zpoolPath) + c.logger.Debug("Cannot open file for reading", "path", zpoolPath) return errZFSNotAvailable } @@ -126,7 +125,7 @@ func (c *zfsCollector) updatePoolStats(ch chan<- prometheus.Metric) error { } if zpoolStatePaths == nil { - level.Debug(c.logger).Log("msg", "No pool state files found") + c.logger.Debug("No pool state files found") return nil } @@ -134,7 +133,7 @@ func (c *zfsCollector) updatePoolStats(ch chan<- prometheus.Metric) error { file, err := os.Open(zpoolPath) if err != nil { // This file should exist, but there is a race where an exporting pool can remove the files. Ok to ignore. - level.Debug(c.logger).Log("msg", "Cannot open file for reading", "path", zpoolPath) + c.logger.Debug("Cannot open file for reading", "path", zpoolPath) return errZFSNotAvailable } diff --git a/collector/zfs_solaris.go b/collector/zfs_solaris.go index 52f2500f25..4ff8ceb242 100644 --- a/collector/zfs_solaris.go +++ b/collector/zfs_solaris.go @@ -17,9 +17,9 @@ package collector import ( + "log/slog" "strings" - "github.com/go-kit/log" "github.com/illumos/go-kstat" "github.com/prometheus/client_golang/prometheus" ) @@ -54,7 +54,7 @@ type zfsCollector struct { arcstatsSize *prometheus.Desc zfetchstatsHits *prometheus.Desc zfetchstatsMisses *prometheus.Desc - logger log.Logger + logger *slog.Logger } const ( @@ -65,7 +65,7 @@ func init() { registerCollector("zfs", defaultEnabled, NewZfsCollector) } -func NewZfsCollector(logger log.Logger) (Collector, error) { +func NewZfsCollector(logger *slog.Logger) (Collector, error) { return &zfsCollector{ abdstatsLinearCount: prometheus.NewDesc( prometheus.BuildFQName(namespace, zfsCollectorSubsystem, "abdstats_linear_count_total"), diff --git a/collector/zoneinfo_linux.go b/collector/zoneinfo_linux.go index 8f7e35d9f1..0b40fd3c59 100644 --- a/collector/zoneinfo_linux.go +++ b/collector/zoneinfo_linux.go @@ -15,10 +15,9 @@ package collector import ( "fmt" + "log/slog" "reflect" - "github.com/go-kit/log" - "github.com/prometheus/client_golang/prometheus" "github.com/prometheus/procfs" ) @@ -28,7 +27,7 @@ const zoneinfoSubsystem = "zoneinfo" type zoneinfoCollector struct { gaugeMetricDescs map[string]*prometheus.Desc counterMetricDescs map[string]*prometheus.Desc - logger log.Logger + logger *slog.Logger fs procfs.FS } @@ -37,7 +36,7 @@ func init() { } // NewZoneinfoCollector returns a new Collector exposing zone stats. -func NewZoneinfoCollector(logger log.Logger) (Collector, error) { +func NewZoneinfoCollector(logger *slog.Logger) (Collector, error) { fs, err := procfs.NewFS(*procPath) if err != nil { return nil, fmt.Errorf("failed to open procfs: %w", err) diff --git a/go.mod b/go.mod index a1938530e8..fdb56b5590 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,6 @@ require ( github.com/coreos/go-systemd/v22 v22.5.0 github.com/dennwc/btrfs v0.0.0-20240418142341-0167142bde7a github.com/ema/qdisc v1.0.0 - github.com/go-kit/log v0.2.1 github.com/godbus/dbus/v5 v5.1.0 github.com/hashicorp/go-envparse v0.1.0 github.com/hodgesds/perf-utils v0.7.0 @@ -25,7 +24,7 @@ require ( github.com/prometheus/client_golang v1.20.3 github.com/prometheus/client_model v0.6.1 github.com/prometheus/common v0.59.1 - github.com/prometheus/exporter-toolkit v0.11.0 + github.com/prometheus/exporter-toolkit v0.13.0 github.com/prometheus/procfs v0.15.1 github.com/safchain/ethtool v0.4.1 golang.org/x/exp v0.0.0-20240909161429-701f63a606c0 @@ -38,13 +37,13 @@ require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/dennwc/ioctl v1.0.0 // indirect - github.com/go-logfmt/logfmt v0.5.1 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/jpillora/backoff v1.0.0 // indirect github.com/klauspost/compress v1.17.9 // indirect github.com/kylelemons/godebug v1.1.0 // indirect github.com/mdlayher/genetlink v1.3.2 // indirect github.com/mdlayher/socket v0.4.1 // indirect + github.com/mdlayher/vsock v1.2.1 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect github.com/siebenmann/go-kstat v0.0.0-20210513183136-173c9b0a9973 // indirect diff --git a/go.sum b/go.sum index af511d4c21..85ff97cda6 100644 --- a/go.sum +++ b/go.sum @@ -21,10 +21,6 @@ github.com/dennwc/ioctl v1.0.0 h1:DsWAAjIxRqNcLn9x6mwfuf2pet3iB7aK90K4tF16rLg= github.com/dennwc/ioctl v1.0.0/go.mod h1:ellh2YB5ldny99SBU/VX7Nq0xiZbHphf1DrtHxxjMk0= github.com/ema/qdisc v1.0.0 h1:EHLG08FVRbWLg8uRICa3xzC9Zm0m7HyMHfXobWFnXYg= github.com/ema/qdisc v1.0.0/go.mod h1:FhIc0fLYi7f+lK5maMsesDqwYojIOh3VfRs8EVd5YJQ= -github.com/go-kit/log v0.2.1 h1:MRVx0/zhvdseW+Gza6N9rVzU/IVzaeE1SFI4raAhmBU= -github.com/go-kit/log v0.2.1/go.mod h1:NwTd00d/i8cPZ3xOwwiv2PO5MOcx78fFErGNcVmBjv0= -github.com/go-logfmt/logfmt v0.5.1 h1:otpy5pqBCBZ1ng9RQ0dPu4PN7ba75Y/aA+UpowDyNVA= -github.com/go-logfmt/logfmt v0.5.1/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/godbus/dbus/v5 v5.1.0 h1:4KLkAxT3aOY8Li4FRJe/KvhoNFFxo0m6fNuFUO8QJUk= github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= @@ -63,6 +59,8 @@ github.com/mdlayher/netlink v1.7.2 h1:/UtM3ofJap7Vl4QWCPDGXY8d3GIY2UGSDbK+QWmY8/ github.com/mdlayher/netlink v1.7.2/go.mod h1:xraEF7uJbxLhc5fpHL4cPe221LI2bdttWlU+ZGLfQSw= github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U= github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA= +github.com/mdlayher/vsock v1.2.1 h1:pC1mTJTvjo1r9n9fbm7S1j04rCgCzhCOS5DY0zqHlnQ= +github.com/mdlayher/vsock v1.2.1/go.mod h1:NRfCibel++DgeMD8z/hP+PPTjlNJsdPOmxcnENvE+SE= github.com/mdlayher/wifi v0.2.0 h1:vwbVyu5MWTiFNvOmWdvIx9veBlMVnEasZ90PhUi1DYU= github.com/mdlayher/wifi v0.2.0/go.mod h1:yOfWhVZ4FFJxeHzAxDzt87Om9EkqqcCiY9Gi5gfSXwI= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= @@ -81,8 +79,8 @@ github.com/prometheus/client_model v0.6.1 h1:ZKSh/rekM+n3CeS952MLRAdFwIKqeY8b62p github.com/prometheus/client_model v0.6.1/go.mod h1:OrxVMOVHjw3lKMa8+x6HeMGkHMQyHDk9E3jmP2AmGiY= github.com/prometheus/common v0.59.1 h1:LXb1quJHWm1P6wq/U824uxYi4Sg0oGvNeUm1z5dJoX0= github.com/prometheus/common v0.59.1/go.mod h1:GpWM7dewqmVYcd7SmRaiWVe9SSqjf0UrwnYnpEZNuT0= -github.com/prometheus/exporter-toolkit v0.11.0 h1:yNTsuZ0aNCNFQ3aFTD2uhPOvr4iD7fdBvKPAEGkNf+g= -github.com/prometheus/exporter-toolkit v0.11.0/go.mod h1:BVnENhnNecpwoTLiABx7mrPB/OLRIgN74qlQbV+FK1Q= +github.com/prometheus/exporter-toolkit v0.13.0 h1:lmA0Q+8IaXgmFRKw09RldZmZdnvu9wwcDLIXGmTPw1c= +github.com/prometheus/exporter-toolkit v0.13.0/go.mod h1:2uop99EZl80KdXhv/MxVI2181fMcwlsumFOqBecGkG0= github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0learggepc= github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk= github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ= diff --git a/node_exporter.go b/node_exporter.go index c7285f6fdf..c315d9f404 100644 --- a/node_exporter.go +++ b/node_exporter.go @@ -15,7 +15,7 @@ package main import ( "fmt" - stdlog "log" + "log/slog" "net/http" _ "net/http/pprof" "os" @@ -23,12 +23,10 @@ import ( "runtime" "sort" - "github.com/prometheus/common/promlog" - "github.com/prometheus/common/promlog/flag" + "github.com/prometheus/common/promslog" + "github.com/prometheus/common/promslog/flag" "github.com/alecthomas/kingpin/v2" - "github.com/go-kit/log" - "github.com/go-kit/log/level" "github.com/prometheus/client_golang/prometheus" promcollectors "github.com/prometheus/client_golang/prometheus/collectors" versioncollector "github.com/prometheus/client_golang/prometheus/collectors/version" @@ -49,10 +47,10 @@ type handler struct { exporterMetricsRegistry *prometheus.Registry includeExporterMetrics bool maxRequests int - logger log.Logger + logger *slog.Logger } -func newHandler(includeExporterMetrics bool, maxRequests int, logger log.Logger) *handler { +func newHandler(includeExporterMetrics bool, maxRequests int, logger *slog.Logger) *handler { h := &handler{ exporterMetricsRegistry: prometheus.NewRegistry(), includeExporterMetrics: includeExporterMetrics, @@ -76,7 +74,7 @@ func newHandler(includeExporterMetrics bool, maxRequests int, logger log.Logger) // ServeHTTP implements http.Handler. func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { filters := r.URL.Query()["collect[]"] - level.Debug(h.logger).Log("msg", "collect query:", "filters", filters) + h.logger.Debug("collect query:", "filters", filters) if len(filters) == 0 { // No filters, use the prepared unfiltered handler. @@ -86,7 +84,7 @@ func (h *handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // To serve filtered metrics, we create a filtering handler on the fly. filteredHandler, err := h.innerHandler(filters...) if err != nil { - level.Warn(h.logger).Log("msg", "Couldn't create filtered metrics handler:", "err", err) + h.logger.Warn("Couldn't create filtered metrics handler:", "err", err) w.WriteHeader(http.StatusBadRequest) w.Write([]byte(fmt.Sprintf("Couldn't create filtered metrics handler: %s", err))) return @@ -108,14 +106,14 @@ func (h *handler) innerHandler(filters ...string) (http.Handler, error) { // Only log the creation of an unfiltered handler, which should happen // only once upon startup. if len(filters) == 0 { - level.Info(h.logger).Log("msg", "Enabled collectors") + h.logger.Info("Enabled collectors") collectors := []string{} for n := range nc.Collectors { collectors = append(collectors, n) } sort.Strings(collectors) for _, c := range collectors { - level.Info(h.logger).Log("collector", c) + h.logger.Info(c) } } @@ -130,7 +128,7 @@ func (h *handler) innerHandler(filters ...string) (http.Handler, error) { handler = promhttp.HandlerFor( prometheus.Gatherers{h.exporterMetricsRegistry, r}, promhttp.HandlerOpts{ - ErrorLog: stdlog.New(log.NewStdlibAdapter(level.Error(h.logger)), "", 0), + ErrorLog: slog.NewLogLogger(h.logger.Handler(), slog.LevelError), ErrorHandling: promhttp.ContinueOnError, MaxRequestsInFlight: h.maxRequests, Registry: h.exporterMetricsRegistry, @@ -145,7 +143,7 @@ func (h *handler) innerHandler(filters ...string) (http.Handler, error) { handler = promhttp.HandlerFor( r, promhttp.HandlerOpts{ - ErrorLog: stdlog.New(log.NewStdlibAdapter(level.Error(h.logger)), "", 0), + ErrorLog: slog.NewLogLogger(h.logger.Handler(), slog.LevelError), ErrorHandling: promhttp.ContinueOnError, MaxRequestsInFlight: h.maxRequests, }, @@ -179,24 +177,24 @@ func main() { toolkitFlags = kingpinflag.AddFlags(kingpin.CommandLine, ":9100") ) - promlogConfig := &promlog.Config{} - flag.AddFlags(kingpin.CommandLine, promlogConfig) + promslogConfig := &promslog.Config{} + flag.AddFlags(kingpin.CommandLine, promslogConfig) kingpin.Version(version.Print("node_exporter")) kingpin.CommandLine.UsageWriter(os.Stdout) kingpin.HelpFlag.Short('h') kingpin.Parse() - logger := promlog.New(promlogConfig) + logger := promslog.New(promslogConfig) if *disableDefaultCollectors { collector.DisableDefaultCollectors() } - level.Info(logger).Log("msg", "Starting node_exporter", "version", version.Info()) - level.Info(logger).Log("msg", "Build context", "build_context", version.BuildContext()) + logger.Info("Starting node_exporter", "version", version.Info()) + logger.Info("Build context", "build_context", version.BuildContext()) if user, err := user.Current(); err == nil && user.Uid == "0" { - level.Warn(logger).Log("msg", "Node Exporter is running as root user. This exporter is designed to run as unprivileged user, root is not required.") + logger.Warn("Node Exporter is running as root user. This exporter is designed to run as unprivileged user, root is not required.") } runtime.GOMAXPROCS(*maxProcs) - level.Debug(logger).Log("msg", "Go MAXPROCS", "procs", runtime.GOMAXPROCS(0)) + logger.Debug("Go MAXPROCS", "procs", runtime.GOMAXPROCS(0)) http.Handle(*metricsPath, newHandler(!*disableExporterMetrics, *maxRequests, logger)) if *metricsPath != "/" { @@ -213,7 +211,7 @@ func main() { } landingPage, err := web.NewLandingPage(landingConfig) if err != nil { - level.Error(logger).Log("err", err) + logger.Error(err.Error()) os.Exit(1) } http.Handle("/", landingPage) @@ -221,7 +219,7 @@ func main() { server := &http.Server{} if err := web.ListenAndServe(server, toolkitFlags, logger); err != nil { - level.Error(logger).Log("err", err) + logger.Error(err.Error()) os.Exit(1) } }