mirror of
https://github.com/alibaba/higress.git
synced 2026-04-26 14:37:26 +08:00
add plugin start log in sdk (#1831)
This commit is contained in:
@@ -32,6 +32,7 @@ const (
|
||||
CustomLogKey = "custom_log"
|
||||
AILogKey = "ai_log"
|
||||
TraceSpanTagPrefix = "trace_span_tag."
|
||||
PluginIDKey = "_plugin_id_"
|
||||
)
|
||||
|
||||
type HttpContext interface {
|
||||
@@ -255,7 +256,7 @@ func parseEmptyPluginConfig[PluginConfig any](gjson.Result, *PluginConfig, Log)
|
||||
}
|
||||
|
||||
func NewCommonVmCtx[PluginConfig any](pluginName string, options ...CtxOption[PluginConfig]) *CommonVmCtx[PluginConfig] {
|
||||
logger := &DefaultLog{pluginName}
|
||||
logger := &DefaultLog{pluginName, "nil"}
|
||||
opts := append([]CtxOption[PluginConfig]{WithLogger[PluginConfig](logger)}, options...)
|
||||
return NewCommonVmCtxWithOptions(pluginName, opts...)
|
||||
}
|
||||
@@ -314,7 +315,10 @@ func (ctx *CommonPluginCtx[PluginConfig]) OnPluginStart(int) types.OnPluginStart
|
||||
}
|
||||
jsonData = gjson.ParseBytes(data)
|
||||
}
|
||||
|
||||
pluginID := jsonData.Get(PluginIDKey).String()
|
||||
if pluginID != "" {
|
||||
ctx.vm.log.resetID(pluginID)
|
||||
}
|
||||
var parseOverrideConfig func(gjson.Result, PluginConfig, *PluginConfig) error
|
||||
if ctx.vm.parseRuleConfig != nil {
|
||||
parseOverrideConfig = func(js gjson.Result, global PluginConfig, cfg *PluginConfig) error {
|
||||
@@ -329,15 +333,18 @@ func (ctx *CommonPluginCtx[PluginConfig]) OnPluginStart(int) types.OnPluginStart
|
||||
)
|
||||
if err != nil {
|
||||
ctx.vm.log.Warnf("parse rule config failed: %v", err)
|
||||
ctx.vm.log.Error("plugin start failed")
|
||||
return types.OnPluginStartStatusFailed
|
||||
}
|
||||
if globalOnTickFuncs != nil {
|
||||
ctx.onTickFuncs = globalOnTickFuncs
|
||||
if err := proxywasm.SetTickPeriodMilliSeconds(100); err != nil {
|
||||
ctx.vm.log.Error("SetTickPeriodMilliSeconds failed, onTick functions will not take effect.")
|
||||
ctx.vm.log.Error("plugin start failed")
|
||||
return types.OnPluginStartStatusFailed
|
||||
}
|
||||
}
|
||||
ctx.vm.log.Error("plugin start successfully")
|
||||
return types.OnPluginStartStatusOK
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user