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

Generating the Telegraf config using PowerShell on Windows results in a vague error #11614

Closed
R290 opened this issue Aug 3, 2022 · 7 comments · Fixed by #11662
Closed

Generating the Telegraf config using PowerShell on Windows results in a vague error #11614

R290 opened this issue Aug 3, 2022 · 7 comments · Fixed by #11662
Labels
bug unexpected problem or unintended behavior help wanted Request for community participation, code, contribution size/s 1 day effort, great beginniner issue

Comments

@R290
Copy link
Contributor

R290 commented Aug 3, 2022

Relevant telegraf.conf

Complete

Logs from Telegraf

2022-08-03T17:48:40Z E! [telegraf] Error running agent: Error loading config file telegraf.conf: Error parsing data: line 1: invalid TOML syntax

System info

Windows 10 21H2, Powershell 5.1.19041.1682 (the default), Telegraf 1.23.3

Docker

No response

Steps to reproduce

  1. .\telegraf.exe config > telegraf.conf
  2. .\telegraf.exe --config telegraf.conf

Expected behavior

Output like:

2022-08-03T17:49:16Z I! Starting Telegraf 1.23.3
etc etc etc etc

Actual behavior

See the logs from Telegraf section, a vague error.

Additional info

The error is caused by the default output encoding of PowerShell 5 being UTF-16 LE BOM instead of UTF-8. In PowerShell 7.2.5 this has been changes to UTF-8. Since PowerShell 5 is going to be the default for a while, maybe we should add a PowerShell specific command to the readme?

 .\telegraf.exe config | Out-File -FilePath telegraf.conf -Encoding utf8

The above results in a config with encoding UTF-8-BOM. To get true UTF-8, the encoding needs to be set to oem.

Additionally some weird characters show up when using the default command:

## Valid time units are "ns", "us" (or "┬Ás"), "ms", "s".
## Max string error size
## This collect thread counts metrics.
@R290 R290 added the bug unexpected problem or unintended behavior label Aug 3, 2022
@powersj
Copy link
Contributor

powersj commented Aug 4, 2022

@R290,

Is this the first time you have noticed this, or has this always been this way? I want to understand if we made a change that caused this or no one had noticed before today?

In either case, the next steps for us would be good to update the docs at the very least.

@powersj powersj added the waiting for response waiting for response from contributor label Aug 4, 2022
@R290
Copy link
Contributor Author

R290 commented Aug 6, 2022

It's been this way since I started using Telegraf on Windows about a year ago. So this would have been around release v1.18 or v1.19.

@telegraf-tiger telegraf-tiger bot removed the waiting for response waiting for response from contributor label Aug 6, 2022
@powersj powersj added help wanted Request for community participation, code, contribution size/s 1 day effort, great beginniner issue labels Aug 8, 2022
@R290
Copy link
Contributor Author

R290 commented Aug 11, 2022

This issue is actually a duplicate of earlier issues:
#4880
#1378
#6662

Should we close this one?

powersj added a commit to powersj/telegraf that referenced this issue Aug 11, 2022
PowerShell 5 is the default version of PowerShell in Windows 10 and
older versions. It does not default to UTF-8 encoding, which can cause
issues with Telegraf trying to parse the file.

Rather than adding lots of weird logic to Telegraf, document the
requirement to specify the encoding when using PowerShell 5.

Newer versions of PowerShell now use UTF-8 encoding.

Fixes: influxdata#11614
Fixes: influxdata#4880
Fixes: influxdata#6662
@powersj
Copy link
Contributor

powersj commented Aug 11, 2022

Hi,

Wow, thanks for finding the various history on this.

As you mention PowerShell 7, and even PowerShell 6, both use BOM-less UTF-8 by default. The issue occurs when using PowerShell 5.

This is not an issue when using Command Prompt or the Git-Bash shell.

In Telegraf, the config subcommand is calling fmt.Print[f], nothing special is happening. This is specific to PowerShell's odd choice of encoding and while it requires a little more work on the user, is overcome versus adding special cases and detection for a particular version and encoding in PowerShell to Telegraf

I think that an update the docs is the best way forward and have put up #11662. Could you comment if that is sufficient documentation?

Thanks!

@powersj
Copy link
Contributor

powersj commented Aug 11, 2022

ha - I see we put up PRs within minutes of each other.

The reason I did not go down that road of adding support for UTF-16LE encoding is the TOML spec specifies the requirement for a valid UTF-8 encoded document. I am unsure what dragons we are opening ourselves up to if we start accepting the additional encoding.

@R290
Copy link
Contributor Author

R290 commented Aug 11, 2022

Seems we both think it's an important issue!

I actually wrote something similar before I went down the encoding rabbit hole: R290@475051d. Your version seems to do a bit more explaining, whereas mine is rather brief, so let's go with yours!

I understand your concerns about accepting additional encoding. In this case it would just be UTF16-LE, the Windows standard. I'll some test cases for UTF8 with an actual error on line 1 and UTF16LE with an actual error on line 1 and will leave the PR at that.

@powersj
Copy link
Contributor

powersj commented Aug 11, 2022

I actually wrote something similar before I went down the encoding rabbit hole: R290@475051d. Your version seems to do a bit more explaining, whereas mine is rather brief, so let's go with yours!

Again, thank you for reporting this and digging up the history. I will go merge my PR and close yours in a bit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug unexpected problem or unintended behavior help wanted Request for community participation, code, contribution size/s 1 day effort, great beginniner issue
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants