MPA: move product hooks out of plugins environment (#21772)
* product: add new hooks manager for porducts * move product hooks out of plugins environment * add hooks for plugin
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
9e79ca7160
Коммит
43e26ccda2
@@ -50,7 +50,6 @@ type PrepackagedPlugin struct {
|
||||
// of active plugins.
|
||||
type Environment struct {
|
||||
registeredPlugins sync.Map
|
||||
registeredProducts sync.Map
|
||||
pluginHealthCheckJob *PluginHealthCheckJob
|
||||
logger *mlog.Logger
|
||||
metrics einterfaces.MetricsInterface
|
||||
@@ -326,26 +325,6 @@ func (env *Environment) Activate(id string) (manifest *model.Manifest, activated
|
||||
return pluginInfo.Manifest, true, nil
|
||||
}
|
||||
|
||||
func (env *Environment) AddProduct(productID string, hooks any) error {
|
||||
prod, err := newAdapter(hooks)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
rp := ®isteredProduct{
|
||||
productID: productID,
|
||||
adapter: prod,
|
||||
}
|
||||
|
||||
env.registeredProducts.Store(productID, rp)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (env *Environment) RemoveProduct(productID string) {
|
||||
env.registeredProducts.Delete(productID)
|
||||
}
|
||||
|
||||
func (env *Environment) RemovePlugin(id string) {
|
||||
if _, ok := env.registeredPlugins.Load(id); ok {
|
||||
env.registeredPlugins.Delete(id)
|
||||
@@ -499,12 +478,6 @@ func (env *Environment) HooksForPlugin(id string) (Hooks, error) {
|
||||
}
|
||||
}
|
||||
|
||||
if p, ok := env.registeredProducts.Load(id); ok {
|
||||
rp := p.(*registeredProduct)
|
||||
|
||||
return rp.adapter, nil
|
||||
}
|
||||
|
||||
return nil, fmt.Errorf("plugin not found: %v", id)
|
||||
}
|
||||
|
||||
@@ -533,24 +506,6 @@ func (env *Environment) RunMultiPluginHook(hookRunnerFunc func(hooks Hooks) bool
|
||||
return result
|
||||
})
|
||||
|
||||
env.registeredProducts.Range(func(key, value any) bool {
|
||||
rp := value.(*registeredProduct)
|
||||
|
||||
if !rp.Implements(hookId) {
|
||||
return true
|
||||
}
|
||||
|
||||
hookStartTime := time.Now()
|
||||
result := hookRunnerFunc(rp.adapter)
|
||||
|
||||
if env.metrics != nil {
|
||||
elapsedTime := float64(time.Since(hookStartTime)) / float64(time.Second)
|
||||
env.metrics.ObservePluginMultiHookIterationDuration(rp.productID, elapsedTime)
|
||||
}
|
||||
|
||||
return result
|
||||
})
|
||||
|
||||
if env.metrics != nil {
|
||||
elapsedTime := float64(time.Since(startTime)) / float64(time.Second)
|
||||
env.metrics.ObservePluginMultiHookDuration(elapsedTime)
|
||||
|
||||
Ссылка в новой задаче
Block a user