Skip to content

Commit cb26caf

Browse files
committed
MEDIUM: log-forward: implement log-forward section
1 parent a9cd4dd commit cb26caf

File tree

56 files changed

+10174
-642
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+10174
-642
lines changed

configure_data_plane.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,6 +353,20 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler {
353353
api.RingGetRingsHandler = &handlers.GetRingsHandlerImpl{Client: client}
354354
api.RingReplaceRingHandler = &handlers.ReplaceRingHandlerImpl{Client: client, ReloadAgent: ra}
355355

356+
// setup log forward handlers
357+
api.LogForwardCreateLogForwardHandler = &handlers.CreateLogForwardHandlerImpl{Client: client, ReloadAgent: ra}
358+
api.LogForwardDeleteLogForwardHandler = &handlers.DeleteLogForwardHandlerImpl{Client: client, ReloadAgent: ra}
359+
api.LogForwardGetLogForwardHandler = &handlers.GetLogForwardHandlerImpl{Client: client}
360+
api.LogForwardGetLogForwardsHandler = &handlers.GetLogForwardsHandlerImpl{Client: client}
361+
api.LogForwardReplaceLogForwardHandler = &handlers.ReplaceLogForwardHandlerImpl{Client: client, ReloadAgent: ra}
362+
363+
// setup dgram bind handlers
364+
api.DgramBindCreateDgramBindHandler = &handlers.CreateDgramBindHandlerImpl{Client: client, ReloadAgent: ra}
365+
api.DgramBindDeleteDgramBindHandler = &handlers.DeleteDgramBindHandlerImpl{Client: client, ReloadAgent: ra}
366+
api.DgramBindGetDgramBindHandler = &handlers.GetDgramBindHandlerImpl{Client: client}
367+
api.DgramBindGetDgramBindsHandler = &handlers.GetDgramBindsHandlerImpl{Client: client}
368+
api.DgramBindReplaceDgramBindHandler = &handlers.ReplaceDgramBindHandlerImpl{Client: client, ReloadAgent: ra}
369+
356370
// setup frontend handlers
357371
api.FrontendCreateFrontendHandler = &handlers.CreateFrontendHandlerImpl{Client: client, ReloadAgent: ra}
358372
api.FrontendDeleteFrontendHandler = &handlers.DeleteFrontendHandlerImpl{Client: client, ReloadAgent: ra}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
global
2+
chroot /var/lib/haproxy
3+
user haproxy
4+
group haproxy
5+
maxconn 4000
6+
pidfile /var/run/haproxy.pid
7+
stats socket /var/lib/haproxy/stats level admin
8+
log 127.0.0.1 local2
9+
10+
backend test_backend_add
11+
mode tcp
12+
option tcp-check
13+
14+
log-forward sylog-loadb
15+
dgram-bind 127.0.0.1:1514 name test_dgram_bind
16+
bind 127.0.0.1:1514
17+
timeout client 50000
18+
# all messages on stderr
19+
log global
20+
# all messages on local tcp syslog server
21+
log ring@myring local0
22+
# load balance messages on 4 udp syslog servers
23+
log 127.0.0.1:10001 sample 1:4 local0
24+
log 127.0.0.1:10002 sample 2:4 local0
25+
log 127.0.0.1:10003 sample 3:4 local0
26+
log 127.0.0.1:10004 sample 4:4 local0
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"address": "127.0.0.1",
3+
"name": "sylog-loadb",
4+
"port": 1622,
5+
"interface": "eth0",
6+
"transparent": true
7+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"address": "127.0.0.1",
3+
"name": "sylog-loadb2",
4+
"port": 1500,
5+
"interface": "eth0",
6+
"transparent": true
7+
}

