-
Notifications
You must be signed in to change notification settings - Fork 77
Replace Fluentbit config generation with modular implementation #164
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some preliminary comments (only on the commits that are on top of #163).
confgenerator/fluentbit/modular.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would help to name the output parameters…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not what named output parameters are for. Go guidance is that you should not name output parameters unless you specifically need them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't find any explicit guidance in either the Go style or the Go best practices on the named parameters. However, Go is supposed to be all about not surprising readers, and not specifying which of the strings is which opens up a possibility of mixing them up. Would you mind pointing me at the guidance about output parameters that you're referencing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The relevant style entry is https://golang.org/doc/effective_go#named-results (plus more internal guidance that I can't link to in a public PR). I agree that's not a strong recommendation; I have personally been given the explicit feedback in readability reviews that named result parameters should not be used unless those names are needed inside the function.
This function's return parameters will obviously be documented with a comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused. The guidance you linked actually says:
The names are not mandatory but they can make code shorter and clearer: they're documentation. If we name the results of
nextIntit becomes obvious which returnedintis which.
which seems very similar to the current situation. As I understand it, you don't even have to use a bare return with named results, though you could.
I can see that the names would not be used inside the function, but the documentation value alone would, IMO, be sufficient. Comments tend to fall out of sync with the code — having the facility to do this in the code itself is something that should be taken advantage of.
That said, I may be missing the experience to recognize the right idioms here. Go style recommendations have been nonsensical to me in the past, and this could be yet another one of those.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My understanding from going through the readability process is that naming result parameters makes it possible to use a bare return, and if you're not actually using that in the function body, you should not use named result parameters to prevent an accidental bare return.
I agree this seems like a fairly weak argument. I think I'm fine going against that guidance if you really want. (Note that this function signature is not new and it didn't have named result parameters before...)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At a minimum, add a function comment describing the return values.
You're welcome to name the return values too even if you're not doing bare return. (And definitely don't use bare return. They should get rid of that feature.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I'll leave this up to you — IMO, the named return parameters would be an aid to readability, but I may be projecting from other languages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's already a function comment documenting the return values.
14f0fa2 to
bbb4269
Compare
|
I pushed the golden diffs, so I would appreciate a review of those looking for any bugs. Then I can rip out all the now-unused code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The golden diffs look fine to me. Have some questions about the implementation.
...ta/valid/linux/all-backward_compatible_with_explicit_exporters/golden_fluent_bit_parser.conf
Show resolved
Hide resolved
...ta/valid/linux/all-backward_compatible_with_explicit_exporters/golden_fluent_bit_parser.conf
Show resolved
Hide resolved
confgenerator/testdata/valid/linux/logging-processor_order/golden_fluent_bit_parser.conf
Show resolved
Hide resolved
...ta/valid/linux/all-backward_compatible_with_explicit_exporters/golden_fluent_bit_parser.conf
Show resolved
Hide resolved
confgenerator/testdata/valid/linux/logging-processor_order/golden_fluent_bit_parser.conf
Show resolved
Hide resolved
confgenerator/fluentbit/modular.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't find any explicit guidance in either the Go style or the Go best practices on the named parameters. However, Go is supposed to be all about not surprising readers, and not specifying which of the strings is which opens up a possibility of mixing them up. Would you mind pointing me at the guidance about output parameters that you're referencing?
|
I've toggled the draft bit off now, PTAL. |
|
I'll do a more thorough review later, but at the moment there seems to be way too much fluent-bit-specific knowledge spread through the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One initial comment.
This is consistent with what happens on the OT side - each receiver or processor is responsible for generating its own OT or fluentbit configuration, using helpers when there is code to be shared, and then I'm not sure what you mean by "spread through" - the only code that touches fluentbit is in the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM functionality wise. Will defer Golang readability to others.
confgenerator/fluentbit/modular.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At a minimum, add a function comment describing the return values.
You're welcome to name the return values too even if you're not doing bare return. (And definitely don't use bare return. They should get rid of that feature.)
|
|
||
| // setLogNameComponents generates a series of components that rewrites the tag on log entries tagged `tag` to be `logName`. | ||
| func setLogNameComponents(tag, logName string) []fluentbit.Component { | ||
| // TODO: Can we just set log_name_key in the output plugin and avoid this mess? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One note: The output plugin uses the tag to populate LogEntry.logName, which may be the reason for some of this mess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but the log_name_key setting overrides it. I still think we ought to just use the default value for that key, and add a record field called logging.googleapis.com/logName…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's what my TODO is all about, but I don't want to make that functional change in the same PR.
...ta/valid/linux/all-backward_compatible_with_explicit_exporters/golden_fluent_bit_parser.conf
Show resolved
Hide resolved
confgenerator/fluentbit/modular.go
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I'll leave this up to you — IMO, the named return parameters would be an aid to readability, but I may be projecting from other languages.
| lines = append(lines, fmt.Sprintf(" %-*s %s", maxLen, k, v)) | ||
| } | ||
| sort.Strings(lines) | ||
| return fmt.Sprintf("[%s]\n%s\n", c.Kind, strings.Join(lines, "\n")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I should asked for this in #163, but can we use "" for v in line 40 above if v is an empty string? If we don't want to filter out blank values, we should at least quote them properly…
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not see any evidence that fluentbit supports quoting config values like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're correct, fluentbit simply splits the string on a space and then trims the key and the value. It also requires the value to be non-empty, so it's not possible to generate a valid config with a blank value.
|
|
||
| // setLogNameComponents generates a series of components that rewrites the tag on log entries tagged `tag` to be `logName`. | ||
| func setLogNameComponents(tag, logName string) []fluentbit.Component { | ||
| // TODO: Can we just set log_name_key in the output plugin and avoid this mess? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but the log_name_key setting overrides it. I still think we ought to just use the default value for that key, and add a record field called logging.googleapis.com/logName…
...nerator/testdata/valid/linux/logging-pipeline_multiple_pipelines/golden_fluent_bit_main.conf
Show resolved
Hide resolved
confgenerator/testdata/valid/linux/logging-processor_order/golden_fluent_bit_main.conf
Show resolved
Hide resolved
confgenerator/testdata/valid/linux/logging-processor_order/golden_fluent_bit_parser.conf
Show resolved
Hide resolved
| Buffer_Chunk_Size 512k | ||
| Buffer_Max_Size 5M | ||
| DB ${buffers_dir}/ops-agent-fluent-bit | ||
| DB ${buffers_dir}/pipeline1_log_source_id1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Btw, does it matter that DB is changing? Will that break any users on upgrade?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be a problem if we change DB. But is it actually changing? I see a reordering of these blocks, but the DB directories are still called pipeline1_sample_logs, pipeline2_sample_logs, and ops-agent-fluent-bit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| lines = append(lines, fmt.Sprintf(" %-*s %s", maxLen, k, v)) | ||
| } | ||
| sort.Strings(lines) | ||
| return fmt.Sprintf("[%s]\n%s\n", c.Kind, strings.Join(lines, "\n")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're correct, fluentbit simply splits the string on a space and then trims the key and the value. It also requires the value to be non-empty, so it's not possible to generate a valid config with a blank value.
No description provided.