From be3890e089cf3627170a2d4b57221807e6fcf360 Mon Sep 17 00:00:00 2001 From: matt durham Date: Tue, 21 Nov 2023 11:25:02 -0500 Subject: [PATCH 1/5] Fix #5831 and use the defaults from windows. --- CHANGELOG.md | 5 ++ .../prometheus/exporter/windows/config.go | 67 ++++++++++--------- .../windows/config_default_windows_test.go | 46 ++++++------- 3 files changed, 61 insertions(+), 57 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78652c614c94..73fb6f240b57 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,11 @@ internal API changes are not present. Main (unreleased) ----------------- + +### Bugfixes + +- Fix issue with windows_exporter defaults not being set correctly. (@mattdurham) + v0.38.0 (2023-11-21) -------------------- diff --git a/component/prometheus/exporter/windows/config.go b/component/prometheus/exporter/windows/config.go index 674d355011c5..c0008f888b88 100644 --- a/component/prometheus/exporter/windows/config.go +++ b/component/prometheus/exporter/windows/config.go @@ -4,6 +4,7 @@ import ( "strings" windows_integration "github.com/grafana/agent/pkg/integrations/windows_exporter" + col "github.com/prometheus-community/windows_exporter/pkg/collector" ) // DefaultArguments holds non-zero default options for Arguments when it is @@ -14,61 +15,61 @@ import ( var DefaultArguments = Arguments{ EnabledCollectors: strings.Split(windows_integration.DefaultConfig.EnabledCollectors, ","), Dfsr: DfsrConfig{ - SourcesEnabled: strings.Split(windows_integration.DefaultConfig.Dfsr.SourcesEnabled, ","), + SourcesEnabled: strings.Split(col.ConfigDefaults.Dfsr.DfsrEnabledCollectors, ","), }, Exchange: ExchangeConfig{ - EnabledList: strings.Split(windows_integration.DefaultConfig.Exchange.EnabledList, ","), + EnabledList: strings.Split(col.ConfigDefaults.Exchange.CollectorsEnabled, ","), }, IIS: IISConfig{ - AppBlackList: windows_integration.DefaultConfig.IIS.AppBlackList, - AppWhiteList: windows_integration.DefaultConfig.IIS.AppWhiteList, - SiteBlackList: windows_integration.DefaultConfig.IIS.SiteBlackList, - SiteWhiteList: windows_integration.DefaultConfig.IIS.SiteWhiteList, - AppInclude: windows_integration.DefaultConfig.IIS.AppInclude, - AppExclude: windows_integration.DefaultConfig.IIS.AppExclude, - SiteInclude: windows_integration.DefaultConfig.IIS.SiteInclude, - SiteExclude: windows_integration.DefaultConfig.IIS.SiteExclude, + 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: windows_integration.DefaultConfig.LogicalDisk.BlackList, - WhiteList: windows_integration.DefaultConfig.LogicalDisk.WhiteList, - Include: windows_integration.DefaultConfig.LogicalDisk.Include, - Exclude: windows_integration.DefaultConfig.LogicalDisk.Exclude, + BlackList: col.ConfigDefaults.LogicalDisk.VolumeExclude, + WhiteList: col.ConfigDefaults.LogicalDisk.VolumeInclude, + Include: col.ConfigDefaults.LogicalDisk.VolumeInclude, + Exclude: col.ConfigDefaults.LogicalDisk.VolumeExclude, }, MSMQ: MSMQConfig{ - Where: windows_integration.DefaultConfig.MSMQ.Where, + Where: col.ConfigDefaults.Msmq.QueryWhereClause, }, MSSQL: MSSQLConfig{ - EnabledClasses: strings.Split(windows_integration.DefaultConfig.MSSQL.EnabledClasses, ","), + EnabledClasses: strings.Split(col.ConfigDefaults.Mssql.EnabledCollectors, ","), }, Network: NetworkConfig{ - BlackList: windows_integration.DefaultConfig.Network.BlackList, - WhiteList: windows_integration.DefaultConfig.Network.WhiteList, - Include: windows_integration.DefaultConfig.Network.Include, - Exclude: windows_integration.DefaultConfig.Network.Exclude, + BlackList: col.ConfigDefaults.Net.NicExclude, + WhiteList: col.ConfigDefaults.Net.NicInclude, + Include: col.ConfigDefaults.Net.NicInclude, + Exclude: col.ConfigDefaults.Net.NicExclude, }, Process: ProcessConfig{ - BlackList: windows_integration.DefaultConfig.Process.BlackList, - WhiteList: windows_integration.DefaultConfig.Process.WhiteList, - Include: windows_integration.DefaultConfig.Process.Include, - Exclude: windows_integration.DefaultConfig.Process.Exclude, + BlackList: col.ConfigDefaults.Process.ProcessExclude, + WhiteList: col.ConfigDefaults.Process.ProcessInclude, + Include: col.ConfigDefaults.Process.ProcessInclude, + Exclude: col.ConfigDefaults.Process.ProcessExclude, }, ScheduledTask: ScheduledTaskConfig{ - Include: windows_integration.DefaultConfig.ScheduledTask.Include, - Exclude: windows_integration.DefaultConfig.ScheduledTask.Exclude, + Include: col.ConfigDefaults.ScheduledTask.TaskInclude, + Exclude: col.ConfigDefaults.ScheduledTask.TaskExclude, }, Service: ServiceConfig{ - UseApi: windows_integration.DefaultConfig.Service.UseApi, - Where: windows_integration.DefaultConfig.Service.Where, + UseApi: "false", + Where: col.ConfigDefaults.Service.ServiceWhereClause, }, SMTP: SMTPConfig{ - BlackList: windows_integration.DefaultConfig.SMTP.BlackList, - WhiteList: windows_integration.DefaultConfig.SMTP.WhiteList, - Include: windows_integration.DefaultConfig.SMTP.Include, - Exclude: windows_integration.DefaultConfig.SMTP.Exclude, + BlackList: col.ConfigDefaults.Smtp.ServerExclude, + WhiteList: col.ConfigDefaults.Smtp.ServerInclude, + Include: col.ConfigDefaults.Smtp.ServerInclude, + Exclude: col.ConfigDefaults.Smtp.ServerExclude, }, TextFile: TextFileConfig{ - TextFileDirectory: windows_integration.DefaultConfig.TextFile.TextFileDirectory, + TextFileDirectory: col.ConfigDefaults.Textfile.TextFileDirectories, }, } diff --git a/component/prometheus/exporter/windows/config_default_windows_test.go b/component/prometheus/exporter/windows/config_default_windows_test.go index c17f6e33fa60..9fddd1d635eb 100644 --- a/component/prometheus/exporter/windows/config_default_windows_test.go +++ b/component/prometheus/exporter/windows/config_default_windows_test.go @@ -1,10 +1,8 @@ package windows import ( - "strings" "testing" - windows_integration "github.com/grafana/agent/pkg/integrations/windows_exporter" "github.com/grafana/river" "github.com/stretchr/testify/require" ) @@ -14,26 +12,26 @@ func TestRiverUnmarshalWithDefaultConfig(t *testing.T) { err := river.Unmarshal([]byte(""), &args) require.NoError(t, err) - require.Equal(t, strings.Split(windows_integration.DefaultConfig.EnabledCollectors, ","), args.EnabledCollectors) - require.Equal(t, strings.Split(windows_integration.DefaultConfig.Dfsr.SourcesEnabled, ","), args.Dfsr.SourcesEnabled) - require.Equal(t, strings.Split(windows_integration.DefaultConfig.Exchange.EnabledList, ","), args.Exchange.EnabledList) - require.Equal(t, windows_integration.DefaultConfig.IIS.AppExclude, args.IIS.AppExclude) - require.Equal(t, windows_integration.DefaultConfig.IIS.AppInclude, args.IIS.AppInclude) - require.Equal(t, windows_integration.DefaultConfig.IIS.SiteExclude, args.IIS.SiteExclude) - require.Equal(t, windows_integration.DefaultConfig.IIS.SiteInclude, args.IIS.SiteInclude) - require.Equal(t, windows_integration.DefaultConfig.LogicalDisk.Exclude, args.LogicalDisk.Exclude) - require.Equal(t, windows_integration.DefaultConfig.LogicalDisk.Include, args.LogicalDisk.Include) - require.Equal(t, windows_integration.DefaultConfig.MSMQ.Where, args.MSMQ.Where) - require.Equal(t, strings.Split(windows_integration.DefaultConfig.MSSQL.EnabledClasses, ","), args.MSSQL.EnabledClasses) - require.Equal(t, windows_integration.DefaultConfig.Network.Exclude, args.Network.Exclude) - require.Equal(t, windows_integration.DefaultConfig.Network.Include, args.Network.Include) - require.Equal(t, windows_integration.DefaultConfig.Process.Exclude, args.Process.Exclude) - require.Equal(t, windows_integration.DefaultConfig.Process.Include, args.Process.Include) - require.Equal(t, windows_integration.DefaultConfig.ScheduledTask.Exclude, args.ScheduledTask.Exclude) - require.Equal(t, windows_integration.DefaultConfig.ScheduledTask.Include, args.ScheduledTask.Include) - require.Equal(t, windows_integration.DefaultConfig.Service.UseApi, args.Service.UseApi) - require.Equal(t, windows_integration.DefaultConfig.Service.Where, args.Service.Where) - require.Equal(t, windows_integration.DefaultConfig.SMTP.Exclude, args.SMTP.Exclude) - require.Equal(t, windows_integration.DefaultConfig.SMTP.Include, args.SMTP.Include) - require.Equal(t, windows_integration.DefaultConfig.TextFile.TextFileDirectory, args.TextFile.TextFileDirectory) + 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.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) } From c19a569bc0bd8143c3fc78c45e90b51961698707 Mon Sep 17 00:00:00 2001 From: matt durham Date: Tue, 21 Nov 2023 11:39:08 -0500 Subject: [PATCH 2/5] fix issue with default --- .../internal/build/windows_exporter.go | 4 +- pkg/integrations/windows_exporter/config.go | 70 +++++++++---------- 2 files changed, 36 insertions(+), 38 deletions(-) diff --git a/converter/internal/staticconvert/internal/build/windows_exporter.go b/converter/internal/staticconvert/internal/build/windows_exporter.go index 27e9679887b8..73aa706e8235 100644 --- a/converter/internal/staticconvert/internal/build/windows_exporter.go +++ b/converter/internal/staticconvert/internal/build/windows_exporter.go @@ -47,8 +47,8 @@ func toWindowsExporter(config *windows_exporter.Config) *windows.Arguments { Network: windows.NetworkConfig{ BlackList: config.Network.BlackList, WhiteList: config.Network.WhiteList, - Exclude: config.Network.Include, - Include: config.Network.Exclude, + Exclude: config.Network.Exclude, + Include: config.Network.Include, }, Process: windows.ProcessConfig{ BlackList: config.Process.BlackList, diff --git a/pkg/integrations/windows_exporter/config.go b/pkg/integrations/windows_exporter/config.go index 37f4e249a8fa..9aa6e58a10f9 100644 --- a/pkg/integrations/windows_exporter/config.go +++ b/pkg/integrations/windows_exporter/config.go @@ -5,70 +5,68 @@ import ( "github.com/grafana/agent/pkg/integrations" integrations_v2 "github.com/grafana/agent/pkg/integrations/v2" "github.com/grafana/agent/pkg/integrations/v2/metricsutils" + col "github.com/prometheus-community/windows_exporter/pkg/collector" ) // DefaultConfig holds the default settings for the windows_exporter integration. var DefaultConfig = Config{ - // NOTE(rfratto): there is an init function in config_windows.go that - // populates defaults for collectors based on the exporter defaults. EnabledCollectors: "cpu,cs,logical_disk,net,os,service,system", - Dfsr: DfsrConfig{ - SourcesEnabled: "", + SourcesEnabled: col.ConfigDefaults.Dfsr.DfsrEnabledCollectors, }, Exchange: ExchangeConfig{ - EnabledList: "", + EnabledList: col.ConfigDefaults.Exchange.CollectorsEnabled, }, IIS: IISConfig{ - AppBlackList: "", - AppWhiteList: "", - SiteBlackList: "", - SiteWhiteList: "", - AppInclude: "", - AppExclude: "", - SiteInclude: "", - SiteExclude: "", + 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: "", - WhiteList: "", - Include: "", - Exclude: "", + BlackList: col.ConfigDefaults.LogicalDisk.VolumeExclude, + WhiteList: col.ConfigDefaults.LogicalDisk.VolumeInclude, + Include: col.ConfigDefaults.LogicalDisk.VolumeInclude, + Exclude: col.ConfigDefaults.LogicalDisk.VolumeExclude, }, MSMQ: MSMQConfig{ - Where: "", + Where: col.ConfigDefaults.Msmq.QueryWhereClause, }, MSSQL: MSSQLConfig{ - EnabledClasses: "", + EnabledClasses: col.ConfigDefaults.Mssql.EnabledCollectors, }, Network: NetworkConfig{ - BlackList: "", - WhiteList: "", - Include: "", - Exclude: "", + BlackList: col.ConfigDefaults.Net.NicExclude, + WhiteList: col.ConfigDefaults.Net.NicInclude, + Include: col.ConfigDefaults.Net.NicInclude, + Exclude: col.ConfigDefaults.Net.NicExclude, }, Process: ProcessConfig{ - BlackList: "", - WhiteList: "", - Include: "", - Exclude: "", + BlackList: col.ConfigDefaults.Process.ProcessExclude, + WhiteList: col.ConfigDefaults.Process.ProcessInclude, + Include: col.ConfigDefaults.Process.ProcessInclude, + Exclude: col.ConfigDefaults.Process.ProcessExclude, }, ScheduledTask: ScheduledTaskConfig{ - Include: "", - Exclude: "", + Include: col.ConfigDefaults.ScheduledTask.TaskInclude, + Exclude: col.ConfigDefaults.ScheduledTask.TaskExclude, }, Service: ServiceConfig{ - UseApi: "", - Where: "", + UseApi: "false", + Where: col.ConfigDefaults.Service.ServiceWhereClause, }, SMTP: SMTPConfig{ - BlackList: "", - WhiteList: "", - Include: "", - Exclude: "", + BlackList: col.ConfigDefaults.Smtp.ServerExclude, + WhiteList: col.ConfigDefaults.Smtp.ServerInclude, + Include: col.ConfigDefaults.Smtp.ServerInclude, + Exclude: col.ConfigDefaults.Smtp.ServerExclude, }, TextFile: TextFileConfig{ - TextFileDirectory: "", + TextFileDirectory: col.ConfigDefaults.Textfile.TextFileDirectories, }, } From 33ad1cd49872afa9f1e7c2493b8b61ca9c04996d Mon Sep 17 00:00:00 2001 From: matt durham Date: Tue, 21 Nov 2023 11:51:49 -0500 Subject: [PATCH 3/5] Ensure the windows changes work on linux. --- .../prometheus/exporter/windows/config.go | 72 ------------------ .../exporter/windows/config_windows.go | 71 ++++++++++++++++++ pkg/integrations/windows_exporter/config.go | 71 ------------------ .../windows_exporter/config_windows.go | 75 ++++++++++++++++++- 4 files changed, 145 insertions(+), 144 deletions(-) create mode 100644 component/prometheus/exporter/windows/config_windows.go diff --git a/component/prometheus/exporter/windows/config.go b/component/prometheus/exporter/windows/config.go index c0008f888b88..cc4cb20e4b17 100644 --- a/component/prometheus/exporter/windows/config.go +++ b/component/prometheus/exporter/windows/config.go @@ -4,75 +4,8 @@ import ( "strings" windows_integration "github.com/grafana/agent/pkg/integrations/windows_exporter" - col "github.com/prometheus-community/windows_exporter/pkg/collector" ) -// DefaultArguments holds non-zero default options for Arguments when it is -// unmarshaled from YAML. -// -// Some defaults are populated from init functions in the github.com/grafana/agent/pkg/integrations/windows_exporter package. - -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, - }, - 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, - }, -} - // Arguments is used for controlling for this exporter. type Arguments struct { // Collectors to mark as enabled @@ -93,11 +26,6 @@ type Arguments struct { TextFile TextFileConfig `river:"text_file,block,optional"` } -// SetToDefault implements river.Defaulter. -func (a *Arguments) SetToDefault() { - *a = DefaultArguments -} - // Convert converts the component's Arguments to the integration's Config. func (a *Arguments) Convert() *windows_integration.Config { return &windows_integration.Config{ diff --git a/component/prometheus/exporter/windows/config_windows.go b/component/prometheus/exporter/windows/config_windows.go new file mode 100644 index 000000000000..3b39687761f1 --- /dev/null +++ b/component/prometheus/exporter/windows/config_windows.go @@ -0,0 +1,71 @@ +package windows + +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, + }, + 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 +} diff --git a/pkg/integrations/windows_exporter/config.go b/pkg/integrations/windows_exporter/config.go index 9aa6e58a10f9..006bc5426d72 100644 --- a/pkg/integrations/windows_exporter/config.go +++ b/pkg/integrations/windows_exporter/config.go @@ -5,71 +5,8 @@ import ( "github.com/grafana/agent/pkg/integrations" integrations_v2 "github.com/grafana/agent/pkg/integrations/v2" "github.com/grafana/agent/pkg/integrations/v2/metricsutils" - col "github.com/prometheus-community/windows_exporter/pkg/collector" ) -// DefaultConfig holds the default settings for the windows_exporter integration. -var DefaultConfig = Config{ - EnabledCollectors: "cpu,cs,logical_disk,net,os,service,system", - Dfsr: DfsrConfig{ - SourcesEnabled: col.ConfigDefaults.Dfsr.DfsrEnabledCollectors, - }, - Exchange: ExchangeConfig{ - EnabledList: 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: 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, - }, - 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, - }, -} - func init() { integrations.RegisterIntegration(&Config{}) integrations_v2.RegisterLegacy(&Config{}, integrations_v2.TypeSingleton, metricsutils.NewNamedShim("windows")) @@ -94,14 +31,6 @@ type Config struct { ScheduledTask ScheduledTaskConfig `yaml:"scheduled_task,omitempty"` } -// UnmarshalYAML implements yaml.Unmarshaler for Config. -func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error { - *c = DefaultConfig - - type plain Config - return unmarshal((*plain)(c)) -} - // Name returns the name used, "windows_explorer" func (c *Config) Name() string { return "windows_exporter" diff --git a/pkg/integrations/windows_exporter/config_windows.go b/pkg/integrations/windows_exporter/config_windows.go index cb556363d084..41079dd7a3e6 100644 --- a/pkg/integrations/windows_exporter/config_windows.go +++ b/pkg/integrations/windows_exporter/config_windows.go @@ -1,6 +1,9 @@ package windows_exporter -import "github.com/prometheus-community/windows_exporter/pkg/collector" +import ( + "github.com/prometheus-community/windows_exporter/pkg/collector" + col "github.com/prometheus-community/windows_exporter/pkg/collector" +) func (c *Config) ToWindowsExporterConfig() collector.Config { cfg := collector.ConfigDefaults @@ -47,3 +50,73 @@ func coalesceString(v ...string) string { } return "" } + +// DefaultConfig holds the default settings for the windows_exporter integration. +var DefaultConfig = Config{ + EnabledCollectors: "cpu,cs,logical_disk,net,os,service,system", + Dfsr: DfsrConfig{ + SourcesEnabled: col.ConfigDefaults.Dfsr.DfsrEnabledCollectors, + }, + Exchange: ExchangeConfig{ + EnabledList: 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: 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, + }, + 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, + }, +} + +// UnmarshalYAML implements yaml.Unmarshaler for Config. +func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error { + *c = DefaultConfig + + type plain Config + return unmarshal((*plain)(c)) +} From 990f264ef074e33d4decd43852a00305b91afb76 Mon Sep 17 00:00:00 2001 From: matt durham Date: Tue, 21 Nov 2023 11:56:18 -0500 Subject: [PATCH 4/5] Fix windows specific issues. --- component/prometheus/exporter/windows/config_windows.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/component/prometheus/exporter/windows/config_windows.go b/component/prometheus/exporter/windows/config_windows.go index 3b39687761f1..b634788eda8c 100644 --- a/component/prometheus/exporter/windows/config_windows.go +++ b/component/prometheus/exporter/windows/config_windows.go @@ -1,6 +1,10 @@ package windows -import col "github.com/prometheus-community/windows_exporter/pkg/collector" +import ( + windows_integration "github.com/grafana/agent/pkg/integrations/windows_exporter" + col "github.com/prometheus-community/windows_exporter/pkg/collector" + "strings" +) // DefaultArguments holds non-zero default options for Arguments when it is // unmarshaled from YAML. From 6eba219f57cb5a5580cbb7383213680a26d99207 Mon Sep 17 00:00:00 2001 From: matt durham Date: Wed, 22 Nov 2023 09:20:38 -0500 Subject: [PATCH 5/5] remove duplicate import --- .../windows_exporter/config_windows.go | 65 +++++++++---------- 1 file changed, 32 insertions(+), 33 deletions(-) diff --git a/pkg/integrations/windows_exporter/config_windows.go b/pkg/integrations/windows_exporter/config_windows.go index 41079dd7a3e6..17fd03d4f80c 100644 --- a/pkg/integrations/windows_exporter/config_windows.go +++ b/pkg/integrations/windows_exporter/config_windows.go @@ -2,7 +2,6 @@ package windows_exporter import ( "github.com/prometheus-community/windows_exporter/pkg/collector" - col "github.com/prometheus-community/windows_exporter/pkg/collector" ) func (c *Config) ToWindowsExporterConfig() collector.Config { @@ -55,61 +54,61 @@ func coalesceString(v ...string) string { var DefaultConfig = Config{ EnabledCollectors: "cpu,cs,logical_disk,net,os,service,system", Dfsr: DfsrConfig{ - SourcesEnabled: col.ConfigDefaults.Dfsr.DfsrEnabledCollectors, + SourcesEnabled: collector.ConfigDefaults.Dfsr.DfsrEnabledCollectors, }, Exchange: ExchangeConfig{ - EnabledList: col.ConfigDefaults.Exchange.CollectorsEnabled, + EnabledList: collector.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, + AppBlackList: collector.ConfigDefaults.Iis.AppExclude, + AppWhiteList: collector.ConfigDefaults.Iis.AppInclude, + SiteBlackList: collector.ConfigDefaults.Iis.SiteExclude, + SiteWhiteList: collector.ConfigDefaults.Iis.SiteInclude, + AppInclude: collector.ConfigDefaults.Iis.AppInclude, + AppExclude: collector.ConfigDefaults.Iis.AppExclude, + SiteInclude: collector.ConfigDefaults.Iis.SiteInclude, + SiteExclude: collector.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, + BlackList: collector.ConfigDefaults.LogicalDisk.VolumeExclude, + WhiteList: collector.ConfigDefaults.LogicalDisk.VolumeInclude, + Include: collector.ConfigDefaults.LogicalDisk.VolumeInclude, + Exclude: collector.ConfigDefaults.LogicalDisk.VolumeExclude, }, MSMQ: MSMQConfig{ - Where: col.ConfigDefaults.Msmq.QueryWhereClause, + Where: collector.ConfigDefaults.Msmq.QueryWhereClause, }, MSSQL: MSSQLConfig{ - EnabledClasses: col.ConfigDefaults.Mssql.EnabledCollectors, + EnabledClasses: collector.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, + BlackList: collector.ConfigDefaults.Net.NicExclude, + WhiteList: collector.ConfigDefaults.Net.NicInclude, + Include: collector.ConfigDefaults.Net.NicInclude, + Exclude: collector.ConfigDefaults.Net.NicExclude, }, Process: ProcessConfig{ - BlackList: col.ConfigDefaults.Process.ProcessExclude, - WhiteList: col.ConfigDefaults.Process.ProcessInclude, - Include: col.ConfigDefaults.Process.ProcessInclude, - Exclude: col.ConfigDefaults.Process.ProcessExclude, + BlackList: collector.ConfigDefaults.Process.ProcessExclude, + WhiteList: collector.ConfigDefaults.Process.ProcessInclude, + Include: collector.ConfigDefaults.Process.ProcessInclude, + Exclude: collector.ConfigDefaults.Process.ProcessExclude, }, ScheduledTask: ScheduledTaskConfig{ - Include: col.ConfigDefaults.ScheduledTask.TaskInclude, - Exclude: col.ConfigDefaults.ScheduledTask.TaskExclude, + Include: collector.ConfigDefaults.ScheduledTask.TaskInclude, + Exclude: collector.ConfigDefaults.ScheduledTask.TaskExclude, }, Service: ServiceConfig{ UseApi: "false", - Where: col.ConfigDefaults.Service.ServiceWhereClause, + Where: collector.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, + BlackList: collector.ConfigDefaults.Smtp.ServerExclude, + WhiteList: collector.ConfigDefaults.Smtp.ServerInclude, + Include: collector.ConfigDefaults.Smtp.ServerInclude, + Exclude: collector.ConfigDefaults.Smtp.ServerExclude, }, TextFile: TextFileConfig{ - TextFileDirectory: col.ConfigDefaults.Textfile.TextFileDirectories, + TextFileDirectory: collector.ConfigDefaults.Textfile.TextFileDirectories, }, }