Skip to content

Commit

Permalink
Filip's comments
Browse files Browse the repository at this point in the history
Signed-off-by: haanhvu <haanh6594@gmail.com>
  • Loading branch information
haanhvu committed May 15, 2023
1 parent 73adb73 commit b9ff267
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
9 changes: 3 additions & 6 deletions pkg/receive/multitsdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -571,9 +571,6 @@ func (t *MultiTSDB) startTSDB(logger log.Logger, tenantID string, tenant *tenant

lset, err := t.extractTenantsLabels(tenantID, initialLset)
if err != nil {
t.mtx.Lock()
delete(t.tenants, tenantID)
t.mtx.Unlock()
return err
}

Expand Down Expand Up @@ -682,9 +679,6 @@ func (t *MultiTSDB) SetHashringConfig(cfg []HashringConfig) error {
if hc.ExternalLabels != nil {
extendedLset, err := extendLabels(lset, hc.ExternalLabels, t.logger)
if err != nil {
t.mtx.Lock()
delete(t.tenants, tenantID)
t.mtx.Unlock()
return errors.Wrap(err, "failed to extend external labels for tenant "+tenantID)
}
lset = extendedLset
Expand Down Expand Up @@ -894,6 +888,9 @@ func extendLabels(labelSet labels.Labels, extend map[string]string, logger log.L
extendLabels = append(extendLabels, labels.Label{Name: name, Value: value})
}

sort.Sort(labelSet)
sort.Sort(extendLabels)

extendedLabelSet := make(labels.Labels, 0, len(labelSet)+len(extendLabels))
for len(labelSet) > 0 && len(extendLabels) > 0 {
d := strings.Compare(labelSet[0].Name, extendLabels[0].Name)
Expand Down
20 changes: 10 additions & 10 deletions pkg/receive/receive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ func TestAddingExternalLabelsForTenants(t *testing.T) {
Endpoints: []string{"node1"},
Tenants: []string{"tenant1", "tenant2", "tenant3"},
ExternalLabels: map[string]string{
"name1": "value1",
"name2": "value2",
"name3": "value3",
"name2": "value2",
"name1": "value1",
},
},
},
Expand Down Expand Up @@ -148,9 +148,9 @@ func TestAddingExternalLabelsForTenants(t *testing.T) {
Endpoints: []string{"node2"},
Tenants: []string{"tenant4", "tenant5", "tenant6"},
ExternalLabels: map[string]string{
"name4": "value4",
"name5": "value5",
"name6": "value6",
"name5": "value5",
"name4": "value4",
},
},
},
Expand All @@ -176,9 +176,9 @@ func TestAddingExternalLabelsForTenants(t *testing.T) {
Endpoints: []string{"node1"},
Tenants: []string{"tenant1", "tenant2", "tenant3"},
ExternalLabels: map[string]string{
"name1": "value1",
"name2": "value2",
"name3": "value3",
"name2": "value2",
"name1": "value1",
},
},
{
Expand Down Expand Up @@ -366,9 +366,9 @@ func TestLabelSetsOfTenantsWhenChangingLabels(t *testing.T) {
Endpoints: []string{"node2"},
Tenants: []string{"tenant4", "tenant5", "tenant6"},
ExternalLabels: map[string]string{
"name4": "value4",
"name5": "value5",
"name6": "value6",
"name5": "value5",
"name4": "value4",
},
},
}
Expand Down Expand Up @@ -587,9 +587,9 @@ func TestAddingLabelsWhenTenantAppearsInMultipleHashrings(t *testing.T) {
Endpoints: []string{"node1"},
Tenants: []string{"tenant1", "tenant2", "tenant3"},
ExternalLabels: map[string]string{
"name1": "value1",
"name2": "value2",
"name3": "value3",
"name2": "value2",
"name1": "value1",
},
},
{
Expand Down

0 comments on commit b9ff267

Please sign in to comment.