feat(ecs): add MaxConn label.
This commit is contained in:
parent
66f46c5b96
commit
7c64f5d31e
2 changed files with 38 additions and 0 deletions
|
@ -1,6 +1,7 @@
|
|||
package ecs
|
||||
|
||||
import (
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
"text/template"
|
||||
|
@ -35,6 +36,9 @@ func (p *Provider) buildConfiguration(services map[string][]ecsInstance) (*types
|
|||
"getHealthCheckInterval": getFuncFirstStringValue(label.TraefikBackendHealthCheckInterval, ""),
|
||||
"hasCircuitBreakerLabel": hasFuncFirst(label.TraefikBackendCircuitBreakerExpression),
|
||||
"getCircuitBreakerExpression": getFuncFirstStringValue(label.TraefikBackendCircuitBreakerExpression, label.DefaultCircuitBreakerExpression),
|
||||
"hasMaxConnLabels": hasMaxConnLabels,
|
||||
"getMaxConnAmount": getFuncFirstInt64Value(label.TraefikBackendMaxConnAmount, math.MaxInt64),
|
||||
"getMaxConnExtractorFunc": getFuncFirstStringValue(label.TraefikBackendMaxConnExtractorFunc, label.DefaultBackendMaxconnExtractorFunc),
|
||||
}
|
||||
return p.GetConfiguration("templates/ecs.tmpl", ecsFuncMap, struct {
|
||||
Services map[string][]ecsInstance
|
||||
|
@ -89,6 +93,12 @@ func hasLoadBalancerLabel(instances []ecsInstance) bool {
|
|||
return method || sticky || stickiness || cookieName
|
||||
}
|
||||
|
||||
func hasMaxConnLabels(instances []ecsInstance) bool {
|
||||
mca := hasFirst(instances, label.TraefikBackendMaxConnAmount)
|
||||
mcef := hasFirst(instances, label.TraefikBackendMaxConnExtractorFunc)
|
||||
return mca && mcef
|
||||
}
|
||||
|
||||
// Label functions
|
||||
|
||||
func getFuncStringValue(labelName string, defaultValue string) func(i ecsInstance) string {
|
||||
|
@ -124,6 +134,15 @@ func getFuncFirstIntValue(labelName string, defaultValue int) func(instances []e
|
|||
}
|
||||
}
|
||||
|
||||
func getFuncFirstInt64Value(labelName string, defaultValue int64) func(instances []ecsInstance) int64 {
|
||||
return func(instances []ecsInstance) int64 {
|
||||
if len(instances) < 0 {
|
||||
return defaultValue
|
||||
}
|
||||
return getInt64Value(instances[0], labelName, defaultValue)
|
||||
}
|
||||
}
|
||||
|
||||
func getFuncFirstBoolValue(labelName string, defaultValue bool) func(instances []ecsInstance) bool {
|
||||
return func(instances []ecsInstance) bool {
|
||||
if len(instances) < 0 {
|
||||
|
@ -172,6 +191,19 @@ func getIntValue(i ecsInstance, labelName string, defaultValue int) int {
|
|||
return defaultValue
|
||||
}
|
||||
|
||||
func getInt64Value(i ecsInstance, labelName string, defaultValue int64) int64 {
|
||||
rawValue, ok := i.containerDefinition.DockerLabels[labelName]
|
||||
if ok {
|
||||
if rawValue != nil {
|
||||
v, err := strconv.ParseInt(*rawValue, 10, 64)
|
||||
if err == nil {
|
||||
return v
|
||||
}
|
||||
}
|
||||
}
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
func getSliceString(i ecsInstance, labelName string) []string {
|
||||
if value, ok := i.containerDefinition.DockerLabels[labelName]; ok {
|
||||
if value == nil {
|
||||
|
|
|
@ -16,6 +16,12 @@
|
|||
{{end}}
|
||||
{{end}}
|
||||
|
||||
{{if hasMaxConnLabels $instances}}
|
||||
[backends.backend-{{ $serviceName }}.maxConn]
|
||||
amount = {{getMaxConnAmount $instances}}
|
||||
extractorFunc = "{{getMaxConnExtractorFunc $instances}}"
|
||||
{{end}}
|
||||
|
||||
{{ if hasHealthCheckLabels $instances }}
|
||||
[backends.backend-{{ $serviceName }}.healthCheck]
|
||||
path = "{{getHealthCheckPath $instances }}"
|
||||
|
|
Loading…
Reference in a new issue