Skip to content

Commit

Permalink
add core.State logging to executor
Browse files Browse the repository at this point in the history
  • Loading branch information
sharnoff committed Sep 27, 2023
1 parent 428fa13 commit 2f639aa
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
16 changes: 11 additions & 5 deletions pkg/agent/executor/core.go
Expand Up @@ -10,6 +10,8 @@ import (
"sync"
"time"

"go.uber.org/zap"

"github.com/neondatabase/autoscaling/pkg/agent/core"
"github.com/neondatabase/autoscaling/pkg/api"
"github.com/neondatabase/autoscaling/pkg/util"
Expand All @@ -20,6 +22,8 @@ type Config = core.Config
type ExecutorCore struct {
mu sync.Mutex

stateLogger *zap.Logger

core *core.State
actions *timedActions

Expand All @@ -32,12 +36,13 @@ type ClientSet struct {
Informant InformantInterface
}

func NewExecutorCore(vm api.VmInfo, config core.Config) *ExecutorCore {
func NewExecutorCore(stateLogger *zap.Logger, vm api.VmInfo, config core.Config) *ExecutorCore {
return &ExecutorCore{
mu: sync.Mutex{},
core: core.NewState(vm, config),
actions: nil, // (*ExecutorCore).getActions() checks if this is nil
updates: util.NewBroadcaster(),
mu: sync.Mutex{},
stateLogger: stateLogger,
core: core.NewState(vm, config),
actions: nil, // (*ExecutorCore).getActions() checks if this is nil
updates: util.NewBroadcaster(),
}
}

Expand Down Expand Up @@ -66,6 +71,7 @@ func (c *ExecutorCore) getActions() timedActions {
if c.actions == nil {
// NOTE: Even though we cache the actions generated using time.Now(), it's *generally* ok.
now := time.Now()
c.stateLogger.Info("Recalculating ActionSet", zap.Time("now", now), zap.Any("state", c.core.Dump()))
c.actions = &timedActions{calculatedAt: now, actions: c.core.NextActions(now)}
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/runner.go
Expand Up @@ -348,7 +348,7 @@ func (r *Runner) Run(ctx context.Context, logger *zap.Logger, vmInfoUpdated util
execLogger := logger.Named("exec")

coreExecLogger := execLogger.Named("core")
executorCore := executor.NewExecutorCore(r.vm, executor.Config{
executorCore := executor.NewExecutorCore(coreExecLogger.Named("state"), r.vm, executor.Config{
DefaultScalingConfig: r.global.config.Scaling.DefaultConfig,
PluginRequestTick: time.Second * time.Duration(r.global.config.Scheduler.RequestAtLeastEverySeconds),
InformantDeniedDownscaleCooldown: time.Second * time.Duration(r.global.config.Informant.RetryDeniedDownscaleSeconds),
Expand Down

0 comments on commit 2f639aa

Please sign in to comment.