Skip to content

Commit

Permalink
use pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
marctc committed Sep 27, 2023
1 parent d59d656 commit c01a7c2
Show file tree
Hide file tree
Showing 107 changed files with 163 additions and 162 deletions.
4 changes: 2 additions & 2 deletions collector/arp_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type arpCollector struct {
deviceFilter deviceFilter
entries *prometheus.Desc
logger log.Logger
config NodeCollectorConfig
config *NodeCollectorConfig
}

func init() {
Expand All @@ -47,7 +47,7 @@ type ArpConfig struct {
}

// NewARPCollector returns a new Collector exposing ARP stats.
func NewARPCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func NewARPCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
fs, err := procfs.NewFS(*config.Path.ProcPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions collector/bcache_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func init() {
type bcacheCollector struct {
fs bcache.FS
logger log.Logger
config NodeCollectorConfig
config *NodeCollectorConfig
}

type BcacheConfig struct {
Expand All @@ -42,7 +42,7 @@ type BcacheConfig struct {

// NewBcacheCollector returns a newly allocated bcacheCollector.
// It exposes a number of Linux bcache statistics.
func NewBcacheCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func NewBcacheCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
fs, err := bcache.NewFS(*config.Path.SysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions collector/bonding_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
type bondingCollector struct {
slaves, active typedDesc
logger log.Logger
config NodeCollectorConfig
config *NodeCollectorConfig
}

func init() {
Expand All @@ -40,7 +40,7 @@ func init() {

// NewBondingCollector returns a newly allocated bondingCollector.
// It exposes the number of configured and active slave of linux bonding interfaces.
func NewBondingCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func NewBondingCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
return &bondingCollector{
slaves: typedDesc{prometheus.NewDesc(
prometheus.BuildFQName(namespace, "bonding", "slaves"),
Expand Down
2 changes: 1 addition & 1 deletion collector/boot_time_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func init() {
}

// newBootTimeCollector returns a new Collector exposing system boot time on BSD systems.
func newBootTimeCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func newBootTimeCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
return &bootTimeCollector{
logger: logger,
}, nil
Expand Down
2 changes: 1 addition & 1 deletion collector/boot_time_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func init() {
registerCollector("boottime", defaultEnabled, newBootTimeCollector)
}

func newBootTimeCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func newBootTimeCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
return &bootTimeCollector{
boottime: typedDesc{
prometheus.NewDesc(
Expand Down
4 changes: 2 additions & 2 deletions collector/btrfs_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ import (
type btrfsCollector struct {
fs btrfs.FS
logger log.Logger
config NodeCollectorConfig
config *NodeCollectorConfig
}

func init() {
registerCollector("btrfs", defaultEnabled, NewBtrfsCollector)
}

// NewBtrfsCollector returns a new Collector exposing Btrfs statistics.
func NewBtrfsCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func NewBtrfsCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
fs, err := btrfs.NewFS(*config.Path.SysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion collector/buddyinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ func init() {
}

// NewBuddyinfoCollector returns a new Collector exposing buddyinfo stats.
func NewBuddyinfoCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func NewBuddyinfoCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
desc := prometheus.NewDesc(
prometheus.BuildFQName(namespace, buddyInfoSubsystem, "blocks"),
"Count of free blocks according to size.",
Expand Down
2 changes: 1 addition & 1 deletion collector/cgroups_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func init() {
}

// NewCgroupSummaryCollector returns a new Collector exposing a summary of cgroups.
func NewCgroupSummaryCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func NewCgroupSummaryCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
fs, err := procfs.NewFS(*config.Path.ProcPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %w", err)
Expand Down
6 changes: 3 additions & 3 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,14 @@ const (
)

var (
factories = make(map[string]func(config NodeCollectorConfig, logger log.Logger) (Collector, error))
factories = make(map[string]func(config *NodeCollectorConfig, logger log.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(config NodeCollectorConfig, logger log.Logger) (Collector, error)) {
func registerCollector(collector string, isDefaultEnabled bool, factory func(config *NodeCollectorConfig, logger log.Logger) (Collector, error)) {
var helpDefaultState string
if isDefaultEnabled {
helpDefaultState = "enabled"
Expand Down Expand Up @@ -104,7 +104,7 @@ func collectorFlagAction(collector string) func(ctx *kingpin.ParseContext) error
}

// NewNodeCollector creates a new NodeCollector.
func NewNodeCollector(config NodeCollectorConfig, logger log.Logger, filters ...string) (*NodeCollector, error) {
func NewNodeCollector(config *NodeCollectorConfig, logger log.Logger, filters ...string) (*NodeCollector, error) {
f := make(map[string]bool)
for _, filter := range filters {
enabled, exist := collectorState[filter]
Expand Down
6 changes: 3 additions & 3 deletions collector/conntrack_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ type conntrackCollector struct {
earlyDrop *prometheus.Desc
searchRestart *prometheus.Desc
logger log.Logger
config NodeCollectorConfig
config *NodeCollectorConfig
}

type conntrackStatistics struct {
Expand All @@ -58,7 +58,7 @@ func init() {
}

// NewConntrackCollector returns a new Collector exposing conntrack stats.
func NewConntrackCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func NewConntrackCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
return &conntrackCollector{
current: prometheus.NewDesc(
prometheus.BuildFQName(namespace, "", "nf_conntrack_entries"),
Expand Down Expand Up @@ -162,7 +162,7 @@ func (c *conntrackCollector) handleErr(err error) error {
return fmt.Errorf("failed to retrieve conntrack stats: %w", err)
}

func getConntrackStatistics(config NodeCollectorConfig) (*conntrackStatistics, error) {
func getConntrackStatistics(config *NodeCollectorConfig) (*conntrackStatistics, error) {
c := conntrackStatistics{}

fs, err := procfs.NewFS(*config.Path.ProcPath)
Expand Down
2 changes: 1 addition & 1 deletion collector/cpu_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func init() {
}

// NewCPUCollector returns a new Collector exposing CPU stats.
func NewCPUCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func NewCPUCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
return &statCollector{
cpu: nodeCPUSecondsDesc,
logger: logger,
Expand Down
2 changes: 1 addition & 1 deletion collector/cpu_dragonfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func init() {
}

// NewStatCollector returns a new Collector exposing CPU stats.
func NewStatCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func NewStatCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
return &statCollector{
cpu: nodeCPUSecondsDesc,
logger: logger,
Expand Down
2 changes: 1 addition & 1 deletion collector/cpu_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func init() {
}

// NewStatCollector returns a new Collector exposing CPU stats.
func NewStatCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func NewStatCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
return &statCollector{
cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue},
temp: typedDesc{prometheus.NewDesc(
Expand Down
6 changes: 3 additions & 3 deletions collector/cpu_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ type cpuCollector struct {
cpuFlagsIncludeRegexp *regexp.Regexp
cpuBugsIncludeRegexp *regexp.Regexp

config NodeCollectorConfig
config *NodeCollectorConfig
}

// Idle jump back limit in seconds.
Expand All @@ -74,7 +74,7 @@ func init() {
}

// NewCPUCollector returns a new Collector exposing kernel/system statistics.
func NewCPUCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func NewCPUCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
fs, err := procfs.NewFS(*config.Path.ProcPath)
if err != nil {
return nil, fmt.Errorf("failed to open procfs: %w", err)
Expand Down Expand Up @@ -254,7 +254,7 @@ func updateFieldInfo(valueList []string, filter *regexp.Regexp, desc *prometheus
}

// updateThermalThrottle reads /sys/devices/system/cpu/cpu* and expose thermal throttle statistics.
func (c *cpuCollector) updateThermalThrottle(config NodeCollectorConfig, ch chan<- prometheus.Metric) error {
func (c *cpuCollector) updateThermalThrottle(config *NodeCollectorConfig, ch chan<- prometheus.Metric) error {
cpus, err := filepath.Glob(config.Path.sysFilePath("devices/system/cpu/cpu[0-9]*"))
if err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion collector/cpu_netbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func init() {
}

// NewStatCollector returns a new Collector exposing CPU stats.
func NewStatCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func NewStatCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
return &statCollector{
cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue},
temp: typedDesc{prometheus.NewDesc(
Expand Down
2 changes: 1 addition & 1 deletion collector/cpu_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func init() {
registerCollector("cpu", defaultEnabled, NewCPUCollector)
}

func NewCPUCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func NewCPUCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
return &cpuCollector{
cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue},
logger: logger,
Expand Down
2 changes: 1 addition & 1 deletion collector/cpu_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func init() {
registerCollector("cpu", defaultEnabled, NewCpuCollector)
}

func NewCpuCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func NewCpuCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
return &cpuCollector{
cpu: typedDesc{nodeCPUSecondsDesc, prometheus.CounterValue},
logger: logger,
Expand Down
4 changes: 2 additions & 2 deletions collector/cpu_vulnerabilities_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ var (
)

type cpuVulnerabilitiesCollector struct {
config NodeCollectorConfig
config *NodeCollectorConfig
}

func init() {
registerCollector(cpuVulerabilitiesCollector, defaultDisabled, NewVulnerabilitySysfsCollector)
}

func NewVulnerabilitySysfsCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func NewVulnerabilitySysfsCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
return &cpuVulnerabilitiesCollector{config}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion collector/cpufreq_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func init() {
}

// NewCPUFreqCollector returns a new Collector exposing kernel/system statistics.
func NewCPUFreqCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func NewCPUFreqCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
fs, err := sysfs.NewFS(*config.Path.SysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion collector/cpufreq_solaris.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func init() {
registerCollector("cpufreq", defaultEnabled, NewCPUFreqCollector)
}

func NewCpuFreqCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func NewCpuFreqCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
return &cpuFreqCollector{
logger: logger,
}, nil
Expand Down
2 changes: 1 addition & 1 deletion collector/devstat_dragonfly.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func init() {
}

// NewDevstatCollector returns a new Collector exposing Device stats.
func NewDevstatCollector(config NodeCollectorConfiglogger log.Logger) (Collector, error) {
func NewDevstatCollector(config *NodeCollectorConfiglogger log.Logger) (Collector, error) {
return &devstatCollector{
bytesDesc: prometheus.NewDesc(
prometheus.BuildFQName(namespace, devstatSubsystem, "bytes_total"),
Expand Down
2 changes: 1 addition & 1 deletion collector/devstat_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func init() {
}

// NewDevstatCollector returns a new Collector exposing Device stats.
func NewDevstatCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func NewDevstatCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
return &devstatCollector{
devinfo: &C.struct_devinfo{},
bytes: typedDesc{prometheus.NewDesc(
Expand Down
2 changes: 1 addition & 1 deletion collector/diskstats_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func init() {
}

// NewDiskstatsCollector returns a new Collector exposing disk device stats.
func NewDiskstatsCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func NewDiskstatsCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
var diskLabelNames = []string{"device"}

deviceFilter, err := newDiskstatsDeviceFilter(config.DiskstatsDeviceFilter, logger)
Expand Down
8 changes: 4 additions & 4 deletions collector/diskstats_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ type diskstatsCollector struct {
deviceMapperInfoDesc typedFactorDesc
ataDescs map[string]typedFactorDesc
logger log.Logger
getUdevDeviceProperties func(NodeCollectorConfig, uint32, uint32) (udevInfo, error)
config NodeCollectorConfig
getUdevDeviceProperties func(*NodeCollectorConfig, uint32, uint32) (udevInfo, error)
config *NodeCollectorConfig
}

func init() {
Expand All @@ -96,7 +96,7 @@ func init() {

// NewDiskstatsCollector returns a new Collector exposing disk device stats.
// Docs from https://www.kernel.org/doc/Documentation/iostats.txt
func NewDiskstatsCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func NewDiskstatsCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
var diskLabelNames = []string{"device"}
fs, err := blockdevice.NewFS(*config.Path.ProcPath, *config.Path.SysPath)
if err != nil {
Expand Down Expand Up @@ -372,7 +372,7 @@ func (c *diskstatsCollector) Update(ch chan<- prometheus.Metric) error {
return nil
}

func getUdevDeviceProperties(config NodeCollectorConfig, major, minor uint32) (udevInfo, error) {
func getUdevDeviceProperties(config *NodeCollectorConfig, major, minor uint32) (udevInfo, error) {
filename := config.Path.udevDataFilePath(fmt.Sprintf("b%d:%d", major, minor))

data, err := os.Open(filename)
Expand Down
4 changes: 2 additions & 2 deletions collector/diskstats_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (c testDiskStatsCollector) Describe(ch chan<- *prometheus.Desc) {
prometheus.DescribeByCollect(c, ch)
}

func NewTestDiskStatsCollector(config NodeCollectorConfig, logger log.Logger) (prometheus.Collector, error) {
func NewTestDiskStatsCollector(config *NodeCollectorConfig, logger log.Logger) (prometheus.Collector, error) {
dsc, err := NewDiskstatsCollector(config, logger)
if err != nil {
return testDiskStatsCollector{}, err
Expand All @@ -50,7 +50,7 @@ func NewTestDiskStatsCollector(config NodeCollectorConfig, logger log.Logger) (p
}

func TestDiskStats(t *testing.T) {
config := NodeCollectorConfig{
config := &NodeCollectorConfig{
DiskstatsDeviceFilter: DiskstatsDeviceFilterConfig{
DeviceExclude: new(string),
DeviceInclude: new(string),
Expand Down
2 changes: 1 addition & 1 deletion collector/diskstats_openbsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func init() {
}

// NewDiskstatsCollector returns a new Collector exposing disk device stats.
func NewDiskstatsCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func NewDiskstatsCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
deviceFilter, err := newDiskstatsDeviceFilter(config.DiskstatsDeviceFilter, logger)
if err != nil {
return nil, fmt.Errorf("failed to parse device filter flags: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion collector/diskstats_openbsd_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func init() {
}

// NewDiskstatsCollector returns a new Collector exposing disk device stats.
func NewDiskstatsCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func NewDiskstatsCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
deviceFilter, err := newDiskstatsDeviceFilter(config.DiskstatsDeviceFilter, logger)
if err != nil {
return nil, fmt.Errorf("failed to parse device filter flags: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion collector/dmi.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func init() {
}

// NewDMICollector returns a new Collector exposing DMI information.
func NewDMICollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func NewDMICollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
fs, err := sysfs.NewFS(*config.Path.SysPath)
if err != nil {
return nil, fmt.Errorf("failed to open sysfs: %w", err)
Expand Down
4 changes: 2 additions & 2 deletions collector/drbd_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,14 @@ type drbdCollector struct {
stringPair map[string]drbdStringPairMetric
connected *prometheus.Desc
logger log.Logger
config NodeCollectorConfig
config *NodeCollectorConfig
}

func init() {
registerCollector("drbd", defaultDisabled, newDRBDCollector)
}

func newDRBDCollector(config NodeCollectorConfig, logger log.Logger) (Collector, error) {
func newDRBDCollector(config *NodeCollectorConfig, logger log.Logger) (Collector, error) {
return &drbdCollector{
numerical: map[string]drbdNumericalMetric{
"ns": newDRBDNumericalMetric(
Expand Down
Loading

0 comments on commit c01a7c2

Please sign in to comment.