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 sqlite database for storing shared agent data; store and monitor startup data #1515

Merged
merged 31 commits into from
Dec 29, 2023

Conversation

RebeccaMahany
Copy link
Contributor

@RebeccaMahany RebeccaMahany commented Dec 15, 2023

The new startup package monitors the flags that it's registered to observe, and updates them in a shared sqlite database on change. It also allows for querying for these flags outside of the launcher root context. This will be useful on launcher startup, when we need to pull autoupdate-related settings before we have knapsack available.

The new agentsqlite database is a partial implementation of a KVStore -- I only added Get/Set/Update, since that was what was required for the new startup package.

@RebeccaMahany RebeccaMahany changed the title Add startup database Add sqlite database for storing shared agent data Dec 20, 2023
@RebeccaMahany RebeccaMahany changed the title Add sqlite database for storing shared agent data Add sqlite database for storing shared agent data; store and monitor startup data Dec 20, 2023
Copy link
Contributor

@James-Pickett James-Pickett left a comment

Choose a reason for hiding this comment

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

Nice

@RebeccaMahany RebeccaMahany marked this pull request as ready for review December 21, 2023 22:15
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.

Mostly nits. (and our future selves, we're having a slack discussion about the call semantics of startup)

James-Pickett
James-Pickett previously approved these changes Dec 28, 2023
Copy link
Contributor

@James-Pickett James-Pickett left a comment

Choose a reason for hiding this comment

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

LGTM!

James-Pickett
James-Pickett previously approved these changes Dec 29, 2023
directionless
directionless previously approved these changes Dec 29, 2023
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 this is okay. I like the underlying functions, but I feel a little nervous about error handling

Comment on lines +45 to +48
conn, err := sql.Open("sqlite", dbLocation(rootDirectory))
if err != nil {
return nil, fmt.Errorf("opening startup db in %s: %w", rootDirectory, err)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What should happen if the file doesn't exist? (I'm honestly not sure)

Should OpenRO return something with nils? Return an error and let the caller handle it? I guess letting the caller handle it is correct

Copy link
Contributor

Choose a reason for hiding this comment

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

Related -- we might want validateDb in here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You'd asked for the RO option to be more lightweight and to skip the validation when we'd discussed on slack, since we need to use the RO option early on in launcher startup.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was thinking about skipping migration -- I'm less sure what should happen if the DB file isn't present. Or doesn't match expected schema. Bailing early and getting nothing isn't wrong

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess that's probably the right way to look at it -- If the DB is wrong, we should bail out and get nothing. Maybe it doesn't exist yet, maybe it hasn't been udpated to the current schema. So whatever we need to catch that and move on

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 will handle that in the next PR that starts to use the RO connection

@RebeccaMahany RebeccaMahany added this pull request to the merge queue Dec 29, 2023
Merged via the queue into kolide:main with commit 111a479 Dec 29, 2023
26 checks passed
@RebeccaMahany RebeccaMahany deleted the becca/startup-info branch December 29, 2023 20:02
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.

4 participants