fix: stop incrementing activity on empty agent stats#15204
Merged
Conversation
johnstcn
approved these changes
Oct 24, 2024
|
|
||
| type Batcher interface { | ||
| Add(now time.Time, agentID uuid.UUID, templateID uuid.UUID, userID uuid.UUID, workspaceID uuid.UUID, st *agentproto.Stats, usage bool) error | ||
| Add(now time.Time, agentID uuid.UUID, templateID uuid.UUID, userID uuid.UUID, workspaceID uuid.UUID, st *agentproto.Stats, usage bool) |
Member
There was a problem hiding this comment.
praise: This does make the whole interface more convenient to use 👍
| err := r.opts.StatsBatcher.Add(now, workspaceAgent.ID, workspace.TemplateID, workspace.OwnerID, workspace.ID, stats, usage) | ||
| // update prometheus metrics | ||
| if r.opts.UpdateAgentMetricsFn != nil { | ||
| user, err := r.opts.Database.GetUserByID(ctx, workspace.OwnerID) |
Member
There was a problem hiding this comment.
thought (non-blocking): It's unfortunate to have to do this just to get the username related to the workspace.
Member
Author
There was a problem hiding this comment.
Yeah we just have generally avoided database types that embed other types as a default strategy which leads to cleaner types but unfortunately sometimes more fetching. I think it's OK for now and can always be optimized if found to be a bottleneck later. It's a good goal to get this func as low IO as possible.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #15174
This adds safeguards around when we decide to bump workspace activity to limit it to only bump if we have active connections to the workspace.
I also cleaned up some code, mostly async code that no longer needed to be async because we moved so many operations to batchers that don't do IO on the
Addcalls.