-
Notifications
You must be signed in to change notification settings - Fork 103
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
Make osq runner responsive to registration updates #2007
base: main
Are you sure you want to change the base?
Conversation
a1d2603
to
01e4063
Compare
01e4063
to
2d74749
Compare
pkg/osquery/runtime/runner.go
Outdated
@@ -49,6 +53,31 @@ func New(k types.Knapsack, serviceClient service.KolideService, opts ...OsqueryI | |||
} | |||
|
|||
func (r *Runner) Run() error { | |||
for { | |||
// if our instances ever exit unexpectedly, return immediately |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this comment comment isn't accurate? I think runRegisteredInstances
only returns if a shutdown was requested. And it only returns an error if a) shutdown was requested and b) we were trying to restart one or more instances during that time and c) hadn't successfully restarted one of them yet.
Either way, why would we return the error here instead of checking rerunRequired
first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's a good point thank you. we'd probably want to rerun regardless if required, I will update that comment and get this fixed up!
) | ||
|
||
// we know there are changes, safe to update the internal registrationIDs now | ||
r.registrationIds = newRegistrationIDs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need a lock on r.registrationIds
to avoid a data race?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that seems like a good idea, will do!
…n reload is required
…unner_registration_ids
OsqRunner
interface and which encompasses the previousInstanceQuerier
interface and adds our newRegistrationChangeHandler
requirementsUpdateRegistrationIDs
method to the runner which will detect any changes and restart the instances accordinglyTo allow for a graceful restart of all known instances after registration IDs has been updated, a few tricky changes were required that I'd like more eyes on. context:
Shutdown
method, we currently close the shutdown channel to signal our shutdown intent. This works well but isn't compatible with needing to read from that channel again when the runner would stay up (e.g. updated registration ID restarts). resetting the channel did not feel correct and introduces data races due to the way we need to thread/use wait groups hereinstance.Exited()
above that)r.shutdown
to hold that message- the reason this worked as expected withclose(r.shutdown)
is because that channel will read a zero value and fire immediately whenever it is read next, even if the select wasn't open before the close was calledIf anyone has alternate suggestions please let me know!