Skip to content

Commit

Permalink
don't reuse pointers for the windows exporter defaults (#6744)
Browse files Browse the repository at this point in the history
Signed-off-by: Erik Baranowski <[email protected]>
  • Loading branch information
erikbaranowski authored Mar 21, 2024
1 parent 7b0ff9a commit 514c541
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,30 @@ func TestRiverUnmarshalWithDefaultConfig(t *testing.T) {
err := river.Unmarshal([]byte(""), &args)
require.NoError(t, err)

require.Equal(t, DefaultArguments.EnabledCollectors, args.EnabledCollectors)
require.Equal(t, DefaultArguments.Dfsr.SourcesEnabled, args.Dfsr.SourcesEnabled)
require.Equal(t, DefaultArguments.Exchange.EnabledList, args.Exchange.EnabledList)
require.Equal(t, DefaultArguments.IIS.AppExclude, args.IIS.AppExclude)
require.Equal(t, DefaultArguments.IIS.AppInclude, args.IIS.AppInclude)
require.Equal(t, DefaultArguments.IIS.SiteExclude, args.IIS.SiteExclude)
require.Equal(t, DefaultArguments.IIS.SiteInclude, args.IIS.SiteInclude)
require.Equal(t, DefaultArguments.LogicalDisk.Exclude, args.LogicalDisk.Exclude)
require.Equal(t, DefaultArguments.LogicalDisk.Include, args.LogicalDisk.Include)
require.Equal(t, DefaultArguments.MSMQ.Where, args.MSMQ.Where)
require.Equal(t, DefaultArguments.MSSQL.EnabledClasses, args.MSSQL.EnabledClasses)
require.Equal(t, DefaultArguments.Network.Exclude, args.Network.Exclude)
require.Equal(t, DefaultArguments.Network.Include, args.Network.Include)
require.Equal(t, DefaultArguments.PhysicalDisk.Exclude, args.PhysicalDisk.Exclude)
require.Equal(t, DefaultArguments.PhysicalDisk.Include, args.PhysicalDisk.Include)
require.Equal(t, DefaultArguments.Process.Exclude, args.Process.Exclude)
require.Equal(t, DefaultArguments.Process.Include, args.Process.Include)
require.Equal(t, DefaultArguments.ScheduledTask.Exclude, args.ScheduledTask.Exclude)
require.Equal(t, DefaultArguments.ScheduledTask.Include, args.ScheduledTask.Include)
require.Equal(t, DefaultArguments.Service.UseApi, args.Service.UseApi)
require.Equal(t, DefaultArguments.Service.Where, args.Service.Where)
require.Equal(t, DefaultArguments.SMTP.Exclude, args.SMTP.Exclude)
require.Equal(t, DefaultArguments.SMTP.Include, args.SMTP.Include)
require.Equal(t, DefaultArguments.TextFile.TextFileDirectory, args.TextFile.TextFileDirectory)
var defaultArgs Arguments
defaultArgs.SetToDefault()
require.Equal(t, defaultArgs.EnabledCollectors, args.EnabledCollectors)
require.Equal(t, defaultArgs.Dfsr.SourcesEnabled, args.Dfsr.SourcesEnabled)
require.Equal(t, defaultArgs.Exchange.EnabledList, args.Exchange.EnabledList)
require.Equal(t, defaultArgs.IIS.AppExclude, args.IIS.AppExclude)
require.Equal(t, defaultArgs.IIS.AppInclude, args.IIS.AppInclude)
require.Equal(t, defaultArgs.IIS.SiteExclude, args.IIS.SiteExclude)
require.Equal(t, defaultArgs.IIS.SiteInclude, args.IIS.SiteInclude)
require.Equal(t, defaultArgs.LogicalDisk.Exclude, args.LogicalDisk.Exclude)
require.Equal(t, defaultArgs.LogicalDisk.Include, args.LogicalDisk.Include)
require.Equal(t, defaultArgs.MSMQ.Where, args.MSMQ.Where)
require.Equal(t, defaultArgs.MSSQL.EnabledClasses, args.MSSQL.EnabledClasses)
require.Equal(t, defaultArgs.Network.Exclude, args.Network.Exclude)
require.Equal(t, defaultArgs.Network.Include, args.Network.Include)
require.Equal(t, defaultArgs.PhysicalDisk.Exclude, args.PhysicalDisk.Exclude)
require.Equal(t, defaultArgs.PhysicalDisk.Include, args.PhysicalDisk.Include)
require.Equal(t, defaultArgs.Process.Exclude, args.Process.Exclude)
require.Equal(t, defaultArgs.Process.Include, args.Process.Include)
require.Equal(t, defaultArgs.ScheduledTask.Exclude, args.ScheduledTask.Exclude)
require.Equal(t, defaultArgs.ScheduledTask.Include, args.ScheduledTask.Include)
require.Equal(t, defaultArgs.Service.UseApi, args.Service.UseApi)
require.Equal(t, defaultArgs.Service.Where, args.Service.Where)
require.Equal(t, defaultArgs.SMTP.Exclude, args.SMTP.Exclude)
require.Equal(t, defaultArgs.SMTP.Include, args.SMTP.Include)
require.Equal(t, defaultArgs.TextFile.TextFileDirectory, args.TextFile.TextFileDirectory)
}
132 changes: 64 additions & 68 deletions internal/component/prometheus/exporter/windows/config_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,74 +7,70 @@ import (
col "github.com/prometheus-community/windows_exporter/pkg/collector"
)

