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

Add hostname to a configurable field name #27

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

emsearcy
Copy link
Contributor

Inspired by fluentd in_forward's source_hostname_key, but done on the endpoint
so that in_forward doesn't have to split apart and re-contruct messagepack
record sets, and so the hostname is used instead of an IP address.

This is useful when using Fluentd to send to a centralized logging system like
Graylog that requires a hostname entry for logs.

Note, format="None" logs use a custom Fluent message structure and do not use a
RecordModifier so hostnames are not added there. (I was unsure why there were were multiple implementations of message sending.)

Note, RecordModifier seemed like the best place to put this, given the name of the structure, however, the name of the file, "fileformat.go", implies that it is about parsing file contents, which adding the hostname is not. I could see instead adding this functionality into hydra.go's NewFluentRecordSet, perhaps using helper function that is called after Modify(). I'd be happy to refactor if that is the better place for this.

Inspired by fluentd in_forward's source_hostname_key, but done on the endpoint
so that in_forward doesn't have to split apart and re-contruct messagepack
record sets, and so the hostname is used instead of an IP address.

This is useful when using Fluentd to send to a centralized logging system like
Graylog that requires a hostname entry for logs.

Note, format="None" logs use a custom Fluent message structure and do not use a
RecordModifier so hostnames are not added there.

Signed-off-by: Eric Searcy <[email protected]>
Copy link
Owner

@fujiwara fujiwara left a comment

Choose a reason for hiding this comment

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

Thank you for a pull request. I wrote some comments.

@@ -62,6 +63,10 @@ var (
convertFloat FloatConverter
)

var (
hostname, hostnameErr = os.Hostname()
Copy link
Owner

Choose a reason for hiding this comment

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

User will not notice an error os.Hostname() returned.
I think this code should be placed in NewInTail().
If config.HostnameKey is defined but os.Hostname() returns an error, NewInTail() should return an error.

@@ -85,12 +90,18 @@ type ConvertMap struct {

type RecordModifier struct {
convertMap ConvertMap
hostnameKey string
Copy link
Owner

Choose a reason for hiding this comment

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

hostname and hostnameErr are global variable currently.
If RecordModifier has hostname member variable, these global variables are not necessary.

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.

2 participants