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

Moved run ID management to knapsack #1929

Merged
merged 3 commits into from
Oct 31, 2024
Merged

Moved run ID management to knapsack #1929

merged 3 commits into from
Oct 31, 2024

Conversation

cesarfda
Copy link
Contributor

@cesarfda cesarfda commented Oct 31, 2024

This pull request moves the run ID system to improve logging and tracking across the application. The changes include generating a unique run ID, setting it in the knapsack, and applying it to the logger and slogger for consistent tracking.

Resolves #1706

Run ID Implementation:

Logger Updates:

Comment on lines 68 to 69
k.slogger.With("run_id", id)
k.systemSlogger.With("run_id", id)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need e.g. --

k.slogger = k.slogger.With("run_id", id)
k.systemSlogger = k.systemSlogger.With("run_id", id)

? I think .With creates and then modifies a clone, so it wouldn't update k.slogger.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I did that in launcher but missed in Knapsack. I have pushed out another commit to fix this with the assignment.

@@ -59,6 +62,18 @@ func New(stores map[storage.Store]types.KVStore, flags types.Flags, db *bbolt.DB
return k
}

// SetRunID sets the run ID in the knapsack
func (k *knapsack) SetRunID(id string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need this method?

I'd probably do something like:

func (k *knapsack) GetRunID() string {
        if runID == "" {
            runID = ulid.New()
        }
	return runID
}

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 that wouldn't cover the scenario where we want every time runLauncher is called to have a newID, I assume we could run into a situation where the ID is persisted if runLauncher is called after an update. Let me know if that's not the case and I can change this

Copy link
Contributor

Choose a reason for hiding this comment

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

Chatted on slack -- I think this is worth testing. I'm not sure if the restart/exec would have access to the same memory

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 if we did need to create a specific create method, my inclination would be to make k.NewRunID() and call it on startup. I think passing in the string feels wrong.

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 was able to test the scenario and after the update we do get a new ID when we generate the ID in the GET method. I refactored the code to not have a set.

@cesarfda cesarfda enabled auto-merge October 31, 2024 20:11
@cesarfda cesarfda added this pull request to the merge queue Oct 31, 2024
Merged via the queue into kolide:main with commit 55714cd Oct 31, 2024
29 checks passed
@cesarfda cesarfda deleted the runid branch October 31, 2024 21:18
Comment on lines +197 to +198
// Generate a new run ID
newRunID := k.GetRunID()
Copy link
Contributor

Choose a reason for hiding this comment

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

I know this has merged, and it's fine, but I'd probably skip the variable here, and put k.GetRunID() into the two With functions

Comment on lines +70 to +71
k.slogger.Logger = k.slogger.Logger.With("run_id", runID)
k.systemSlogger.Logger = k.systemSlogger.Logger.With("run_id", runID)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hrm. This here, and the part in runLauncher feels off somehow.

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.

Make launcher run ID available in knapsack
3 participants