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

feat: enable sampling for stdout logger #892

Merged
merged 6 commits into from
Nov 3, 2023
Merged

Conversation

VinozzZ
Copy link
Contributor

@VinozzZ VinozzZ commented Nov 1, 2023

Which problem is this PR solving?

#705

Short description of the changes

This PR implements the same sampling logic from HoneycombLogger in the StdoutLogger.

@VinozzZ VinozzZ marked this pull request as ready for review November 1, 2023 20:27
@VinozzZ VinozzZ requested a review from a team as a code owner November 1, 2023 20:27
Copy link
Contributor

@kentquirk kentquirk left a comment

Choose a reason for hiding this comment

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

Sorry, I didn't save this yesterday.

logger/logrus.go Outdated
if shouldDrop(uint(rate)){
return
}
l.entry.WithField("sample_rate", rate)
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's call this SampleRate so that it's compatible with what happens in Beelines; that way if someone eventually sends these logs to honeycomb they'll be handled properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I'm not familiar with Beelines. Do you mind to explain a bit more on what the incompatibility looks like here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Whenever Honeycomb receives data in a column called SampleRate, we use that in calculations as the sample rate. It's how we compensate for sampling. So we should name the field the way Honeycomb expects to receive it, in case that data is ever forwarded to us.

logger/logrus.go Show resolved Hide resolved
logger/logrus.go Show resolved Hide resolved
Comment on lines +487 to +507
- name: SamplerEnabled
type: bool
valuetype: nondefault
default: false
reload: false
summary: controls whether logs are sampled before sending to stdout.
description: >
The sample rate is controlled by the `SamplerThroughput` setting.

- name: SamplerThroughput
valuetype: showexample
type: float
default: 10
example: 10
reload: false
summary: is the sampling throughput for logs in events per second.
description: >
The sampling algorithm attempts to make sure that the average
throughput approximates this value, while also ensuring that all
unique logs arrive at stdout at least once per sampling
period.
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a reason for using a ">" and the newline before this description?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I see, this formatting is consistent for this document. Please disregard.

Copy link
Contributor

Choose a reason for hiding this comment

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

That's a YAML feature that means this is the start of a string that is a paragraph. A line with a smaller indent ends it.

@@ -276,6 +276,8 @@ type HoneycombLoggerConfig struct {

type StdoutLoggerConfig struct {
Structured bool `yaml:"Structured" default:"false"`
SamplerEnabled bool `yaml:"SamplerEnabled" `
SamplerThroughput int `yaml:"SamplerThroughput" default:"5"`
Copy link
Contributor

Choose a reason for hiding this comment

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

This SamplerThroughput default value conflicts with the default set in configMeta.yaml.

Copy link
Contributor

Choose a reason for hiding this comment

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

It also conflicts with the stated default value in the generated documentation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good find! I honestly don't really understand the relationship here. I got the default from line 274, which is the config for HoneycombLogger. It looks like that one also has the same issue.
@kentquirk , do you mind to explain a bit more on the relationship between each default values?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I took a look of the config logic and here's my understanding. Please correct me if I'm wrong in any way @kentquirk. I believe the ones in metadata is purely for documentation and validation logic. It looks the default value defined in the yaml tag is the one that's being loaded and used.
I modified the metadata file to match with this value

Copy link
Contributor

Choose a reason for hiding this comment

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

Awesome! Then everything looks good to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

Please see #894 -- turns out there were a few of these.

Copy link
Contributor

@fchikwekwe fchikwekwe left a comment

Choose a reason for hiding this comment

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

Overall, this looks fine. Make sure the default values are consistent.

@VinozzZ VinozzZ requested a review from kentquirk November 3, 2023 15:54
@VinozzZ VinozzZ merged commit bb92f71 into main Nov 3, 2023
3 checks passed
@VinozzZ VinozzZ deleted the yingrong.sampling_stdout_logs branch November 3, 2023 19:36
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.

3 participants