Merge pull request #12585 from influxdata/label-names

Label names
pull/12618/head
Jade McGough 2019-03-15 16:29:35 -07:00 committed by GitHub
commit 4a4bd76e70
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 43 additions and 78 deletions

View File

@ -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,

View File

@ -7708,6 +7708,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.

View File

@ -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))
}
@ -172,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)
}
@ -184,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,

View File

@ -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,

View File

@ -97,14 +97,14 @@ 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"`
}
// LabelFilter represents a set of filters that restrict the returned results.
type LabelFilter struct {
ID ID
Name string
}

View File

@ -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 {
@ -368,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{
@ -467,44 +464,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{