Skip to content

Commit

Permalink
Rename fields
Browse files Browse the repository at this point in the history
  • Loading branch information
marctc committed Sep 27, 2023
1 parent fbff3bb commit d59d656
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 22 deletions.
28 changes: 14 additions & 14 deletions collector/diskstats_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,35 +78,35 @@ var (
)

type DiskstatsDeviceFilterConfig struct {
DiskstatsDeviceExclude *string
DiskstatsDeviceExcludeSet bool
OldDiskstatsDeviceExclude *string
DiskstatsDeviceInclude *string
DeviceExclude *string
DeviceExcludeSet bool
OldDeviceExclude *string
DeviceInclude *string
}

func newDiskstatsDeviceFilter(config DiskstatsDeviceFilterConfig, logger log.Logger) (deviceFilter, error) {
if *config.OldDiskstatsDeviceExclude != "" {
if !config.DiskstatsDeviceExcludeSet {
if *config.OldDeviceExclude != "" {
if !config.DeviceExcludeSet {
level.Warn(logger).Log("msg", "--collector.diskstats.ignored-devices is DEPRECATED and will be removed in 2.0.0, use --collector.diskstats.device-exclude")
*config.DiskstatsDeviceExclude = *config.OldDiskstatsDeviceExclude
*config.DeviceExclude = *config.OldDeviceExclude
} else {
return deviceFilter{}, errors.New("--collector.diskstats.ignored-devices and --collector.diskstats.device-exclude are mutually exclusive")
}
}

if *config.DiskstatsDeviceExclude != "" && *config.DiskstatsDeviceInclude != "" {
if *config.DeviceExclude != "" && *config.DeviceInclude != "" {
return deviceFilter{}, errors.New("device-exclude & device-include are mutually exclusive")
}

if *config.DiskstatsDeviceExclude != "" {
level.Info(logger).Log("msg", "Parsed flag --collector.diskstats.device-exclude", "flag", *config.DiskstatsDeviceExclude)
if *config.DeviceExclude != "" {
level.Info(logger).Log("msg", "Parsed flag --collector.diskstats.device-exclude", "flag", *config.DeviceExclude)
} else {
*config.DiskstatsDeviceExclude = diskstatsDefaultIgnoredDevices
*config.DeviceExclude = diskstatsDefaultIgnoredDevices
}

if *config.DiskstatsDeviceInclude != "" {
level.Info(logger).Log("msg", "Parsed Flag --collector.diskstats.device-include", "flag", *config.DiskstatsDeviceInclude)
if *config.DeviceInclude != "" {
level.Info(logger).Log("msg", "Parsed Flag --collector.diskstats.device-include", "flag", *config.DeviceInclude)
}

return newDeviceFilter(*config.DiskstatsDeviceExclude, *config.DiskstatsDeviceInclude), nil
return newDeviceFilter(*config.DeviceExclude, *config.DeviceInclude), nil
}
8 changes: 4 additions & 4 deletions collector/diskstats_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,9 @@ func NewTestDiskStatsCollector(config NodeCollectorConfig, logger log.Logger) (p
func TestDiskStats(t *testing.T) {
config := NodeCollectorConfig{
DiskstatsDeviceFilter: DiskstatsDeviceFilterConfig{
DiskstatsDeviceExclude: new(string),
DiskstatsDeviceInclude: new(string),
OldDiskstatsDeviceExclude: new(string),
DeviceExclude: new(string),
DeviceInclude: new(string),
OldDeviceExclude: new(string),
},
}
sysPath := "fixtures/sys"
Expand All @@ -67,7 +67,7 @@ func TestDiskStats(t *testing.T) {
config.Path.UdevDataPath = &udevDataPath

diskstatsDeviceExclude := "^(ram|loop|fd|(h|s|v|xv)d[a-z]|nvme\\d+n\\d+p)\\d+$"
config.DiskstatsDeviceFilter.DiskstatsDeviceExclude = &diskstatsDeviceExclude
config.DiskstatsDeviceFilter.DeviceExclude = &diskstatsDeviceExclude
testcase := `# HELP node_disk_ata_rotation_rate_rpm ATA disk rotation rate in RPMs (0 for SSDs).
# TYPE node_disk_ata_rotation_rate_rpm gauge
node_disk_ata_rotation_rate_rpm{device="sda"} 7200
Expand Down
8 changes: 4 additions & 4 deletions kingpinconfig/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,18 @@ func AddFlags(a *kingpin.Application) collector.NodeCollectorConfig {
config.CPU.FlagsInclude = a.Flag("collector.cpu.info.flags-include", "Filter the `flags` field in cpuInfo with a value that must be a regular expression").String()
config.CPU.BugsInclude = a.Flag("collector.cpu.info.bugs-include", "Filter the `bugs` field in cpuInfo with a value that must be a regular expression").String()

config.DiskstatsDeviceFilter.DiskstatsDeviceExclude = a.Flag(
config.DiskstatsDeviceFilter.DeviceExclude = a.Flag(
"collector.diskstats.device-exclude",
"Regexp of diskstats devices to exclude (mutually exclusive to device-include).",
).PreAction(func(c *kingpin.ParseContext) error {
config.DiskstatsDeviceFilter.DiskstatsDeviceExcludeSet = true
config.DiskstatsDeviceFilter.DeviceExcludeSet = true
return nil
}).String()
config.DiskstatsDeviceFilter.OldDiskstatsDeviceExclude = a.Flag(
config.DiskstatsDeviceFilter.OldDeviceExclude = a.Flag(
"collector.diskstats.ignored-devices",
"DEPRECATED: Use collector.diskstats.device-exclude",
).Hidden().String()
config.DiskstatsDeviceFilter.DiskstatsDeviceInclude = a.Flag("collector.diskstats.device-include", "Regexp of diskstats devices to include (mutually exclusive to device-exclude).").String()
config.DiskstatsDeviceFilter.DeviceInclude = a.Flag("collector.diskstats.device-include", "Regexp of diskstats devices to include (mutually exclusive to device-exclude).").String()

config.Ethtool.DeviceInclude = a.Flag("collector.ethtool.device-include", "Regexp of ethtool devices to include (mutually exclusive to device-exclude).").String()
config.Ethtool.DeviceExclude = a.Flag("collector.ethtool.device-exclude", "Regexp of ethtool devices to exclude (mutually exclusive to device-include).").String()
Expand Down

0 comments on commit d59d656

Please sign in to comment.