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

Commit

Permalink
Fix #403: Change to checking to see if a metric's policy has any rule…
Browse files Browse the repository at this point in the history
…s before processing config
  • Loading branch information
geauxvirtual committed Oct 13, 2015
1 parent 544d1d6 commit 2d36075
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion control/control.go
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,10 @@ func (p *pluginControl) validateMetricTypeSubscription(mt core.RequestedMetric,
}
m.config = cd

if m.policy != nil {
// When a metric is added to the MetricCatalog, the policy of rules defined by the plugin is added to the metric's policy.
// If no rules are defined for a metric, we set the metric's policy to an empty ConfigPolicyNode.
// Checking m.policy for nil will not work, we need to check if rules are nil.
if m.policy.HasRules() {
if m.Config() == nil {
perrs = append(perrs, perror.New(errors.New(fmt.Sprintf("Policy defined for metric, (%s) version (%d), but no config defined in manifest", mt.Namespace(), mt.Version()))))
return nil, perrs
Expand Down
1 change: 1 addition & 0 deletions control/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type metricType struct {

type processesConfigData interface {
Process(map[string]ctypes.ConfigValue) (*map[string]ctypes.ConfigValue, *cpolicy.ProcessingErrors)
HasRules() bool
}

func newMetricType(ns []string, last time.Time, plugin *loadedPlugin) *metricType {
Expand Down
7 changes: 7 additions & 0 deletions control/plugin/cpolicy/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@ func (p *ConfigPolicyNode) RulesAsTable() []RuleTable {
return rt
}

func (c *ConfigPolicyNode) HasRules() bool {
if len(c.rules) > 0 {
return true
}
return false
}

// Validates and returns a processed policy node or nil and error if validation has failed
func (c *ConfigPolicyNode) Process(m map[string]ctypes.ConfigValue) (*map[string]ctypes.ConfigValue, *ProcessingErrors) {
c.mutex.Lock()
Expand Down

0 comments on commit 2d36075

Please sign in to comment.