Fix defaults

This commit is contained in:
Marc Tuduri 2023-09-27 18:26:51 +02:00
parent c01a7c2c57
commit 399ce78c36
No known key found for this signature in database
GPG key ID: 761973D5AE312AF4
5 changed files with 27 additions and 12 deletions

View file

@ -100,13 +100,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
}

View file

@ -82,10 +82,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 != "" {
@ -96,11 +100,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"

View file

@ -70,7 +70,8 @@ func init() {
}
type IPVSConfig struct {
Labels *string
Labels *string
LabelsSet bool
}
// NewIPVSCollector sets up a new collector for IPVS metrics. It accepts the
@ -86,8 +87,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 {

View file

@ -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 != "<none>" {
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 != "<none>" {
config.IPVS.LabelsSet = true
config.IPVS.Labels = &test.labels
}
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.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()