Skip to content

nginx-migration-mcp 插件在 Higress 下效果验证和优化 #3080

@imp2002

Description

@imp2002

现有工具效果优化

convert_lua_to_wasm 优化

1. 自动添加错误处理和日志

优化代码生成模板:

// 当前生成
header, _ := proxywasm.GetHttpRequestHeader("Auth")

// 优化后生成
header, err := proxywasm.GetHttpRequestHeader("Auth")
if err != nil {
    log.Warnf("Failed to get header: %v", err)
}

实现方式:

方式一:直接优化代码模板

// 在 tools/lua_converter.go 中
const wasmCodeTemplate = `
func onHttpRequestHeaders(...) types.Action {
    {{range .APICalls}}
    {{.Name}}, err := proxywasm.{{.Function}}({{.Args}})
    if err != nil {
        proxywasm.LogWarnf("Failed to {{.Operation}}: %v", err)
        {{if .Critical}}return types.ActionPause{{end}}
    }
    {{end}}
    return types.ActionContinue
}
`

方式二:在返回结果中添加优化建议

// convert_lua_to_wasm 返回时
result := ConversionResult{
    Code: generatedCode,
    Suggestions: []string{
        "建议为所有 API 调用添加错误处理",
        "建议在第 23 行添加日志",
    }
}

2. 优化配置结构生成

// 当前生成 - 配置字段简陋
type Config struct {
    Enabled bool `json:"enabled"`
}

// 优化后 - 完善字段定义
type Config struct {
    Secret         string   `json:"secret" required:"true"`
    WhitelistPaths []string `json:"whitelist_paths"`
    Timeout        int      `json:"timeout" default:"30"`
}

Originally posted by @imp2002 in #2916 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Todo

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions