From 334b9ec0aebd89a1e1aac0f832970619b567a70a Mon Sep 17 00:00:00 2001 From: Jade McGough Date: Tue, 12 Mar 2019 17:05:37 -0700 Subject: [PATCH 1/3] remove unnecessary ID filtering logic --- inmem/label_service.go | 8 -------- label.go | 1 - 2 files changed, 9 deletions(-) diff --git a/inmem/label_service.go b/inmem/label_service.go index 1967cc9b0e..f64cbae73c 100644 --- a/inmem/label_service.go +++ b/inmem/label_service.go @@ -96,14 +96,6 @@ func (s *Service) FindLabelByID(ctx context.Context, id influxdb.ID) (*influxdb. // FindLabels will retrieve a list of labels from storage. func (s *Service) FindLabels(ctx context.Context, filter influxdb.LabelFilter, opt ...influxdb.FindOptions) ([]*influxdb.Label, error) { - if filter.ID.Valid() { - l, err := s.FindLabelByID(ctx, filter.ID) - if err != nil { - return nil, err - } - return []*influxdb.Label{l}, nil - } - filterFunc := func(label *influxdb.Label) bool { return (filter.Name == "" || (filter.Name == label.Name)) } diff --git a/label.go b/label.go index 4cfd7ff897..5b651a2a9b 100644 --- a/label.go +++ b/label.go @@ -104,7 +104,6 @@ type LabelUpdate struct { // LabelFilter represents a set of filters that restrict the returned results. type LabelFilter struct { - ID ID Name string } From 8da46143606f957f88950d634b87141daaa92c99 Mon Sep 17 00:00:00 2001 From: Jade McGough Date: Tue, 12 Mar 2019 17:05:53 -0700 Subject: [PATCH 2/3] remove dead label tests --- testing/label_service.go | 66 ---------------------------------------- 1 file changed, 66 deletions(-) diff --git a/testing/label_service.go b/testing/label_service.go index 8693665b8f..08cf12736e 100644 --- a/testing/label_service.go +++ b/testing/label_service.go @@ -130,34 +130,6 @@ func CreateLabel( }, }, }, - // { - // name: "duplicate labels fail", - // fields: LabelFields{ - // IDGenerator: mock.NewIDGenerator(labelTwoID, t), - // Labels: []*influxdb.Label{ - // { - // Name: "Tag1", - // }, - // }, - // }, - // args: args{ - // label: &influxdb.Label{ - // Name: "Tag1", - // }, - // }, - // wants: wants{ - // labels: []*influxdb.Label{ - // { - // Name: "Tag1", - // }, - // }, - // err: &influxdb.Error{ - // Code: influxdb.EConflict, - // Op: influxdb.OpCreateLabel, - // Msg: "label Tag1 already exists", - // }, - // }, - // }, } for _, tt := range tests { @@ -467,44 +439,6 @@ func UpdateLabel( }, }, }, - // { - // name: "label update proliferation", - // fields: LabelFields{ - // Labels: []*influxdb.Label{ - // { - // ResourceID: MustIDBase16(bucketOneID), - // Name: "Tag1", - // }, - // { - // ResourceID: MustIDBase16(bucketTwoID), - // Name: "Tag1", - // }, - // }, - // }, - // args: args{ - // label: influxdb.Label{ - // ResourceID: MustIDBase16(bucketOneID), - // Name: "Tag1", - // }, - // update: influxdb.LabelUpdate{ - // Color: &validColor, - // }, - // }, - // wants: wants{ - // labels: []*influxdb.Label{ - // { - // ResourceID: MustIDBase16(bucketOneID), - // Name: "Tag1", - // Color: "fff000", - // }, - // { - // ResourceID: MustIDBase16(bucketTwoID), - // Name: "Tag1", - // Color: "fff000", - // }, - // }, - // }, - // }, { name: "updating a non-existent label", fields: LabelFields{ From b2775ef9da673741dab00b06d9148bcf0fd0a8df Mon Sep 17 00:00:00 2001 From: Jade McGough Date: Tue, 12 Mar 2019 17:28:15 -0700 Subject: [PATCH 3/3] feat(labels): allow label names to be updated --- bolt/label.go | 4 ++++ http/swagger.yml | 2 ++ inmem/label_service.go | 6 +++++- kv/label.go | 6 +++++- label.go | 3 ++- testing/label_service.go | 25 +++++++++++++++++++++++++ 6 files changed, 43 insertions(+), 3 deletions(-) diff --git a/bolt/label.go b/bolt/label.go index f86504f391..a34ea39a8c 100644 --- a/bolt/label.go +++ b/bolt/label.go @@ -341,6 +341,10 @@ func (c *Client) updateLabel(ctx context.Context, tx *bolt.Tx, id influxdb.ID, u } } + if upd.Name != "" { + label.Name = upd.Name + } + if err := label.Validate(); err != nil { return nil, &influxdb.Error{ Code: influxdb.EInvalid, diff --git a/http/swagger.yml b/http/swagger.yml index 8882db38bb..d566c5a452 100644 --- a/http/swagger.yml +++ b/http/swagger.yml @@ -7712,6 +7712,8 @@ components: LabelUpdate: type: object properties: + name: + type: string properties: type: object description: Key/Value pairs associated with this label. Keys can be removed by sending an update with an empty value. diff --git a/inmem/label_service.go b/inmem/label_service.go index f64cbae73c..246f597309 100644 --- a/inmem/label_service.go +++ b/inmem/label_service.go @@ -164,7 +164,7 @@ func (s *Service) UpdateLabel(ctx context.Context, id influxdb.ID, upd influxdb. } } - if label.Properties == nil { + if len(upd.Properties) > 0 && label.Properties == nil { label.Properties = make(map[string]string) } @@ -176,6 +176,10 @@ func (s *Service) UpdateLabel(ctx context.Context, id influxdb.ID, upd influxdb. } } + if upd.Name != "" { + label.Name = upd.Name + } + if err := label.Validate(); err != nil { return nil, &influxdb.Error{ Code: influxdb.EInvalid, diff --git a/kv/label.go b/kv/label.go index 3e68d21034..d63ca71c97 100644 --- a/kv/label.go +++ b/kv/label.go @@ -342,7 +342,7 @@ func (s *Service) updateLabel(ctx context.Context, tx Tx, id influxdb.ID, upd in return nil, err } - if label.Properties == nil { + if len(upd.Properties) > 0 && label.Properties == nil { label.Properties = make(map[string]string) } @@ -354,6 +354,10 @@ func (s *Service) updateLabel(ctx context.Context, tx Tx, id influxdb.ID, upd in } } + if upd.Name != "" { + label.Name = upd.Name + } + if err := label.Validate(); err != nil { return nil, &influxdb.Error{ Code: influxdb.EInvalid, diff --git a/label.go b/label.go index 5b651a2a9b..8377761d33 100644 --- a/label.go +++ b/label.go @@ -97,8 +97,9 @@ func (l *LabelMapping) Validate() error { } // LabelUpdate represents a changeset for a label. -// Only fields which are set are updated. +// Only the properties specified are updated. type LabelUpdate struct { + Name string `json:"name,omitempty"` Properties map[string]string `json:"properties,omitempty"` } diff --git a/testing/label_service.go b/testing/label_service.go index 08cf12736e..0c07803fe4 100644 --- a/testing/label_service.go +++ b/testing/label_service.go @@ -340,6 +340,31 @@ func UpdateLabel( args args wants wants }{ + { + name: "update label name", + fields: LabelFields{ + Labels: []*influxdb.Label{ + { + ID: MustIDBase16(labelOneID), + Name: "Tag1", + }, + }, + }, + args: args{ + labelID: MustIDBase16(labelOneID), + update: influxdb.LabelUpdate{ + Name: "NotTag1", + }, + }, + wants: wants{ + labels: []*influxdb.Label{ + { + ID: MustIDBase16(labelOneID), + Name: "NotTag1", + }, + }, + }, + }, { name: "update label properties", fields: LabelFields{