Skip to content
This repository has been archived by the owner on Aug 23, 2023. It is now read-only.

fix garbled output #524

Merged
merged 1 commit into from
Feb 10, 2017
Merged

fix garbled output #524

merged 1 commit into from
Feb 10, 2017

Conversation

Dieterbe
Copy link
Contributor

@Dieterbe Dieterbe commented Feb 9, 2017

No description provided.

while executing a template concurrently is OK, and writes to os.Stdout
are atomic as well, we had a bug:
Template.Execute does separate writes for each "step", i.e. each
variable that needs to be printed, and the final newline.
So even under a medium workload of 10kMsg/s occasionally the output
would be garbled due to attributes and newlines being printed
intermingled.

We could probably have solved this without any locks:
have the template do its complete execution into a temporary buffer,
and then write the buffer (all at once) to stdout, which is atomic.
But then you may have to worry about managing the temporary buffers.
This is a simple solution that seems to work well.
@Dieterbe Dieterbe changed the title WIP: attempt to fix garbled output fix garbled output Feb 10, 2017
@@ -20,6 +21,8 @@ import (
var (
confFile = flag.String("config", "/etc/raintank/metrictank.ini", "configuration file path")
format = flag.String("format", "{{.Part}} {{.OrgId}} {{.Id}} {{.Name}} {{.Metric}} {{.Interval}} {{.Value}} {{.Time}} {{.Unit}} {{.Mtype}} {{.Tags}}", "template to render the data with")

stdoutLock = sync.Mutex{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If i see that right mdm.Start(newInputPrinter(*format)) is never creating more than 1 instance of inputPrinter. So couldn't this lock be local to the inputPrinter struct? did you just make it package global in case something else wants to print?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indeed, having it local to inputPrinter should also work fine.
But i don't see a strong reason to prefer it one way or another.

@Dieterbe Dieterbe merged commit 87a7a1d into master Feb 10, 2017
@Dieterbe Dieterbe deleted the mt-kafka-mdm-sniff-garbled branch September 18, 2018 09:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants