Skip to content

Commit

Permalink
ProxyLB: BackendHttpKeepAlive (#184)
Browse files Browse the repository at this point in the history
  • Loading branch information
yamamoto-febc authored Mar 24, 2023
1 parent aebefb9 commit a1b6494
Show file tree
Hide file tree
Showing 7 changed files with 432 additions and 271 deletions.
4 changes: 2 additions & 2 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ linters:
- misspell
- nakedret
- nolintlint
- revive
- stylecheck
- typecheck
- unconvert
- unused
Expand All @@ -45,8 +43,10 @@ linters:
# - goerr113
# - lll
# - prealloc
# - revive
# - staticcheck
# - structcheck
# - stylecheck
# - testpackage
# - unparam
# - wsl
18 changes: 18 additions & 0 deletions internal/define/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -1676,6 +1676,24 @@ func (f *fieldsDef) ProxyLBGzip() *dsl.FieldDesc {
}
}

func (f *fieldsDef) ProxyLBBackendHttpKeepAlive() *dsl.FieldDesc {
return &dsl.FieldDesc{
Name: "BackendHttpKeepAlive",
Type: &dsl.Model{
Name: "ProxyLBBackendHttpKeepAlive",
Fields: []*dsl.FieldDesc{
{
Name: "Mode",
Type: meta.Static(types.EProxyLBBackendHttpKeepAlive("")),
},
},
},
Tags: &dsl.FieldTags{
MapConv: "Settings.ProxyLB.BackendHttpKeepAlive,recursive",
},
}
}

