Skip to content

Commit

Permalink
Add traces in autoscaler (#629)
Browse files Browse the repository at this point in the history
- Add a couple more traces in autoscaler and instance
  • Loading branch information
luke-lombardi authored Oct 17, 2024
1 parent 37b20cb commit 2522a69
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/abstractions/common/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ func (i *AutoscaledInstance) HandleScalingEvent(desiredContainers int) error {

err := i.Lock.Acquire(i.Ctx, i.InstanceLockKey, common.RedisLockOptions{TtlS: 10, Retries: 0})
if err != nil {
trace.Span.AddEvent("Failed to acquire lock")
return err
}
defer i.Lock.Release(i.InstanceLockKey)
Expand Down
9 changes: 9 additions & 0 deletions pkg/abstractions/endpoint/autoscaler.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ func endpointSampleFunc(i *endpointInstance) (*endpointAutoscalerSample, error)
}

func endpointDeploymentScaleFunc(i *endpointInstance, s *endpointAutoscalerSample) *abstractions.AutoscalerResult {
trace := common.TraceFunc(i.Ctx, "pkg/abstractions/endpoint", "endpointDeploymentScaleFunc",
attribute.String("stub.id", i.Stub.ExternalId))
defer trace.End()

desiredContainers := 0

if s.TotalRequests == 0 {
Expand All @@ -54,6 +58,9 @@ func endpointDeploymentScaleFunc(i *endpointInstance, s *endpointAutoscalerSampl
}
}

trace.Span.AddEvent(fmt.Sprintf("Total requests: %d", s.TotalRequests))
trace.Span.AddEvent(fmt.Sprintf("Tasks per container: %d", i.StubConfig.Autoscaler.TasksPerContainer))

desiredContainers = int(s.TotalRequests / int64(i.StubConfig.Autoscaler.TasksPerContainer))
if s.TotalRequests%int64(i.StubConfig.Autoscaler.TasksPerContainer) > 0 {
desiredContainers += 1
Expand All @@ -64,6 +71,8 @@ func endpointDeploymentScaleFunc(i *endpointInstance, s *endpointAutoscalerSampl
desiredContainers = int(math.Min(maxReplicas, float64(desiredContainers)))
}

trace.Span.AddEvent(fmt.Sprintf("Desired containers: %d", desiredContainers))

return &abstractions.AutoscalerResult{
DesiredContainers: desiredContainers,
ResultValid: true,
Expand Down

0 comments on commit 2522a69

Please sign in to comment.