// DefaultArguments holds non-zero default options for Arguments when it is
// unmarshaled from YAML.
var DefaultArguments = Arguments{
EnabledCollectors: strings.Split(windows_integration.DefaultConfig.EnabledCollectors, ","),
Dfsr: DfsrConfig{
SourcesEnabled: strings.Split(col.ConfigDefaults.Dfsr.DfsrEnabledCollectors, ","),
},
Exchange: ExchangeConfig{
EnabledList: strings.Split(col.ConfigDefaults.Exchange.CollectorsEnabled, ","),
},
IIS: IISConfig{
AppBlackList: col.ConfigDefaults.Iis.AppExclude,
AppWhiteList: col.ConfigDefaults.Iis.AppInclude,
SiteBlackList: col.ConfigDefaults.Iis.SiteExclude,
SiteWhiteList: col.ConfigDefaults.Iis.SiteInclude,
AppInclude: col.ConfigDefaults.Iis.AppInclude,
AppExclude: col.ConfigDefaults.Iis.AppExclude,
SiteInclude: col.ConfigDefaults.Iis.SiteInclude,
SiteExclude: col.ConfigDefaults.Iis.SiteExclude,
},
LogicalDisk: LogicalDiskConfig{
BlackList: col.ConfigDefaults.LogicalDisk.VolumeExclude,
WhiteList: col.ConfigDefaults.LogicalDisk.VolumeInclude,
Include: col.ConfigDefaults.LogicalDisk.VolumeInclude,
Exclude: col.ConfigDefaults.LogicalDisk.VolumeExclude,
},
MSMQ: MSMQConfig{
Where: col.ConfigDefaults.Msmq.QueryWhereClause,
},
MSSQL: MSSQLConfig{
EnabledClasses: strings.Split(col.ConfigDefaults.Mssql.EnabledCollectors, ","),
},
Network: NetworkConfig{
BlackList: col.ConfigDefaults.Net.NicExclude,
WhiteList: col.ConfigDefaults.Net.NicInclude,
Include: col.ConfigDefaults.Net.NicInclude,
Exclude: col.ConfigDefaults.Net.NicExclude,
},
PhysicalDisk: PhysicalDiskConfig{
Exclude: col.ConfigDefaults.PhysicalDisk.DiskExclude,
Include: col.ConfigDefaults.PhysicalDisk.DiskInclude,
},
Process: ProcessConfig{
BlackList: col.ConfigDefaults.Process.ProcessExclude,
WhiteList: col.ConfigDefaults.Process.ProcessInclude,
Include: col.ConfigDefaults.Process.ProcessInclude,
Exclude: col.ConfigDefaults.Process.ProcessExclude,
},
ScheduledTask: ScheduledTaskConfig{
Include: col.ConfigDefaults.ScheduledTask.TaskInclude,
Exclude: col.ConfigDefaults.ScheduledTask.TaskExclude,
},
Service: ServiceConfig{
UseApi: "false",
Where: col.ConfigDefaults.Service.ServiceWhereClause,
},
SMTP: SMTPConfig{
BlackList: col.ConfigDefaults.Smtp.ServerExclude,
WhiteList: col.ConfigDefaults.Smtp.ServerInclude,
Include: col.ConfigDefaults.Smtp.ServerInclude,
Exclude: col.ConfigDefaults.Smtp.ServerExclude,
},
TextFile: TextFileConfig{
TextFileDirectory: col.ConfigDefaults.Textfile.TextFileDirectories,
},
}

