commit
4a4bd76e70
|
@ -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 {
|
if err := label.Validate(); err != nil {
|
||||||
return nil, &influxdb.Error{
|
return nil, &influxdb.Error{
|
||||||
Code: influxdb.EInvalid,
|
Code: influxdb.EInvalid,
|
||||||
|
|
|
@ -7708,6 +7708,8 @@ components:
|
||||||
LabelUpdate:
|
LabelUpdate:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
|
name:
|
||||||
|
type: string
|
||||||
properties:
|
properties:
|
||||||
type: object
|
type: object
|
||||||
description: Key/Value pairs associated with this label. Keys can be removed by sending an update with an empty value.
|
description: Key/Value pairs associated with this label. Keys can be removed by sending an update with an empty value.
|
||||||
|
|
|
@ -96,14 +96,6 @@ func (s *Service) FindLabelByID(ctx context.Context, id influxdb.ID) (*influxdb.
|
||||||
|
|
||||||
// FindLabels will retrieve a list of labels from storage.
|
// 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) {
|
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 {
|
filterFunc := func(label *influxdb.Label) bool {
|
||||||
return (filter.Name == "" || (filter.Name == label.Name))
|
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)
|
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 {
|
if err := label.Validate(); err != nil {
|
||||||
return nil, &influxdb.Error{
|
return nil, &influxdb.Error{
|
||||||
Code: influxdb.EInvalid,
|
Code: influxdb.EInvalid,
|
||||||
|
|
|
@ -342,7 +342,7 @@ func (s *Service) updateLabel(ctx context.Context, tx Tx, id influxdb.ID, upd in
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if label.Properties == nil {
|
if len(upd.Properties) > 0 && label.Properties == nil {
|
||||||
label.Properties = make(map[string]string)
|
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 {
|
if err := label.Validate(); err != nil {
|
||||||
return nil, &influxdb.Error{
|
return nil, &influxdb.Error{
|
||||||
Code: influxdb.EInvalid,
|
Code: influxdb.EInvalid,
|
||||||
|
|
4
label.go
4
label.go
|
@ -97,14 +97,14 @@ func (l *LabelMapping) Validate() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// LabelUpdate represents a changeset for a label.
|
// LabelUpdate represents a changeset for a label.
|
||||||
// Only fields which are set are updated.
|
// Only the properties specified are updated.
|
||||||
type LabelUpdate struct {
|
type LabelUpdate struct {
|
||||||
|
Name string `json:"name,omitempty"`
|
||||||
Properties map[string]string `json:"properties,omitempty"`
|
Properties map[string]string `json:"properties,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// LabelFilter represents a set of filters that restrict the returned results.
|
// LabelFilter represents a set of filters that restrict the returned results.
|
||||||
type LabelFilter struct {
|
type LabelFilter struct {
|
||||||
ID ID
|
|
||||||
Name string
|
Name string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 {
|
for _, tt := range tests {
|
||||||
|
@ -368,6 +340,31 @@ func UpdateLabel(
|
||||||
args args
|
args args
|
||||||
wants wants
|
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",
|
name: "update label properties",
|
||||||
fields: LabelFields{
|
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",
|
name: "updating a non-existent label",
|
||||||
fields: LabelFields{
|
fields: LabelFields{
|
||||||
|
|
Loading…
Reference in New Issue