func (f *fieldsDef) ProxyLBProxyProtocol() *dsl.FieldDesc {
return &dsl.FieldDesc{
Name: "ProxyProtocol",
Expand Down
4 changes: 4 additions & 0 deletions internal/define/proxylb.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ var (
fields.ProxyLBLetsEncrypt(),
fields.ProxyLBStickySession(),
fields.ProxyLBGzip(),
fields.ProxyLBBackendHttpKeepAlive(),
fields.ProxyLBProxyProtocol(),
fields.ProxyLBSyslog(),
fields.ProxyLBTimeout(),
Expand Down Expand Up @@ -225,6 +226,7 @@ var (
fields.ProxyLBStickySession(),
fields.ProxyLBTimeout(),
fields.ProxyLBGzip(),
fields.ProxyLBBackendHttpKeepAlive(),
fields.ProxyLBProxyProtocol(),
fields.ProxyLBSyslog(),
// status
Expand Down Expand Up @@ -254,6 +256,7 @@ var (
fields.ProxyLBStickySession(),
fields.ProxyLBTimeout(),
fields.ProxyLBGzip(),
fields.ProxyLBBackendHttpKeepAlive(),
fields.ProxyLBProxyProtocol(),
fields.ProxyLBSyslog(),
// settings hash
Expand Down Expand Up @@ -281,6 +284,7 @@ var (
fields.ProxyLBStickySession(),
fields.ProxyLBTimeout(),
fields.ProxyLBGzip(),
fields.ProxyLBBackendHttpKeepAlive(),
fields.ProxyLBProxyProtocol(),
fields.ProxyLBSyslog(),
// settings hash
Expand Down
27 changes: 16 additions & 11 deletions naked/proxylb.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,17 +85,18 @@ type ProxyLBSettings struct {

// ProxyLBSetting エンハンスドロードバランサ設定
type ProxyLBSetting struct {
HealthCheck ProxyLBHealthCheck `yaml:"health_check"` // ヘルスチェック
SorryServer ProxyLBSorryServer `yaml:"sorry_server"` // ソーリーサーバー
BindPorts []*ProxyLBBindPorts `yaml:"bind_ports"` // プロキシ方式(プロトコル&ポート)
Servers []ProxyLBServer `yaml:"servers"` // サーバー
Rules []ProxyLBRule `yaml:"rules"` // 振り分けルール
LetsEncrypt *ProxyLBACMESetting `json:",omitempty" yaml:"lets_encrypt,omitempty" structs:",omitempty"` // Let's encryptでの証明書取得設定
StickySession ProxyLBStickySession `yaml:"sticky_session"` // StickySession
Timeout ProxyLBTimeout `json:",omitempty" yaml:"timeout,omitempty" structs:",omitempty"` // タイムアウト
Gzip ProxyLBGzip `yaml:"gzip"` // Gzip
ProxyProtocol ProxyLBProxyProtocol `yaml:"proxy_protocol"`
Syslog ProxyLBSyslog `yaml:"syslog"`
HealthCheck ProxyLBHealthCheck `yaml:"health_check"` // ヘルスチェック
SorryServer ProxyLBSorryServer `yaml:"sorry_server"` // ソーリーサーバー
BindPorts []*ProxyLBBindPorts `yaml:"bind_ports"` // プロキシ方式(プロトコル&ポート)
Servers []ProxyLBServer `yaml:"servers"` // サーバー
Rules []ProxyLBRule `yaml:"rules"` // 振り分けルール
LetsEncrypt *ProxyLBACMESetting `json:",omitempty" yaml:"lets_encrypt,omitempty" structs:",omitempty"` // Let's encryptでの証明書取得設定
StickySession ProxyLBStickySession `yaml:"sticky_session"` // StickySession
Timeout ProxyLBTimeout `json:",omitempty" yaml:"timeout,omitempty" structs:",omitempty"` // タイムアウト
Gzip ProxyLBGzip `yaml:"gzip"` // Gzip
BackendHttpKeepAlive ProxyLBBackendHTTPKeepAlive `yaml:"backend_http_keey_alive"` // 実サーバとのHTTP持続接続
ProxyProtocol ProxyLBProxyProtocol `yaml:"proxy_protocol"`
Syslog ProxyLBSyslog `yaml:"syslog"`
}

// MarshalJSON nullの場合に空配列を出力するための実装
Expand Down Expand Up @@ -237,6 +238,10 @@ type ProxyLBGzip struct {
Enabled bool `yaml:"enabled"`
}

type ProxyLBBackendHTTPKeepAlive struct {
Mode types.EProxyLBBackendHttpKeepAlive `json:",omitempty" yaml:"mode,omitempty" structs:",omitempty"`
}

// ProxyLBProxyProtocol ProxyProtocol(v2)の有効設定
type ProxyLBProxyProtocol struct {
Enabled bool `yaml:"enabled"`
Expand Down
91 changes: 54 additions & 37 deletions test/proxylb_op_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ func initProxyLBVariables() {
Gzip: &iaas.ProxyLBGzip{
Enabled: true,
},
BackendHttpKeepAlive: &iaas.ProxyLBBackendHttpKeepAlive{
Mode: types.ProxyLBBackendHttpKeepAlive.Aggressive,
},
ProxyProtocol: &iaas.ProxyLBProxyProtocol{
Enabled: true,
},
Expand All @@ -233,20 +236,21 @@ func initProxyLBVariables() {
Tags: createProxyLBParam.Tags,
Availability: types.Availabilities.Available,

Plan: createProxyLBParam.Plan,
HealthCheck: createProxyLBParam.HealthCheck,
SorryServer: createProxyLBParam.SorryServer,
BindPorts: createProxyLBParam.BindPorts,
Servers: createProxyLBParam.Servers,
Rules: createProxyLBParam.Rules,
LetsEncrypt: createProxyLBParam.LetsEncrypt,
StickySession: createProxyLBParam.StickySession,
Gzip: createProxyLBParam.Gzip,
ProxyProtocol: createProxyLBParam.ProxyProtocol,
Syslog: createProxyLBParam.Syslog,
Timeout: createProxyLBParam.Timeout,
UseVIPFailover: createProxyLBParam.UseVIPFailover,
Region: createProxyLBParam.Region,
Plan: createProxyLBParam.Plan,
HealthCheck: createProxyLBParam.HealthCheck,
SorryServer: createProxyLBParam.SorryServer,
BindPorts: createProxyLBParam.BindPorts,
Servers: createProxyLBParam.Servers,
Rules: createProxyLBParam.Rules,
LetsEncrypt: createProxyLBParam.LetsEncrypt,
StickySession: createProxyLBParam.StickySession,
Gzip: createProxyLBParam.Gzip,
BackendHttpKeepAlive: createProxyLBParam.BackendHttpKeepAlive,
ProxyProtocol: createProxyLBParam.ProxyProtocol,
Syslog: createProxyLBParam.Syslog,
Timeout: createProxyLBParam.Timeout,
UseVIPFailover: createProxyLBParam.UseVIPFailover,
Region: createProxyLBParam.Region,
}
updateProxyLBParam = &iaas.ProxyLBUpdateRequest{
Name: testutil.ResourceName("proxylb-upd"),
Expand Down Expand Up @@ -336,6 +340,9 @@ func initProxyLBVariables() {
Gzip: &iaas.ProxyLBGzip{
Enabled: false,
},
BackendHttpKeepAlive: &iaas.ProxyLBBackendHttpKeepAlive{
Mode: types.ProxyLBBackendHttpKeepAlive.Safe,
},
ProxyProtocol: &iaas.ProxyLBProxyProtocol{
Enabled: false,
},
Expand Down Expand Up @@ -364,11 +371,12 @@ func initProxyLBVariables() {
Timeout: &iaas.ProxyLBTimeout{
InactiveSec: 10,
},
Gzip: updateProxyLBParam.Gzip,
ProxyProtocol: updateProxyLBParam.ProxyProtocol,
Syslog: updateProxyLBParam.Syslog,
UseVIPFailover: createProxyLBParam.UseVIPFailover,
Region: createProxyLBParam.Region,
Gzip: updateProxyLBParam.Gzip,
BackendHttpKeepAlive: updateProxyLBParam.BackendHttpKeepAlive,
ProxyProtocol: updateProxyLBParam.ProxyProtocol,
Syslog: updateProxyLBParam.Syslog,
UseVIPFailover: createProxyLBParam.UseVIPFailover,
Region: createProxyLBParam.Region,
}
updateProxyLBPlanExpected = &iaas.ProxyLB{
Name: updateProxyLBParam.Name,
Expand All @@ -387,11 +395,12 @@ func initProxyLBVariables() {
Timeout: &iaas.ProxyLBTimeout{
InactiveSec: 10,
},
Gzip: updateProxyLBParam.Gzip,
ProxyProtocol: updateProxyLBParam.ProxyProtocol,
Syslog: updateProxyLBParam.Syslog,
UseVIPFailover: createProxyLBParam.UseVIPFailover,
Region: createProxyLBParam.Region,
Gzip: updateProxyLBParam.Gzip,
BackendHttpKeepAlive: updateProxyLBParam.BackendHttpKeepAlive,
ProxyProtocol: updateProxyLBParam.ProxyProtocol,
Syslog: updateProxyLBParam.Syslog,
UseVIPFailover: createProxyLBParam.UseVIPFailover,
Region: createProxyLBParam.Region,
}
updateProxyLBSettingsParam = &iaas.ProxyLBUpdateSettingsRequest{
HealthCheck: &iaas.ProxyLBHealthCheck{
Expand Down Expand Up @@ -456,6 +465,9 @@ func initProxyLBVariables() {
Gzip: &iaas.ProxyLBGzip{
Enabled: false,
},
BackendHttpKeepAlive: &iaas.ProxyLBBackendHttpKeepAlive{
Mode: types.ProxyLBBackendHttpKeepAlive.Safe,
},
ProxyProtocol: &iaas.ProxyLBProxyProtocol{
Enabled: false,
},
Expand All @@ -481,11 +493,12 @@ func initProxyLBVariables() {
Timeout: &iaas.ProxyLBTimeout{
InactiveSec: 10,
},
Gzip: updateProxyLBSettingsParam.Gzip,
ProxyProtocol: updateProxyLBSettingsParam.ProxyProtocol,
Syslog: updateProxyLBSettingsParam.Syslog,
UseVIPFailover: createProxyLBParam.UseVIPFailover,
Region: createProxyLBParam.Region,
Gzip: updateProxyLBSettingsParam.Gzip,
BackendHttpKeepAlive: updateProxyLBSettingsParam.BackendHttpKeepAlive,
ProxyProtocol: updateProxyLBSettingsParam.ProxyProtocol,
Syslog: updateProxyLBSettingsParam.Syslog,
UseVIPFailover: createProxyLBParam.UseVIPFailover,
Region: createProxyLBParam.Region,
}

updateProxyLBToMinParam = &iaas.ProxyLBUpdateRequest{
Expand All @@ -506,6 +519,9 @@ func initProxyLBVariables() {
Gzip: &iaas.ProxyLBGzip{
Enabled: false,
},
BackendHttpKeepAlive: &iaas.ProxyLBBackendHttpKeepAlive{
Mode: types.ProxyLBBackendHttpKeepAlive.Safe,
},
ProxyProtocol: &iaas.ProxyLBProxyProtocol{
Enabled: false,
},
Expand All @@ -532,14 +548,15 @@ func initProxyLBVariables() {
Timeout: &iaas.ProxyLBTimeout{
InactiveSec: 10,
},
BindPorts: updateProxyLBToMinParam.BindPorts,
Rules: updateProxyLBToMinParam.Rules,
Servers: updateProxyLBToMinParam.Servers,
Gzip: updateProxyLBToMinParam.Gzip,
ProxyProtocol: updateProxyLBToMinParam.ProxyProtocol,
Syslog: updateProxyLBToMinParam.Syslog,
UseVIPFailover: createProxyLBParam.UseVIPFailover,
Region: createProxyLBParam.Region,
BindPorts: updateProxyLBToMinParam.BindPorts,
Rules: updateProxyLBToMinParam.Rules,
Servers: updateProxyLBToMinParam.Servers,
Gzip: updateProxyLBToMinParam.Gzip,
BackendHttpKeepAlive: updateProxyLBToMinParam.BackendHttpKeepAlive,
ProxyProtocol: updateProxyLBToMinParam.ProxyProtocol,
Syslog: updateProxyLBToMinParam.Syslog,
UseVIPFailover: createProxyLBParam.UseVIPFailover,
Region: createProxyLBParam.Region,
}

createProxyLBForACMEParam = &iaas.ProxyLBCreateRequest{
Expand Down
37 changes: 37 additions & 0 deletions types/proxylb_backend_http_keep_alive.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright 2022-2023 The sacloud/iaas-api-go Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package types

// EProxyLBBackendHttpKeepAlive エンハンスドロードバランサ 実サーバとのHTTP持続接続
type EProxyLBBackendHttpKeepAlive string

// String EProxyLBBackendHttpKeepAlive
func (p EProxyLBBackendHttpKeepAlive) String() string {
return string(p)
}

// ProxyLBBackendHttpKeepAlive エンハンスドロードバランサ 実サーバとのHTTP持続接続
var ProxyLBBackendHttpKeepAlive = struct {
// SAFE クライアントからの接続に応じて実サーバとの持続的接続が使われ、クライアント間での接続の共有は行われにくい設定
Safe EProxyLBBackendHttpKeepAlive
// AGGRESSIVE 再使用可能な接続があればより積極的に使用する設定
Aggressive EProxyLBBackendHttpKeepAlive
}{
Safe: EProxyLBBackendHttpKeepAlive("safe"),
Aggressive: EProxyLBBackendHttpKeepAlive("aggressive"),
}

// ProxyLBBackendHttpKeepAliveStrings 実サーバとのHTTP持続接続を表す文字列
var ProxyLBBackendHttpKeepAliveStrings = []string{"safe", "aggressive"}
Loading

0 comments on commit a1b6494

Please sign in to comment.