Skip to content

Commit

Permalink
support expose metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
wonderflow committed Dec 18, 2024
1 parent bde6f6f commit b77ff78
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/pkg/filtermanager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
10 changes: 10 additions & 0 deletions api/pkg/plugins/plugins.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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{}

Expand Down

0 comments on commit b77ff78

Please sign in to comment.