Skip to content

Commit

Permalink
GCLOUD2-13059: Add connection limit for listener (#107)
Browse files Browse the repository at this point in the history
* Add connection limit for listener

* Format
  • Loading branch information
lapson97 authored Feb 5, 2024
1 parent 681fa68 commit 1214c66
Show file tree
Hide file tree
Showing 5 changed files with 164 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,34 @@ var listenerCreateSubCommand = cli.Command{
Name: "allowed-cidrs",
Usage: "List of networks from which listener is accessible",
},
&cli.IntFlag{
Name: "timeout-client-data",
Aliases: []string{"tcd"},
Usage: "Frontend client inactivity timeout in milliseconds",
Value: 50000,
Required: false,
},
&cli.IntFlag{
Name: "timeout-member-connect",
Aliases: []string{"tmc"},
Usage: "Backend member connection timeout in milliseconds",
Value: 5000,
Required: false,
},
&cli.IntFlag{
Name: "timeout-member-data",
Aliases: []string{"tmd"},
Usage: "Backend member inactivity timeout in milliseconds",
Value: 50000,
Required: false,
},
&cli.IntFlag{
Name: "connection-limit",
Aliases: []string{"cl"},
Usage: "Limit of the simultaneous connections",
Value: 100000,
Required: false,
},
}, flags.WaitCommandFlags...),
Action: func(c *cli.Context) error {
client, err := client.NewLBListenerClientV1(c)
Expand All @@ -119,6 +147,22 @@ var listenerCreateSubCommand = cli.Command{
SNISecretID: c.StringSlice("sni-secret-id"),
AllowedCIDRS: c.StringSlice("allowed-cidrs") ,
}
if c.IsSet("timeout-client-data") {
timeoutClientData := c.Int("timeout-client-data")
opts.TimeoutClientData = &timeoutClientData
}
if c.IsSet("timeout-member-connect") {
timeoutMemberConnect := c.Int("timeout-member-connect")
opts.TimeoutMemberConnect = &timeoutMemberConnect
}
if c.IsSet("timeout-member-data") {
timeoutMemberData := c.Int("timeout-member-data")
opts.TimeoutMemberData = &timeoutMemberData
}
if c.IsSet("connection-limit") {
connectionLimit := c.Int("connection-limit")
opts.ConnectionLimit = &connectionLimit
}

results, err := listeners.Create(client, opts).Extract()
if err != nil {
Expand Down Expand Up @@ -217,11 +261,43 @@ var listenerUpdateSubCommand = cli.Command{
Name: "name",
Aliases: []string{"n"},
Usage: "listener name",
Required: true,
},
&cli.StringFlag{
Name: "secret-id",
Aliases: []string{"s"},
Usage: "ID of the secret where PKCS12 file is stored for TERMINATED_HTTPS load balancer",
},
&cli.StringSliceFlag{
Name: "sni-secret-id",
Usage: "List of secret's ID containing PKCS12 format certificate/key bundles for TERMINATED_HTTPS listeners",
},
&cli.StringSliceFlag{
Name: "allowed-cidrs",
Usage: "List of networks from which listener is accessible",
},
&cli.IntFlag{
Name: "timeout-client-data",
Aliases: []string{"tcd"},
Usage: "Frontend client inactivity timeout in milliseconds",
},
&cli.IntFlag{
Name: "timeout-member-connect",
Aliases: []string{"tmc"},
Usage: "Backend member connection timeout in milliseconds",
},
&cli.IntFlag{
Name: "timeout-member-data",
Aliases: []string{"tmd"},
Usage: "Backend member inactivity timeout in milliseconds",
},
&cli.IntFlag{
Name: "connection-limit",
Aliases: []string{"cl"},
Usage: "Limit of the simultaneous connections",
},
},
Action: func(c *cli.Context) error {
clusterID, err := flags.GetFirstStringArg(c, listenerIDText)
listenerID, err := flags.GetFirstStringArg(c, listenerIDText)
if err != nil {
_ = cli.ShowCommandHelp(c, "update")
return err
Expand All @@ -231,10 +307,30 @@ var listenerUpdateSubCommand = cli.Command{
_ = cli.ShowAppHelp(c)
return cli.NewExitError(err, 1)
}
opts := listeners.UpdateOpts{
Name: c.String("name"),
SecretID: c.String("secret-id"),
SNISecretID: c.StringSlice("sni-secret-id"),
AllowedCIDRS: c.StringSlice("allowed-cidrs"),
}
if c.IsSet("timeout-client-data") {
timeoutClientData := c.Int("timeout-client-data")
opts.TimeoutClientData = &timeoutClientData
}
if c.IsSet("timeout-member-connect") {
timeoutMemberConnect := c.Int("timeout-member-connect")
opts.TimeoutMemberConnect = &timeoutMemberConnect
}
if c.IsSet("timeout-member-data") {
timeoutMemberData := c.Int("timeout-member-data")
opts.TimeoutMemberData = &timeoutMemberData
}
if c.IsSet("connection-limit") {
connectionLimit := c.Int("connection-limit")
opts.ConnectionLimit = &connectionLimit
}

opts := listeners.UpdateOpts{Name: c.String("name")}

result, err := listeners.Update(client, clusterID, opts).Extract()
result, err := listeners.Update(client, listenerID, opts).Extract()
if err != nil {
return cli.NewExitError(err, 1)
}
Expand Down
2 changes: 2 additions & 0 deletions gcore/loadbalancer/v1/listeners/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type CreateOpts struct {
TimeoutClientData *int `json:"timeout_client_data,omitempty"`
TimeoutMemberData *int `json:"timeout_member_data,omitempty"`
TimeoutMemberConnect *int `json:"timeout_member_connect,omitempty"`
ConnectionLimit *int `json:"connection_limit,omitempty"`
}

// ToListenerCreateMap builds a request body from CreateOpts.
Expand Down Expand Up @@ -101,6 +102,7 @@ type UpdateOpts struct {
TimeoutClientData *int `json:"timeout_client_data,omitempty"`
TimeoutMemberData *int `json:"timeout_member_data,omitempty"`
TimeoutMemberConnect *int `json:"timeout_member_connect,omitempty"`
ConnectionLimit *int `json:"connection_limit,omitempty"`
}

// ToListenerUpdateMap builds a request body from UpdateOpts.
Expand Down
28 changes: 16 additions & 12 deletions gcore/loadbalancer/v1/listeners/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,22 @@ type UpdateResult struct {

// Listener represents a listener structure.
type Listener struct {
PoolCount int `json:"pool_count"`
ProtocolPort int `json:"protocol_port"`
Protocol types.ProtocolType `json:"protocol"`
Name string `json:"name"`
ID string `json:"id"`
ProvisioningStatus types.ProvisioningStatus `json:"provisioning_status"`
OperationStatus types.OperatingStatus `json:"operating_status"`
CreatorTaskID *string `json:"creator_task_id"`
TaskID *string `json:"task_id"`
SecretID *string `json:"secret_id"`
SNISecretID []string `json:"sni_secret_id,omitempty"`
AllowedCIDRS []string `json:"allowed_cidrs,omitempty" validate:"omitempty,dive,cidr"`
PoolCount int `json:"pool_count"`
ProtocolPort int `json:"protocol_port"`
Protocol types.ProtocolType `json:"protocol"`
Name string `json:"name"`
ID string `json:"id"`
ProvisioningStatus types.ProvisioningStatus `json:"provisioning_status"`
OperationStatus types.OperatingStatus `json:"operating_status"`
CreatorTaskID *string `json:"creator_task_id"`
TaskID *string `json:"task_id"`
SecretID *string `json:"secret_id"`
SNISecretID []string `json:"sni_secret_id,omitempty"`
AllowedCIDRS []string `json:"allowed_cidrs,omitempty" validate:"omitempty,dive,cidr"`
TimeoutClientData *int `json:"timeout_client_data,omitempty"`
TimeoutMemberData *int `json:"timeout_member_data,omitempty"`
TimeoutMemberConnect *int `json:"timeout_member_connect,omitempty"`
ConnectionLimit *int `json:"connection_limit"`
}

func (l Listener) IsDeleted() bool {
Expand Down
44 changes: 30 additions & 14 deletions gcore/loadbalancer/v1/listeners/testing/fixtures.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ const ListResponse = `
"id": "43658ea9-54bd-4807-90b1-925921c9a0d1",
"protocol": "TCP",
"provisioning_status": "ACTIVE",
"allowed_cidrs": ["10.10.0.0/24"]
"allowed_cidrs": ["10.10.0.0/24"],
"timeout_client_data": 50000,
"timeout_member_data": 50000,
"timeout_member_connect": 5000,
"connection_limit": 100000
}
]
}
Expand All @@ -37,7 +41,11 @@ const GetResponse = `
"id": "43658ea9-54bd-4807-90b1-925921c9a0d1",
"protocol": "TCP",
"provisioning_status": "ACTIVE",
"allowed_cidrs": ["10.10.0.0/24"]
"allowed_cidrs": ["10.10.0.0/24"],
"timeout_client_data": 50000,
"timeout_member_data": 50000,
"timeout_member_connect": 5000,
"connection_limit": 100000
}
`

Expand Down Expand Up @@ -82,20 +90,28 @@ const DeleteResponse = `
`

var (
creatorTaskID = "9f3ec11e-bcd4-4fe6-924a-a4439a56ad22"
taskID = "9f3ec11e-bcd4-4fe6-924a-a4439a56ad22"
creatorTaskID = "9f3ec11e-bcd4-4fe6-924a-a4439a56ad22"
taskID = "9f3ec11e-bcd4-4fe6-924a-a4439a56ad22"
timeoutClientData = 50000
timeoutMemberData = 50000
timeoutMemberConnect = 5000
connectionLimit = 100000

Listener1 = listeners.Listener{
PoolCount: 1,
ProtocolPort: 80,
Protocol: types.ProtocolTypeTCP,
Name: "lbaas_test_listener",
ID: "43658ea9-54bd-4807-90b1-925921c9a0d1",
ProvisioningStatus: types.ProvisioningStatusActive,
OperationStatus: types.OperatingStatusOnline,
CreatorTaskID: &creatorTaskID,
TaskID: &taskID,
AllowedCIDRS: []string{"10.10.0.0/24"},
PoolCount: 1,
ProtocolPort: 80,
Protocol: types.ProtocolTypeTCP,
Name: "lbaas_test_listener",
ID: "43658ea9-54bd-4807-90b1-925921c9a0d1",
ProvisioningStatus: types.ProvisioningStatusActive,
OperationStatus: types.OperatingStatusOnline,
CreatorTaskID: &creatorTaskID,
TaskID: &taskID,
AllowedCIDRS: []string{"10.10.0.0/24"},
TimeoutClientData: &timeoutClientData,
TimeoutMemberData: &timeoutMemberData,
TimeoutMemberConnect: &timeoutMemberConnect,
ConnectionLimit: &connectionLimit,
}
Tasks1 = tasks.TaskResults{
Tasks: []tasks.TaskID{"50f53a35-42ed-40c4-82b2-5a37fb3e00bc"},
Expand Down
26 changes: 15 additions & 11 deletions gcore/loadbalancer/v1/loadbalancers/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,21 @@ type CreatePoolOpts struct {

// CreateListenerOpts represents options used to create a loadbalancer listener.
type CreateListenerOpts struct {
Name string `json:"name" required:"true" validate:"required,name"`
ProtocolPort int `json:"protocol_port" required:"true"`
Protocol types.ProtocolType `json:"protocol" required:"true"`
Certificate string `json:"certificate,omitempty"`
CertificateChain string `json:"certificate_chain,omitempty"`
PrivateKey string `json:"private_key,omitempty"`
Pools []CreatePoolOpts `json:"pools,omitempty" validate:"omitempty,dive"`
SecretID string `json:"secret_id,omitempty"`
SNISecretID []string `json:"sni_secret_id,omitempty"`
InsertXForwarded bool `json:"insert_x_forwarded"`
AllowedCIDRS []string `json:"allowed_cidrs,omitempty" validate:"omitempty,dive,cidr"`
Name string `json:"name" required:"true" validate:"required,name"`
ProtocolPort int `json:"protocol_port" required:"true"`
Protocol types.ProtocolType `json:"protocol" required:"true"`
Certificate string `json:"certificate,omitempty"`
CertificateChain string `json:"certificate_chain,omitempty"`
PrivateKey string `json:"private_key,omitempty"`
Pools []CreatePoolOpts `json:"pools,omitempty" validate:"omitempty,dive"`
SecretID string `json:"secret_id,omitempty"`
SNISecretID []string `json:"sni_secret_id,omitempty"`
InsertXForwarded bool `json:"insert_x_forwarded"`
AllowedCIDRS []string `json:"allowed_cidrs,omitempty" validate:"omitempty,dive,cidr"`
TimeoutClientData *int `json:"timeout_client_data,omitempty"`
TimeoutMemberData *int `json:"timeout_member_data,omitempty"`
TimeoutMemberConnect *int `json:"timeout_member_connect,omitempty"`
ConnectionLimit *int `json:"connection_limit,omitempty"`
}

// CreateLoggingOpts represents options used to configure logging for a loadbalancer.
Expand Down

0 comments on commit 1214c66

Please sign in to comment.