Update logs
This commit is contained in:
parent
ba322e084d
commit
404161953b
6 changed files with 52 additions and 8 deletions
11
api.go
11
api.go
|
|
@ -347,6 +347,17 @@ type stringWriter interface {
|
|||
WriteString(s string) (int, error)
|
||||
}
|
||||
|
||||
// getPtafFallbackCode возвращает значение ptaf_fallback из первого ресурса где оно задано.
|
||||
// Дефолт: 418. Допустимые значения: число (например 503) или 'pass'
|
||||
func getPtafFallbackCode(resources []ResourceData) string {
|
||||
for _, res := range resources {
|
||||
if res.AppsSettings.PtafFallbackCode.Valid && strings.TrimSpace(res.AppsSettings.PtafFallbackCode.String) != "" {
|
||||
return strings.TrimSpace(res.AppsSettings.PtafFallbackCode.String)
|
||||
}
|
||||
}
|
||||
return "418"
|
||||
}
|
||||
|
||||
// getProxyNextUpstream формирует строку proxy_next_upstream из кодов в settings.
|
||||
// Дефолт: error timeout invalid_header http_500 http_502 http_503 http_504
|
||||
func getProxyNextUpstream(settings AppsSettings) string {
|
||||
|
|
|
|||
|
|
@ -69,7 +69,7 @@ func setupContainers(config Config, clientTitle string, clientInfo *ClientInfo,
|
|||
ptafConfig = clientInfo.PTAFConfig.String
|
||||
}
|
||||
|
||||
changed, err := generateNginxConf(nginxConfPath, config, ptafConfig, existingPodIP, clientInfo.Debug)
|
||||
changed, err := generateNginxConf(nginxConfPath, config, ptafConfig, existingPodIP, clientInfo.Debug, getPtafFallbackCode(resources))
|
||||
if err != nil {
|
||||
return fmt.Errorf("ошибка генерации nginx.conf: %w", err)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -401,7 +401,7 @@ func reloadAngie() {
|
|||
}
|
||||
|
||||
// generateNginxConf генерирует основной nginx.conf для PTAF
|
||||
func generateNginxConf(filePath string, config Config, ptafConfig string, existingPodIP string, debug bool) (bool, error) {
|
||||
func generateNginxConf(filePath string, config Config, ptafConfig string, existingPodIP string, debug bool, ptafFallbackCode string) (bool, error) {
|
||||
var randomIP string
|
||||
if existingPodIP != "" {
|
||||
randomIP = existingPodIP
|
||||
|
|
@ -465,6 +465,7 @@ http {
|
|||
'{'
|
||||
'"SID":$http_x_sid,'
|
||||
'"server_name":"$server_name",'
|
||||
'"request_id":"$http_x_request_id",'
|
||||
'"app_name":"$host",'
|
||||
'"proxyed_to":"$upstream_addr",'
|
||||
'"upstream_status":"$upstream_status",'
|
||||
|
|
@ -501,7 +502,7 @@ http {
|
|||
gzip on;
|
||||
server_names_hash_bucket_size 512;
|
||||
server_tokens off;
|
||||
ptaf_fallback 418;
|
||||
ptaf_fallback %s;
|
||||
proxy_read_timeout 120s;
|
||||
proxy_send_timeout 120s;
|
||||
send_timeout 60s;
|
||||
|
|
@ -538,7 +539,7 @@ http {
|
|||
|
||||
include /opt/ptaf/conf/conf.d/*.conf;
|
||||
}
|
||||
`, config.WorkerProcesses, randomIP, ptafLogLevel, debugEnv, hostname, errorLogLevel, config.WorkerConnections, clientTitle, ptafConfig)
|
||||
`, config.WorkerProcesses, randomIP, ptafLogLevel, debugEnv, hostname, errorLogLevel, config.WorkerConnections, clientTitle, ptafFallbackCode, ptafConfig)
|
||||
|
||||
return writeFileIfChanged(filePath, content)
|
||||
}
|
||||
|
|
|
|||
2
db.go
2
db.go
|
|
@ -161,6 +161,7 @@ func getAppsSettingsByClientTitle(db *sql.DB, clientTitle string) ([]AppsSetting
|
|||
fail_timeout,
|
||||
balancing_method,
|
||||
proxy_next_upstream_codes,
|
||||
ptaf_fallback_code,
|
||||
custom_sw_nginx_ssl
|
||||
FROM apps_settings
|
||||
WHERE client_title = $1
|
||||
|
|
@ -196,6 +197,7 @@ func getAppsSettingsByClientTitle(db *sql.DB, clientTitle string) ([]AppsSetting
|
|||
&a.FailTimeout,
|
||||
&a.BalancingMethod,
|
||||
&a.ProxyNextUpstreamCodes,
|
||||
&a.PtafFallbackCode,
|
||||
&a.CustomSWNginxSSL,
|
||||
)
|
||||
if err != nil {
|
||||
|
|
|
|||
37
nginx.go
37
nginx.go
|
|
@ -420,7 +420,7 @@ func writeStandardServerSettings(f *os.File, customDirectives string, debug bool
|
|||
if debug {
|
||||
f.WriteString(" client_body_buffer_size 1m;\n")
|
||||
}
|
||||
writeCustomOrDefaultDirectives(f, customDirectives)
|
||||
writeAngieCustomOrDefaultDirectives(f, customDirectives)
|
||||
}
|
||||
|
||||
// writeNginxStandardSettings записывает стандартные настройки сервера (Nginx)
|
||||
|
|
@ -440,11 +440,11 @@ func writeNginxStandardSettings(f *os.File, customDirectives string, proxyNextUp
|
|||
f.WriteString(" proxy_set_header Host $backend_host;\n")
|
||||
f.WriteString(" proxy_pass_header Date;\n")
|
||||
f.WriteString(" proxy_pass_header Server;\n")
|
||||
writeCustomOrDefaultDirectives(f, customDirectives)
|
||||
writeNginxCustomOrDefaultDirectives(f, customDirectives)
|
||||
}
|
||||
|
||||
// writeCustomOrDefaultDirectives записывает кастомные или дефолтные директивы таймаутов/буферов
|
||||
func writeCustomOrDefaultDirectives(f *os.File, customDirectives string) {
|
||||
// writeAngieCustomOrDefaultDirectives записывает кастомные или дефолтные директивы для Angie
|
||||
func writeAngieCustomOrDefaultDirectives(f *os.File, customDirectives string) {
|
||||
if customDirectives != "" {
|
||||
f.WriteString("\n # Custom server directives (override defaults)\n")
|
||||
lines := strings.Split(strings.TrimSpace(customDirectives), "\n")
|
||||
|
|
@ -456,6 +456,35 @@ func writeCustomOrDefaultDirectives(f *os.File, customDirectives string) {
|
|||
}
|
||||
} else {
|
||||
f.WriteString("\n # Default timeouts and buffers\n")
|
||||
f.WriteString(" proxy_set_header X-Request-ID $req_id_resolved;\n")
|
||||
f.WriteString(" proxy_connect_timeout 60s;\n")
|
||||
f.WriteString(" proxy_read_timeout 120s;\n")
|
||||
f.WriteString(" proxy_send_timeout 120s;\n")
|
||||
f.WriteString(" send_timeout 60s;\n")
|
||||
f.WriteString(" keepalive_timeout 80s;\n")
|
||||
f.WriteString(" keepalive_requests 1000;\n")
|
||||
f.WriteString(" resolver_timeout 30s;\n")
|
||||
f.WriteString(" large_client_header_buffers 4 128k;\n")
|
||||
f.WriteString(" proxy_buffers 8 64k;\n")
|
||||
f.WriteString(" proxy_buffer_size 64k;\n")
|
||||
f.WriteString(" proxy_busy_buffers_size 128k;\n")
|
||||
}
|
||||
}
|
||||
|
||||
// writeNginxCustomOrDefaultDirectives записывает кастомные или дефолтные директивы для nginx внутри контейнера
|
||||
func writeNginxCustomOrDefaultDirectives(f *os.File, customDirectives string) {
|
||||
if customDirectives != "" {
|
||||
f.WriteString("\n # Custom server directives (override defaults)\n")
|
||||
lines := strings.Split(strings.TrimSpace(customDirectives), "\n")
|
||||
for _, line := range lines {
|
||||
trimmed := strings.TrimSpace(line)
|
||||
if trimmed != "" {
|
||||
f.WriteString(" " + trimmed + "\n")
|
||||
}
|
||||
}
|
||||
} else {
|
||||
f.WriteString("\n # Default timeouts and buffers\n")
|
||||
f.WriteString(" proxy_set_header X-Request-ID $http_x_request_id;\n")
|
||||
f.WriteString(" proxy_connect_timeout 60s;\n")
|
||||
f.WriteString(" proxy_read_timeout 120s;\n")
|
||||
f.WriteString(" proxy_send_timeout 120s;\n")
|
||||
|
|
|
|||
1
types.go
1
types.go
|
|
@ -38,6 +38,7 @@ type AppsSettings struct {
|
|||
FailTimeout sql.NullInt64 // Время в секундах после которого origin снова доступен (дефолт 15)
|
||||
BalancingMethod sql.NullString // Метод балансировки: least_conn, ip_hash, random и т.д.
|
||||
ProxyNextUpstreamCodes sql.NullString // HTTP-коды для proxy_next_upstream (дефолт: 500,502,503,504)
|
||||
PtafFallbackCode sql.NullString // Код ответа ptaf_fallback: число или 'pass' (дефолт: 418)
|
||||
CustomSWNginxSSL sql.NullString // Кастомные SSL директивы для SW nginx - полностью заменяют дефолтные если заполнено
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue