-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
Comments
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. |
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. |
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
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 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! |
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. |
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. |
Again, thank you for reporting this and digging up the history. I will go merge my PR and close yours in a bit. |
Relevant telegraf.conf
Complete
Logs from Telegraf
System info
Windows 10 21H2, Powershell 5.1.19041.1682 (the default), Telegraf 1.23.3
Docker
No response
Steps to reproduce
.\telegraf.exe config > telegraf.conf
.\telegraf.exe --config telegraf.conf
Expected behavior
Output like:
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 ofUTF-8
. In PowerShell 7.2.5 this has been changes toUTF-8
. Since PowerShell 5 is going to be the default for a while, maybe we should add a PowerShell specific command to the readme?The above results in a config with encoding
UTF-8-BOM
. To get trueUTF-8
, the encoding needs to be set tooem
.Additionally some weird characters show up when using the default command:
The text was updated successfully, but these errors were encountered: