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: Forbids "log" package only for aggregators, inputs, outputs, parsers and processors #10191

Merged
merged 4 commits into from
Dec 3, 2021
Merged

chore: Forbids "log" package only for aggregators, inputs, outputs, parsers and processors #10191

merged 4 commits into from
Dec 3, 2021

Conversation

zak-pawel
Copy link
Collaborator

@zak-pawel zak-pawel commented Nov 26, 2021

It is possible to inject telegraf.Logger (instead of log) only into aggregators, inputs, outputs, parsers and processors so there is no point in forbidding usages of log in other places.

@zak-pawel zak-pawel changed the title chore: Forbids "log" package only for inputs, outputs, parsers and serializers chore: Forbids "log" package only for aggregators, inputs, outputs, parsers and serializers Nov 26, 2021
@srebhan
Copy link
Contributor

srebhan commented Nov 30, 2021

Hey @zak-pawel, can we be a bit more specific in plugins/common? I only see a valid use in the shim and logrus subdirs. Everything else either already uses a telegraf.Logger or can (and should) be fixed in my view... What do you think?

@srebhan srebhan self-assigned this Nov 30, 2021
@srebhan
Copy link
Contributor

srebhan commented Nov 30, 2021

Can't we even disable the blacklist in those files directly instead of the config file to make people aware of the exception?

@zak-pawel
Copy link
Collaborator Author

@srebhan

Can't we even disable the blacklist in those files directly instead of the config file to make people aware of the exception?

Do you want to place //nolint ... in every file which is not in aggregators, inputs, outputs, parsers or serializers directory?

Hey @zak-pawel, can we be a bit more specific in plugins/common? I only see a valid use in the shim and logrus subdirs. Everything else either already uses a telegraf.Logger or can (and should) be fixed in my view... What do you think?

If I understand this document correctly, telegraf.Logger should be used only in places where it is automatically injected, so for these types of plugins: aggregators, inputs, outputs, parsers and serializers. So for common package log should be used. Am I right?

@srebhan
Copy link
Contributor

srebhan commented Nov 30, 2021

So for common package log should be used. Am I right?

I have no idea, maybe that's for discussion with the core-devs...

Do you want to place //nolint ... in every file which is not in aggregators, inputs, outputs, parsers or serializers directory?
No, but maybe only in the ones in plugins/common that really need it. The background is that people tend to take all code as examples and then copy the behavior to other places, spreading the word. :-) So in my ideal world, everything under plugins/ is 'no-log' land except for the few places where it is really needed. And in those locations we should be explicit in stating that this is an exception (like in common/shim and common/logrus). That is two files IIRC...

@reimda
Copy link
Contributor

reimda commented Nov 30, 2021

So for common package log should be used. Am I right?

I have no idea, maybe that's for discussion with the core-devs...

Makes sense to me only to blacklist using the log package where the Log is injected.

@zak-pawel
Copy link
Collaborator Author

So for common package log should be used. Am I right?

I have no idea, maybe that's for discussion with the core-devs...

Makes sense to me only to blacklist using the log package where the Log is injected.

@reimda Exactly this happens thanks to current changes in this PR :)

@srebhan
Copy link
Contributor

srebhan commented Dec 1, 2021

First, let me be clear, my only concern is about plugins/common here.

Makes sense to me only to blacklist using the log package where the Log is injected.

I guess the question is: Should we blacklist plugins/common in general or only the two places (shim and logrus) that need log? For example, http and starlark use the telegraf logger passed in by their users, so I'm a bit hesitant to disable checks for those parts.
Wouldn't the following be sufficient in the two files

	"log" //nolint:revive // Allow exceptional but valid use of log here.

@zak-pawel
Copy link
Collaborator Author

First, let me be clear, my only concern is about plugins/common here.

Makes sense to me only to blacklist using the log package where the Log is injected.

I guess the question is: Should we blacklist plugins/common in general or only the two places (shim and logrus) that need log? For example, http and starlark use the telegraf logger passed in by their users, so I'm a bit hesitant to disable checks for those parts. Wouldn't the following be sufficient in the two files

	"log" //nolint:revive // Allow exceptional but valid use of log here.

If @reimda is OK with that, I will make a change :)

@powersj
Copy link
Contributor

powersj commented Dec 1, 2021

I'm also +1 on adding limited exceptions via //no lint:revive comments in specific files versus adding exceptions to a global file.

@Hipska
Copy link
Contributor

Hipska commented Dec 1, 2021

Same with Sven

@zak-pawel
Copy link
Collaborator Author

@srebhan @reimda @powersj @Hipska Exclusion of plugins/common package for importing "log" rule was removed.
Moreover I corrected path filter (in previous commit it also ruled out wrong files)

@telegraf-tiger
Copy link
Contributor

telegraf-tiger bot commented Dec 2, 2021

.golangci.yml Show resolved Hide resolved
@zak-pawel zak-pawel changed the title chore: Forbids "log" package only for aggregators, inputs, outputs, parsers and serializers chore: Forbids "log" package only for aggregators, inputs, outputs, parsers and processors Dec 3, 2021
@sspaink sspaink merged commit 1143a50 into influxdata:master Dec 3, 2021
@sspaink sspaink deleted the linter-allow-log-sometimes branch December 3, 2021 17:50
MyaLongmire pushed a commit that referenced this pull request Dec 8, 2021
…arsers and processors (#10191)

Co-authored-by: Pawel Zak <Pawel Zak>
(cherry picked from commit 1143a50)
powersj pushed a commit to powersj/telegraf that referenced this pull request Jan 21, 2022
…arsers and processors (influxdata#10191)

Co-authored-by: Pawel Zak <Pawel Zak>
phemmer added a commit to phemmer/telegraf that referenced this pull request Feb 18, 2022
* origin/master: (133 commits)
  chore: restart service if it is already running and upgraded via RPM (influxdata#9970)
  feat: update etc/telegraf.conf and etc/telegraf_windows.conf (influxdata#10237)
  fix: Handle duplicate registration of protocol-buffer files gracefully. (influxdata#10188)
  fix(http_listener_v2): fix panic on close (influxdata#10132)
  feat: add Vault input plugin (influxdata#10198)
  feat: support aws managed service for prometheus (influxdata#10202)
  fix: Make telegraf compile on Windows with golang 1.16.2 (influxdata#10246)
  Update changelog
  feat: Modbus add per-request tags (influxdata#10231)
  fix: Implement NaN and inf handling for elasticsearch output (influxdata#10196)
  feat: add nomad input plugin (influxdata#10106)
  fix: Print loaded plugins and deprecations for once and test (influxdata#10205)
  fix: eliminate MIB dependency for ifname processor (influxdata#10214)
  feat: Optimize locking for SNMP MIBs loading. (influxdata#10206)
  feat: Add SMART plugin concurrency configuration option, nvme-cli v1.14+ support and lint fixes. (influxdata#10150)
  feat: update configs (influxdata#10236)
  fix(inputs/kube_inventory): set TLS server name config properly (influxdata#9975)
  fix: Sudden close of Telegraf caused by OPC UA input plugin (influxdata#10230)
  fix: bump github.com/eclipse/paho.mqtt.golang from 1.3.0 to 1.3.5 (influxdata#9913)
  fix: json_v2 parser timestamp setting (influxdata#10221)
  fix: ensure graylog spec fields not prefixed with '_' (influxdata#10209)
  docs: remove duplicate links in CONTRIBUTING.md (influxdata#10218)
  fix: pool detection and metrics gathering for ZFS >= 2.1.x (influxdata#10099)
  fix: parallelism fix for ifname processor (influxdata#10007)
  chore: Forbids "log" package only for aggregators, inputs, outputs, parsers and processors (influxdata#10191)
  docs: address documentation gap when running telegraf in k8s (influxdata#10215)
  feat: update etc/telegraf.conf and etc/telegraf_windows.conf (influxdata#10211)
  fix: mqtt topic extracting no longer requires all three fields (influxdata#10208)
  fix: windows service - graceful shutdown of telegraf (influxdata#9616)
  feat: update etc/telegraf.conf and etc/telegraf_windows.conf (influxdata#10201)
  feat: Modbus support multiple slaves (gateway feature) (influxdata#9279)
  fix: Revert unintented corruption of the Makefile from influxdata#10200. (influxdata#10203)
  chore: remove triggering update-config bot in CI (influxdata#10195)
  Update changelog
  feat: Implement deprecation infrastructure (influxdata#10200)
  fix: extra lock on init for safety (influxdata#10199)
  fix: resolve influxdata#10027 (influxdata#10112)
  fix: register bigquery to output plugins influxdata#10177 (influxdata#10178)
  fix: sysstat use unique temp file vs hard-coded (influxdata#10165)
  refactor: snmp to use gosmi (influxdata#9518)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants