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

ship logs to http endpoint #1228

Merged
merged 41 commits into from
Jun 28, 2023
Merged

Conversation

James-Pickett
Copy link
Contributor

@James-Pickett James-Pickett commented Jun 13, 2023

  • adds a new logger "LogShipper" that gets added via TeeLogger at launcher startup
  • LogShipper ship logs on an interval using endpoint and token provided by control server or flags
  • updates tracing code to use "TraceIngestURL" flag and LogShipper to use "LogIngestUrl"

@James-Pickett James-Pickett changed the title rough http buffer for to use for logger ship logs to http endpoint Jun 13, 2023
pkg/log/httpbuffer/httpbuffer.go Outdated Show resolved Hide resolved
pkg/log/httpbuffer/httpbuffer.go Outdated Show resolved Hide resolved
pkg/log/httpbuffer/httpbuffer.go Outdated Show resolved Hide resolved
pkg/log/httpbuffer/httpbuffer.go Outdated Show resolved Hide resolved
pkg/log/httpbuffer/httpbuffer.go Outdated Show resolved Hide resolved
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.

This looks pretty clean, I think it'll be easy to play with.

I've been stalling on #1183 but I think it would be easy to integrate this with it

pkg/log/httpbuffer/httpbuffer.go Outdated Show resolved Hide resolved
pkg/log/httpbuffer/httpbuffer.go Outdated Show resolved Hide resolved
pkg/log/httpbuffer/httpbuffer.go Outdated Show resolved Hide resolved
@directionless
Copy link
Contributor

directionless commented Jun 16, 2023 via email

pkg/log/httpbuffer/httpbuffer.go Outdated Show resolved Hide resolved
pkg/sendbuffer/sendbuffer.go Outdated Show resolved Hide resolved
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.

(early comments)

pkg/sendbuffer/sendbuffer.go Outdated Show resolved Hide resolved
pkg/sendbuffer/sendbuffer.go Outdated Show resolved Hide resolved
pkg/sendbuffer/sendbuffer.go Outdated Show resolved Hide resolved
pkg/log/logshipper/logshipper.go Outdated Show resolved Hide resolved
pkg/sendbuffer/sendbuffer.go Outdated Show resolved Hide resolved
pkg/sendbuffer/sendbuffer.go Outdated Show resolved Hide resolved
pkg/sendbuffer/sendbuffer.go Outdated Show resolved Hide resolved
pkg/sendbuffer/sendbuffer.go Show resolved Hide resolved
pkg/sendbuffer/sendbuffer.go Outdated Show resolved Hide resolved
pkg/sendbuffer/sendbuffer.go Outdated Show resolved Hide resolved
pkg/log/logshipper/logshipper.go Outdated Show resolved Hide resolved
pkg/log/logshipper/logshipper.go Outdated Show resolved Hide resolved
pkg/log/logshipper/logshipper.go Outdated Show resolved Hide resolved
pkg/log/logshipper/logger.go Outdated Show resolved Hide resolved
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.

I think I'm okay with it. But I have some questions about how this works if we merge it today. (it should be disabled unless the control server sets a target host, or we push a build with a default target host)

cmd/launcher/launcher.go Outdated Show resolved Hide resolved
@@ -148,8 +148,9 @@ func runLauncher(ctx context.Context, cancel func(), opts *launcher.Options) err

// Need to set up the log shipper so that we can get the logger early
// and pass it to the various systems.
isShippingLogs := k.ObservabilityIngestServerURL() != ""
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably okay to start with it. Interesting question is whether it's possible to enable/disable/change the URL from the control server

Comment on lines 102 to 104
if !ls.knapsack.LogShippingEnabled() {
return nil
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I cannot remember -- how performant is this? Vs storing a boolean on logshipper and registering it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the values are cached, but just to be safe, I'll store the boolean on log shipper

Copy link
Contributor

@RebeccaMahany RebeccaMahany left a comment

Choose a reason for hiding this comment

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

Didn't make it through the sendbuffer, will come back and review that later

Edit -- sendbuffer looked fine to me, I didn't have any additional comments there!

cmd/launcher/launcher.go Outdated Show resolved Hide resolved
pkg/log/logshipper/logshipper.go Outdated Show resolved Hide resolved
pkg/agent/knapsack/knapsack.go Outdated Show resolved Hide resolved
pkg/log/logshipper/logshipper.go Outdated Show resolved Hide resolved
pkg/log/logshipper/logshipper.go Outdated Show resolved Hide resolved
pkg/log/logshipper/logshipper.go Outdated Show resolved Hide resolved
token, _ := ls.knapsack.TokenStore().Get(observabilityIngestTokenKey)
ls.sender.authtoken = string(token)

endpoint, err := logEndpoint(ls.knapsack)
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't you need to implement FlagsChanged(flagKeys ...keys.FlagKey) and call knapsack.RegisterChangeObserver to get agent flags (i.e. LogIngestServerURL) updates on time?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I kinda took the lazy rout and just subscribed to all agent_flags updates, felt easier to just handle all the control server updates in Ping(), however if I'm willing to change it if you think it would be cleaner.

https://github.com/James-Pickett/launcher/blob/james/log-shipping/cmd/launcher/launcher.go#L324

Copy link
Contributor

Choose a reason for hiding this comment

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

I think I have a slight preference for doing it consistently the same way everywhere. But maybe the best way is to do everything in Ping like you've got it here? Maybe can chat about it later, I'm fine with this as-is regardless

Copy link
Contributor

Choose a reason for hiding this comment

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

I think you're right that we should come up with some patterns for doing this consistently. But I don't know what it'll be yet.

pkg/log/logshipper/logshipper.go Outdated Show resolved Hide resolved
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.

Let's try!

@James-Pickett James-Pickett merged commit 3f9bc17 into kolide:main Jun 28, 2023
14 checks passed
@James-Pickett James-Pickett deleted the james/log-shipping branch June 28, 2023 03:37
@directionless directionless mentioned this pull request Aug 30, 2023
3 tasks
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