feat: support enbale nginx debug_connection (#8637)
This commit is contained in:
parent
0005c080da
commit
2852e2998c
5 changed files with 39 additions and 0 deletions
|
@ -211,6 +211,7 @@ The following table shows a configuration option's name, type, and the default v
|
|||
|[global-rate-limit-status-code](#global-rate-limit)|int|429|
|
||||
|[service-upstream](#service-upstream)|bool|"false"|
|
||||
|[ssl-reject-handshake](#ssl-reject-handshake)|bool|"false"|
|
||||
|[debug-connections](#debug-connections)|[]string|"127.0.0.1,1.1.1.1/24"|
|
||||
|
||||
## add-headers
|
||||
|
||||
|
@ -1300,3 +1301,10 @@ _**default:**_ "false"
|
|||
|
||||
_References:_
|
||||
[https://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_reject_handshake](https://nginx.org/en/docs/http/ngx_http_ssl_module.html#ssl_reject_handshake)
|
||||
|
||||
## debug-connections
|
||||
Enables debugging log for selected client connections.
|
||||
_**default:**_ ""
|
||||
|
||||
_References:_
|
||||
[http://nginx.org/en/docs/ngx_core_module.html#debug_connection](http://nginx.org/en/docs/ngx_core_module.html#debug_connection)
|
||||
|
|
|
@ -768,6 +768,11 @@ type Configuration struct {
|
|||
// GlobalRateLimitStatucCode determines the HTTP status code to return
|
||||
// when limit is exceeding during global rate limiting.
|
||||
GlobalRateLimitStatucCode int `json:"global-rate-limit-status-code"`
|
||||
|
||||
// DebugConnections Enables debugging log for selected client connections
|
||||
// http://nginx.org/en/docs/ngx_core_module.html#debug_connection
|
||||
// Default: ""
|
||||
DebugConnections []string `json:"debug-connections"`
|
||||
}
|
||||
|
||||
// NewDefault returns the default nginx configuration
|
||||
|
@ -932,6 +937,7 @@ func NewDefault() Configuration {
|
|||
GlobalRateLimitMemcachedMaxIdleTimeout: 10000,
|
||||
GlobalRateLimitMemcachedPoolSize: 50,
|
||||
GlobalRateLimitStatucCode: 429,
|
||||
DebugConnections: []string{},
|
||||
}
|
||||
|
||||
if klog.V(5).Enabled() {
|
||||
|
|
|
@ -65,6 +65,7 @@ const (
|
|||
globalAuthAlwaysSetCookie = "global-auth-always-set-cookie"
|
||||
luaSharedDictsKey = "lua-shared-dicts"
|
||||
plugins = "plugins"
|
||||
debugConnections = "debug-connections"
|
||||
)
|
||||
|
||||
var (
|
||||
|
@ -111,6 +112,7 @@ func ReadConfig(src map[string]string) config.Configuration {
|
|||
blockRefererList := make([]string, 0)
|
||||
responseHeaders := make([]string, 0)
|
||||
luaSharedDicts := make(map[string]int)
|
||||
debugConnectionsList := make([]string, 0)
|
||||
|
||||
//parse lua shared dict values
|
||||
if val, ok := conf[luaSharedDictsKey]; ok {
|
||||
|
@ -373,6 +375,24 @@ func ReadConfig(src map[string]string) config.Configuration {
|
|||
delete(conf, plugins)
|
||||
}
|
||||
|
||||
if val, ok := conf[debugConnections]; ok {
|
||||
delete(conf, debugConnections)
|
||||
for _, i := range splitAndTrimSpace(val, ",") {
|
||||
validIp := net.ParseIP(i)
|
||||
if validIp != nil {
|
||||
debugConnectionsList = append(debugConnectionsList, i)
|
||||
} else {
|
||||
_, _, err := net.ParseCIDR(i)
|
||||
if err == nil {
|
||||
debugConnectionsList = append(debugConnectionsList, i)
|
||||
} else {
|
||||
klog.Warningf("%v is not a valid IP or CIDR address", i)
|
||||
}
|
||||
}
|
||||
}
|
||||
to.DebugConnections = debugConnectionsList
|
||||
}
|
||||
|
||||
to.CustomHTTPErrors = filterErrors(errors)
|
||||
to.SkipAccessLogURLs = skipUrls
|
||||
to.WhitelistSourceRange = whiteList
|
||||
|
|
|
@ -75,6 +75,7 @@ func TestMergeConfigMapToStruct(t *testing.T) {
|
|||
"proxy-add-original-uri-header": "false",
|
||||
"disable-ipv6-dns": "true",
|
||||
"default-type": "text/plain",
|
||||
"debug-connections": "127.0.0.1,1.1.1.1/24,::1",
|
||||
}
|
||||
def := config.NewDefault()
|
||||
def.CustomHTTPErrors = []int{300, 400}
|
||||
|
@ -99,6 +100,7 @@ func TestMergeConfigMapToStruct(t *testing.T) {
|
|||
def.LuaSharedDicts = defaultLuaSharedDicts
|
||||
def.DisableIpv6DNS = true
|
||||
def.DefaultType = "text/plain"
|
||||
def.DebugConnections = []string{"127.0.0.1", "1.1.1.1/24", "::1"}
|
||||
|
||||
hash, err := hashstructure.Hash(def, &hashstructure.HashOptions{
|
||||
TagName: "json",
|
||||
|
|
|
@ -58,6 +58,9 @@ events {
|
|||
multi_accept {{ if $cfg.EnableMultiAccept }}on{{ else }}off{{ end }};
|
||||
worker_connections {{ $cfg.MaxWorkerConnections }};
|
||||
use epoll;
|
||||
{{ range $index , $v := $cfg.DebugConnections }}
|
||||
debug_connection {{ $v }};
|
||||
{{ end }}
|
||||
}
|
||||
|
||||
http {
|
||||
|
|
Loading…
Reference in a new issue