Skip to content

Commit 7d08503

Browse files
rmaticevicmjuraga
authored andcommitted
MINOR: add support for set-retries option for tcp/http requests
1 parent e80fbf6 commit 7d08503

22 files changed

+337
-98
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
Copyright 2019 HAProxy Technologies
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
//nolint:dupl
18+
package actions
19+
20+
import (
21+
stderrors "errors"
22+
"strings"
23+
24+
"github.com/haproxytech/client-native/v6/config-parser/common"
25+
"github.com/haproxytech/client-native/v6/config-parser/errors"
26+
"github.com/haproxytech/client-native/v6/config-parser/types"
27+
)
28+
29+
type SetRetries struct {
30+
Expr common.Expression
31+
Cond string
32+
CondTest string
33+
Comment string
34+
}
35+
36+
func (f *SetRetries) Parse(parts []string, parserType types.ParserType, comment string) error {
37+
if comment != "" {
38+
f.Comment = comment
39+
}
40+
if len(parts) < 3 {
41+
return stderrors.New("not enough params")
42+
}
43+
var command []string
44+
switch parserType {
45+
case types.HTTP:
46+
command = parts[2:]
47+
case types.TCP:
48+
command = parts[3:]
49+
}
50+
command, condition := common.SplitRequest(command)
51+
if len(command) == 0 {
52+
return errors.ErrInvalidData
53+
}
54+
expr := common.Expression{}
55+
if expr.Parse(command) != nil {
56+
return stderrors.New("not enough params")
57+
}
58+
f.Expr = expr
59+
if len(condition) > 1 {
60+
f.Cond = condition[0]
61+
f.CondTest = strings.Join(condition[1:], " ")
62+
}
63+
return nil
64+
}
65+
66+
func (f *SetRetries) String() string {
67+
var result strings.Builder
68+
result.WriteString("set-retries ")
69+
result.WriteString(f.Expr.String())
70+
if f.Cond != "" {
71+
result.WriteString(" ")
72+
result.WriteString(f.Cond)
73+
result.WriteString(" ")
74+
result.WriteString(f.CondTest)
75+
}
76+
return result.String()
77+
}
78+
79+
func (f *SetRetries) GetComment() string {
80+
return f.Comment
81+
}

config-parser/parsers/http/http-request.go

+2
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ func (h *Requests) Parse(line string, parts []string, comment string) (string, e
145145
err = h.ParseHTTPRequest(&actions.SetFcMark{}, parts, comment)
146146
case "set-fc-tos":
147147
err = h.ParseHTTPRequest(&actions.SetFcTos{}, parts, comment)
148+
case "set-retries":
149+
err = h.ParseHTTPRequest(&actions.SetRetries{}, parts, comment)
148150
default:
149151
switch {
150152
case strings.HasPrefix(parts[1], "track-sc"):

config-parser/parsers/tcp/types/content.go

+2
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ func (f *Content) Parse(parts []string, comment string) error {
9494
err = f.ParseAction(&actions.SetFcMark{}, parts)
9595
case "set-fc-tos":
9696
err = f.ParseAction(&actions.SetFcTos{}, parts)
97+
case "set-retries":
98+
err = f.ParseAction(&actions.SetRetries{}, parts)
9799
default:
98100
switch {
99101
case strings.HasPrefix(parts[2], "track-sc"):

config-parser/tests/configs/haproxy_generated.cfg.go

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config-parser/tests/http-request_generated_test.go

+2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config-parser/tests/integration/backend_data_test.go

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config-parser/tests/integration/backend_test.go

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config-parser/tests/integration/defaults_data_test.go

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config-parser/tests/integration/defaults_test.go

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config-parser/tests/integration/frontend_data_test.go

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config-parser/tests/integration/frontend_test.go

+4
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)