diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 8325e3fee..17bb6c80f 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -16,14 +16,33 @@ permissions: jobs: golangci: name: lint-codebase - runs-on: ubuntu-latest + strategy: + fail-fast: false + max-parallel: 3 + matrix: + os: [ ubuntu-latest, macos-latest, windows-latest ] + runs-on: ${{ matrix.os }} + timeout-minutes: 360 #default steps: - - uses: actions/setup-go@v3 + - name: Checkout code + uses: actions/checkout@v3 + - name: Setup Go + uses: actions/setup-go@v4 with: go-version: '1.20' - - uses: actions/checkout@v3 - - name: golangci-lint + - name: golangci-lint standard + if: runner.os != 'Windows' uses: golangci/golangci-lint-action@v3 + timeout-minutes: 60 with: version: v1.53.2 - args: --timeout 15m0s --verbose --out-${NO_FUTURE}format tab + args: --timeout 60m0s --verbose --out-${NO_FUTURE}format tab + - name: golangci-lint windows + if: runner.os == 'Windows' + uses: golangci/golangci-lint-action@v3 + timeout-minutes: 60 + env: + nofuture: out-format + with: + version: v1.53.2 + args: --timeout 60m0s --verbose --%nofuture% tab diff --git a/plugins/inputs/diskio/diskio.go b/plugins/inputs/diskio/diskio.go index 5f2d9993f..f24eb5613 100644 --- a/plugins/inputs/diskio/diskio.go +++ b/plugins/inputs/diskio/diskio.go @@ -20,20 +20,6 @@ var ( varRegex = regexp.MustCompile(`\$(?:\w+|\{\w+\})`) ) -type DiskIO struct { - ps system.PS - - Devices []string - DeviceTags []string - NameTemplates []string - SkipSerialNumber bool - - Log telegraf.Logger - - infoCache map[string]diskInfoCache - deviceFilter filter.Filter -} - // hasMeta reports whether s contains any special glob characters. func hasMeta(s string) bool { return strings.ContainsAny(s, "*?[") diff --git a/plugins/inputs/diskio/diskio_linux.go b/plugins/inputs/diskio/diskio_linux.go index 2b0cea53f..c8416c26e 100644 --- a/plugins/inputs/diskio/diskio_linux.go +++ b/plugins/inputs/diskio/diskio_linux.go @@ -10,9 +10,26 @@ import ( "path/filepath" "strings" + "github.com/influxdata/telegraf" + "github.com/influxdata/telegraf/filter" + "github.com/influxdata/telegraf/plugins/inputs/system" "golang.org/x/sys/unix" ) +type DiskIO struct { + ps system.PS + + Devices []string + DeviceTags []string + NameTemplates []string + SkipSerialNumber bool + + Log telegraf.Logger + + infoCache map[string]diskInfoCache + deviceFilter filter.Filter +} + type diskInfoCache struct { modifiedAt int64 // Unix Nano timestamp of the last modification of the device. This value is used to invalidate the cache udevDataPath string diff --git a/plugins/inputs/diskio/diskio_other.go b/plugins/inputs/diskio/diskio_other.go index 44507ae3f..63a9d2416 100644 --- a/plugins/inputs/diskio/diskio_other.go +++ b/plugins/inputs/diskio/diskio_other.go @@ -2,7 +2,24 @@ package diskio -type diskInfoCache struct{} +import ( + "github.com/influxdata/telegraf" + "github.com/influxdata/telegraf/filter" + "github.com/influxdata/telegraf/plugins/inputs/system" +) + +type DiskIO struct { + ps system.PS + + Devices []string + DeviceTags []string + NameTemplates []string + SkipSerialNumber bool + + Log telegraf.Logger + + deviceFilter filter.Filter +} func (*DiskIO) diskInfo(_ string) (map[string]string, error) { return nil, nil diff --git a/plugins/inputs/ethtool/ethtool.go b/plugins/inputs/ethtool/ethtool.go index 314272c50..70decafef 100644 --- a/plugins/inputs/ethtool/ethtool.go +++ b/plugins/inputs/ethtool/ethtool.go @@ -3,11 +3,10 @@ package ethtool import ( _ "embed" - - "github.com/influxdata/telegraf" - "github.com/influxdata/telegraf/filter" ) +const pluginName = "ethtool" + //go:embed sample.conf var sampleConfig string @@ -19,43 +18,6 @@ type Command interface { Get(intf NamespacedInterface) (map[string]uint64, error) } -type Ethtool struct { - // This is the list of interface names to include - InterfaceInclude []string `toml:"interface_include"` - - // This is the list of interface names to ignore - InterfaceExclude []string `toml:"interface_exclude"` - - // Behavior regarding metrics for downed interfaces - DownInterfaces string `toml:" down_interfaces"` - - // This is the list of namespace names to include - NamespaceInclude []string `toml:"namespace_include"` - - // This is the list of namespace names to ignore - NamespaceExclude []string `toml:"namespace_exclude"` - - // Normalization on the key names - NormalizeKeys []string `toml:"normalize_keys"` - - Log telegraf.Logger `toml:"-"` - - interfaceFilter filter.Filter - namespaceFilter filter.Filter - includeNamespaces bool - - // the ethtool command - command Command -} - func (*Ethtool) SampleConfig() string { return sampleConfig } - -const ( - pluginName = "ethtool" - tagInterface = "interface" - tagNamespace = "namespace" - tagDriverName = "driver" - fieldInterfaceUp = "interface_up" -) diff --git a/plugins/inputs/ethtool/ethtool_linux.go b/plugins/inputs/ethtool/ethtool_linux.go index afbcaaeb7..d506a5a23 100644 --- a/plugins/inputs/ethtool/ethtool_linux.go +++ b/plugins/inputs/ethtool/ethtool_linux.go @@ -19,8 +19,44 @@ import ( "github.com/influxdata/telegraf/plugins/inputs" ) +const ( + tagInterface = "interface" + tagNamespace = "namespace" + tagDriverName = "driver" + fieldInterfaceUp = "interface_up" +) + var downInterfacesBehaviors = []string{"expose", "skip"} +type Ethtool struct { + // This is the list of interface names to include + InterfaceInclude []string `toml:"interface_include"` + + // This is the list of interface names to ignore + InterfaceExclude []string `toml:"interface_exclude"` + + // Behavior regarding metrics for downed interfaces + DownInterfaces string `toml:" down_interfaces"` + + // This is the list of namespace names to include + NamespaceInclude []string `toml:"namespace_include"` + + // This is the list of namespace names to ignore + NamespaceExclude []string `toml:"namespace_exclude"` + + // Normalization on the key names + NormalizeKeys []string `toml:"normalize_keys"` + + Log telegraf.Logger `toml:"-"` + + interfaceFilter filter.Filter + namespaceFilter filter.Filter + includeNamespaces bool + + // the ethtool command + command Command +} + type CommandEthtool struct { Log telegraf.Logger namespaceGoroutines map[string]*NamespaceGoroutine diff --git a/plugins/inputs/ethtool/ethtool_notlinux.go b/plugins/inputs/ethtool/ethtool_notlinux.go index 59d40ba62..a51c1bee2 100644 --- a/plugins/inputs/ethtool/ethtool_notlinux.go +++ b/plugins/inputs/ethtool/ethtool_notlinux.go @@ -7,6 +7,28 @@ import ( "github.com/influxdata/telegraf/plugins/inputs" ) +type Ethtool struct { + // This is the list of interface names to include + InterfaceInclude []string `toml:"interface_include"` + + // This is the list of interface names to ignore + InterfaceExclude []string `toml:"interface_exclude"` + + // Behavior regarding metrics for downed interfaces + DownInterfaces string `toml:" down_interfaces"` + + // This is the list of namespace names to include + NamespaceInclude []string `toml:"namespace_include"` + + // This is the list of namespace names to ignore + NamespaceExclude []string `toml:"namespace_exclude"` + + // Normalization on the key names + NormalizeKeys []string `toml:"normalize_keys"` + + Log telegraf.Logger `toml:"-"` +} + func (e *Ethtool) Init() error { e.Log.Warn("Current platform is not supported") return nil diff --git a/plugins/inputs/win_wmi/win_wmi_test.go b/plugins/inputs/win_wmi/win_wmi_test.go index 18b9c2c76..175268aa4 100644 --- a/plugins/inputs/win_wmi/win_wmi_test.go +++ b/plugins/inputs/win_wmi/win_wmi_test.go @@ -18,16 +18,20 @@ var sysDrive = fmt.Sprintf(`%s\`, os.Getenv("SystemDrive")) // C:\ // include Name as a tag, FreeSpace as a field, and Purpose as a known-null class property var testQuery = Query{ - Namespace: "ROOT\\cimv2", - ClassName: "Win32_Volume", - Properties: []string{"Name", "FreeSpace", "Purpose"}, + Namespace: "ROOT\\cimv2", + ClassName: "Win32_Volume", + Properties: []string{"Name", "FreeSpace", "Purpose"}, + //nolint:gocritic // sprintfQuotedString - "%s" used by purpose, string escaping is done by special function Filter: fmt.Sprintf(`NOT Name LIKE "\\\\?\\%%" AND Name LIKE "%s"`, regexp.QuoteMeta(sysDrive)), TagPropertiesInclude: []string{"Name"}, tagFilter: nil, // this is filled in by CompileInputs() } + +//nolint:gocritic // sprintfQuotedString - "%s" used by purpose, string escaping is done by special function var expectedWql = fmt.Sprintf( `SELECT Name, FreeSpace, Purpose FROM Win32_Volume WHERE NOT Name LIKE "\\\\?\\%%" AND Name LIKE "%s"`, - regexp.QuoteMeta(sysDrive)) + regexp.QuoteMeta(sysDrive), +) // test buildWqlStatements func TestWmi_buildWqlStatements(t *testing.T) {