Skip to content

Commit

Permalink
Update logging
Browse files Browse the repository at this point in the history
Switch from promlog/go-kit to promslog/slog for logging.
* Update Go build to 1.23.

Signed-off-by: Ben Kochie <[email protected]>
  • Loading branch information
SuperQ committed Sep 9, 2024
1 parent b9d0932 commit 271751c
Show file tree
Hide file tree
Showing 156 changed files with 627 additions and 674 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ executors:
# should also be updated.
golang:
docker:
- image: cimg/go:1.22
- image: cimg/go:1.23
arm:
machine:
image: ubuntu-2204:current
Expand Down
2 changes: 1 addition & 1 deletion .promu-cgo.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
go:
# Whenever the Go version is updated here, .circle/config.yml and
# .promu.yml should also be updated.
version: 1.22
version: 1.23
cgo: true
repository:
path: github.com/prometheus/node_exporter
Expand Down
2 changes: 1 addition & 1 deletion .promu.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
go:
# Whenever the Go version is updated here, .circle/config.yml and
# .promu-cgo.yml should also be updated.
version: 1.22
version: 1.23
repository:
path: github.com/prometheus/node_exporter
build:
Expand Down
6 changes: 3 additions & 3 deletions collector/arp_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -39,15 +39,15 @@ type arpCollector struct {
fs procfs.FS
deviceFilter deviceFilter
entries *prometheus.Desc
logger log.Logger
logger slog.Logger
}

func init() {
registerCollector("arp", defaultEnabled, NewARPCollector)
}

// 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)
Expand Down
6 changes: 3 additions & 3 deletions collector/bcache_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
Expand Down
9 changes: 4 additions & 5 deletions collector/bonding_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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"),
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions collector/bonding_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package collector

import (
"log/slog"
"testing"
)

Expand Down
6 changes: 3 additions & 3 deletions collector/boot_time_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
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() {
registerCollector("boottime", defaultEnabled, newBootTimeCollector)
}

// 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
Expand Down
6 changes: 3 additions & 3 deletions collector/boot_time_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
21 changes: 10 additions & 11 deletions collector/btrfs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,28 @@ 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"
)

// 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() {
registerCollector("btrfs", defaultEnabled, NewBtrfsCollector)
}

// 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)
Expand All @@ -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)
}
Expand Down Expand Up @@ -129,7 +128,7 @@ 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(
c.logger.Debug(
"msg", "Error inspecting btrfs mountpoint",
"mountPoint", mountPath,
"err", err)
Expand All @@ -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
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions collector/btrfs_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package collector

import (
"log/slog"
"strings"
"testing"

Expand Down
9 changes: 4 additions & 5 deletions collector/buddyinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -33,15 +32,15 @@ const (
type buddyinfoCollector struct {
fs procfs.FS
desc *prometheus.Desc
logger log.Logger
logger slog.Logger
}

func init() {
registerCollector("buddyinfo", defaultDisabled, NewBuddyinfoCollector)
}

// 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.",
Expand All @@ -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(
Expand Down
6 changes: 3 additions & 3 deletions collector/cgroups_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -30,15 +30,15 @@ type cgroupSummaryCollector struct {
fs procfs.FS
cgroups *prometheus.Desc
enabled *prometheus.Desc
logger log.Logger
logger slog.Logger
}

func init() {
registerCollector(cgroupsCollectorSubsystem, defaultDisabled, NewCgroupSummaryCollector)
}

// 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)
Expand Down
Loading

0 comments on commit 271751c

Please sign in to comment.