Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions lib/aptible/cli/helpers/vhost/option_set_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class OptionSetBuilder
tls
ports
port
alb
).freeze

def initialize(&block)
Expand Down Expand Up @@ -51,6 +52,17 @@ def declare_options(thor)
desc: 'A port to expose on this Endpoint'
)
end

if builder.alb?
option(
:load_balancing_algorithm_type,
type: :string,
desc: 'The load balancing algorithm for this Endpoint.' \
'valid options are round_robin, ' \
'least_outstanding_requests, and ' \
'weighted_random'
)
end
end

if builder.create?
Expand Down Expand Up @@ -168,6 +180,20 @@ def prepare(account, options)

process_tls(account, options, params) if tls?

if alb?
lba_type = options.delete(:load_balancing_algorithm_type)
if lba_type
valid_types = %w(round_robin least_outstanding_requests
weighted_random)
unless valid_types.include?(lba_type)
e = "Invalid load balancing algorithm type: #{lba_type}. " \
"Valid options are: #{valid_types.join(', ')}"
raise Thor::Error, e
end
params[:load_balancing_algorithm_type] = lba_type
end
end

options.delete(:environment)

# NOTE: This is here to ensure that specs don't test for options
Expand Down
2 changes: 2 additions & 0 deletions lib/aptible/cli/resource_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,8 @@ def inject_vhost(node, vhost, service)
port = vhost.container_port ? vhost.container_port : 'default'
node.value('type', 'https')
node.value('port', port)
node.value('load_balancing_algorithm_type', vhost
.load_balancing_algorithm_type)
end

node.value('internal', vhost.internal)
Expand Down
2 changes: 2 additions & 0 deletions lib/aptible/cli/subcommands/endpoints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ def self.included(thor)
create!
port!
tls!
alb!
end

desc 'endpoints:https:create [--app APP] SERVICE',
Expand All @@ -177,6 +178,7 @@ def self.included(thor)
app!
port!
tls!
alb!
end

desc 'endpoints:https:modify [--app APP] ENDPOINT_HOSTNAME',
Expand Down
4 changes: 3 additions & 1 deletion spec/aptible/cli/resource_formatter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def capture(m, *args)
internal: false,
ip_whitelist: [],
default: false,
acme: false
acme: false,
load_balancing_algorithm_type: 'least_outstanding_requests'
)

expected = [
Expand All @@ -30,6 +31,7 @@ def capture(m, *args)
"Created At: #{fmt_time(service.created_at)}",
'Type: https',
'Port: default',
'Load Balancing Algorithm Type: least_outstanding_requests',
'Internal: false',
'IP Whitelist: all traffic',
'Default Domain Enabled: false',
Expand Down
16 changes: 16 additions & 0 deletions spec/aptible/cli/subcommands/endpoints_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,14 @@ def stub_options(**opts)
stub_options(port: 10)
subject.send(m, 'web')
end
it 'creates an Endpoint with a load balancing algorithm' do
expect_create_vhost(service,
load_balancing_algorithm_type:
'least_outstanding_requests')
stub_options(load_balancing_algorithm_type:
'least_outstanding_requests')
subject.send(m, 'web')
end
end

describe 'endpoints:grpc:create' do
Expand Down Expand Up @@ -637,6 +645,14 @@ def stub_options(**opts)
stub_options(port: 10)
subject.send(m, v.external_host)
end
it 'allows updating the load balancing algorithm' do
v = Fabricate(:vhost, service: service)
expect_modify_vhost(v, load_balancing_algorithm_type:
'least_outstanding_requests')
stub_options(load_balancing_algorithm_type:
'least_outstanding_requests')
subject.send(m, v.external_host)
end
end

describe 'endpoints:grpc:modify' do
Expand Down