Merge refactor changes merge

This commit is contained in:
matt durham 2023-09-28 09:27:55 -04:00
commit 33af25f572
No known key found for this signature in database
GPG key ID: A62E920AE398897B
5 changed files with 25 additions and 11 deletions

View file

@ -93,13 +93,16 @@ func newDiskstatsDeviceFilter(config DiskstatsDeviceFilterConfig, logger log.Log
if *config.DeviceExclude != "" { if *config.DeviceExclude != "" {
level.Info(logger).Log("msg", "Parsed flag --collector.diskstats.device-exclude", "flag", *config.DeviceExclude) level.Info(logger).Log("msg", "Parsed flag --collector.diskstats.device-exclude", "flag", *config.DeviceExclude)
} else {
*config.DeviceExclude = diskstatsDefaultIgnoredDevices
} }
if *config.DeviceInclude != "" { if *config.DeviceInclude != "" {
level.Info(logger).Log("msg", "Parsed Flag --collector.diskstats.device-include", "flag", *config.DeviceInclude) level.Info(logger).Log("msg", "Parsed Flag --collector.diskstats.device-include", "flag", *config.DeviceInclude)
} }
if !config.DeviceExcludeSet { // use default exclude devices if flag is not set
devices := diskstatsDefaultIgnoredDevices
config.DeviceExclude = &devices
}
return newDeviceFilter(*config.DeviceExclude, *config.DeviceInclude), nil return newDeviceFilter(*config.DeviceExclude, *config.DeviceInclude), nil
} }

View file

@ -70,10 +70,14 @@ func NewFilesystemCollector(config *NodeCollectorConfig, logger log.Logger) (Col
return nil, errors.New("--collector.filesystem.ignored-mount-points and --collector.filesystem.mount-points-exclude are mutually exclusive") return nil, errors.New("--collector.filesystem.ignored-mount-points and --collector.filesystem.mount-points-exclude are mutually exclusive")
} }
} }
if *config.Filesystem.MountPointsExclude != "" { if *config.Filesystem.MountPointsExclude != "" {
level.Info(logger).Log("msg", "Parsed flag --collector.filesystem.mount-points-exclude", "flag", *config.Filesystem.MountPointsExclude) level.Info(logger).Log("msg", "Parsed flag --collector.filesystem.mount-points-exclude", "flag", *config.Filesystem.MountPointsExclude)
} else { }
*config.Filesystem.MountPointsExclude = defMountPointsExcluded
if !config.Filesystem.MountPointsExcludeSet { // use default mount points if flag is not set
mountPoints := defMountPointsExcluded
config.Filesystem.MountPointsExclude = &mountPoints
} }
if *config.Filesystem.OldFSTypesExcluded != "" { if *config.Filesystem.OldFSTypesExcluded != "" {
@ -84,11 +88,14 @@ func NewFilesystemCollector(config *NodeCollectorConfig, logger log.Logger) (Col
return nil, errors.New("--collector.filesystem.ignored-fs-types and --collector.filesystem.fs-types-exclude are mutually exclusive") return nil, errors.New("--collector.filesystem.ignored-fs-types and --collector.filesystem.fs-types-exclude are mutually exclusive")
} }
} }
if *config.Filesystem.FSTypesExclude != "" { if *config.Filesystem.FSTypesExclude != "" {
level.Info(logger).Log("msg", "Parsed flag --collector.filesystem.fs-types-exclude", "flag", *config.Filesystem.FSTypesExclude) level.Info(logger).Log("msg", "Parsed flag --collector.filesystem.fs-types-exclude", "flag", *config.Filesystem.FSTypesExclude)
}
} else { if !config.Filesystem.FSTypesExcludeSet { // use default fs types if flag is not set
*config.Filesystem.FSTypesExclude = defFSTypesExcluded fsTypes := defFSTypesExcluded
config.Filesystem.FSTypesExclude = &fsTypes
} }
subsystem := "filesystem" subsystem := "filesystem"

