diff --git a/collector/diskstats_common.go b/collector/diskstats_common.go index e636aa68..dbe0b5cf 100644 --- a/collector/diskstats_common.go +++ b/collector/diskstats_common.go @@ -93,13 +93,16 @@ func newDiskstatsDeviceFilter(config DiskstatsDeviceFilterConfig, logger log.Log if *config.DeviceExclude != "" { level.Info(logger).Log("msg", "Parsed flag --collector.diskstats.device-exclude", "flag", *config.DeviceExclude) - } else { - *config.DeviceExclude = diskstatsDefaultIgnoredDevices } if *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 } diff --git a/collector/filesystem_common.go b/collector/filesystem_common.go index aca57da7..824cf2c8 100644 --- a/collector/filesystem_common.go +++ b/collector/filesystem_common.go @@ -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") } } + if *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 != "" { @@ -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") } } + if *config.Filesystem.FSTypesExclude != "" { level.Info(logger).Log("msg", "Parsed flag --collector.filesystem.fs-types-exclude", "flag", *config.Filesystem.FSTypesExclude) + } - } else { - *config.Filesystem.FSTypesExclude = defFSTypesExcluded + if !config.Filesystem.FSTypesExcludeSet { // use default fs types if flag is not set + fsTypes := defFSTypesExcluded + config.Filesystem.FSTypesExclude = &fsTypes } subsystem := "filesystem" diff --git a/collector/ipvs_linux.go b/collector/ipvs_linux.go index 487a25dc..3a7c1389 100644 --- a/collector/ipvs_linux.go +++ b/collector/ipvs_linux.go @@ -82,8 +82,9 @@ func newIPVSCollector(config *NodeCollectorConfig, logger log.Logger) (*ipvsColl subsystem = "ipvs" ) - if *config.IPVS.Labels == "" { - *config.IPVS.Labels = strings.Join(fullIpvsBackendLabels, ",") + if !config.IPVS.LabelsSet { // use default labels if flag is not set + labels := strings.Join(fullIpvsBackendLabels, ",") + config.IPVS.Labels = &labels } if c.backendLabels, err = c.parseIpvsLabels(*config.IPVS.Labels); err != nil { diff --git a/collector/ipvs_linux_test.go b/collector/ipvs_linux_test.go index 62fab681..c33c65f3 100644 --- a/collector/ipvs_linux_test.go +++ b/collector/ipvs_linux_test.go @@ -110,8 +110,8 @@ func TestIPVSCollector(t *testing.T) { } for _, test := range testcases { t.Run(test.labels, func(t *testing.T) { - config.IPVS.Labels = new(string) if test.labels != "" { + config.IPVS.LabelsSet = true config.IPVS.Labels = &test.labels } collector, err := newIPVSCollector(config, log.NewNopLogger()) @@ -179,8 +179,8 @@ func TestIPVSCollectorResponse(t *testing.T) { } for _, test := range testcases { t.Run(test.labels, func(t *testing.T) { - config.IPVS.Labels = new(string) if test.labels != "" { + config.IPVS.LabelsSet = true config.IPVS.Labels = &test.labels } collector, err := NewIPVSCollector(config, log.NewNopLogger()) diff --git a/kingpinconfig/flags.go b/kingpinconfig/flags.go index 0a543208..626678d4 100644 --- a/kingpinconfig/flags.go +++ b/kingpinconfig/flags.go @@ -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.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.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()