Skip to content

Commit 7f38efb

Browse files
committed
MEDIUM: Add support for the log-profile section
1 parent 67e0697 commit 7f38efb

31 files changed

+4708
-187
lines changed

configure_data_plane.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -839,6 +839,13 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler { //nolint:cyclop,m
839839
api.TracesCreateTraceEntryHandler = &handlers.CreateTraceEntryHandlerImpl{Client: client, ReloadAgent: ra}
840840
api.TracesDeleteTraceEntryHandler = &handlers.DeleteTraceEntryHandlerImpl{Client: client, ReloadAgent: ra}
841841

842+
// log-profile handlers
843+
api.LogProfileGetLogProfilesHandler = &handlers.GetLogProfilesHandlerImpl{Client: client}
844+
api.LogProfileGetLogProfileHandler = &handlers.GetLogProfileHandlerImpl{Client: client}
845+
api.LogProfileCreateLogProfileHandler = &handlers.CreateLogProfileHandlerImpl{Client: client, ReloadAgent: ra}
846+
api.LogProfileEditLogProfileHandler = &handlers.EditLogProfileHandler{Client: client, ReloadAgent: ra}
847+
api.LogProfileDeleteLogProfileHandler = &handlers.DeleteLogProfileHandlerImpl{Client: client, ReloadAgent: ra}
848+
842849
// setup info handler
843850
api.InformationGetInfoHandler = &handlers.GetInfoHandlerImpl{SystemInfo: haproxyOptions.ShowSystemInfo, BuildTime: BuildTime, Version: Version}
844851

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"name": "logp1",
3+
"log_tag": "tag2",
4+
"steps": [
5+
{
6+
"step": "connect",
7+
"drop": "disabled",
8+
"format": "new connection"
9+
},
10+
{
11+
"step": "error",
12+
"drop": "disabled",
13+
"format": "%ci: error",
14+
"sd": "%T %H sd"
15+
}
16+
]
17+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "logp1",
3+
"log_tag": "tag1",
4+
"steps": [
5+
{
6+
"step": "connect",
7+
"drop": "enabled"
8+
},
9+
{
10+
"step": "error",
11+
"drop": "disabled",
12+
"format": "%ci: error",
13+
"sd": "%T %H sd"
14+
},
15+
{
16+
"step": "any",
17+
"drop": "disabled",
18+
"sd": "custom sd"
19+
}
20+
]
21+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bats
2+
#
3+
# Copyright 2025 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/debug'
20+
load '../../libs/get_json_path'
21+
load '../../libs/haproxy_version'
22+
load '../../libs/resource_client'
23+
load '../../libs/version'
24+
25+
load 'utils/_helpers'
26+
27+
@test "log_profile: all tests (>=3.1)" {
28+
haproxy_version_ge "3.1" || skip
29+
30+
debug "log_profile: create a new section"
31+
resource_post "$_LOG_PROFILE_PATH" "data/new_profile.json" "force_reload=true"
32+
assert_equal "$SC" "201"
33+
34+
debug "log_profile: get a section"
35+
resource_get "$_LOG_PROFILE_PATH/$_PROFILE_NAME"
36+
assert_equal "$SC" "200"
37+
assert_equal "$_PROFILE_NAME" "$(get_json_path "$BODY" .name)"
38+
assert_equal "tag1" "$(get_json_path "$BODY" .log_tag)"
39+
assert_equal "enabled" "$(get_json_path "$BODY" .steps.[0].drop)"
40+
assert_equal "any" "$(get_json_path "$BODY" .steps.[2].step)"
41+
42+
debug "log_profile: edit a section"
43+
resource_put "$_LOG_PROFILE_PATH/$_PROFILE_NAME" "data/edit_profile.json" "force_reload=true"
44+
assert_equal "$SC" "200"
45+
resource_get "$_LOG_PROFILE_PATH/$_PROFILE_NAME"
46+
assert_equal "tag2" "$(get_json_path "$BODY" .log_tag)"
47+
assert_equal "disabled" "$(get_json_path "$BODY" .steps.[0].drop)"
48+
assert_equal 2 "$(get_json_path "$BODY" '.steps|length')"
49+
50+
debug "log_profile: get a list of sections"
51+
resource_get "$_LOG_PROFILE_PATH"
52+
assert_equal "$SC" "200"
53+
assert_equal "$_PROFILE_NAME" "$(get_json_path "$BODY" .[0].name)"
54+
55+
debug "log_profile: delete a section"
56+
resource_delete "$_LOG_PROFILE_PATH/$_PROFILE_NAME" "force_reload=true"
57+
assert_equal "$SC" "204"
58+
resource_get "$_LOG_PROFILE_PATH/$_PROFILE_NAME"
59+
assert_equal "$SC" "404"
60+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright 2025 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+
_PROFILE_NAME="logp1"
19+
_LOG_PROFILE_PATH="/services/haproxy/configuration/log_profiles"

0 commit comments

Comments
 (0)