Skip to content
Open
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
22 changes: 19 additions & 3 deletions lib/cloud_controller/diego/app_recipe_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def generate_healthcheck_definition(lrp_builder)
def generate_readiness_health_check_definition(lrp_builder)
return [] unless MONITORED_READINESS_HEALTH_CHECK_TYPES.include?(process.readiness_health_check_type)

ports = lrp_builder.ports
ports = readiness_health_check_ports(lrp_builder)
readiness_checks = []
ports.each_with_index do |port, index|
readiness_checks << build_readiness_check(port, index)
Expand All @@ -224,7 +224,7 @@ def generate_readiness_health_check_definition(lrp_builder)
def generate_liveness_and_startup_health_check_defintion(lrp_builder)
return [] unless MONITORED_HEALTH_CHECK_TYPES.include?(process.health_check_type)

desired_ports = lrp_builder.ports
desired_ports = health_check_ports(lrp_builder)
checks = []
desired_ports.each_with_index do |port, index|
checks << build_check(port, index)
Expand Down Expand Up @@ -280,7 +280,7 @@ def build_check(port, index)
def generate_monitor_action(lrp_builder)
return unless MONITORED_HEALTH_CHECK_TYPES.include?(process.health_check_type)

desired_ports = lrp_builder.ports
desired_ports = health_check_ports(lrp_builder)
actions = []
desired_ports.each_with_index do |port, index|
actions << build_action(lrp_builder, port, index)
Expand All @@ -305,6 +305,22 @@ def build_action(lrp_builder, port, index)
)
end

def health_check_ports(lrp_builder)
if process.health_check_type == HealthCheckTypes::HTTP
lrp_builder.ports.first(1)
else
lrp_builder.ports
end
end

def readiness_health_check_ports(lrp_builder)
if process.readiness_health_check_type == HealthCheckTypes::HTTP
lrp_builder.ports.first(1)
else
lrp_builder.ports
end
end

def generate_network
Protocol::ContainerNetworkInfo.new(process.app, Protocol::ContainerNetworkInfo::APP).to_bbs_network
end
Expand Down
32 changes: 13 additions & 19 deletions spec/unit/lib/cloud_controller/diego/app_recipe_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -564,16 +564,6 @@ module Diego
log_source: HEALTH_LOG_SOURCE,
suppress_log_output: true
)
),
::Diego::Bbs::Models::Action.new(
run_action: ::Diego::Bbs::Models::RunAction.new(
user: 'lrp-action-user',
path: '/tmp/lifecycle/healthcheck',
args: ['-port=5555', '-timeout=10s'],
resource_limits: ::Diego::Bbs::Models::ResourceLimits.new(nofile: expected_file_descriptor_limit),
log_source: HEALTH_LOG_SOURCE,
suppress_log_output: true
)
)
]
)
Expand All @@ -582,12 +572,18 @@ module Diego
)
end

it 'adds a http healthcheck action using the first port' do
it 'adds an HTTP healthcheck action using only the first port' do
lrp = builder.build_app_lrp

expect(lrp.monitor).to eq(expected_monitor_action)
end

it 'does not add monitor actions for additional ports' do
lrp = builder.build_app_lrp
actions = lrp.monitor.timeout_action.action.parallel_action.actions
expect(actions.size).to eq(1)
end

it 'adds an HTTP health check definition using the first port' do
lrp = builder.build_app_lrp
http_check = lrp.check_definition.checks.first.http_check
Expand All @@ -608,10 +604,9 @@ module Diego
expect(monitor_args).to eq(['-port=4444', '-uri=http-endpoint'])
end

it 'keeps a TCP health check definition for other ports' do
lrp = builder.build_app_lrp
tcp_check = lrp.check_definition.checks[1].tcp_check
expect(tcp_check.port).to eq(5555)
it 'does not add TCP health check definitions for other ports' do
lrp = builder.build_app_lrp
expect(lrp.check_definition.checks.size).to eq(1)
end
end

Expand Down Expand Up @@ -715,10 +710,9 @@ module Diego
expect(http_check.request_timeout_ms).to eq(0)
end

it 'keeps a TCP readiness health check definition for other ports' do
lrp = builder.build_app_lrp
tcp_check = lrp.check_definition.readiness_checks[1].tcp_check
expect(tcp_check.port).to eq(5555)
it 'does not add TCP readiness health check definitions for other ports' do
lrp = builder.build_app_lrp
expect(lrp.check_definition.readiness_checks.size).to eq(1)
end
end

Expand Down