Sets parameters for a shared memory zone that will keep states for various keys.

This commit is contained in:
Georgiy Kutsurua 2017-07-07 03:13:32 +04:00
parent 4aef07d1c9
commit d56e261835
5 changed files with 21 additions and 5 deletions

View file

@ -73,6 +73,10 @@ const (
// Default setting for load balancer algorithm
defaultLoadBalancerAlgorithm = "least_conn"
// Parameters for a shared memory zone that will keep states for various keys.
// http://nginx.org/en/docs/http/ngx_http_limit_conn_module.html#limit_conn_zone
defaultLimitConnZoneVariable = "$binary_remote_addr"
)
// Configuration represents the content of nginx.conf file
@ -298,6 +302,10 @@ type Configuration struct {
// http://nginx.org/en/docs/http/ngx_http_upstream_module.html#keepalive
// Default: 0 (disabled)
UpstreamKeepaliveConnections int `json:"upstream-keepalive-connections,omitempty"`
// Sets the maximum size of the variables hash table.
// http://nginx.org/en/docs/http/ngx_http_map_module.html#variables_hash_max_size
LimitConnZoneVariable string `json:"limit-conn-zone-variable,omitempty"`
}
// NewDefault returns the default nginx configuration
@ -360,6 +368,7 @@ func NewDefault() Configuration {
SkipAccessLogURLs: []string{},
},
UpstreamKeepaliveConnections: 0,
LimitConnZoneVariable: defaultLimitConnZoneVariable,
}
if glog.V(5) {

View file

@ -328,7 +328,7 @@ func buildProxyPass(host string, b interface{}, loc interface{}) string {
// buildRateLimitZones produces an array of limit_conn_zone in order to allow
// rate limiting of request. Each Ingress rule could have up to two zones, one
// for connection limit by IP address and other for limiting request per second
func buildRateLimitZones(input interface{}) []string {
func buildRateLimitZones(variable string, input interface{}) []string {
zones := sets.String{}
servers, ok := input.([]*ingress.Server)
@ -340,7 +340,8 @@ func buildRateLimitZones(input interface{}) []string {
for _, loc := range server.Locations {
if loc.RateLimit.Connections.Limit > 0 {
zone := fmt.Sprintf("limit_conn_zone $binary_remote_addr zone=%v:%vm;",
zone := fmt.Sprintf("limit_conn_zone %v zone=%v:%vm;",
variable,
loc.RateLimit.Connections.Name,
loc.RateLimit.Connections.SharedSize)
if !zones.Has(zone) {
@ -349,7 +350,8 @@ func buildRateLimitZones(input interface{}) []string {
}
if loc.RateLimit.RPS.Limit > 0 {
zone := fmt.Sprintf("limit_req_zone $binary_remote_addr zone=%v:%vm rate=%vr/s;",
zone := fmt.Sprintf("limit_req_zone %v zone=%v:%vm rate=%vr/s;",
variable,
loc.RateLimit.RPS.Name,
loc.RateLimit.RPS.SharedSize,
loc.RateLimit.RPS.Limit)