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

Unified Queue: tentative DB schema, start refactoring scripts #25215

Merged
merged 13 commits into from
Jan 8, 2025

Conversation

mna
Copy link
Member

@mna mna commented Jan 7, 2025

#23913 and #23918 , both only partially addressed by this PR.

Checklist for submitter

  • Changes file added for user-visible changes in changes/, orbit/changes/ or ee/fleetd-chrome/changes.
    See Changes files for more information.
  • Input data is properly validated, SELECT * is avoided, SQL injection is prevented (using placeholders for values in statements)
  • If database migrations are included, checked table schema to confirm autoupdate
  • For database migrations:
    • Ensured the correct collation is explicitly set for character columns (COLLATE utf8mb4_unicode_ci).
  • Added/updated automated tests

Copy link
Member Author

@mna mna left a comment

Choose a reason for hiding this comment

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

This is a small starting point for the unified queue story:

  • Tentative upcoming activities table, only supports scripts for now
  • Creates scripts in this new table
  • Handles some lookups for pending scripts
  • Handles some deletions

A couple of tests are passing that verify the new code, but most of the tests will not pass, and won't pass for quite a while due to the nature of this story.


func Up_20250106162751(tx *sql.Tx) error {
_, err := tx.Exec(`
CREATE TABLE upcoming_activities (
Copy link
Member Author

Choose a reason for hiding this comment

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

Keep in mind that this will still evolve - it only handles scripts for now, as I try to take small bites at that huge story. Be ready to reset your DB with future changes to this same migration if you try that out.

@@ -64,199 +63,237 @@ func testHostScriptResult(t *testing.T, ds *Datastore) {

// create a createdScript execution request (with a user)
u := test.NewUser(t, ds, "Bob", "bob@example.com", true)
createdScript, err := ds.NewHostScriptExecutionRequest(ctx, &fleet.HostScriptRequestPayload{
Copy link
Member Author

Choose a reason for hiding this comment

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

I adapted this test so that my new code is lightly tested and I'm not totally in the blind until the end of the story.

@mna mna marked this pull request as ready for review January 7, 2025 21:33
@mna mna requested a review from a team as a code owner January 7, 2025 21:33
Copy link
Member

@getvictor getvictor left a comment

Choose a reason for hiding this comment

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

Added a couple more comments.

-- user_id is the user that triggered the activity, it may be null if the
-- activity is fleet-initiated or the user was deleted. Additional user
-- information (name, email, etc.) is stored in the JSON payload.
user_id INT UNSIGNED NULL,
Copy link
Member

Choose a reason for hiding this comment

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

If user was deleted, the id should point to the new deleted_users table (or whatever we call it).

Copy link
Member Author

Choose a reason for hiding this comment

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

I'm not sure I'll be able to add that feature as part of this already-huge story. I'm trying to keep the scope in check as there are still tons of unknowns, storing the deleted user's info in the JSON for now.

Comment on lines +39 to +44
script_id INT UNSIGNED NULL,
script_content_id INT UNSIGNED NULL,
policy_id INT UNSIGNED NULL,
setup_experience_script_id INT UNSIGNED NULL,

payload JSON NOT NULL,
Copy link
Member

Choose a reason for hiding this comment

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

This doesn't feel very clean -- a bunch of columns specific to one type of activity. What if we need to add another column -- will we keep growing this table?

What do you think about normalizing and having a separate table for this script-specific data?

We can still have FKs by having the JOIN column like script_activity_id. If we have this column, then maybe we also don't need activity_type/execution_id columns. Or at least the activity_type can be autogenerated by simply checking if script_activity_id is null or not.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I think a join table makes sense for specific activity stuff that is outside of the JSON payload. I think I'll keep the activity type as a) it cleanly describes the supported types and b) we may have some activity types that don't require a join table at all.

As mentioned, I'll address those things by going forward in the next PR, please approve if there's nothing else.

@mna mna merged commit 2c3fc20 into feat-upcoming-activites-queue Jan 8, 2025
9 of 13 checks passed
@mna mna deleted the mna-23913-23918-unified-queue branch January 8, 2025 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants