Skip to content

Commit dc7eaee

Browse files
implement configurable http-reuse feature (#765)
feat: introduce backend targeted config Co-authored-by: b1tamara <tamara.boehm@sap.com>
1 parent 187de6d commit dc7eaee

File tree

3 files changed

+65
-1
lines changed

3 files changed

+65
-1
lines changed

jobs/haproxy/spec

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,15 @@ properties:
707707
ha_proxy.backend_config:
708708
description: |
709709
Raw HAProxy config that will be added to the default HTTP + routed HTTP backend definitions, provided either as a multiline text blob or as an array of lines.
710-
710+
ha_proxy.backend_config_targeted:
711+
description: |
712+
A map of existing backends which enables more fine-grained configuration of the backend.
713+
example:
714+
backend_config_targeted:
715+
http-routers-http1: |
716+
http-reuse aggressive
717+
http-routers-http2: |
718+
http-reuse safe
711719
ha_proxy.custom_http_error_files:
712720
description: |
713721
A map of status codes to errorfile contents

jobs/haproxy/templates/haproxy.config.erb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,13 @@ backend <%= backend[:name] %>
875875
<%- if properties.ha_proxy.backend_config -%>
876876
<%= format_indented_multiline_config(p("ha_proxy.backend_config")) %>
877877
<%- end -%>
878+
<%- backend_configs = p('ha_proxy.backend_config_targeted', {}) -%>
879+
<%- backend_configs.keys.each do |backend_name| -%>
880+
<%- if backend[:name] == backend_name -%>
881+
<%= format_indented_multiline_config(backend_configs[backend_name]) -%>
882+
<%- end -%>
883+
<%- end -%>
884+
878885
<%- p('ha_proxy.custom_http_error_files', {}).keys.each do |status_code| -%>
879886
errorfile <%= status_code %> /var/vcap/jobs/haproxy/errorfiles/custom<%=status_code%>.http
880887
<%- end -%>

spec/haproxy/templates/haproxy_config/backend_http_spec.rb

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,55 @@
4040
end
4141
end
4242

43+
context 'when ha_proxy.backend_config_targeted is h1' do
44+
let(:properties) do
45+
{
46+
'backend_config_targeted' => {
47+
'http-routers-http1' => 'http-reuse aggressive'
48+
}
49+
}
50+
end
51+
52+
it 'includes the config' do
53+
expect(backend_http1).to include('http-reuse aggressive')
54+
end
55+
end
56+
57+
context 'when ha_proxy.backend_config_targeted is h2' do
58+
let(:properties) do
59+
{
60+
'enable_http2' => true,
61+
'backend_ssl' => 'verify',
62+
'backend_config_targeted' => {
63+
'http-routers-http2' => 'http-reuse safe'
64+
}
65+
}
66+
end
67+
68+
it 'includes the config' do
69+
expect(backend_http2).to include('http-reuse safe')
70+
end
71+
end
72+
73+
context 'when ha_proxy.backend_config_targeted is h1 and h2' do
74+
let(:properties) do
75+
{
76+
'enable_http2' => true,
77+
'backend_ssl' => 'verify',
78+
'disable_backend_http2_websockets' => true,
79+
'backend_config_targeted' => {
80+
'http-routers-http1' => 'http-reuse aggressive',
81+
'http-routers-http2' => 'http-reuse safe'
82+
}
83+
}
84+
end
85+
86+
it 'includes the config' do
87+
expect(backend_http1).to include('http-reuse aggressive')
88+
expect(backend_http2).to include('http-reuse safe')
89+
end
90+
end
91+
4392
context 'when ha_proxy.custom_http_error_files is provided' do
4493
let(:properties) do
4594
{

0 commit comments

Comments
 (0)