refactor: drop global resource limits

Global limits make it harder to reason about the inheritance in the system. Rather than support global limits, Dokku should provide primitives to automatically set them on an app at provision time, or explicitly set them for an app. Both of these are likely best suited for a higher-level provisioner, or a community plugin.
This commit is contained in:
Jose Diaz-Gonzalez
2019-03-18 16:01:19 -04:00
parent 278a80cc25
commit c9bbddcfcb
7 changed files with 52 additions and 57 deletions

View File

@@ -3,11 +3,11 @@
> New as of 0.15.0 > New as of 0.15.0
``` ```
dokku resource:limit [--global] [--process-type <process-type,...>] [RESOURCE_OPTS...] <app> resource:limit [--process-type <process-type>] [RESOURCE_OPTS...] <app> # Limit resources for a given app/process-type combination
dokku resource:reserve [--global] [--process-type <process-type,...>] [RESOURCE_OPTS...] <app> resource:limit-clear [--process-type <process-type>] <app> # Limit resources for a given app/process-type combination
dokku resource:limit-clear [--process-type <process-type,...>] [<app>] resource:report [<app>] [<flag>] # Displays a resource report for one or more apps
dokku resource:reserve-clear [--process-type <process-type,...>] [<app>] resource:reserve [--process-type <process-type>] [RESOURCE_OPTS...] <app> # Reserve resources for a given app/process-type combination
dokku resource:report [<app>] resource:reserve-clear [--process-type <process-type>] <app> # Reserve resources for a given app/process-type combination
``` ```
The resource plugin is meant to allow users to limit or reserve resources for a given app/process-type combination. The resource plugin is meant to allow users to limit or reserve resources for a given app/process-type combination.

View File

@@ -19,8 +19,11 @@ Manages resource settings for an app
Additional commands:` Additional commands:`
helpContent = ` helpContent = `
resource:limit [--global] [--process-type process-type] [RESOURCE_OPTS...] <app>, Limit resources for a given app/process-type combination resource:limit [--process-type <process-type>] [RESOURCE_OPTS...] <app>, Limit resources for a given app/process-type combination
resource:reserve [--global] [--process-type process-type] [RESOURCE_OPTS...] <app>, Reserve resources for a given app/process-type combination resource:limit-clear [--process-type <process-type>] <app>, Limit resources for a given app/process-type combination
resource:report [<app>] [<flag>], Displays a resource report for one or more apps
resource:reserve [--process-type <process-type>] [RESOURCE_OPTS...] <app>, Reserve resources for a given app/process-type combination
resource:reserve-clear [--process-type <process-type>] <app>, Reserve resources for a given app/process-type combination
` `
) )

View File