View file

@ -82,8 +82,9 @@ func newIPVSCollector(config *NodeCollectorConfig, logger log.Logger) (*ipvsColl
subsystem = "ipvs" subsystem = "ipvs"
) )
if *config.IPVS.Labels == "" { if !config.IPVS.LabelsSet { // use default labels if flag is not set
*config.IPVS.Labels = strings.Join(fullIpvsBackendLabels, ",") labels := strings.Join(fullIpvsBackendLabels, ",")
config.IPVS.Labels = &labels
} }
if c.backendLabels, err = c.parseIpvsLabels(*config.IPVS.Labels); err != nil { if c.backendLabels, err = c.parseIpvsLabels(*config.IPVS.Labels); err != nil {

View file

@ -110,8 +110,8 @@ func TestIPVSCollector(t *testing.T) {
} }
for _, test := range testcases { for _, test := range testcases {
t.Run(test.labels, func(t *testing.T) { t.Run(test.labels, func(t *testing.T) {
config.IPVS.Labels = new(string)
if test.labels != "<none>" { if test.labels != "<none>" {
config.IPVS.LabelsSet = true
config.IPVS.Labels = &test.labels config.IPVS.Labels = &test.labels
} }
collector, err := newIPVSCollector(config, log.NewNopLogger()) collector, err := newIPVSCollector(config, log.NewNopLogger())
@ -179,8 +179,8 @@ func TestIPVSCollectorResponse(t *testing.T) {
} }
for _, test := range testcases { for _, test := range testcases {
t.Run(test.labels, func(t *testing.T) { t.Run(test.labels, func(t *testing.T) {
config.IPVS.Labels = new(string)
if test.labels != "<none>" { if test.labels != "<none>" {
config.IPVS.LabelsSet = true
config.IPVS.Labels = &test.labels config.IPVS.Labels = &test.labels
} }
collector, err := NewIPVSCollector(config, log.NewNopLogger()) collector, err := NewIPVSCollector(config, log.NewNopLogger())

View file

@ -83,7 +83,10 @@ func AddFlags(a *kingpin.Application) *collector.NodeCollectorConfig {
config.HwMon.ChipInclude = a.Flag("collector.hwmon.chip-include", "Regexp of hwmon chip to include (mutually exclusive to device-exclude).").String() config.HwMon.ChipInclude = a.Flag("collector.hwmon.chip-include", "Regexp of hwmon chip to include (mutually exclusive to device-exclude).").String()
config.HwMon.ChipExclude = a.Flag("collector.hwmon.chip-exclude", "Regexp of hwmon chip to exclude (mutually exclusive to device-include).").String() config.HwMon.ChipExclude = a.Flag("collector.hwmon.chip-exclude", "Regexp of hwmon chip to exclude (mutually exclusive to device-include).").String()
config.IPVS.Labels = a.Flag("collector.ipvs.backend-labels", "Comma separated list for IPVS backend stats labels.").String() config.IPVS.Labels = a.Flag("collector.ipvs.backend-labels", "Comma separated list for IPVS backend stats labels.").PreAction(func(c *kingpin.ParseContext) error {
config.IPVS.LabelsSet = true
return nil
}).String()
config.NetClass.IgnoredDevices = a.Flag("collector.netclass.ignored-devices", "Regexp of net devices to ignore for netclass collector.").Default("^$").String() config.NetClass.IgnoredDevices = a.Flag("collector.netclass.ignored-devices", "Regexp of net devices to ignore for netclass collector.").Default("^$").String()
config.NetClass.InvalidSpeed = a.Flag("collector.netclass.ignore-invalid-speed", "Ignore devices where the speed is invalid. This will be the default behavior in 2.x.").Bool() config.NetClass.InvalidSpeed = a.Flag("collector.netclass.ignore-invalid-speed", "Ignore devices where the speed is invalid. This will be the default behavior in 2.x.").Bool()