Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support custom request headers in http health check #135

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pkg/config/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ type HealthCheckConf struct {
// HealthCheckURL specifies the address to send health checks to if the
// health check type is "http".
HealthCheckURL string `ini:"health_check_url,omitempty" http:"true"`
// HealthCheckHTTPHeaders specifies the headers to send with the http request.
HealthCheckHTTPHeaders map[string]string `ini:"-" http:"true"`
}

type Proxy struct {
Expand Down
6 changes: 6 additions & 0 deletions pkg/config/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,9 @@ func clientProxyBaseFromV1(c *v1.ProxyBaseConfig, out *Proxy) {
out.HealthCheckMaxFailed = c.HealthCheck.MaxFailed
out.HealthCheckIntervalS = c.HealthCheck.IntervalSeconds
out.HealthCheckURL = c.HealthCheck.Path
out.HealthCheckHTTPHeaders = lo.SliceToMap(c.HealthCheck.HTTPHeaders, func(item v1.HTTPHeader) (string, string) {
return item.Name, item.Value
})
out.LocalIP = c.LocalIP
if c.LocalPort != 0 {
out.LocalPort = strconv.Itoa(c.LocalPort)
Expand Down Expand Up @@ -468,6 +471,9 @@ func clientProxyBaseToV1(c *BaseProxyConf) (v1.ProxyBaseConfig, error) {
MaxFailed: c.HealthCheckMaxFailed,
IntervalSeconds: c.HealthCheckIntervalS,
Path: c.HealthCheckURL,
HTTPHeaders: lo.MapToSlice(c.HealthCheckHTTPHeaders, func(key string, value string) v1.HTTPHeader {
return v1.HTTPHeader{Name: key, Value: value}
}),
},
ProxyBackend: v1.ProxyBackend{
LocalIP: c.LocalIP,
Expand Down
15 changes: 14 additions & 1 deletion ui/editproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,19 @@ func (pd *EditProxyDialog) loadBalanceProxyPage() TabPage {
}

func (pd *EditProxyDialog) healthCheckProxyPage() TabPage {
var url Widget = LineEdit{Visible: Bind("vm.HealthCheckURLVisible"), Text: Bind("HealthCheckURL")}
if !pd.legacyFormat {
url = Composite{
Visible: Bind("vm.HealthCheckURLVisible"),
Layout: HBox{MarginsZero: true},
Children: []Widget{
url,
ToolButton{Text: "H", ToolTipText: i18n.Sprintf("Request headers"), OnClicked: func() {
NewAttributeDialog(i18n.Sprintf("Request headers"), &pd.binder.HealthCheckHTTPHeaders).Run(pd.Form())
}},
},
}
}
return AlignGrid(TabPage{
Title: i18n.Sprintf("Health Check"),
Layout: Grid{Columns: 2},
Expand All @@ -423,7 +436,7 @@ func (pd *EditProxyDialog) healthCheckProxyPage() TabPage {
{Text: i18n.Sprintf("None"), Value: "", Enabled: Bind("vm.HealthCheckEnable"), OnClicked: pd.switchType, MaxSize: Size{Width: 80}},
}),
Label{Visible: Bind("vm.HealthCheckURLVisible"), Text: "URL:"},
LineEdit{Visible: Bind("vm.HealthCheckURLVisible"), Text: Bind("HealthCheckURL")},
url,
Label{Visible: Bind("vm.HealthCheckVisible"), Text: i18n.SprintfColon("Check Timeout")},
NewNumberInput(NIOption{Visible: Bind("vm.HealthCheckVisible"), Value: Bind("HealthCheckTimeoutS"), Suffix: i18n.Sprintf("s")}),
Label{Visible: Bind("vm.HealthCheckVisible"), Text: i18n.SprintfColon("Check Interval")},
Expand Down