Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update windows defaults to use upstream defaults except for enabled collectors. #5832

Merged
merged 9 commits into from
Nov 23, 2023
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
--------------------

Expand Down
71 changes: 0 additions & 71 deletions component/prometheus/exporter/windows/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,72 +6,6 @@ import (
windows_integration "github.com/grafana/agent/pkg/integrations/windows_exporter"
)

// 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(windows_integration.DefaultConfig.Dfsr.SourcesEnabled, ","),
},
Exchange: ExchangeConfig{
EnabledList: strings.Split(windows_integration.DefaultConfig.Exchange.EnabledList, ","),
},
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,
},
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,
},
MSMQ: MSMQConfig{
Where: windows_integration.DefaultConfig.MSMQ.Where,
},
MSSQL: MSSQLConfig{
EnabledClasses: strings.Split(windows_integration.DefaultConfig.MSSQL.EnabledClasses, ","),
},
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,
},
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,
},
ScheduledTask: ScheduledTaskConfig{
Include: windows_integration.DefaultConfig.ScheduledTask.Include,
Exclude: windows_integration.DefaultConfig.ScheduledTask.Exclude,
},
Service: ServiceConfig{
UseApi: windows_integration.DefaultConfig.Service.UseApi,
Where: windows_integration.DefaultConfig.Service.Where,
},
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,
},
TextFile: TextFileConfig{
TextFileDirectory: windows_integration.DefaultConfig.TextFile.TextFileDirectory,
},
}

// Arguments is used for controlling for this exporter.
type Arguments struct {
// Collectors to mark as enabled
Expand All @@ -92,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{
Expand Down
Original file line number Diff line number Diff line change
@@ -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"
)
Expand All @@ -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)
}
75 changes: 75 additions & 0 deletions component/prometheus/exporter/windows/config_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package windows

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.
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
73 changes: 0 additions & 73 deletions pkg/integrations/windows_exporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,71 +7,6 @@ import (
"github.com/grafana/agent/pkg/integrations/v2/metricsutils"
)

// 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: "",
},
Exchange: ExchangeConfig{
EnabledList: "",
},
IIS: IISConfig{
AppBlackList: "",
AppWhiteList: "",
SiteBlackList: "",
SiteWhiteList: "",
AppInclude: "",
AppExclude: "",
SiteInclude: "",
SiteExclude: "",
},
LogicalDisk: LogicalDiskConfig{
BlackList: "",
WhiteList: "",
Include: "",
Exclude: "",
},
MSMQ: MSMQConfig{
Where: "",
},
MSSQL: MSSQLConfig{
EnabledClasses: "",
},
Network: NetworkConfig{
BlackList: "",
WhiteList: "",
Include: "",
Exclude: "",
},
Process: ProcessConfig{
BlackList: "",
WhiteList: "",
Include: "",
Exclude: "",
},
ScheduledTask: ScheduledTaskConfig{
Include: "",
Exclude: "",
},
Service: ServiceConfig{
UseApi: "",
Where: "",
},
SMTP: SMTPConfig{
BlackList: "",
WhiteList: "",
Include: "",
Exclude: "",
},
TextFile: TextFileConfig{
TextFileDirectory: "",
},
}

func init() {
integrations.RegisterIntegration(&Config{})
integrations_v2.RegisterLegacy(&Config{}, integrations_v2.TypeSingleton, metricsutils.NewNamedShim("windows"))
Expand All @@ -96,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"
Expand Down
Loading