Skip to content

Commit

Permalink
Add Manager::Worker::HireFire::JobLatency
Browse files Browse the repository at this point in the history
  • Loading branch information
PChambino committed Apr 9, 2022
1 parent 9a69578 commit e5ba237
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 2 deletions.
2 changes: 2 additions & 0 deletions client/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ type Manager struct {

Aggregation *string `json:"aggregation"`
Percentile *int `json:"percentile"`
MinimumLatency *int `json:"minimum_latency"`
MaximumLatency *int `json:"maximum_latency"`
MinimumQueueTime *int `json:"minimum_queue_time"`
MaximumQueueTime *int `json:"maximum_queue_time"`
MinimumResponseTime *int `json:"minimum_response_time"`
Expand Down
4 changes: 4 additions & 0 deletions client/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ func TestGetManagerEverything(t *testing.T) {
"aggregation": "percentile",
"percentile": 99,
"minimum_latency": 100,
"maximum_latency": 150,
"minimum_queue_time": 200,
"maximum_queue_time": 400,
"minimum_response_time": 500,
Expand Down Expand Up @@ -109,6 +111,8 @@ func TestGetManagerEverything(t *testing.T) {

Aggregation: ptr.String("percentile"),
Percentile: ptr.Int(99),
MinimumLatency: ptr.Int(100),
MaximumLatency: ptr.Int(150),
MinimumQueueTime: ptr.Int(200),
MaximumQueueTime: ptr.Int(400),
MinimumResponseTime: ptr.Int(500),
Expand Down
15 changes: 13 additions & 2 deletions docs/resources/manager.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ The following arguments are supported:
- `type` - (required) The autoscaling strategy to use. Each strategy has a
different set of additional fields documented below. Strategies:
- [`Manager::Worker::HireFire::JobQueue`](#managerworkerhirefirejobqueue)
- [`Manager::Worker::HireFire::JobLatency`](#managerworkerhirefirejoblatency)
- [`Manager::Web::Logplex::Load`](#managerweblogplexload)
- [`Manager::Web::Logplex::ResponseTime`](#managerweblogplexresponsetime)
- [`Manager::Web::Logplex::ConnectTime`](#managerweblogplexconnecttime)
Expand All @@ -68,10 +69,20 @@ The following arguments are supported:
- `upscale_limit` - Limits the amount of dynos by which the manager scales up at a time. 0 means no limit.
- `downscale_limit` - Limits the amount of dynos by which the manager scales down at a time. 0 means no limit.

### Manager::Worker::HireFire::JobLatency
- `minimum_latency` - Scales down if your application's job latency goes below this amount in seconds.
- `maximum_latency` - Scales up if your application's job latency goes above this amount in seconds.
- `upscale_quantity` - The amount of dynos to scale up at a time.
- `downscale_quantity` - The amount of dynos to scale down at a time.
- `upscale_sensitivity` - The amount of threshold breaches to wait before scaling up.
- `downscale_sensitivity` - The amount of threshold breaches to wait before scaling down.
- `upscale_timeout` - The amount of minutes to wait before performing upscale operations.
- `downscale_timeout` - The amount of minutes to wait before performing downscale operations.

### Manager::Web::Logplex::Load
- `last_minutes` - The load average over the last n minutes. Possible values are `1`, `5`, and `15`.
- `minimum_load` - Scales up if your application's load exceeds this amount (`100` equals load 1).
- `maximum_load` - Scales down if your application's load exceeds this amount (`100` equals load 1).
- `minimum_load` - Scales down if your application's load goes below this amount (`100` equals load 1).
- `maximum_load` - Scales up if your application's load goes above this amount (`100` equals load 1).
- `upscale_quantity` - The amount of dynos to scale up at a time.
- `downscale_quantity` - The amount of dynos to scale down at a time.
- `upscale_sensitivity` - The amount of threshold breaches to wait before scaling up.
Expand Down
21 changes: 21 additions & 0 deletions resources/manager/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func Resource() *schema.Resource {
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
"Manager::Worker::HireFire::JobLatency",
"Manager::Worker::HireFire::JobQueue",
"Manager::Web::Logplex::Load",
"Manager::Web::Logplex::ResponseTime",
Expand Down Expand Up @@ -70,6 +71,14 @@ func Resource() *schema.Resource {
Type: schema.TypeInt,
Optional: true,
},
"minimum_latency": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
"maximum_latency": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
},
"minimum_queue_time": &schema.Schema{
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -202,6 +211,8 @@ func setAttributes(d *schema.ResourceData, manager *client.Manager) {

d.Set("aggregation", manager.Aggregation)
d.Set("percentile", manager.Percentile)
d.Set("minimum_latency", manager.MinimumLatency)
d.Set("maximum_latency", manager.MaximumLatency)
d.Set("minimum_queue_time", manager.MinimumQueueTime)
d.Set("maximum_queue_time", manager.MaximumQueueTime)
d.Set("minimum_response_time", manager.MinimumResponseTime)
Expand Down Expand Up @@ -254,6 +265,16 @@ func getAttributes(d *schema.ResourceData) client.Manager {
manager.Percentile = &value
}

if v, ok := d.GetOk("minimum_latency"); ok {
value := v.(int)
manager.MinimumLatency = &value
}

if v, ok := d.GetOk("maximum_latency"); ok {
value := v.(int)
manager.MaximumLatency = &value
}

if v, ok := d.GetOk("minimum_queue_time"); ok {
value := v.(int)
manager.MinimumQueueTime = &value
Expand Down
44 changes: 44 additions & 0 deletions resources/manager/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,28 @@ func TestAccManager(t *testing.T) {
}(orgName, manager),
Check: checks(*manager),
},
{
Config: func(orgName string, manager *client.Manager) string {
*manager = client.Manager{
Name: fmt.Sprintf("test-%s", helper.RandString(10)),
Type: "Manager::Worker::HireFire::JobLatency",
Enabled: true,
Minimum: 2,
Maximum: 10,

MinimumLatency: ptr.Int(100),
MaximumLatency: ptr.Int(150),
UpscaleQuantity: ptr.Int(5),
DownscaleQuantity: ptr.Int(1),
UpscaleSensitivity: ptr.Int(2),
DownscaleSensitivity: ptr.Int(1),
UpscaleTimeout: 0,
DownscaleTimeout: 2,
}
return config(orgName, manager)
}(orgName, manager),
Check: checks(*manager),
},
{
ResourceName: resourceName,
ImportState: true,
Expand Down Expand Up @@ -238,6 +260,26 @@ func config(orgName string, manager *client.Manager) string {
manager.UpscaleLimit,
manager.DownscaleLimit,
))
case "Manager::Worker::HireFire::JobLatency":
return configBase(orgName, manager, fmt.Sprintf(`
minimum_latency = %d
maximum_latency = %d
upscale_quantity = %d
downscale_quantity = %d
upscale_sensitivity = %d
downscale_sensitivity = %d
upscale_timeout = %d
downscale_timeout = %d
`,
*manager.MinimumLatency,
*manager.MaximumLatency,
*manager.UpscaleQuantity,
*manager.DownscaleQuantity,
*manager.UpscaleSensitivity,
*manager.DownscaleSensitivity,
manager.UpscaleTimeout,
manager.DownscaleTimeout,
))
default:
return configBase(orgName, manager, "")
}
Expand All @@ -260,6 +302,8 @@ func checkAttributes(manager client.Manager) resource.TestCheckFunc {

"aggregation": helper.StringOrEmpty(manager.Aggregation),
"percentile": helper.ItoaOrZero(manager.Percentile),
"minimum_latency": helper.ItoaOrZero(manager.MinimumLatency),
"maximum_latency": helper.ItoaOrZero(manager.MaximumLatency),
"minimum_queue_time": helper.ItoaOrZero(manager.MinimumQueueTime),
"maximum_queue_time": helper.ItoaOrZero(manager.MaximumQueueTime),
"minimum_response_time": helper.ItoaOrZero(manager.MinimumResponseTime),
Expand Down

0 comments on commit e5ba237

Please sign in to comment.