Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: [2.4] add the config to control the way when fail to init plugin #32682

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion internal/proxy/hook_interceptor.go
Expand Up @@ -86,7 +86,11 @@ func initHook() error {

func UnaryServerHookInterceptor() grpc.UnaryServerInterceptor {
if hookError := initHook(); hookError != nil {
logger.Error("hook error", zap.String("path", Params.ProxyCfg.SoPath.GetValue()), zap.Error(hookError))
logFunc := logger.Warn
if paramtable.Get().CommonCfg.PanicWhenPluginFail.GetAsBool() {
logFunc = logger.Panic
}
logFunc("hook error", zap.String("path", Params.ProxyCfg.SoPath.GetValue()), zap.Error(hookError))
hoo = defaultHook{}
}
return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (interface{}, error) {
Expand Down
26 changes: 26 additions & 0 deletions internal/proxy/hook_interceptor_test.go
Expand Up @@ -139,6 +139,32 @@ func TestHookInterceptor(t *testing.T) {
assert.NoError(t, err)
}

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() {
UnaryServerHookInterceptor()
})
}

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() {
UnaryServerHookInterceptor()
})
}

func TestDefaultHook(t *testing.T) {
d := defaultHook{}
assert.NoError(t, d.Init(nil))
Expand Down
9 changes: 9 additions & 0 deletions pkg/util/paramtable/component_param.go
Expand Up @@ -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) {
Expand Down Expand Up @@ -717,6 +718,14 @@ like the old password verification when updating the credential`,
Doc: "max false positive rate for bloom filter",
}
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 {
Expand Down