diff --git a/api/pkg/filtermanager/config.go b/api/pkg/filtermanager/config.go index 6cd411fe..9911f914 100644 --- a/api/pkg/filtermanager/config.go +++ b/api/pkg/filtermanager/config.go @@ -216,6 +216,11 @@ func (p *FilterManagerConfigParser) Parse(any *anypb.Any, callbacks capi.ConfigC for _, proto := range plugins { name := proto.Name + + if registerMetrics := pkgPlugins.LoadMetricsCallback(name); registerMetrics != nil { + registerMetrics(callbacks) + } + if plugin := pkgPlugins.LoadHTTPFilterFactoryAndParser(name); plugin != nil { config, err := plugin.ConfigParser.Parse(proto.Config) if err != nil { diff --git a/api/pkg/plugins/plugins.go b/api/pkg/plugins/plugins.go index 5ab2742a..80468af5 100644 --- a/api/pkg/plugins/plugins.go +++ b/api/pkg/plugins/plugins.go @@ -20,6 +20,7 @@ import ( "errors" "runtime/debug" + capi "github.com/envoyproxy/envoy/contrib/golang/common/go/api" "mosn.io/htnn/api/internal/proto" "mosn.io/htnn/api/pkg/filtermanager/api" "mosn.io/htnn/api/pkg/log" @@ -31,6 +32,7 @@ var ( pluginTypes = map[string]Plugin{} plugins = map[string]Plugin{} httpFilterFactoryAndParser = map[string]*FilterFactoryAndParser{} + metricsRegister = map[string]func(capi.ConfigCallbacks){} ) // Here we introduce extra struct to avoid cyclic import between pkg/filtermanager and pkg/plugins @@ -188,6 +190,14 @@ func (cp *PluginConfigParser) Parse(any interface{}) (res interface{}, err error return conf, nil } +func RegisterMetricsCallback(pluginName string, registerMetricFunc func(capi.ConfigCallbacks)) { + metricsRegister[pluginName] = registerMetricFunc +} + +func LoadMetricsCallback(pluginName string) func(capi.ConfigCallbacks) { + return metricsRegister[pluginName] +} + // PluginMethodDefaultImpl provides reasonable implementation for optional methods type PluginMethodDefaultImpl struct{}