Skip to content

Commit

Permalink
MINOR: add support for set-retries option for tcp/http requests
Browse files Browse the repository at this point in the history
  • Loading branch information
rmaticevic authored and mjuraga committed Dec 2, 2024
1 parent e80fbf6 commit 7d08503
Show file tree
Hide file tree
Showing 22 changed files with 337 additions and 98 deletions.
81 changes: 81 additions & 0 deletions config-parser/parsers/actions/set-retries.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
Copyright 2019 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.
*/

//nolint:dupl
package actions

import (
stderrors "errors"
"strings"

"github.com/haproxytech/client-native/v6/config-parser/common"
"github.com/haproxytech/client-native/v6/config-parser/errors"
"github.com/haproxytech/client-native/v6/config-parser/types"
)

type SetRetries struct {
Expr common.Expression
Cond string
CondTest string
Comment string
}

func (f *SetRetries) Parse(parts []string, parserType types.ParserType, comment string) error {
if comment != "" {
f.Comment = comment
}
if len(parts) < 3 {
return stderrors.New("not enough params")
}
var command []string
switch parserType {
case types.HTTP:
command = parts[2:]
case types.TCP:
command = parts[3:]
}
command, condition := common.SplitRequest(command)
if len(command) == 0 {
return errors.ErrInvalidData
}
expr := common.Expression{}
if expr.Parse(command) != nil {
return stderrors.New("not enough params")
}
f.Expr = expr
if len(condition) > 1 {
f.Cond = condition[0]
f.CondTest = strings.Join(condition[1:], " ")
}
return nil
}

func (f *SetRetries) String() string {
var result strings.Builder
result.WriteString("set-retries ")
result.WriteString(f.Expr.String())
if f.Cond != "" {
result.WriteString(" ")
result.WriteString(f.Cond)
result.WriteString(" ")
result.WriteString(f.CondTest)
}
return result.String()
}

func (f *SetRetries) GetComment() string {
return f.Comment
}
2 changes: 2 additions & 0 deletions config-parser/parsers/http/http-request.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ func (h *Requests) Parse(line string, parts []string, comment string) (string, e
err = h.ParseHTTPRequest(&actions.SetFcMark{}, parts, comment)
case "set-fc-tos":
err = h.ParseHTTPRequest(&actions.SetFcTos{}, parts, comment)
case "set-retries":
err = h.ParseHTTPRequest(&actions.SetRetries{}, parts, comment)
default:
switch {
case strings.HasPrefix(parts[1], "track-sc"):
Expand Down
2 changes: 2 additions & 0 deletions config-parser/parsers/tcp/types/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ func (f *Content) Parse(parts []string, comment string) error {
err = f.ParseAction(&actions.SetFcMark{}, parts)
case "set-fc-tos":
err = f.ParseAction(&actions.SetFcTos{}, parts)
case "set-retries":
err = f.ParseAction(&actions.SetRetries{}, parts)
default:
switch {
case strings.HasPrefix(parts[2], "track-sc"):
Expand Down
20 changes: 20 additions & 0 deletions config-parser/tests/configs/haproxy_generated.cfg.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions config-parser/tests/http-request_generated_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions config-parser/tests/integration/backend_data_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions config-parser/tests/integration/backend_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions config-parser/tests/integration/defaults_data_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions config-parser/tests/integration/defaults_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions config-parser/tests/integration/frontend_data_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions config-parser/tests/integration/frontend_test.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 7d08503

Please sign in to comment.