Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions packages/api/internal/orchestrator/analytics.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,12 @@ func (o *Orchestrator) reportLongRunningSandboxes(ctx context.Context) {
case <-ticker.C:
sandboxes := o.sandboxStore.Items(nil, []sandbox.State{sandbox.StateRunning})
longRunningSandboxes := make([]sandbox.Sandbox, 0, len(sandboxes))
now := time.Now()
for _, sandbox := range sandboxes {
if time.Since(sandbox.StartTime) > oldSandboxThreshold {
if sandbox.StartTime.IsZero() {
continue
}
Copy link
Member

Choose a reason for hiding this comment

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

this check isn't really needed

if now.Sub(sandbox.StartTime) > oldSandboxThreshold {
Copy link
Member

Choose a reason for hiding this comment

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

can we keep

time.Since(sandbox.StartTime) > oldSandboxThreshold

I think it's more readable and the improvement is negligible

longRunningSandboxes = append(longRunningSandboxes, sandbox)
}
}
Expand All @@ -57,14 +61,14 @@ func sendAnalyticsForLongRunningSandboxes(ctx context.Context, analytics *analyt
return
}

childCtx, cancel := context.WithTimeout(ctx, syncAnalyticsTime)
childCtx, cancel := context.WithTimeout(ctx, reportTimeout)
defer cancel()

instanceIds := make([]string, len(instances))
executionIds := make([]string, len(instances))
for idx, i := range instances {
instanceIds[idx] = i.SandboxID
executionIds[idx] = i.ExecutionID
instanceIds := make([]string, 0, len(instances))
executionIds := make([]string, 0, len(instances))
Copy link
Member

Choose a reason for hiding this comment

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

We know the length will be exactly instances, so it's seems to be safe to preallocate and do it as it is now. What was the reason behind this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well ok — given your current logic always appends exactly one entry per instance, this change doesn’t add much value. I will revert it to keep the code simpler.

for _, i := range instances {
instanceIds = append(instanceIds, i.SandboxID)
executionIds = append(executionIds, i.ExecutionID)
}

_, err := analytics.RunningInstances(childCtx,
Expand Down
Loading