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

populate device id attributes to buffered logs before turning on shipping #1472

Merged

Conversation

James-Pickett
Copy link
Contributor

@James-Pickett James-Pickett commented Nov 22, 2023

  • log shipper waits until it has all device id attributes before shipping
  • populates buffered logs with device id attributes before sending

} else {
ls.shippingLogger = log.With(ls.shippingLogger, "k2_device_id", string(deviceId))
additionalSlogAttrs = append(additionalSlogAttrs, slog.String("k2_device_id", string(deviceId)))
for _, key := range []string{"device_id", "munemo", "organization_id", "serial_number"} {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this drops the k2 prefix from some of the attributes, is that okay?

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't feel strongly.

I often like k2 because it makes it very clear what I'm looking at. But I'm not sure we need that disambiguation

@James-Pickett James-Pickett marked this pull request as ready for review November 22, 2023 18:48
Copy link
Contributor

@directionless directionless left a comment

Choose a reason for hiding this comment

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

Some nits/questions, but I think this is mostly okay.

If I understand correctly, the way this works is to have the log shipper keep a set of attributes it uses to apply to things shipped through it.

And when it receives a Ping, it does two things:

  1. it rebuilds the saved shipper with the new attributes
  2. it iterates over the logs pending and updates them

That seems reasonable

zackattack01
zackattack01 previously approved these changes Nov 27, 2023
Copy link
Contributor

@zackattack01 zackattack01 left a comment

Choose a reason for hiding this comment

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

looks great 🔥

deviceInfo[key] = string(v)
}

ls.shippingLogger = log.With(ls.shippingLogger, deviceInfo)
Copy link
Contributor

Choose a reason for hiding this comment

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

Okay, I'm somewhat wrong -- you have to splat it out. Calling like this has the key set to deviceInfo and the value nil. Take a look at https://go.dev/play/p/bJMUWw28Ekp (Or building the array as you go)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ahh, good catch, updated

@James-Pickett James-Pickett added this pull request to the merge queue Nov 28, 2023
Merged via the queue into kolide:main with commit 51b289e Nov 28, 2023
@James-Pickett James-Pickett deleted the james/add-attributes-to-early-logs branch November 28, 2023 15:51
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