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

Config - Cannot use hash (#) inside of inner single quotes within multi-line literal string #14237

Closed
joahwoodward-sfmc opened this issue Nov 1, 2023 · 5 comments · Fixed by #14240
Assignees
Labels
bug unexpected problem or unintended behavior

Comments

@joahwoodward-sfmc
Copy link

joahwoodward-sfmc commented Nov 1, 2023

Relevant telegraf.conf

[[inputs.myplugin]]
value = '''This isn't a #comment.'''

Logs from Telegraf

error loading config file /etc/telegraf/inputs/myplugin.conf: error parsing data: line 3: invalid TOML syntax

System info

Telegraf 1.28.2

Docker

No response

Steps to reproduce

We are using a custom input plugin to execute sql queries read from config files, some of which operate on temp tables or have single quotes and/or #'s inside of SQL comments. Telegraf is truncating lines from these queries if it finds a # after a single quote inside of a multiline literal string and causing unexpected behavior and syntax errors.

Expected behavior

Valid TOML is supported and #'s inside multi-line literal strings are never treated as comments or stripped by the config preprocessor.

Actual behavior

Telegraf is treating the # as the beginning of a comment, resulting in invalid toml syntax or unexpected values.
From the example, the config preprocessor will turn it into:

[[inputs.myplugin]]
value = '''This isn't a 

Additional info

Seems to be a regression caused by 7c636b4

@joahwoodward-sfmc joahwoodward-sfmc added the bug unexpected problem or unintended behavior label Nov 1, 2023
@powersj
Copy link
Contributor

powersj commented Nov 1, 2023

Hi,

Can you modify the following to give me an actual example:

[agent]
    debug = true
    omit_hostname = true

[[inputs.exec]]
    commands = ["echo influx value=42"]
    data_format = "influx"

[[processors.starlark]]
  source = '''
# this is a comment
def apply(metric):
  metric.tags["tag"] = "foo#bar"
  return metric
'''

[[outputs.file]]

As-is this returns the following and I don't seem to treat it as a comment:

influx,tag=foo#bar value=42 1698880266000000000

Additionally, do you know if a previous version worked and then a new version did?

@powersj
Copy link
Contributor

powersj commented Nov 1, 2023

Ah I think I missed this part:

if it finds a # after a single quote inside of a multiline literal string

I'll take a look more tomorrow.

srebhan added a commit to srebhan/telegraf that referenced this issue Nov 2, 2023
@srebhan
Copy link
Member

srebhan commented Nov 2, 2023

@joahwoodward-sfmc please test the binary in #14240 available as soon as CI finishes the tests. Let me know if this fixes the issue!

@srebhan srebhan self-assigned this Nov 6, 2023
@Zegorax
Copy link

Zegorax commented Jan 19, 2024

Hello everyone,

I'm getting the same issue with the SQL input when there is a # (hash, sign number) in the DSN. It's removing the end of the string after the hash because it considers it as a comment, but it should not.

Here is my config :

[[inputs.sql]]
  driver = "oracle"
  dsn = "oracle://usernamewith#inside:password@db:1521/service"

It will throw the following error :
2024-01-19T09:50:59Z E! [inputs.sql] unable to connect to database: unable to connect to database: address usernamewith: missing port in address

I'm not sure how I can fix it. I've tried with the unicode escape method as well (\uXXX), but it's not working as it will parse the rest as a comment.

@Zegorax
Copy link

Zegorax commented Jan 19, 2024

Hello again,

I've investigated further, and it is not linked to this issue. The oracle plugin driver is using an URL parse. Therefore, replacing the # with %23 made it work.

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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants