mirror of
https://github.com/Rain-kl/OpenFlare.git
synced 2026-10-13 02:26:36 +08:00
[优化] 添加错误日志路径占位符并更新相关逻辑
This commit is contained in:
@@ -393,6 +393,8 @@ func (m *Manager) CurrentChecksum() (string, error) {
|
|||||||
}
|
}
|
||||||
if accessLogPath := m.accessLogRuntimePath(); accessLogPath != "" {
|
if accessLogPath := m.accessLogRuntimePath(); accessLogPath != "" {
|
||||||
normalizedMain = strings.ReplaceAll(normalizedMain, accessLogPath, openrestyrender.AccessLogPlaceholder)
|
normalizedMain = strings.ReplaceAll(normalizedMain, accessLogPath, openrestyrender.AccessLogPlaceholder)
|
||||||
|
errorLogPath := filepath.Join(filepath.Dir(accessLogPath), "error.log")
|
||||||
|
normalizedMain = strings.ReplaceAll(normalizedMain, filepath.ToSlash(errorLogPath), openrestyrender.ErrorLogPlaceholder)
|
||||||
}
|
}
|
||||||
if luaDir := m.luaRuntimePath(); luaDir != "" {
|
if luaDir := m.luaRuntimePath(); luaDir != "" {
|
||||||
normalizedMain = strings.ReplaceAll(normalizedMain, luaDir, openrestyrender.LuaDirPlaceholder)
|
normalizedMain = strings.ReplaceAll(normalizedMain, luaDir, openrestyrender.LuaDirPlaceholder)
|
||||||
@@ -1061,6 +1063,8 @@ func (m *Manager) renderMainConfig(content string) string {
|
|||||||
}
|
}
|
||||||
if accessLogPath := m.accessLogRuntimePath(); accessLogPath != "" {
|
if accessLogPath := m.accessLogRuntimePath(); accessLogPath != "" {
|
||||||
rendered = strings.ReplaceAll(rendered, openrestyrender.AccessLogPlaceholder, accessLogPath)
|
rendered = strings.ReplaceAll(rendered, openrestyrender.AccessLogPlaceholder, accessLogPath)
|
||||||
|
errorLogPath := filepath.Join(filepath.Dir(accessLogPath), "error.log")
|
||||||
|
rendered = strings.ReplaceAll(rendered, openrestyrender.ErrorLogPlaceholder, filepath.ToSlash(errorLogPath))
|
||||||
}
|
}
|
||||||
if luaDir := m.luaRuntimePath(); luaDir != "" {
|
if luaDir := m.luaRuntimePath(); luaDir != "" {
|
||||||
rendered = strings.ReplaceAll(rendered, openrestyrender.LuaDirPlaceholder, luaDir)
|
rendered = strings.ReplaceAll(rendered, openrestyrender.LuaDirPlaceholder, luaDir)
|
||||||
|
|||||||
@@ -97,6 +97,7 @@ var OpenRestyMainConfigTemplate = `# This file is generated by OpenFlare. Do not
|
|||||||
worker_processes {{OpenRestyWorkerProcesses}};
|
worker_processes {{OpenRestyWorkerProcesses}};
|
||||||
worker_rlimit_nofile {{OpenRestyWorkerRlimitNofile}};
|
worker_rlimit_nofile {{OpenRestyWorkerRlimitNofile}};
|
||||||
pid logs/nginx.pid;
|
pid logs/nginx.pid;
|
||||||
|
error_log {{OpenRestyErrorLogPath}} warn;
|
||||||
|
|
||||||
events {
|
events {
|
||||||
worker_connections {{OpenRestyWorkerConnections}};
|
worker_connections {{OpenRestyWorkerConnections}};
|
||||||
|
|||||||
@@ -58,6 +58,9 @@ func TestCreateTLSCertificateAndRenderHTTPSConfig(t *testing.T) {
|
|||||||
if !strings.Contains(result.Version.MainConfig, "access_log __OPENFLARE_ACCESS_LOG__ openflare_json;") {
|
if !strings.Contains(result.Version.MainConfig, "access_log __OPENFLARE_ACCESS_LOG__ openflare_json;") {
|
||||||
t.Fatal("expected main config to include managed access log placeholder")
|
t.Fatal("expected main config to include managed access log placeholder")
|
||||||
}
|
}
|
||||||
|
if !strings.Contains(result.Version.MainConfig, "error_log __OPENFLARE_ERROR_LOG__ warn;") {
|
||||||
|
t.Fatal("expected main config to include managed error log placeholder")
|
||||||
|
}
|
||||||
if !strings.Contains(result.Version.MainConfig, "log_by_lua_file __OPENFLARE_LUA_DIR__/log.lua;") {
|
if !strings.Contains(result.Version.MainConfig, "log_by_lua_file __OPENFLARE_LUA_DIR__/log.lua;") {
|
||||||
t.Fatal("expected main config to include managed openresty lua log hook")
|
t.Fatal("expected main config to include managed openresty lua log hook")
|
||||||
}
|
}
|
||||||
@@ -1242,6 +1245,9 @@ func TestOpenRestyMainConfigTemplateRenderAndValidate(t *testing.T) {
|
|||||||
if !strings.Contains(preview.MainConfig, "access_log __OPENFLARE_ACCESS_LOG__ openflare_json;") {
|
if !strings.Contains(preview.MainConfig, "access_log __OPENFLARE_ACCESS_LOG__ openflare_json;") {
|
||||||
t.Fatal("expected preview main config to preserve managed access log placeholder")
|
t.Fatal("expected preview main config to preserve managed access log placeholder")
|
||||||
}
|
}
|
||||||
|
if !strings.Contains(preview.MainConfig, "error_log __OPENFLARE_ERROR_LOG__ warn;") {
|
||||||
|
t.Fatal("expected preview main config to preserve managed error log placeholder")
|
||||||
|
}
|
||||||
if !strings.Contains(preview.MainConfig, "map $http_upgrade $connection_upgrade {") {
|
if !strings.Contains(preview.MainConfig, "map $http_upgrade $connection_upgrade {") {
|
||||||
t.Fatal("expected preview main config to preserve managed websocket upgrade map")
|
t.Fatal("expected preview main config to preserve managed websocket upgrade map")
|
||||||
}
|
}
|
||||||
@@ -1281,6 +1287,15 @@ func TestOpenRestyMainConfigTemplateRenderAndValidate(t *testing.T) {
|
|||||||
if err := ValidateOpenRestyMainConfigTemplate(invalidTemplate); err == nil {
|
if err := ValidateOpenRestyMainConfigTemplate(invalidTemplate); err == nil {
|
||||||
t.Fatal("expected template without managed websocket upgrade map placeholder to fail validation")
|
t.Fatal("expected template without managed websocket upgrade map placeholder to fail validation")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
invalidTemplate = strings.ReplaceAll(
|
||||||
|
common.OpenRestyMainConfigTemplate,
|
||||||
|
"{{OpenRestyErrorLogPath}}",
|
||||||
|
"",
|
||||||
|
)
|
||||||
|
if err := ValidateOpenRestyMainConfigTemplate(invalidTemplate); err == nil {
|
||||||
|
t.Fatal("expected template without managed error log placeholder to fail validation")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestOpenRestyCommonRequestOptionsRender(t *testing.T) {
|
func TestOpenRestyCommonRequestOptionsRender(t *testing.T) {
|
||||||
|
|||||||
@@ -278,6 +278,7 @@ func renderMainConfigTemplate(templateText string, cfg ConfigSnapshot) string {
|
|||||||
"{{OpenRestyConnectionUpgradeMap}}", renderConnectionUpgradeMap(),
|
"{{OpenRestyConnectionUpgradeMap}}", renderConnectionUpgradeMap(),
|
||||||
"{{OpenRestyDefaultServerBlock}}", renderDefaultServerBlock(),
|
"{{OpenRestyDefaultServerBlock}}", renderDefaultServerBlock(),
|
||||||
"{{OpenRestyAccessLogPath}}", AccessLogPlaceholder,
|
"{{OpenRestyAccessLogPath}}", AccessLogPlaceholder,
|
||||||
|
"{{OpenRestyErrorLogPath}}", ErrorLogPlaceholder,
|
||||||
"{{OpenRestyEventsUseDirective}}", renderTemplateDirective(cfg.EventsUse != "", fmt.Sprintf("use %s;", cfg.EventsUse)),
|
"{{OpenRestyEventsUseDirective}}", renderTemplateDirective(cfg.EventsUse != "", fmt.Sprintf("use %s;", cfg.EventsUse)),
|
||||||
"{{OpenRestyEventsMultiAcceptDirective}}", renderTemplateDirective(cfg.EventsMultiAcceptEnabled, "multi_accept on;"),
|
"{{OpenRestyEventsMultiAcceptDirective}}", renderTemplateDirective(cfg.EventsMultiAcceptEnabled, "multi_accept on;"),
|
||||||
"{{OpenRestyKeepaliveTimeout}}", fmt.Sprintf("%d", cfg.KeepaliveTimeout),
|
"{{OpenRestyKeepaliveTimeout}}", fmt.Sprintf("%d", cfg.KeepaliveTimeout),
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ const (
|
|||||||
CertDirPlaceholder = "__OPENFLARE_CERT_DIR__"
|
CertDirPlaceholder = "__OPENFLARE_CERT_DIR__"
|
||||||
RouteConfigPlaceholder = "__OPENFLARE_ROUTE_CONFIG__"
|
RouteConfigPlaceholder = "__OPENFLARE_ROUTE_CONFIG__"
|
||||||
AccessLogPlaceholder = "__OPENFLARE_ACCESS_LOG__"
|
AccessLogPlaceholder = "__OPENFLARE_ACCESS_LOG__"
|
||||||
|
ErrorLogPlaceholder = "__OPENFLARE_ERROR_LOG__"
|
||||||
LuaDirPlaceholder = "__OPENFLARE_LUA_DIR__"
|
LuaDirPlaceholder = "__OPENFLARE_LUA_DIR__"
|
||||||
ObservabilityListenPlaceholder = "__OPENFLARE_OBSERVABILITY_LISTEN__"
|
ObservabilityListenPlaceholder = "__OPENFLARE_OBSERVABILITY_LISTEN__"
|
||||||
ObservabilityPortPlaceholder = "__OPENFLARE_OBSERVABILITY_PORT__"
|
ObservabilityPortPlaceholder = "__OPENFLARE_OBSERVABILITY_PORT__"
|
||||||
@@ -25,6 +26,7 @@ const defaultMainConfigTemplate = `# This file is generated by OpenFlare. Do not
|
|||||||
worker_processes {{OpenRestyWorkerProcesses}};
|
worker_processes {{OpenRestyWorkerProcesses}};
|
||||||
worker_rlimit_nofile {{OpenRestyWorkerRlimitNofile}};
|
worker_rlimit_nofile {{OpenRestyWorkerRlimitNofile}};
|
||||||
pid logs/nginx.pid;
|
pid logs/nginx.pid;
|
||||||
|
error_log {{OpenRestyErrorLogPath}} warn;
|
||||||
|
|
||||||
events {
|
events {
|
||||||
worker_connections {{OpenRestyWorkerConnections}};
|
worker_connections {{OpenRestyWorkerConnections}};
|
||||||
@@ -222,6 +224,7 @@ var requiredMainConfigTemplatePlaceholders = []string{
|
|||||||
"{{OpenRestyConnectionUpgradeMap}}",
|
"{{OpenRestyConnectionUpgradeMap}}",
|
||||||
"{{OpenRestyDefaultServerBlock}}",
|
"{{OpenRestyDefaultServerBlock}}",
|
||||||
"{{OpenRestyAccessLogPath}}",
|
"{{OpenRestyAccessLogPath}}",
|
||||||
|
"{{OpenRestyErrorLogPath}}",
|
||||||
"{{OpenRestyEventsUseDirective}}",
|
"{{OpenRestyEventsUseDirective}}",
|
||||||
"{{OpenRestyEventsMultiAcceptDirective}}",
|
"{{OpenRestyEventsMultiAcceptDirective}}",
|
||||||
"{{OpenRestyKeepaliveTimeout}}",
|
"{{OpenRestyKeepaliveTimeout}}",
|
||||||
|
|||||||
Reference in New Issue
Block a user