@@ -11,10 +11,9 @@ import (
func main() { func main() {
args := flag.NewFlagSet("resource:limit-clear", flag.ExitOnError) args := flag.NewFlagSet("resource:limit-clear", flag.ExitOnError)
processType := args.String("process-type", "", "process-type: A process type to clear") processType := args.String("process-type", "", "process-type: A process type to clear")
global := args.Bool("global", false, "global: Whether to clear global settings or not")
args.Parse(os.Args[2:]) args.Parse(os.Args[2:])
err := resource.CommandLimitClear(args.Args(), *processType, *global) err := resource.CommandLimitClear(args.Args(), *processType)
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFail(err.Error())
} }

View File

@@ -11,7 +11,6 @@ import (
func main() { func main() {
args := flag.NewFlagSet("resource:limit", flag.ExitOnError) args := flag.NewFlagSet("resource:limit", flag.ExitOnError)
processType := args.String("process-type", "", "process-type: A process type to manage") processType := args.String("process-type", "", "process-type: A process type to manage")
global := args.Bool("global", false, "global: Whether to clear global settings or not")
cpu := args.String("cpu", "", "cpu: The amount of cpu to limit processes by") cpu := args.String("cpu", "", "cpu: The amount of cpu to limit processes by")
memory := args.String("memory", "", "memory: The amount of memory to limit processes by") memory := args.String("memory", "", "memory: The amount of memory to limit processes by")
memorySwap := args.String("memory-swap", "", "memory-swap: The amount of swap memory to limit processes by") memorySwap := args.String("memory-swap", "", "memory-swap: The amount of swap memory to limit processes by")
@@ -29,7 +28,7 @@ func main() {
NetworkEgress: *networkEgress, NetworkEgress: *networkEgress,
} }
err := resource.CommandLimit(args.Args(), *processType, resources, *global) err := resource.CommandLimit(args.Args(), *processType, resources)
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFail(err.Error())
} }

View File

@@ -11,10 +11,9 @@ import (
func main() { func main() {
args := flag.NewFlagSet("resource:reserve-clear", flag.ExitOnError) args := flag.NewFlagSet("resource:reserve-clear", flag.ExitOnError)
processType := args.String("process-type", "", "process-type: A process type to clear") processType := args.String("process-type", "", "process-type: A process type to clear")
global := args.Bool("global", false, "global: Whether to clear global settings or not")
args.Parse(os.Args[2:]) args.Parse(os.Args[2:])
err := resource.CommandReserveClear(args.Args(), *processType, *global) err := resource.CommandReserveClear(args.Args(), *processType)
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFail(err.Error())
} }

View File

@@ -11,7 +11,6 @@ import (
func main() { func main() {
args := flag.NewFlagSet("resource:reserve", flag.ExitOnError) args := flag.NewFlagSet("resource:reserve", flag.ExitOnError)
processType := args.String("process-type", "", "process-type: A process type to manage") processType := args.String("process-type", "", "process-type: A process type to manage")
global := args.Bool("global", false, "global: Whether to clear global settings or not")
cpu := args.String("cpu", "", "cpu: The amount of cpu to reserve for processes") cpu := args.String("cpu", "", "cpu: The amount of cpu to reserve for processes")
memory := args.String("memory", "", "memory: The amount of memory to reserve for processes") memory := args.String("memory", "", "memory: The amount of memory to reserve for processes")
memorySwap := args.String("memory-swap", "", "memory-swap: The amount of swap memory to reserve for processes") memorySwap := args.String("memory-swap", "", "memory-swap: The amount of swap memory to reserve for processes")
@@ -29,7 +28,7 @@ func main() {
NetworkEgress: *networkEgress, NetworkEgress: *networkEgress,
} }
err := resource.CommandReserve(args.Args(), *processType, resources, *global) err := resource.CommandReserve(args.Args(), *processType, resources)
if err != nil { if err != nil {
common.LogFail(err.Error()) common.LogFail(err.Error())
} }

View File

@@ -7,8 +7,8 @@ import (
) )
// CommandLimit implements resource:limit // CommandLimit implements resource:limit
func CommandLimit(args []string, processType string, r Resource, global bool) error { func CommandLimit(args []string, processType string, r Resource) error {
appName, err := getAppName(args, global) appName, err := getAppName(args)
if err != nil { if err != nil {
return err return err
} }
@@ -17,8 +17,8 @@ func CommandLimit(args []string, processType string, r Resource, global bool) er
} }
// CommandLimitClear implements resource:limit-clear // CommandLimitClear implements resource:limit-clear
func CommandLimitClear(args []string, processType string, global bool) error { func CommandLimitClear(args []string, processType string) error {
appName, err := getAppName(args, global) appName, err := getAppName(args)
if err != nil { if err != nil {
return err return err
} }
@@ -27,8 +27,8 @@ func CommandLimitClear(args []string, processType string, global bool) error {
} }
// CommandReserve implements resource:reserve // CommandReserve implements resource:reserve
func CommandReserve(args []string, processType string, r Resource, global bool) error { func CommandReserve(args []string, processType string, r Resource) error {
appName, err := getAppName(args, global) appName, err := getAppName(args)
if err != nil { if err != nil {
return err return err
} }
@@ -37,8 +37,8 @@ func CommandReserve(args []string, processType string, r Resource, global bool)
} }
// CommandReserveClear implements resource:reserve-clear // CommandReserveClear implements resource:reserve-clear
func CommandReserveClear(args []string, processType string, global bool) error { func CommandReserveClear(args []string, processType string) error {
appName, err := getAppName(args, global) appName, err := getAppName(args)
if err != nil { if err != nil {
return err return err
} }
@@ -52,31 +52,40 @@ func clearByRequestType(appName string, processType string, requestType string)
noun = "reservation" noun = "reservation"
} }
humanAppName := appName message := fmt.Sprintf("clearing %v %v", appName, noun)
if appName == "_all_" { if processType != "_default_" && processType != "" {
humanAppName = "default"
}
message := fmt.Sprintf("clearing %v %v", humanAppName, noun)
if processType != "_default_" {
message = fmt.Sprintf("%v (%v)", message, processType) message = fmt.Sprintf("%v (%v)", message, processType)
} }
common.LogInfo2Quiet(message) common.LogInfo2Quiet(message)
resources := []string{ if processType == "" {
"cpu", resources, err := common.PropertyGetAll("resource", appName)
"memory",
"memory-swap",
"network",
"network-ingress",
"network-egress",
}
for _, key := range resources {
property := propertyKey(processType, requestType, key)
err := common.PropertyDelete("resource", appName, property)
if err != nil { if err != nil {
return err return err
} }
for key, _ := range resources {
err := common.PropertyDelete("resource", appName, key)
if err != nil {
return err
}
}
} else {
resources := []string{
"cpu",
"memory",
"memory-swap",
"network",
"network-ingress",
"network-egress",
}
for _, key := range resources {
property := propertyKey(processType, requestType, key)
err := common.PropertyDelete("resource", appName, property)
if err != nil {
return err
}
}
} }
return nil return nil
} }
@@ -112,10 +121,6 @@ func setRequestType(appName string, processType string, r Resource, requestType
noun = "reservation" noun = "reservation"
} }
message := fmt.Sprintf("Setting resource %v for %v", noun, appName) message := fmt.Sprintf("Setting resource %v for %v", noun, appName)
if appName == "_all_" {
message = fmt.Sprintf("Setting default resource %v", noun)
}
if processType != "_default_" { if processType != "_default_" {
message = fmt.Sprintf("%v (%v)", message, processType) message = fmt.Sprintf("%v (%v)", message, processType)
} }
@@ -142,11 +147,7 @@ func reportRequestType(appName string, processType string, requestType string) {
noun = "reservation" noun = "reservation"
} }
humanAppName := appName message := fmt.Sprintf("resource %v %v information", noun, appName)
if appName == "_all_" {
humanAppName = "default"
}
message := fmt.Sprintf("resource %v %v information", noun, humanAppName)
if processType != "_default_" { if processType != "_default_" {
message = fmt.Sprintf("%v (%v)", message, processType) message = fmt.Sprintf("%v (%v)", message, processType)
} }
@@ -173,17 +174,12 @@ func propertyKey(processType string, requestType string, key string) string {
return fmt.Sprintf("%v.%v.%v", processType, requestType, key) return fmt.Sprintf("%v.%v.%v", processType, requestType, key)
} }
func getAppName(args []string, global bool) (string, error) { func getAppName(args []string) (string, error) {
appName := "_all_"
if global {
return appName, nil
}
if len(args) < 1 { if len(args) < 1 {
return "", errors.New("Please specify an app to run the command on") return "", errors.New("Please specify an app to run the command on")
} }
appName = args[0] appName := args[0]
if err := common.VerifyAppName(appName); err != nil { if err := common.VerifyAppName(appName); err != nil {
return "", err return "", err
} }