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

added new store for uptime history and uptime tracking with knapsack #1923

Merged
merged 3 commits into from
Oct 29, 2024

Conversation

cesarfda
Copy link
Contributor

Resolves #1702

  • Added a start time entry at launcher that is available at the knapsack
  • Added UpTimeHistoryStore to store start_time
  • Modified kolide_launcher_info table to take in the UpTimeHistoryStore, calculate the delta and save the value in a new Column called uptime.

Preview:
image

// start counting uptime
processStartTime := time.Now()

k.UpTimeHistoryStore().Set([]byte("process_start_time"), []byte(processStartTime.Format(time.RFC3339)))
Copy link
Contributor

Choose a reason for hiding this comment

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

HistoryStore makes me think this would hold a series of process start times - but I feel like we would want to do that eventually anyway so probably not worth changing the name. might be nice to add a comment somewhere (maybe here or near knapsack definition) saying that we only currently track the running process start time, but would like to push these into a historical list in the future

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated to LauncherHistoryStore

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.

One question about naming -- LGTM!

@@ -18,6 +18,7 @@ const (
ServerProvidedDataStore Store = "server_provided_data" // The store used for pushing values from server-backed tables.
TokenStore Store = "token_store" // The store used for holding bearer auth tokens, e.g. the ones used to authenticate with the observability ingest server.
ControlServerActionsStore Store = "action_store" // The store used for storing actions sent by control server.
UpTimeHistoryStore Store = "uptime_history" // The store used for storing uptime history.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe we'd want something like LauncherHistoryStore Store = "launcher_history" -- I think that might be a little more extensible for the future, and would match osquery_instance_history. I don't feel strongly about it, though -- what do others think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I like that more too, it makes sense to me to report as just uptime for the table column but internally here it is a little more confusing what this refers to

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That makes sense, I updated the name to LauncherHistoryStore

uptime := ""

if uptimeBytes != nil {
startTime, _ := time.Parse(time.RFC3339, string(uptimeBytes))
Copy link
Contributor

Choose a reason for hiding this comment

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

should probably check the error here before processing startTime

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if err != nil {
// No logger here, so we can't easily log. Move on with blank values
publicKey = ""
fingerprint = ""
}

uptimeBytes, _ := upTimeHistoryStore.Get([]byte("process_start_time"))
Copy link
Contributor

Choose a reason for hiding this comment

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

should probably check the error here before processing uptimeBytes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I avoided returning the err because I don't want uptime blocking the rest of the info on the table, so I set a default value to use if the uptime err are not nil.

Copy link
Contributor

@zackattack01 zackattack01 left a comment

Choose a reason for hiding this comment

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

looks great! just a few small comments

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!

@cesarfda cesarfda added this pull request to the merge queue Oct 29, 2024
Copy link
Contributor

@zackattack01 zackattack01 left a comment

Choose a reason for hiding this comment

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

nice!

Merged via the queue into kolide:main with commit bfc42f4 Oct 29, 2024
29 checks passed
@cesarfda cesarfda deleted the uptime branch October 29, 2024 16:43
@@ -33,6 +33,7 @@ func MakeStores(ctx context.Context, slogger *slog.Logger, db *bbolt.DB) (map[st
storage.ServerProvidedDataStore,
storage.TokenStore,
storage.ControlServerActionsStore,
storage.LauncherHistoryStore,
Copy link
Contributor

Choose a reason for hiding this comment

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

Wow. Looking at the stores here, I'm not sure there was an obvious one. But creating a new one to hold a single value feels big. Done now though

@RebeccaMahany RebeccaMahany added component:table Table Changes features-improvements Features and Improvements labels Nov 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component:table Table Changes features-improvements Features and Improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The kolide_launcher_info should expose runtime.
5 participants