Skip to content

Commit

Permalink
Disable panic scale by default (#102)
Browse files Browse the repository at this point in the history
* Disable panic scale by default
  • Loading branch information
victor-carvalho committed Aug 18, 2020
1 parent 51e6dd7 commit 3158ebe
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 7 deletions.
5 changes: 4 additions & 1 deletion controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -1145,8 +1145,11 @@ func SetRoomStatus(
) error {
log := logger.WithFields(logrus.Fields{
"operation": "SetRoomStatus",
"status": roomPayload.Status,
})

log.Debug("Updating room status")

cachedScheduler, err := schedulerCache.LoadScheduler(db, room.SchedulerName, true)
if err != nil {
return err
Expand All @@ -1158,7 +1161,7 @@ func SetRoomStatus(
return err
}

if roomPayload.Status != models.StatusOccupied {
if roomPayload.Status != models.StatusOccupied || !cachedScheduler.ConfigYAML.AutoScaling.EnablePanicScale {
return nil
}

Expand Down
84 changes: 84 additions & 0 deletions controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ requests:
cpu: "2"
shutdownTimeout: 20
autoscaling:
enablePanicScale: true
min: 3
up:
delta: 2
Expand Down Expand Up @@ -136,6 +137,47 @@ containers:
cmd:
- "./helper"
`
yamlWithoutPanic = `
name: controller-name
game: controller
image: controller/controller:v123
affinity: maestro-dedicated
toleration: maestro
ports:
- containerPort: 1234
protocol: UDP
name: port1
- containerPort: 7654
protocol: TCP
name: port2
limits:
memory: "66Mi"
cpu: "2"
requests:
memory: "66Mi"
cpu: "2"
shutdownTimeout: 20
autoscaling:
min: 3
up:
delta: 2
trigger:
usage: 60
time: 100
cooldown: 200
down:
delta: 1
trigger:
usage: 30
time: 500
cooldown: 500
env:
- name: MY_ENV_VAR
value: myvalue
cmd:
- "./room"
`

yamlWithLimit = `
name: controller-name
game: controller
Expand Down Expand Up @@ -5924,6 +5966,48 @@ containers:
}
room := models.NewRoom(roomName, schedulerName)

It("should not scale up if panic lock is disabled", func() {
var configYaml models.ConfigYAML
err := yaml.Unmarshal([]byte(yamlWithoutPanic), &configYaml)
Expect(err).ToNot(HaveOccurred())

status := "ready"

mt.MockLoadScheduler(configYaml.Name, mockDb).
Do(func(scheduler *models.Scheduler, query string, modifier string) {
*scheduler = *models.NewScheduler(configYaml.Name, configYaml.Game, yaml1)
})

mockRedisClient.EXPECT().TxPipeline().Return(mockPipeline)
mockPipeline.EXPECT().HMSet(rKey, map[string]interface{}{
"lastPing": time.Now().Unix(),
"status": status,
})
mockPipeline.EXPECT().ZAdd(pKey, gomock.Any())
mockPipeline.EXPECT().ZRem(lKey, roomName)
mockPipeline.EXPECT().SAdd(sKey, rKey)
for _, key := range allStatusKeys {
if !strings.Contains(key, status) {
mockPipeline.EXPECT().SRem(key, rKey)
}
}
mockPipeline.EXPECT().Exec()

err = controller.SetRoomStatus(
logger,
roomManager,
mockRedisClient,
mockDb,
mr,
clientset,
&models.RoomStatusPayload{Status: status},
config,
room,
schedulerCache,
)
Expect(err).ToNot(HaveOccurred())
})

It("should not scale up if has enough ready rooms", func() {
status := "ready"

Expand Down
5 changes: 5 additions & 0 deletions docs/autoscaling.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ It is the period to wait before running another scaling if it is needed. Cooldow
## Min and Max
These are hard caps for the total number of rooms (ready, occupied and creating) that can exist simultaneously. If Max is set to 0, it means that the scheduler can scale up indefinitely.

## Panic Scale
A **panic scale** happens when a new room is set to occupied and the percentage of occupied rooms is above the limit so it triggers a scale up.

This behaviour is deprecated and disabled by default but can be enabled with `enablePanicScale` flag.

## Requests
Containers resources requests. It is required to define these values in order to use resource triggers(cpu and memory)

Expand Down
5 changes: 3 additions & 2 deletions models/config_yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ func (c *ConfigYAML) EnsureDefaultValues() {

if c.AutoScaling == nil {
c.AutoScaling = &AutoScaling{
Up: defaultScalingPolicy,
Down: defaultScalingPolicy,
Up: defaultScalingPolicy,
Down: defaultScalingPolicy,
EnablePanicScale: false,
}
}

Expand Down
9 changes: 5 additions & 4 deletions models/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,11 @@ type ScalingPolicy struct {

// AutoScaling has the configuration for the GRU's auto scaling
type AutoScaling struct {
Min int `yaml:"min" json:"min" valid:"int64"`
Max int `yaml:"max" json:"max" valid:"int64"`
Up *ScalingPolicy `yaml:"up" json:"up" valid:"int64"`
Down *ScalingPolicy `yaml:"down" json:"down" valid:"int64"`
Min int `yaml:"min" json:"min" valid:"int64"`
Max int `yaml:"max" json:"max" valid:"int64"`
Up *ScalingPolicy `yaml:"up" json:"up" valid:"int64"`
Down *ScalingPolicy `yaml:"down" json:"down" valid:"int64"`
EnablePanicScale bool `yaml:"enablePanicScale" json:"enablePanicScale" valid:"bool"`
}

// Forwarder has the configuration for the event forwarders
Expand Down

0 comments on commit 3158ebe

Please sign in to comment.