Skip to content

Conversation

@quentinmit
Copy link
Member

No description provided.

Copy link
Contributor

@igorpeshansky igorpeshansky left a 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).

Copy link
Contributor

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…

Copy link
Member Author

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.

Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

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 nextInt it becomes obvious which returned int is 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.

Copy link
Member Author

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...)

Copy link
Contributor

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.)

Copy link
Contributor

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.

Copy link
Member Author

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.

@quentinmit quentinmit force-pushed the quentin-fluentbit-modular branch from 14f0fa2 to bbb4269 Compare August 24, 2021 20:16
@quentinmit
Copy link
Member Author

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.

Copy link
Contributor

@igorpeshansky igorpeshansky left a 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.

Copy link
Contributor

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?

@quentinmit quentinmit marked this pull request as ready for review August 25, 2021 07:03
@quentinmit
Copy link
Member Author

I've toggled the draft bit off now, PTAL.

@igorpeshansky
Copy link
Contributor

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 confgenerator code, which is probably better off confined to the fluentbit package…

Copy link
Contributor

@davidbtucker davidbtucker left a comment

Choose a reason for hiding this comment

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

One initial comment.

@quentinmit
Copy link
Member Author

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 confgenerator code, which is probably better off confined to the fluentbit package…

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 fluentbit/otel is responsible for serializing that config into a config file.

I'm not sure what you mean by "spread through" - the only code that touches fluentbit is in the GenerateFluentBitConfigs and generateFluentbitComponents methods in confgenerator.go, and the receiver/processor specific code in logging*.go. Note that some of the latter will be broken off into the apps package as well.

Copy link
Contributor

@qingling128 qingling128 left a 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.

Copy link
Contributor

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?
Copy link
Contributor

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.

Copy link
Contributor

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

Copy link
Member Author

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.

Copy link
Contributor

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"))
Copy link
Contributor

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…

Copy link
Member Author

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.

Copy link
Contributor

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?
Copy link
Contributor

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

Buffer_Chunk_Size 512k
Buffer_Max_Size 5M
DB ${buffers_dir}/ops-agent-fluent-bit
DB ${buffers_dir}/pipeline1_log_source_id1
Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Contributor

@igorpeshansky igorpeshansky left a comment

Choose a reason for hiding this comment

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

LGTM :shipit:

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"))
Copy link
Contributor

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.

@quentinmit quentinmit merged commit 6c39ea5 into master Aug 26, 2021
@quentinmit quentinmit deleted the quentin-fluentbit-modular branch August 26, 2021 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants