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

chore: Fix linter findings for Windows (part4) #13246

Merged
merged 5 commits into from
Jun 9, 2023
Merged

chore: Fix linter findings for Windows (part4) #13246

merged 5 commits into from
Jun 9, 2023

Conversation

zak-pawel
Copy link
Collaborator

It is last part of the bigger job: #13036
After merging this PR, linter CI job for Windows and Darwin can be enabled.

Fixes for following findings have been made:

agent/agent_windows.go:7:26                                 revive  unused-parameter: parameter 'flushRequested' seems to be unused, consider removing or renaming it as _
agent/agent_windows.go:11:34                                revive  unused-parameter: parameter 'flushRequested' seems to be unused, consider removing or renaming it as _
cmd/telegraf/telegraf_windows.go:78:25                      revive  unused-parameter: parameter 's' seems to be unused, consider removing or renaming it as _
cmd/telegraf/telegraf_windows.go:90:19                      unused  func `(*program).run` is unused
cmd/telegraf/telegraf_windows.go:97:24                      revive  unused-parameter: parameter 's' seems to be unused, consider removing or renaming it as _
logger/event_logger.go:51:43                                revive  unused-parameter: parameter 'config' seems to be unused, consider removing or renaming it as _
plugins/inputs/diskio/diskio.go:33:2                        unused  field `infoCache` is unused
plugins/inputs/diskio/diskio_other.go:5:6                   unused  type `diskInfoCache` is unused
plugins/inputs/ethtool/ethtool.go:43:2                      unused  field `interfaceFilter` is unused
plugins/inputs/ethtool/ethtool.go:44:2                      unused  field `namespaceFilter` is unused
plugins/inputs/ethtool/ethtool.go:45:2                      unused  field `includeNamespaces` is unused
plugins/inputs/ethtool/ethtool.go:48:2                      unused  field `command` is unused
plugins/inputs/execd/execd_windows.go:15:24                 revive  unused-parameter: parameter 'acc' seems to be unused, consider removing or renaming it as _
plugins/inputs/filecount/filesystem_helpers.go:43:6         unused  type `fakeFileSystem` is unused
plugins/inputs/filecount/filesystem_helpers.go:47:6         unused  type `fakeFileInfo` is unused
plugins/inputs/filecount/filesystem_helpers.go:56:23        unused  func `fakeFileInfo.Name` is unused
plugins/inputs/filecount/filesystem_helpers.go:57:23        unused  func `fakeFileInfo.Size` is unused
plugins/inputs/filecount/filesystem_helpers.go:58:23        unused  func `fakeFileInfo.Mode` is unused
plugins/inputs/filecount/filesystem_helpers.go:59:23        unused  func `fakeFileInfo.ModTime` is unused
plugins/inputs/filecount/filesystem_helpers.go:60:23        unused  func `fakeFileInfo.IsDir` is unused
plugins/inputs/filecount/filesystem_helpers.go:61:23        unused  func `fakeFileInfo.Sys` is unused
plugins/inputs/filecount/filesystem_helpers.go:63:25        unused  func `fakeFileSystem.Open` is unused
plugins/inputs/filecount/filesystem_helpers.go:67:25        unused  func `fakeFileSystem.Stat` is unused
plugins/inputs/ping/ping.go:91:6                            unused  type `roundTripTimeStats` is unused
plugins/inputs/ping/ping.go:98:6                            unused  type `stats` is unused
plugins/inputs/ping/ping_windows.go:88:1                    revive  function-result-limit: maximum number of return results per function exceeded; max 3 but got 7
plugins/inputs/ping/ping_windows.go:88:1                    revive  confusing-results: unnamed results of the same type may be confusing, consider using named results
plugins/inputs/ping/ping_windows.go:96:26                   revive  var-declaration: should drop = 0 from declaration of var receivedReply; it is the zero value
plugins/inputs/ping/ping_windows_test.go:64:21              revive  unused-parameter: parameter 'binary' seems to be unused, consider removing or renaming it as _
plugins/inputs/ping/ping_windows_test.go:64:36              revive  unused-parameter: parameter 'timeout' seems to be unused, consider removing or renaming it as _
plugins/inputs/ping/ping_windows_test.go:64:53              revive  unused-parameter: parameter 'args' seems to be unused, consider removing or renaming it as _
plugins/inputs/ping/ping_windows_test.go:107:26             revive  unused-parameter: parameter 'binary' seems to be unused, consider removing or renaming it as _
plugins/inputs/ping/ping_windows_test.go:107:41             revive  unused-parameter: parameter 'timeout' seems to be unused, consider removing or renaming it as _
plugins/inputs/ping/ping_windows_test.go:107:58             revive  unused-parameter: parameter 'args' seems to be unused, consider removing or renaming it as _
plugins/inputs/ping/ping_windows_test.go:168:26             revive  unused-parameter: parameter 'binary' seems to be unused, consider removing or renaming it as _
plugins/inputs/ping/ping_windows_test.go:168:41             revive  unused-parameter: parameter 'timeout' seems to be unused, consider removing or renaming it as _
plugins/inputs/ping/ping_windows_test.go:168:58             revive  unused-parameter: parameter 'args' seems to be unused, consider removing or renaming it as _
plugins/inputs/ping/ping_windows_test.go:231:26             revive  unused-parameter: parameter 'binary' seems to be unused, consider removing or renaming it as _
plugins/inputs/ping/ping_windows_test.go:231:41             revive  unused-parameter: parameter 'timeout' seems to be unused, consider removing or renaming it as _
plugins/inputs/ping/ping_windows_test.go:231:58             revive  unused-parameter: parameter 'args' seems to be unused, consider removing or renaming it as _
plugins/inputs/ping/ping_windows_test.go:276:32             revive  unused-parameter: parameter 'binary' seems to be unused, consider removing or renaming it as _
plugins/inputs/ping/ping_windows_test.go:276:47             revive  unused-parameter: parameter 'timeout' seems to be unused, consider removing or renaming it as _
plugins/inputs/ping/ping_windows_test.go:276:64             revive  unused-parameter: parameter 'args' seems to be unused, consider removing or renaming it as _
plugins/inputs/ping/ping_windows_test.go:327:27             revive  unused-parameter: parameter 'binary' seems to be unused, consider removing or renaming it as _
plugins/inputs/ping/ping_windows_test.go:327:42             revive  unused-parameter: parameter 'timeout' seems to be unused, consider removing or renaming it as _
plugins/inputs/ping/ping_windows_test.go:327:59             revive  unused-parameter: parameter 'args' seems to be unused, consider removing or renaming it as _
plugins/inputs/postfix/stat_none.go:9:6                     unused  func `statCTime` is unused
plugins/inputs/processes/processes_windows.go:19:28         revive  unused-parameter: parameter 'acc' seems to be unused, consider removing or renaming it as _
plugins/inputs/procstat/native_finder_windows_test.go:39:2  revive  import-shadowing: The name 'user' shadows an import name
plugins/inputs/win_eventlog/syscall_windows.go:39:2         revive  var-naming: const EvtRenderEventXml should be EvtRenderEventXML
plugins/inputs/win_eventlog/util.go:21:44                   revive  empty-lines: extra empty line at the start of a block
plugins/inputs/win_eventlog/util.go:46:1                    revive  confusing-results: unnamed results of the same type may be confusing, consider using named results
plugins/inputs/win_eventlog/util.go:46:1                    revive  function-result-limit: maximum number of return results per function exceeded; max 3 but got 4
plugins/inputs/win_eventlog/zsyscall_windows.go:79:1        revive  argument-limit: maximum number of arguments per function exceeded; max 6 but got 8
plugins/inputs/win_eventlog/zsyscall_windows.go:113:1       revive  argument-limit: maximum number of arguments per function exceeded; max 6 but got 7
plugins/inputs/win_eventlog/zsyscall_windows.go:179:1       revive  argument-limit: maximum number of arguments per function exceeded; max 6 but got 9
plugins/inputs/win_services/win_services.go:84:9            revive  indent-error-flow: if block ends with a return statement, so drop this else and outdent its block
plugins/inputs/win_services/win_services_test.go:51:11      revive  indent-error-flow: if block ends with a return statement, so drop this else and outdent its block
plugins/inputs/win_services/win_services_test.go:62:9       revive  indent-error-flow: if block ends with a return statement, so drop this else and outdent its block
plugins/inputs/win_services/win_services_test.go:74:9       revive  indent-error-flow: if block ends with a return statement, so drop this else and outdent its block
plugins/inputs/win_services/win_services_test.go:89:9       revive  indent-error-flow: if block ends with a return statement, so drop this else and outdent its block
plugins/inputs/win_services/win_services_test.go:108:9      revive  indent-error-flow: if block ends with a return statement, so drop this else and outdent its block
plugins/inputs/win_wmi/win_wmi.go:165:3                     revive  defer: prefer not to defer inside loops
plugins/inputs/win_wmi/win_wmi.go:172:4                     revive  defer: prefer not to defer inside loops
plugins/inputs/win_wmi/win_wmi_test.go:20:15                revive  var-declaration: should omit type Query from declaration of var testQuery; it will be inferred from the right-hand side

