Thanks to visit codestin.com
Credit goes to github.com

Skip to content

fix: stop incrementing activity on empty agent stats #15204

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

Merged
merged 10 commits into from
Oct 25, 2024

Conversation

f0ssel
Copy link
Contributor

@f0ssel f0ssel commented Oct 23, 2024

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 Add calls.

@f0ssel f0ssel requested a review from johnstcn October 23, 2024 18:55
@f0ssel f0ssel changed the title fix: stop incrementing on empty agent stats fix: stop incrementing activity on empty agent stats Oct 23, 2024
Copy link
Member

@johnstcn johnstcn left a comment

Choose a reason for hiding this comment

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

Looks good to me! Thanks for finding this! Just need to fix up the failing tests.

@@ -25,7 +25,7 @@ const (
)

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)
Copy link
Member

Choose a reason for hiding this comment

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

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)
Copy link
Member

Choose a reason for hiding this comment

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

thought (non-blocking): It's unfortunate to have to do this just to get the username related to the workspace.

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 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.

Base automatically changed from f0ssel/last_used_at_inc to main October 24, 2024 19:12
@f0ssel f0ssel enabled auto-merge (squash) October 25, 2024 16:02
@f0ssel f0ssel merged commit 0dd942e into main Oct 25, 2024
26 checks passed
@f0ssel f0ssel deleted the f0ssel/last_used_at_inc_2 branch October 25, 2024 16:49
@github-actions github-actions bot locked and limited conversation to collaborators Oct 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

last_used_at continues to increment with workspace-usage experiment
2 participants