enhance: add the config to control the way when fail to init plugin (#32680)

issue: #32679

Signed-off-by: SimFG <bang.fu@zilliz.com>
This commit is contained in:
SimFG 2024-05-07 11:01:31 +08:00 committed by GitHub
parent 7da1ca9efb
commit 0ea08b008a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 43 additions and 1 deletions

View File

@ -94,7 +94,11 @@ func InitOnceHook() {
initOnce.Do(func() {
err := initHook()
if err != nil {
log.Warn("fail to init hook",
logFunc := log.Warn
if paramtable.Get().CommonCfg.PanicWhenPluginFail.GetAsBool() {
logFunc = log.Panic
}
logFunc("fail to init hook",
zap.String("so_path", paramtable.Get().ProxyCfg.SoPath.GetValue()),
zap.Error(err))
}

View File

@ -19,6 +19,7 @@
package hookutil
import (
"sync"
"testing"
"github.com/stretchr/testify/assert"
@ -39,6 +40,34 @@ func TestInitHook(t *testing.T) {
paramtable.Get().Save(Params.ProxyCfg.SoPath.Key, "")
}
func TestHookInitPanicError(t *testing.T) {
paramtable.Init()
p := paramtable.Get()
p.Save(p.ProxyCfg.SoPath.Key, "/a/b/hook.so")
defer p.Reset(p.ProxyCfg.SoPath.Key)
err := initHook()
assert.Error(t, err)
assert.Panics(t, func() {
initOnce = sync.Once{}
InitOnceHook()
})
}
func TestHookInitLogError(t *testing.T) {
paramtable.Init()
p := paramtable.Get()
p.Save(p.ProxyCfg.SoPath.Key, "/a/b/hook.so")
defer p.Reset(p.ProxyCfg.SoPath.Key)
p.Save(p.CommonCfg.PanicWhenPluginFail.Key, "false")
defer p.Reset(p.CommonCfg.PanicWhenPluginFail.Key)
err := initHook()
assert.Error(t, err)
assert.NotPanics(t, func() {
initOnce = sync.Once{}
InitOnceHook()
})
}
func TestDefaultHook(t *testing.T) {
d := &DefaultHook{}
assert.NoError(t, d.Init(nil))

View File

@ -244,6 +244,7 @@ type commonConfig struct {
TraceLogMode ParamItem `refreshable:"true"`
BloomFilterSize ParamItem `refreshable:"true"`
MaxBloomFalsePositive ParamItem `refreshable:"true"`
PanicWhenPluginFail ParamItem `refreshable:"false"`
}
func (p *commonConfig) init(base *BaseTable) {
@ -723,6 +724,14 @@ like the old password verification when updating the credential`,
Export: true,
}
p.MaxBloomFalsePositive.Init(base.mgr)
p.PanicWhenPluginFail = ParamItem{
Key: "common.panicWhenPluginFail",
Version: "2.4.2",
DefaultValue: "true",
Doc: "panic or not when plugin fail to init",
}
p.PanicWhenPluginFail.Init(base.mgr)
}
type gpuConfig struct {