Skip to content
This repository has been archived by the owner on Nov 8, 2022. It is now read-only.

Commit

Permalink
Fixes #733: Removed panic from control/metric.go
Browse files Browse the repository at this point in the history
  • Loading branch information
tiffanyfay committed Feb 25, 2016
1 parent c027304 commit cf857f5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion control/control_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

}

Expand Down
12 changes: 10 additions & 2 deletions control/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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) {
Expand Down
14 changes: 13 additions & 1 deletion control/plugin_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down

0 comments on commit cf857f5

Please sign in to comment.