diff --git a/control/control.go b/control/control.go index da6e95ec3..fbedc67be 100644 --- a/control/control.go +++ b/control/control.go @@ -110,7 +110,7 @@ type managesPlugins interface { type catalogsMetrics interface { Get([]string, int) (*metricType, error) Add(*metricType) - AddLoadedMetricType(*loadedPlugin, core.Metric) + AddLoadedMetricType(*loadedPlugin, core.Metric) error RmUnloadedPluginMetrics(lp *loadedPlugin) GetVersions([]string) ([]*metricType, error) Fetch([]string) ([]*metricType, error) diff --git a/control/control_test.go b/control/control_test.go index 1e83f2de0..723553a7e 100644 --- a/control/control_test.go +++ b/control/control_test.go @@ -647,7 +647,8 @@ func (m *mc) Next() bool { return false } -func (m *mc) AddLoadedMetricType(*loadedPlugin, core.Metric) { +func (m *mc) AddLoadedMetricType(*loadedPlugin, core.Metric) error { + return nil } diff --git a/control/metrics.go b/control/metrics.go index 3d0214813..2c3b3c458 100644 --- a/control/metrics.go +++ b/control/metrics.go @@ -176,9 +176,16 @@ func newMetricCatalog() *metricCatalog { } } -func (mc *metricCatalog) AddLoadedMetricType(lp *loadedPlugin, mt core.Metric) { +func (mc *metricCatalog) AddLoadedMetricType(lp *loadedPlugin, mt core.Metric) error { if lp.ConfigPolicy == nil { - panic("NO") + err := errors.New("Config policy is nil") + log.WithFields(log.Fields{ + "_module": "control", + "_file": "metrics.go,", + "_block": "add-loaded-metric-type", + "error": err, + }).Error("error adding loaded metric type") + return err } newMt := metricType{ @@ -191,6 +198,7 @@ func (mc *metricCatalog) AddLoadedMetricType(lp *loadedPlugin, mt core.Metric) { policy: lp.ConfigPolicy.Get(mt.Namespace()), } mc.Add(&newMt) + return nil } func (mc *metricCatalog) RmUnloadedPluginMetrics(lp *loadedPlugin) { diff --git a/control/plugin_manager.go b/control/plugin_manager.go index 908f85bd5..20d0ddd1b 100644 --- a/control/plugin_manager.go +++ b/control/plugin_manager.go @@ -400,7 +400,19 @@ func (p *pluginManager) LoadPlugin(details *pluginDetails, emitter gomit.Emitter }).Error("received metric with bad version") return nil, serror.New(err) } - p.metricCatalog.AddLoadedMetricType(lPlugin, nmt) + if err := p.metricCatalog.AddLoadedMetricType(lPlugin, nmt); err != nil { + pmLogger.WithFields(log.Fields{ + "_block": "load-plugin", + "plugin-name": resp.Meta.Name, + "plugin-version": resp.Meta.Version, + "plugin-type": resp.Meta.Type.String(), + "plugin-path": filepath.Base(lPlugin.Details.ExecPath), + "metric-namespace": nmt.Namespace(), + "metric-version": nmt.Version(), + "error": err.Error(), + }).Error("error adding loaded metric type") + return nil, serror.New(err) + } } }