Few notes:

  1. cmd/telegraf/telegraf_windows.go - seems that run() has been unused since https://github.com/influxdata/telegraf/pull/11700/files#diff-e92b823b01e2753ed78851f62eeed84d917d61d172b3666312c1ae5289ab0ff6L40-L51
  2. diskio plugin supports windows (I've tested that) - few movements were performed to avoid unused findings for windows and darwin.
  3. ethtool - few movements were performed to avoid unused findings for windows and darwin.
  4. filecount - few movements were performed to avoid unused findings for windows. They can be rollbacked after this FIlestat plugin and super asterisks not working on windows? #6248 is fixed.
  5. ping - to get rid of function-result-limit, similar operation was made as for https://github.com/influxdata/telegraf/pull/10066/files#diff-ee4d8ab6f17ad76a4f4297c7e1a6b8b2e3fdf1935ecbee0bc98b00b075d9a46f

@telegraf-tiger telegraf-tiger bot added the chore label May 5, 2023
plugins/inputs/diskio/README.md Show resolved Hide resolved
plugins/inputs/ping/ping_windows.go Show resolved Hide resolved
plugins/inputs/ping/ping_windows.go Show resolved Hide resolved
@Hipska Hipska added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label May 8, 2023
Copy link
Member

@srebhan srebhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fixes @zak-pawel. Please revert the massive change to ethtool and leave the file-structure as-is for now. Similar for diskio where duplicating the general struct will result in pain (and forgotten sync-ups) when adding config-options.

Comment on lines 23 to 35
type DiskIO struct {
ps system.PS

Devices []string
DeviceTags []string
NameTemplates []string
SkipSerialNumber bool

Log telegraf.Logger

infoCache map[string]diskInfoCache
deviceFilter filter.Filter
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing I don't like about duplicating this struct is that you now have two places to edit if you add an option. So I would prefer not to do this. We could move the internal fields to a struct that is defined by linux/not-linux though...

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that we need to have dedicated talk about best solution. For now, I'm reverting changes for diskio plugin.

Comment on lines 55 to 61
const (
pluginName = "ethtool"
tagInterface = "interface"
tagNamespace = "namespace"
tagDriverName = "driver"
fieldInterfaceUp = "interface_up"
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of completely changing the setup you should just move those definitions into the _linux.go file!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of completely changing the setup you should just move those definitions into the _linux.go file!

@srebhan Can you elaborate how would this help with following findings for non-linux OSes?

plugins/inputs/ethtool/ethtool.go:43:2                      unused  field `interfaceFilter` is unused
plugins/inputs/ethtool/ethtool.go:44:2                      unused  field `namespaceFilter` is unused
plugins/inputs/ethtool/ethtool.go:45:2                      unused  field `includeNamespaces` is unused
plugins/inputs/ethtool/ethtool.go:48:2                      unused  field `command` is unused

I strongly believe that situation in ethtool plugin is much clearer right now. Content of ethtool.go and ethtool_linux.go were merged into single ethtool.go for linux only. Other OSes are gently handled by ethtool_notlinux.go.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason why I don't like the structural changes is

  1. It is a massive change not necessarily required to accommodate the linter issue.
  2. The structure is now again different from other plugins that are platform dependent!

Can you elaborate how would this help with following findings for non-linux OSes?

Those constants are used in the linux-only build and are undefined in the non-linux build. Doesn't that solve the linter issues?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must admit that I don't know why you are talking about those constants. Problem is only with struct fields:

plugins/inputs/ethtool/ethtool.go:43:2     unused  field `interfaceFilter` is unused
plugins/inputs/ethtool/ethtool.go:44:2     unused  field `namespaceFilter` is unused
plugins/inputs/ethtool/ethtool.go:45:2     unused  field `includeNamespaces` is unused
plugins/inputs/ethtool/ethtool.go:48:2     unused  field `command` is unused

I think that we need to have dedicated talk about best solution. For now, I'm reverting changes for ethtool plugin.

@srebhan srebhan self-assigned this May 16, 2023
@powersj powersj removed the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label May 17, 2023
@powersj powersj added the waiting for response waiting for response from contributor label May 31, 2023
@zak-pawel
Copy link
Collaborator Author

After merging this PR, these will be the only findings for both windows and darwin:

plugins/inputs/diskio/diskio.go:33:2       unused  field `infoCache` is unused
plugins/inputs/diskio/diskio_other.go:5:6  unused  type `diskInfoCache` is unused
plugins/inputs/ethtool/ethtool.go:43:2     unused  field `interfaceFilter` is unused
plugins/inputs/ethtool/ethtool.go:44:2     unused  field `namespaceFilter` is unused
plugins/inputs/ethtool/ethtool.go:45:2     unused  field `includeNamespaces` is unused
plugins/inputs/ethtool/ethtool.go:48:2     unused  field `command` is unused

@telegraf-tiger telegraf-tiger bot removed the waiting for response waiting for response from contributor label Jun 7, 2023
Copy link
Contributor

@powersj powersj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rebase on master to grab the test fixes.

@powersj powersj added the ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review. label Jun 8, 2023
@zak-pawel
Copy link
Collaborator Author

Please rebase on master to grab the test fixes.

@powersj This code is based on current upstream master branch
image

Don't know why still failing...

@powersj
Copy link
Contributor

powersj commented Jun 8, 2023

2023/06/07 22:30:58 I! [processors.execd] Starting process: go [run testcases/pass-through.go]

oh I did not read this close enough, sure enough it is :( @srebhan updated that to change from cat to go in hope it would resolve the issue. I'll hit retry

@telegraf-tiger
Copy link
Contributor

telegraf-tiger bot commented Jun 8, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore linter ready for final review This pull request has been reviewed and/or tested by multiple users and is ready for a final review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants