Skip to content

Commit

Permalink
MEDIUM: Add support for the log-profile section
Browse files Browse the repository at this point in the history
  • Loading branch information
oliwer committed Feb 3, 2025
1 parent 67e0697 commit 7f38efb
Show file tree
Hide file tree
Showing 31 changed files with 4,708 additions and 187 deletions.
7 changes: 7 additions & 0 deletions configure_data_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -839,6 +839,13 @@ func configureAPI(api *operations.DataPlaneAPI) http.Handler { //nolint:cyclop,m
api.TracesCreateTraceEntryHandler = &handlers.CreateTraceEntryHandlerImpl{Client: client, ReloadAgent: ra}
api.TracesDeleteTraceEntryHandler = &handlers.DeleteTraceEntryHandlerImpl{Client: client, ReloadAgent: ra}

// log-profile handlers
api.LogProfileGetLogProfilesHandler = &handlers.GetLogProfilesHandlerImpl{Client: client}
api.LogProfileGetLogProfileHandler = &handlers.GetLogProfileHandlerImpl{Client: client}
api.LogProfileCreateLogProfileHandler = &handlers.CreateLogProfileHandlerImpl{Client: client, ReloadAgent: ra}
api.LogProfileEditLogProfileHandler = &handlers.EditLogProfileHandler{Client: client, ReloadAgent: ra}
api.LogProfileDeleteLogProfileHandler = &handlers.DeleteLogProfileHandlerImpl{Client: client, ReloadAgent: ra}

// setup info handler
api.InformationGetInfoHandler = &handlers.GetInfoHandlerImpl{SystemInfo: haproxyOptions.ShowSystemInfo, BuildTime: BuildTime, Version: Version}

Expand Down
17 changes: 17 additions & 0 deletions e2e/tests/log_profile/data/edit_profile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "logp1",
"log_tag": "tag2",
"steps": [
{
"step": "connect",
"drop": "disabled",
"format": "new connection"
},
{
"step": "error",
"drop": "disabled",
"format": "%ci: error",
"sd": "%T %H sd"
}
]
}
21 changes: 21 additions & 0 deletions e2e/tests/log_profile/data/new_profile.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "logp1",
"log_tag": "tag1",
"steps": [
{
"step": "connect",
"drop": "enabled"
},
{
"step": "error",
"drop": "disabled",
"format": "%ci: error",
"sd": "%T %H sd"
},
{
"step": "any",
"drop": "disabled",
"sd": "custom sd"
}
]
}
60 changes: 60 additions & 0 deletions e2e/tests/log_profile/log_profile.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bats
#
# Copyright 2025 HAProxy Technologies
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

load '../../libs/dataplaneapi'
load '../../libs/debug'
load '../../libs/get_json_path'
load '../../libs/haproxy_version'
load '../../libs/resource_client'
load '../../libs/version'

load 'utils/_helpers'

@test "log_profile: all tests (>=3.1)" {
haproxy_version_ge "3.1" || skip

debug "log_profile: create a new section"
resource_post "$_LOG_PROFILE_PATH" "data/new_profile.json" "force_reload=true"
assert_equal "$SC" "201"

debug "log_profile: get a section"
resource_get "$_LOG_PROFILE_PATH/$_PROFILE_NAME"
assert_equal "$SC" "200"
assert_equal "$_PROFILE_NAME" "$(get_json_path "$BODY" .name)"
assert_equal "tag1" "$(get_json_path "$BODY" .log_tag)"
assert_equal "enabled" "$(get_json_path "$BODY" .steps.[0].drop)"
assert_equal "any" "$(get_json_path "$BODY" .steps.[2].step)"

debug "log_profile: edit a section"
resource_put "$_LOG_PROFILE_PATH/$_PROFILE_NAME" "data/edit_profile.json" "force_reload=true"
assert_equal "$SC" "200"
resource_get "$_LOG_PROFILE_PATH/$_PROFILE_NAME"
assert_equal "tag2" "$(get_json_path "$BODY" .log_tag)"
assert_equal "disabled" "$(get_json_path "$BODY" .steps.[0].drop)"
assert_equal 2 "$(get_json_path "$BODY" '.steps|length')"

debug "log_profile: get a list of sections"
resource_get "$_LOG_PROFILE_PATH"
assert_equal "$SC" "200"
assert_equal "$_PROFILE_NAME" "$(get_json_path "$BODY" .[0].name)"

debug "log_profile: delete a section"
resource_delete "$_LOG_PROFILE_PATH/$_PROFILE_NAME" "force_reload=true"
assert_equal "$SC" "204"
resource_get "$_LOG_PROFILE_PATH/$_PROFILE_NAME"
assert_equal "$SC" "404"
}
19 changes: 19 additions & 0 deletions e2e/tests/log_profile/utils/_helpers.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
#
# Copyright 2025 HAProxy Technologies
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:#www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

_PROFILE_NAME="logp1"
_LOG_PROFILE_PATH="/services/haproxy/configuration/log_profiles"
Loading

0 comments on commit 7f38efb

Please sign in to comment.