// SetToDefault implements river.Defaulter.
func (a *Arguments) SetToDefault() {
*a = DefaultArguments
*a = Arguments{
EnabledCollectors: strings.Split(windows_integration.DefaultConfig.EnabledCollectors, ","),
Dfsr: DfsrConfig{
SourcesEnabled: strings.Split(col.ConfigDefaults.Dfsr.DfsrEnabledCollectors, ","),
},
Exchange: ExchangeConfig{
EnabledList: strings.Split(col.ConfigDefaults.Exchange.CollectorsEnabled, ","),
},
IIS: IISConfig{
AppBlackList: col.ConfigDefaults.Iis.AppExclude,
AppWhiteList: col.ConfigDefaults.Iis.AppInclude,
SiteBlackList: col.ConfigDefaults.Iis.SiteExclude,
SiteWhiteList: col.ConfigDefaults.Iis.SiteInclude,
AppInclude: col.ConfigDefaults.Iis.AppInclude,
AppExclude: col.ConfigDefaults.Iis.AppExclude,
SiteInclude: col.ConfigDefaults.Iis.SiteInclude,
SiteExclude: col.ConfigDefaults.Iis.SiteExclude,
},
LogicalDisk: LogicalDiskConfig{
BlackList: col.ConfigDefaults.LogicalDisk.VolumeExclude,
WhiteList: col.ConfigDefaults.LogicalDisk.VolumeInclude,
Include: col.ConfigDefaults.LogicalDisk.VolumeInclude,
Exclude: col.ConfigDefaults.LogicalDisk.VolumeExclude,
},
MSMQ: MSMQConfig{
Where: col.ConfigDefaults.Msmq.QueryWhereClause,
},
MSSQL: MSSQLConfig{
EnabledClasses: strings.Split(col.ConfigDefaults.Mssql.EnabledCollectors, ","),
},
Network: NetworkConfig{
BlackList: col.ConfigDefaults.Net.NicExclude,
WhiteList: col.ConfigDefaults.Net.NicInclude,
Include: col.ConfigDefaults.Net.NicInclude,
Exclude: col.ConfigDefaults.Net.NicExclude,
},
PhysicalDisk: PhysicalDiskConfig{
Exclude: col.ConfigDefaults.PhysicalDisk.DiskExclude,
Include: col.ConfigDefaults.PhysicalDisk.DiskInclude,
},
Process: ProcessConfig{
BlackList: col.ConfigDefaults.Process.ProcessExclude,
WhiteList: col.ConfigDefaults.Process.ProcessInclude,
Include: col.ConfigDefaults.Process.ProcessInclude,
Exclude: col.ConfigDefaults.Process.ProcessExclude,
},
ScheduledTask: ScheduledTaskConfig{
Include: col.ConfigDefaults.ScheduledTask.TaskInclude,
Exclude: col.ConfigDefaults.ScheduledTask.TaskExclude,
},
Service: ServiceConfig{
UseApi: "false",
Where: col.ConfigDefaults.Service.ServiceWhereClause,
},
SMTP: SMTPConfig{
BlackList: col.ConfigDefaults.Smtp.ServerExclude,
WhiteList: col.ConfigDefaults.Smtp.ServerInclude,
Include: col.ConfigDefaults.Smtp.ServerInclude,
Exclude: col.ConfigDefaults.Smtp.ServerExclude,
},
TextFile: TextFileConfig{
TextFileDirectory: col.ConfigDefaults.Textfile.TextFileDirectories,
},
}
}

0 comments on commit 514c541

Please sign in to comment.