e2e/tests/dgram_binds/test.bats

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2021 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load "../../libs/get_json_path"
20+
load '../../libs/resource_client'
21+
load '../../libs/version'
22+
load '../../libs/haproxy_config_setup'
23+
load '../../libs/haproxy_version'
24+
25+
load 'utils/_helpers'
26+
27+
@test "dgram_binds: Add a dgram bind" {
28+
if haproxy_version_ge "2.3"
29+
then
30+
resource_post "$_DGRAMBIND_BASE_PATH" "data/post.json" "log_forward=sylog-loadb&force_reload=true"
31+
assert_equal "$SC" "201"
32+
fi
33+
}
34+
35+
@test "dgram_binds: Return a dgram bind" {
36+
if haproxy_version_ge "2.3"
37+
then
38+
resource_get "$_DGRAMBIND_BASE_PATH/test_dgram_bind" "log_forward=sylog-loadb"
39+
assert_equal "$SC" 200
40+
assert_equal "test_dgram_bind" "$(get_json_path "$BODY" '.data.name')"
41+
fi
42+
}
43+
44+
@test "dgram_binds: Replace a dgram bind" {
45+
if haproxy_version_ge "2.3"
46+
then
47+
resource_put "$_DGRAMBIND_BASE_PATH/test_dgram_bind" "data/put.json" "log_forward=sylog-loadb&force_reload=true"
48+
assert_equal "$SC" 200
49+
fi
50+
}
51+
52+
@test "dgram_binds: Return an array of dgram binds" {
53+
if haproxy_version_ge "2.3"
54+
then
55+
resource_get "$_DGRAMBIND_BASE_PATH" "log_forward=sylog-loadb"
56+
assert_equal "$SC" 200
57+
assert_equal "test_dgram_bind" "$(get_json_path "$BODY" '.data[0].name')"
58+
fi
59+
}
60+
61+
@test "dgram_binds: Delete a dgram bind" {
62+
if haproxy_version_ge "2.3"
63+
then
64+
resource_delete "$_DGRAMBIND_BASE_PATH/test_dgram_bind" "log_forward=sylog-loadb&force_reload=true"
65+
assert_equal "$SC" 204
66+
fi
67+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright 2021 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
_DGRAMBIND_BASE_PATH="/services/haproxy/configuration/dgram_binds"
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
global
2+
chroot /var/lib/haproxy
3+
user haproxy
4+
group haproxy
5+
maxconn 4000
6+
pidfile /var/run/haproxy.pid
7+
stats socket /var/lib/haproxy/stats level admin
8+
log 127.0.0.1 local2
9+
10+
backend test_backend_add
11+
mode tcp
12+
option tcp-check
13+
14+
log-forward sylog-loadb
15+
dgram-bind 127.0.0.1:1514
16+
bind 127.0.0.1:1514
17+
timeout client 50000
18+
# all messages on stderr
19+
log global
20+
# all messages on local tcp syslog server
21+
log ring@myring local0
22+
# load balance messages on 4 udp syslog servers
23+
log 127.0.0.1:10001 sample 1:4 local0
24+
log 127.0.0.1:10002 sample 2:4 local0
25+
log 127.0.0.1:10003 sample 3:4 local0
26+
log 127.0.0.1:10004 sample 4:4 local0
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"backlog": 10,
3+
"maxconn": 20,
4+
"name": "test_log_forward",
5+
"timeout_client": 50000
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"backlog": 100,
3+
"maxconn": 200,
4+
"name": "sylog-loadb",
5+
"timeout_client": 40000
6+
}

e2e/tests/log_forwards/test.bats

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2021 HAProxy Technologies
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http:#www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
load '../../libs/dataplaneapi'
19+
load "../../libs/get_json_path"
20+
load '../../libs/resource_client'
21+
load '../../libs/version'
22+
load '../../libs/haproxy_config_setup'
23+
load '../../libs/haproxy_version'
24+
25+
load 'utils/_helpers'
26+
27+
@test "log_forwards: Add a log forward" {
28+
if haproxy_version_ge "2.3"
29+
then
30+
resource_post "$_LOG_FORWARD_BASE_PATH" "data/post.json" "force_reload=true"
31+
assert_equal "$SC" "201"
32+
fi
33+
}
34+
35+
@test "log_forwards: Return a log forward" {
36+
if haproxy_version_ge "2.3"
37+
then
38+
resource_get "$_LOG_FORWARD_BASE_PATH/sylog-loadb"
39+
assert_equal "$SC" 200
40+
assert_equal "sylog-loadb" "$(get_json_path "$BODY" '.data.name')"
41+
fi
42+
}
43+
44+
@test "log_forwards: Replace a log forward" {
45+
if haproxy_version_ge "2.3"
46+
then
47+
resource_put "$_LOG_FORWARD_BASE_PATH/sylog-loadb" "data/put.json" "force_reload=true"
48+
assert_equal "$SC" 200
49+
fi
50+
}
51+
52+
@test "log_forwards: Return an array of log_forwards" {
53+
if haproxy_version_ge "2.3"
54+
then
55+
resource_get "$_LOG_FORWARD_BASE_PATH"
56+
assert_equal "$SC" 200
57+
assert_equal "sylog-loadb" "$(get_json_path "$BODY" '.data[0].name')"
58+
fi
59+
}
60+
61+
@test "log_forwards: Delete a log forward" {
62+
if haproxy_version_ge "2.3"
63+
then
64+
resource_delete "$_LOG_FORWARD_BASE_PATH/sylog-loadb" "force_reload=true"
65+
assert_equal "$SC" 204
66+
fi
67+
}

0 commit comments

Comments
 (0)