diff --git a/control/plugin/collector_proxy_test.go b/control/plugin/collector_proxy_test.go index b4830fd8f..d549d934c 100644 --- a/control/plugin/collector_proxy_test.go +++ b/control/plugin/collector_proxy_test.go @@ -74,7 +74,6 @@ func (p *mockPlugin) GetConfigPolicy() (*cpolicy.ConfigPolicy, error) { cpn.Add(r1, r2, r3, r4, r5, r6) ns := []string{"one", "two", "potato"} cp.Add(ns, cpn) - cp.Freeze() return cp, nil } diff --git a/control/plugin/cpolicy/tree.go b/control/plugin/cpolicy/tree.go index 4a51e34da..ca925400d 100644 --- a/control/plugin/cpolicy/tree.go +++ b/control/plugin/cpolicy/tree.go @@ -126,10 +126,6 @@ func (c *ConfigPolicy) Add(ns []string, cpn *ConfigPolicyNode) { // Returns a ConfigPolicyNode that is a merged version of the namespace provided. func (c *ConfigPolicy) Get(ns []string) *ConfigPolicyNode { - // Automatically freeze on first Get - if !c.config.Frozen() { - c.config.Freeze() - } n := c.config.Get(ns) if n == nil { @@ -140,28 +136,23 @@ func (c *ConfigPolicy) Get(ns []string) *ConfigPolicyNode { return &t default: return t.(*ConfigPolicyNode) - } } -func (c *ConfigPolicy) GetAll() map[string]*ConfigPolicyNode { - // Automatically freeze on first Get - if !c.config.Frozen() { - c.config.Freeze() - } +type keyNode struct { + Key []string + Node *ConfigPolicyNode +} - ret := map[string]*ConfigPolicyNode{} - for key, node := range c.config.GetAll() { - switch t := node.(type) { +func (c *ConfigPolicy) GetAll() []keyNode { + + ret := make([]keyNode, 0) + for _, node := range c.config.GetAll() { + key := node.Key + switch t := node.N.(type) { case *ConfigPolicyNode: - ret[key] = t + ret = append(ret, keyNode{Key: key, Node: t}) } } return ret } - -// Freezes the ConfigPolicy from future writes (adds) and triggers compression -// of tree into read-performant version. -func (c *ConfigPolicy) Freeze() { - c.config.Freeze() -} diff --git a/control/plugin/cpolicy/tree_test.go b/control/plugin/cpolicy/tree_test.go index 904c00d99..4b4ad778a 100644 --- a/control/plugin/cpolicy/tree_test.go +++ b/control/plugin/cpolicy/tree_test.go @@ -45,7 +45,6 @@ func TestConfigPolicy(t *testing.T) { ns := []string{"one", "two", "potato"} cp.Add(ns, cpn) - cp.Freeze() Convey("retrieves store policy", func() { gc := cp.Get(ns) So(gc.rules["username"].Required(), ShouldEqual, false) diff --git a/control/plugin/rpc/plugin.go b/control/plugin/rpc/plugin.go index 1d0491494..ba33bbc96 100644 --- a/control/plugin/rpc/plugin.go +++ b/control/plugin/rpc/plugin.go @@ -24,8 +24,10 @@ func NewGetConfigPolicyReply(policy *cpolicy.ConfigPolicy) (*GetConfigPolicyRepl StringPolicy: map[string]*StringPolicy{}, } - for key, node := range policy.GetAll() { - for _, rule := range node.RulesAsTable() { + for _, node := range policy.GetAll() { + key := strings.Join(node.Key, ".") + + for _, rule := range node.Node.RulesAsTable() { switch rule.Type { case cpolicy.BoolType: r := &BoolRule{ @@ -35,7 +37,10 @@ func NewGetConfigPolicyReply(policy *cpolicy.ConfigPolicy) (*GetConfigPolicyRepl r.Default = rule.Default.(ctypes.ConfigValueBool).Value } if ret.BoolPolicy[key] == nil { - ret.BoolPolicy[key] = &BoolPolicy{Rules: map[string]*BoolRule{}} + ret.BoolPolicy[key] = &BoolPolicy{ + Rules: map[string]*BoolRule{}, + Key: node.Key, + } } ret.BoolPolicy[key].Rules[rule.Name] = r case cpolicy.StringType: @@ -46,7 +51,10 @@ func NewGetConfigPolicyReply(policy *cpolicy.ConfigPolicy) (*GetConfigPolicyRepl r.Default = rule.Default.(ctypes.ConfigValueStr).Value } if ret.StringPolicy[key] == nil { - ret.StringPolicy[key] = &StringPolicy{Rules: map[string]*StringRule{}} + ret.StringPolicy[key] = &StringPolicy{ + Rules: map[string]*StringRule{}, + Key: node.Key, + } } ret.StringPolicy[key].Rules[rule.Name] = r case cpolicy.IntegerType: @@ -63,7 +71,10 @@ func NewGetConfigPolicyReply(policy *cpolicy.ConfigPolicy) (*GetConfigPolicyRepl r.Minimum = int64(rule.Minimum.(ctypes.ConfigValueInt).Value) } if ret.IntegerPolicy[key] == nil { - ret.IntegerPolicy[key] = &IntegerPolicy{Rules: map[string]*IntegerRule{}} + ret.IntegerPolicy[key] = &IntegerPolicy{ + Rules: map[string]*IntegerRule{}, + Key: node.Key, + } } ret.IntegerPolicy[key].Rules[rule.Name] = r case cpolicy.FloatType: @@ -80,7 +91,10 @@ func NewGetConfigPolicyReply(policy *cpolicy.ConfigPolicy) (*GetConfigPolicyRepl r.Minimum = rule.Minimum.(ctypes.ConfigValueFloat).Value } if ret.FloatPolicy[key] == nil { - ret.FloatPolicy[key] = &FloatPolicy{Rules: map[string]*FloatRule{}} + ret.FloatPolicy[key] = &FloatPolicy{ + Rules: map[string]*FloatRule{}, + Key: node.Key, + } } ret.FloatPolicy[key].Rules[rule.Name] = r } @@ -191,7 +205,20 @@ func ToConfigPolicy(reply *GetConfigPolicyReply) *cpolicy.ConfigPolicy { } for key, node := range nodes { - keys := strings.Split(key, ".") + var keys []string + // if the []string is present, use it. + // if not, fall back to dot separated key + if val, ok := reply.BoolPolicy[key]; ok && val != nil && val.Key != nil { + keys = val.Key + } else if val, ok := reply.StringPolicy[key]; ok && val != nil && val.Key != nil { + keys = val.Key + } else if val, ok := reply.FloatPolicy[key]; ok && val != nil && val.Key != nil { + keys = val.Key + } else if val, ok := reply.IntegerPolicy[key]; ok && val != nil && val.Key != nil { + keys = val.Key + } else { + keys = strings.Split(key, ".") + } result.Add(keys, node) } diff --git a/control/plugin/rpc/plugin.pb.go b/control/plugin/rpc/plugin.pb.go index 8606f029f..229ef80ef 100644 --- a/control/plugin/rpc/plugin.pb.go +++ b/control/plugin/rpc/plugin.pb.go @@ -528,6 +528,7 @@ func (*BoolRule) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{9} type BoolPolicy struct { Rules map[string]*BoolRule `protobuf:"bytes,1,rep,name=rules" json:"rules,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + Key []string `protobuf:"bytes,2,rep,name=key" json:"key,omitempty"` } func (m *BoolPolicy) Reset() { *m = BoolPolicy{} } @@ -559,6 +560,7 @@ func (*FloatRule) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{1 type FloatPolicy struct { Rules map[string]*FloatRule `protobuf:"bytes,1,rep,name=rules" json:"rules,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + Key []string `protobuf:"bytes,2,rep,name=key" json:"key,omitempty"` } func (m *FloatPolicy) Reset() { *m = FloatPolicy{} } @@ -590,6 +592,7 @@ func (*IntegerRule) Descriptor() ([]byte, []int) { return fileDescriptor0, []int type IntegerPolicy struct { Rules map[string]*IntegerRule `protobuf:"bytes,1,rep,name=rules" json:"rules,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + Key []string `protobuf:"bytes,2,rep,name=key" json:"key,omitempty"` } func (m *IntegerPolicy) Reset() { *m = IntegerPolicy{} } @@ -617,6 +620,7 @@ func (*StringRule) Descriptor() ([]byte, []int) { return fileDescriptor0, []int{ type StringPolicy struct { Rules map[string]*StringRule `protobuf:"bytes,1,rep,name=rules" json:"rules,omitempty" protobuf_key:"bytes,1,opt,name=key" protobuf_val:"bytes,2,opt,name=value"` + Key []string `protobuf:"bytes,2,rep,name=key" json:"key,omitempty"` } func (m *StringPolicy) Reset() { *m = StringPolicy{} } @@ -1238,90 +1242,90 @@ func init() { } var fileDescriptor0 = []byte{ - // 1345 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xcc, 0x58, 0xdb, 0x6e, 0x13, 0x47, - 0x18, 0xf6, 0x66, 0x7d, 0xda, 0x7f, 0x1d, 0x27, 0x19, 0x51, 0xea, 0x1a, 0x10, 0x66, 0x29, 0x60, - 0x0a, 0x75, 0x5a, 0x87, 0x52, 0x08, 0xed, 0x05, 0x94, 0x94, 0x00, 0x0d, 0xb2, 0x96, 0x94, 0x9b, - 0x4a, 0x45, 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23, 0x41, 0x62, 0xb9, 0xf6, 0x60, 0xea, - 0xe2, 0xfc, 0x9c, 0xab, 0x61, 0x8a, 0x50, 0x31, 0xf2, 0x42, 0xec, 0xfc, 0x00, 0xd0, 0x1b, 0xf5, - 0x7b, 0x34, 0xf6, 0x1f, 0xd2, 0x21, 0xba, 0x06, 0x95, 0x03, 0xcc, 0x28, 0xf1, 0xd3, 0x86, 0xd1, - 0x32, 0xdb, 0x76, 0xd7, 0xee, 0xd0, 0xc4, 0xef, 0x48, 0x9f, 0x5b, 0x09, 0x65, 0x0c, 0x5d, 0x87, - 0xf2, 0x37, 0x71, 0x74, 0x44, 0x86, 0xe2, 0x57, 0xec, 0x6e, 0x5d, 0x64, 0x49, 0xd7, 0x81, 0x97, - 0xb8, 0x65, 0x5f, 0x0c, 0x9d, 0x7f, 0x8b, 0x50, 0x96, 0x58, 0xb4, 0x03, 0xd6, 0xa4, 0x0e, 0xc5, - 0xfd, 0x81, 0x40, 0xcd, 0x56, 0xe7, 0x5a, 0x51, 0xe6, 0x41, 0x0d, 0xa8, 0xbc, 0xc2, 0x34, 0xcd, - 0xca, 0x31, 0xdd, 0xca, 0x89, 0x34, 0xb5, 0x19, 0x98, 0x6f, 0x9b, 0x01, 0xba, 0x0f, 0xe8, 0x3b, - 0x2f, 0x65, 0x0f, 0x07, 0x27, 0x98, 0x32, 0x92, 0xe2, 0x01, 0x97, 0xbe, 0x51, 0x14, 0x18, 0x4b, - 0x60, 0xb8, 0xc3, 0x45, 0xc1, 0x5c, 0x12, 0xba, 0x09, 0xc5, 0x43, 0x6f, 0x98, 0x36, 0x4a, 0xda, - 0x64, 0x65, 0x31, 0x1d, 0xee, 0xdf, 0x8b, 0x18, 0x1d, 0xbb, 0x45, 0xe6, 0x0d, 0x53, 0x74, 0x03, - 0x2c, 0x0e, 0x49, 0x99, 0x17, 0x26, 0x8d, 0xf2, 0x2c, 0xb9, 0xc5, 0xb2, 0x18, 0x5f, 0x81, 0xef, - 0x23, 0xc2, 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25, 0xec, 0xfc, 0x17, 0x00, 0x00, 0xff, 0xff, 0x25, 0xb7, 0x84, 0x93, 0x88, 0x10, 0x00, - 0x00, + // 1356 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xcc, 0x58, 0xdb, 0x6e, 0x1b, 0x45, + 0x18, 0xf6, 0x66, 0x7d, 0xda, 0x7f, 0x1d, 0x27, 0x19, 0x95, 0x62, 0xdc, 0x56, 0x75, 0xb7, 0xb4, + 0x75, 0x69, 0x71, 0xc0, 0x29, 0xa5, 0x4d, 0xe1, 0xa2, 0xa5, 0xa1, 0x69, 0x4b, 0x2a, 0x6b, 0x1b, + 0x7a, 0x83, 0x44, 0xb5, 0x5e, 0x4f, 0x9c, 0x11, 0x7b, 0x62, 0x76, 0x5c, 0xc5, 0xaf, 0xc0, 0x1b, + 0x20, 0x21, 0x21, 0xf1, 0x18, 0x5c, 0x71, 0xc1, 0x05, 0xe2, 0x25, 0x78, 0x09, 0x1e, 0x00, 0xcd, + 0x61, 0xed, 0x59, 0x1f, 0xea, 0xe4, 0x02, 0xa9, 0x77, 0xfb, 0x1f, 0xbe, 0x6f, 0xe6, 0xff, 0xe6, + 0x9f, 0x19, 0x8f, 0x61, 0x77, 0x48, 0xd8, 0xf1, 0xa8, 0xdf, 0xf1, 0xe3, 0x70, 0x9b, 0x44, 0x0c, + 0x07, 0xe9, 0x80, 0x7c, 0x7c, 0xb2, 0x9d, 0x46, 0x5e, 0xb2, 0xed, 0xc7, 0x11, 0xa3, 0x71, 0xb0, + 0x9d, 0x04, 0xa3, 0x21, 0x89, 0xb6, 0x69, 0xe2, 0xab, 0xcf, 0x4e, 0x42, 0x63, 0x16, 0x23, 0x93, + 0x26, 0xbe, 0x53, 0x81, 0xd2, 0x5e, 0x98, 0xb0, 0xb1, 0xd3, 0x82, 0xea, 0x1e, 0xa5, 0x2e, 0x4e, + 0x82, 0x31, 0x3a, 0x07, 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 0x7c, 0xdb, 0x0c, 0xd0, 0x7d, + 0x40, 0xdf, 0x78, 0x29, 0x7b, 0x38, 0x78, 0x83, 0x29, 0x23, 0x29, 0x1e, 0x70, 0xe9, 0x1b, 0x45, + 0x81, 0xb1, 0x04, 0x86, 0x3b, 0x5c, 0x14, 0xcc, 0x25, 0xa1, 0x9b, 0x50, 0x3c, 0xf4, 0x86, 0x69, + 0xa3, 0xa4, 0x4d, 0x56, 0x16, 0xd3, 0xe1, 0xfe, 0xbd, 0x88, 0xd1, 0xb1, 0x5b, 0x64, 0xde, 0x30, + 0x45, 0x37, 0xc0, 0xe2, 0x90, 0x94, 0x79, 0x61, 0xd2, 0x28, 0xcf, 0x92, 0x5b, 0x2c, 0x8b, 0xf1, + 0x15, 0xf8, 0x36, 0x22, 0xac, 0x51, 0x91, 0x2b, 0x30, 0x8a, 0x08, 0x9b, 0x5d, 0xb7, 0xea, 0xfc, + 0xba, 0x5d, 0x01, 0x3b, 0x65, 0x94, 0x44, 0xc3, 0xd7, 0x03, 0x8f, 0x79, 0x0d, 0x8b, 0x67, 0xec, + 0x17, 0x5c, 0x90, 0xce, 0xc7, 0x1e, 0xf3, 0xd0, 0x55, 0xa8, 0x1d, 0x05, 0xb1, 0xc7, 0x76, 0xba, + 0x32, 0x07, 0x5a, 0x46, 0x7b, 0x6d, 0xbf, 0xe0, 0xda, 0xca, 0x9b, 0x4b, 0xba, 0x7b, 0x47, 0x26, + 0xd9, 0x2d, 0xa3, 0x6d, 0x4c, 0x92, 0xee, 0xde, 0x11, 0x49, 0x97, 0x01, 0x48, 0x34, 0xe1, 0xa9, + 0xb5, 0x8c, 0x76, 0x69, 0xbf, 0xe0, 0x5a, 0xc2, 0xa7, 0x25, 0x64, 0x1c, 0xeb, 0x7c, 0x5d, 0x54, + 0xc2, 0x94, 0xa1, 0x3f, 0x66, 0x38, 0x95, 0x09, 0xf5, 0x96, 0xd1, 0xae, 0xf1, 0x04, 0xe1, 0x13, + 0x09, 0x97, 0xc0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0x69, 0x1c, 0x29, 0x64, 0x99, 0x0a, + 0xcb, 0xf9, 0xbd, 0x04, 0xe7, 0x9e, 0x60, 0x26, 0xb5, 0xeb, 0xc5, 0x01, 0xf1, 0xc7, 0x6f, 0x39, + 0x95, 0xd1, 0x33, 0xb0, 0x45, 0x4f, 0x26, 0x22, 0x53, 0xad, 0xf9, 0x4d, 0x21, 0xff, 0x22, 0x16, + 0xb1, 0x12, 0xd2, 0x96, 0x8b, 0x01, 0xfd, 0x89, 0x03, 0x1d, 0xa8, 0x7d, 0x96, 0x91, 0xc9, 0x26, + 0xf8, 0x68, 0x39, 0x99, 0x10, 0x51, 0x67, 0x93, 0x3b, 0x52, 0xd1, 0xbd, 0x84, 0x3a, 0xbf, 0x93, + 0x86, 0x98, 0x66, 0x84, 0xb2, 0x39, 0x6e, 0x2f, 0x27, 0x7c, 0x2a, 0xf3, 0x75, 0xca, 0x75, 0xa2, + 0xfb, 0x50, 0x0f, 0xd6, 0xd5, 0x99, 0xa2, 0x38, 0xe5, 0x31, 0x77, 0x6b, 0x39, 0xa7, 0xec, 0x13, + 0x9d, 0xb2, 0x96, 0x6a, 0xae, 0xe6, 0x0b, 0xd8, 0x98, 0x11, 0x65, 0xc1, 0x92, 0x5e, 0xd3, 0x97, + 0xd4, 0xee, 0x6e, 0x88, 0xe1, 0xa6, 0x30, 0xbd, 0x3f, 0x7a, 0xb0, 0x39, 0xab, 0xcb, 0x02, 0xc2, + 0xeb, 0x79, 0xc2, 0x4d, 0x41, 0xa8, 0xe1, 0x74, 0xc6, 0x43, 0x40, 0xf3, 0xc2, 0x2c, 0xe0, 0x6c, + 0xe7, 0x39, 0x91, 0xe0, 0xcc, 0x21, 0x75, 0x56, 0x17, 0xb6, 0xe6, 0xa4, 0x59, 0x40, 0x7a, 0x23, + 0x4f, 0xba, 0x25, 0x48, 0x75, 0xa0, 0xde, 0xdf, 0x1e, 0x54, 0xb9, 0x28, 0xee, 0x28, 0xc0, 0xa8, + 0x09, 0x55, 0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0, + 0x4e, 0x01, 0x5d, 0x83, 0x22, 0xff, 0xa9, 0x84, 0x6a, 0x22, 0xa0, 0x7e, 0x35, 0xcd, 0xa7, 0xed, + 0xc2, 0xc6, 0xcc, 0xad, 0x9f, 0xa3, 0xfd, 0x60, 0xe9, 0xef, 0x02, 0xa7, 0xd0, 0xfd, 0xd3, 0x00, + 0x8b, 0xbf, 0x20, 0x71, 0x9a, 0xc6, 0x14, 0x6d, 0x43, 0x45, 0x19, 0x4a, 0x85, 0xe9, 0xfb, 0xf2, + 0xdd, 0x2e, 0xe3, 0x0f, 0x5e, 0xc6, 0xa8, 0x1f, 0x90, 0xf4, 0x18, 0x53, 0x74, 0x0b, 0x2a, 0xca, + 0x98, 0x2f, 0x63, 0x6e, 0xd8, 0x77, 0xa4, 0x84, 0x7e, 0x59, 0xfc, 0x25, 0xb1, 0xf3, 0x5f, 0x00, + 0x00, 0x00, 0xff, 0xff, 0x51, 0xb5, 0x89, 0x63, 0xd0, 0x10, 0x00, 0x00, } diff --git a/control/plugin/rpc/plugin.proto b/control/plugin/rpc/plugin.proto index c6f3e3033..5b5b7fe2b 100644 --- a/control/plugin/rpc/plugin.proto +++ b/control/plugin/rpc/plugin.proto @@ -46,56 +46,56 @@ message Empty{ } message ErrReply { - string error = 1; + string error = 1; } message Time{ - int64 sec = 1; - int64 nsec = 2; + int64 sec = 1; + int64 nsec = 2; } message NamespaceElement { - string Value = 1; - string Description = 2; - string Name = 3; + string Value = 1; + string Description = 2; + string Name = 3; } message PubProcArg { - repeated Metric Metrics = 1; - ConfigMap Config = 2; + repeated Metric Metrics = 1; + ConfigMap Config = 2; } // core.Metric message Metric { - repeated NamespaceElement Namespace = 1; - int64 Version = 2; - ConfigMap Config = 3; - Time LastAdvertisedTime = 4; - map Tags = 5; - Time Timestamp = 6; - string Unit = 7; - string Description = 8; - oneof data { - string string_data = 9; - float float32_data = 10; - double float64_data = 11; - int32 int32_data = 12; - int64 int64_data = 13; - bytes bytes_data = 14; - bool bool_data = 15; - } + repeated NamespaceElement Namespace = 1; + int64 Version = 2; + ConfigMap Config = 3; + Time LastAdvertisedTime = 4; + map Tags = 5; + Time Timestamp = 6; + string Unit = 7; + string Description = 8; + oneof data { + string string_data = 9; + float float32_data = 10; + double float64_data = 11; + int32 int32_data = 12; + int64 int64_data = 13; + bytes bytes_data = 14; + bool bool_data = 15; + } } message ConfigMap { - map IntMap = 1; - map StringMap = 2; - // double is float64 - map FloatMap = 3; - map BoolMap = 4; + map IntMap = 1; + map StringMap = 2; + // double is float64 + map FloatMap = 3; + map BoolMap = 4; } message KillArg { - string Reason = 1; + string Reason = 1; } message GetConfigPolicyReply { @@ -109,11 +109,12 @@ message GetConfigPolicyReply { message BoolRule { bool required = 1; bool default = 2; - bool has_default = 3; + bool has_default = 3; } message BoolPolicy { map rules = 1; + repeated string key = 2; } message FloatRule { @@ -121,13 +122,14 @@ message FloatRule { double minimum = 2; double maximum = 3; double default = 4; - bool has_default = 5; - bool has_min = 6; - bool has_max = 7; + bool has_default = 5; + bool has_min = 6; + bool has_max = 7; } message FloatPolicy { map rules = 1; + repeated string key = 2; } message IntegerRule { @@ -135,23 +137,25 @@ message IntegerRule { int64 minimum = 2; int64 maximum = 3; int64 default = 4; - bool has_default = 5; - bool has_min = 6; - bool has_max = 7; + bool has_default = 5; + bool has_min = 6; + bool has_max = 7; } message IntegerPolicy { map rules = 1; + repeated string key = 2; } message StringRule { bool required = 1; string default = 2; - bool has_default = 3; + bool has_default = 3; } message StringPolicy { map rules = 1; + repeated string key = 2; } message MetricsArg { diff --git a/control/plugin_manager.go b/control/plugin_manager.go index 4981e2d60..1ec6092d3 100644 --- a/control/plugin_manager.go +++ b/control/plugin_manager.go @@ -362,8 +362,8 @@ func (p *pluginManager) LoadPlugin(details *pluginDetails, emitter gomit.Emitter if lPlugin.ConfigPolicy != nil { // Get plugin config defaults defaults := cdata.NewNode() - cpolicies := lPlugin.ConfigPolicy.GetAll() - for _, cpolicy := range cpolicies { + for _, kn := range lPlugin.ConfigPolicy.GetAll() { + cpolicy := kn.Node _, errs := cpolicy.AddDefaults(defaults.Table()) if len(errs.Errors()) > 0 { for _, err := range errs.Errors() { diff --git a/core/cdata/tree.go b/core/cdata/tree.go index 852beaf40..b9d656b6f 100644 --- a/core/cdata/tree.go +++ b/core/cdata/tree.go @@ -61,11 +61,6 @@ func (c *ConfigDataTree) Add(ns []string, cdn *ConfigDataNode) { // Returns a ConfigDataNode that is a merged version of the namespace provided. func (c *ConfigDataTree) Get(ns []string) *ConfigDataNode { - // Automatically freeze on first Get - if !c.cTree.Frozen() { - c.cTree.Freeze() - } - n := c.cTree.Get(ns) if n == nil { return nil @@ -78,9 +73,3 @@ func (c *ConfigDataTree) Get(ns []string) *ConfigDataNode { } } - -// Freezes the ConfigDataTree from future writes (adds) and triggers compression -// of tree into read-performant version. -func (c *ConfigDataTree) Freeze() { - c.cTree.Freeze() -} diff --git a/core/cdata/tree_test.go b/core/cdata/tree_test.go index e9b49c158..f1bc55175 100644 --- a/core/cdata/tree_test.go +++ b/core/cdata/tree_test.go @@ -51,9 +51,6 @@ func TestConfigDataTree(t *testing.T) { cdt.Add([]string{"1"}, cd1) cdt.Add([]string{"1", "2"}, cd2) - So(func() { - cdt.Freeze() - }, ShouldNotPanic) }) Convey("get", func() { diff --git a/pkg/ctree/tree.go b/pkg/ctree/tree.go index a81b33772..94e9c7b14 100644 --- a/pkg/ctree/tree.go +++ b/pkg/ctree/tree.go @@ -24,7 +24,6 @@ import ( "encoding/gob" "encoding/json" "fmt" - "strings" log "github.com/Sirupsen/logrus" ) @@ -33,9 +32,7 @@ import ( type ConfigTree struct { // Debug turns on verbose logging of the tree functions to stdout Debug bool - - freezeFlag bool - root *node + root *node } // New returns a new instance of ConfigTree @@ -62,9 +59,6 @@ func (c *ConfigTree) GobEncode() ([]byte, error) { if err := encoder.Encode(c.root); err != nil { return nil, err } - if err := encoder.Encode(c.freezeFlag); err != nil { - return nil, err - } return w.Bytes(), nil } @@ -75,7 +69,7 @@ func (c *ConfigTree) GobDecode(buf []byte) error { if err := decoder.Decode(&c.root); err != nil { return err } - return decoder.Decode(&c.freezeFlag) + return nil } // MarshalJSON marshals ConfigTree @@ -120,41 +114,44 @@ func (c *ConfigTree) Add(ns []string, inNode Node) { } -func (c *ConfigTree) GetAll() map[string]Node { - ret := map[string]Node{} - if !c.Frozen() { - panic("must freeze before getting") - } +type keyNode struct { + Key []string + N Node +} + +func (c *ConfigTree) GetAll() []keyNode { + var ret []keyNode if c.root == nil { c.log(fmt.Sprintln("ctree: no root - returning nil")) return nil } - return c.getAll(c.root, "", ret) + return c.getAll(c.root, []string{}, &ret) } -func (c *ConfigTree) getAll(node *node, base string, results map[string]Node) map[string]Node { +func (c *ConfigTree) getAll(node *node, key []string, res *[]keyNode) []keyNode { if len(node.keys) > 0 { - if base != "" { - base = base + "." + strings.Join(node.keys, ".") + if key != nil { + key = append(key, node.keys[0]) } else { - base = strings.Join(node.keys, ".") + key = []string{node.keys[0]} } if node.Node != nil { - results[base] = node.Node + k := keyNode{ + Key: key, + N: node.Node, + } + *res = append(*res, k) } } for _, child := range node.nodes { - c.getAll(child, base, results) + c.getAll(child, key, res) } - return results + return *res } // Get returns a tree node given the namespace func (c *ConfigTree) Get(ns []string) Node { c.log(fmt.Sprintf("Get on ns (%s)\n", ns)) - if !c.Frozen() { - panic("must freeze before getting") - } retNodes := new([]Node) // Return if no root exists (no tree without a root) if c.root == nil { @@ -205,25 +202,6 @@ func (c *ConfigTree) Get(ns []string) Node { return rn } -// Freeze sets the ConfigTree's freezeFlag to true -func (c *ConfigTree) Freeze() { - if !c.freezeFlag { - c.freezeFlag = true - c.compact() - } -} - -// Frozen returns the bool value of ConfigTree freezeFlag -func (c *ConfigTree) Frozen() bool { - return c.freezeFlag -} - -func (c *ConfigTree) compact() { - if c.root != nil { - c.root.compact() - } -} - // Print prints out the ConfigTree func (c *ConfigTree) Print() { c.root.print("") diff --git a/pkg/ctree/tree_test.go b/pkg/ctree/tree_test.go index 6d8e37477..54ed887a6 100644 --- a/pkg/ctree/tree_test.go +++ b/pkg/ctree/tree_test.go @@ -84,7 +84,6 @@ func TestConfigTree(t *testing.T) { c.Add([]string{"intel", "sdilabs", "joel", "dan", "nick", "justin", "sarah"}, newMockNode()) c.Add([]string{"intel", "sdilabs", "joel", "dan"}, newMockNode()) c.Add([]string{"intel", "manhole", "joel", "dan"}, newMockNode()) - c.Freeze() results := c.GetAll() So(results, ShouldNotBeNil) So(len(results), ShouldEqual, 3) @@ -105,7 +104,6 @@ func TestConfigTree(t *testing.T) { c.Add([]string{"intel", "foo", "sdilabs", "joel", "dan"}, d2) c.Add([]string{"intel", "foo", "manhole", "joel", "dan"}, d3) c.Add([]string{"intel", "foo", "manhole", "joel", "dan", "mark"}, d4) - c.Freeze() c.Print() g := c.Get([]string{"intel", "foo", "sdilabs", "joel", "dan", "nick", "justin", "sarah"}) So(g, ShouldNotBeNil) @@ -132,7 +130,6 @@ func TestConfigTree(t *testing.T) { d1.data = "a" c := New() c.Add([]string{"1"}, d1) - c.Freeze() g := c.Get([]string{"1"}) So(g, ShouldNotBeNil) So(g.(*mockNode).data, ShouldResemble, "a") @@ -147,7 +144,6 @@ func TestConfigTree(t *testing.T) { c.Debug = true c.Add([]string{"1"}, d1) c.Add([]string{"1", "2"}, d2) - c.Freeze() g := c.Get([]string{"1", "2"}) So(g, ShouldNotBeNil) So(g.(mockNode).data, ShouldResemble, "a/b") @@ -155,7 +151,6 @@ func TestConfigTree(t *testing.T) { Convey("blank tree return nil", func() { c := New() - c.Freeze() n := c.Get([]string{"intel", "foo", "sdilabs", "joel", "dan", "nick", "justin", "sarah"}) So(n, ShouldBeNil) }) @@ -164,7 +159,6 @@ func TestConfigTree(t *testing.T) { d1 := newMockNode() d1.data = "a" c := New() - c.Freeze() c.Add([]string{"1"}, d1) n := c.Get([]string{"2"}) So(n, ShouldBeNil) @@ -176,7 +170,6 @@ func TestConfigTree(t *testing.T) { d1 := newMockNode() d1.data = "a" c.Add([]string{"intel"}, d1) - c.Freeze() n := c.Get([]string{"intel", "foo", "sdilabs", "joel", "dan", "nick", "justin", "sarah"}) So(n, ShouldNotBeNil) }) @@ -186,7 +179,6 @@ func TestConfigTree(t *testing.T) { d1 := newMockNode() d1.data = "a" c.Add([]string{"intel", "foo", "sdilabs", "joel", "dan", "nick", "justin", "sarah"}, d1) - c.Freeze() n := c.Get([]string{"intel"}) So(n, ShouldBeNil) }) @@ -199,7 +191,6 @@ func TestConfigTree(t *testing.T) { c := New() c.Add([]string{"intel", "foo", "sdilabs", "joel", "dan", "nick", "justin", "sarah"}, d1) c.Add([]string{"intel", "foo", "sdilabs", "joel", "dan"}, d2) - c.Freeze() g := c.Get([]string{"intel", "foo", "sdilabs", "joel", "dan", "nick", "justin", "sarah"}) So(g, ShouldNotBeNil) }) @@ -212,7 +203,6 @@ func TestConfigTree(t *testing.T) { c := New() c.Add([]string{"intel", "foo", "sdilabs", "joel", "dan", "nick", "justin", "sarah"}, d1) c.Add([]string{"intel", "foo", "sdilabs"}, d2) - c.Freeze() g := c.Get([]string{"intel", "foo", "sdilabs", "joel"}) So(g, ShouldNotBeNil) }) @@ -238,7 +228,6 @@ func TestConfigTree(t *testing.T) { c := New() c.Add([]string{"intel", "foo", "sdi-x", "cody"}, d1) c.Add([]string{"intel", "foo", "sdi-x", "nan"}, d2) - c.Freeze() So(func() { g := c.Get([]string{"intel", "foo", "sdi-x", "emily", "tiffany", "matt"}) So(g, ShouldBeNil) @@ -251,28 +240,9 @@ func TestConfigTree(t *testing.T) { c := New() So(func() { c.Add([]string{}, d1) - c.Freeze() g := c.Get([]string{}) So(g, ShouldBeNil) }, ShouldNotPanic) }) - - Convey("should panic on non frozen get", func() { - d1 := newMockNode() - d1.data = "a" - c := New() - So(func() { - c.Add([]string{}, d1) - g := c.Get([]string{}) - So(g, ShouldBeNil) - }, ShouldPanic) - }) }) - - Convey("Frozen()", t, func() { - c := New() - c.Freeze() - So(c.Frozen(), ShouldBeTrue) - }) - }