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

execd output with JSON format & use_batch_format = true is broken due to missing trailing newline #14142

Closed
carlosabalde opened this issue Oct 18, 2023 · 2 comments · Fixed by #14150
Assignees
Labels
bug unexpected problem or unintended behavior

Comments

@carlosabalde
Copy link

Relevant telegraf.conf

[[inputs.cpu]]
 interval = '1s'

[[outputs.execd]]
 command = ['/usr/bin/bash', '/tmp/foo.sh']
 data_format = 'json'
 use_batch_format = true

Logs from Telegraf

-

System info

Telegraf 1.28.2 + Ubuntu 22.04

Docker

No response

Steps to reproduce

Use the suggested minimal configuration, being /tmp/foo.sh something like this:

while read line; do
  echo "$line" >> /tmp/foo.log
done < /dev/stdin

Expected behavior

Output logged to /tmp/foo.log, one JSON object per line.

Actual behavior

Nothing logged to /tmp/foo.log.

Additional info

Problem is, unlike the simple JSON serializer, the batch JSON serializer doesn't append a trailing newline. As a result, the execd output writes the serialized string to the stdin of the script, but without a newline, the script will never consume it.

In other words, metrics are pushed to stdin as JSON objects, but without newlines is imposible for scripts to know how to delimit those objects. Not sure if the right solution is to add the newline in the batch JSON serializer (looks dirty, but that's current behavior for the simple serializer), or adding it in the execd output.

@carlosabalde carlosabalde added the bug unexpected problem or unintended behavior label Oct 18, 2023
@carlosabalde carlosabalde changed the title execd output with use_batch_format = true is broken due to missing trailing newline execd output with JSON format & use_batch_format = true is broken due to missing trailing newline Oct 18, 2023
@srebhan srebhan self-assigned this Oct 19, 2023
@srebhan
Copy link
Member

srebhan commented Oct 19, 2023

@carlosabalde can you please test the binary in PR #14150 available once CI finished all tests!? Let me know if this fixes the issue!

@carlosabalde
Copy link
Author

@srebhan tested and working fine now. Thanks!

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.

2 participants