Skip to content

Commit

Permalink
remove useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
tsukanov-as committed Dec 25, 2023
1 parent 8003321 commit 4198d77
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 27 deletions.
21 changes: 2 additions & 19 deletions tagger/tagger.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,7 @@ func cutMetricsIntoParts(metricList []Metric, threads int) ([][]Metric, int) {
partSize := (tagsCount-1)/threads + 1 // round up for cases like 99/50
cnt := 0
for j, m := range metricList {
if m.Tags == nil || m.Tags.Len() == 0 {
continue
}
// assert m.Tags != nil && m.Tags.Len() != 0
cnt += m.Tags.Len()
if cnt >= partSize {
parts = append(parts, metricList[i:j+1])
Expand All @@ -394,22 +392,7 @@ func cutMetricsIntoParts(metricList []Metric, threads int) ([][]Metric, int) {
}
}
if i < len(metricList) {
if cnt <= partSize/2 && len(parts) > 0 {
// It is necessary to keep this short tail in the previous part.
// Otherwise, for example, with 3 threads the following list will contain only 1 item in the last part.
// []Metric{
// {Tags: new(Set).Add("tag1", "tag2")},
// {Tags: new(Set).Add("tag3", "tag4")},
// {Tags: new(Set).Add("tag5")},
// {Tags: new(Set).Add("tag6")},
// {Tags: new(Set).Add("tag7", "tag8")},
// {Tags: new(Set).Add("tag9")},
// }
last := len(parts) - 1
parts[last] = parts[last][:len(parts[last])+len(metricList[i:])]
} else {
parts = append(parts, metricList[i:])
}
parts = append(parts, metricList[i:])
}
return parts, tagsCount
}
Expand Down
14 changes: 6 additions & 8 deletions tagger/tagger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ func TestCutMetricsIntoParts(t *testing.T) {

metricList1 := []Metric{
{Tags: new(Set).Add("tag1", "tag2")},
{Tags: new(Set)},
{Tags: new(Set).Add("tag3", "tag4", "tag5")},
{Tags: new(Set).Add("tag6")},
}
Expand Down Expand Up @@ -62,7 +61,6 @@ func TestCutMetricsIntoParts(t *testing.T) {
{Tags: new(Set).Add("tag0", "tag1")},
{Tags: new(Set).Add("tag0", "tag1")},
{Tags: new(Set).Add("tag0", "tag1")},
{Tags: new(Set)},
}

testCases := []struct {
Expand All @@ -75,24 +73,23 @@ func TestCutMetricsIntoParts(t *testing.T) {
{"case 1.1", metricList1, 0, [][]Metric{
{
{Tags: new(Set).Add("tag1", "tag2")},
{Tags: new(Set)},
{Tags: new(Set).Add("tag3", "tag4", "tag5")},
{Tags: new(Set).Add("tag6")},
},
}},
{"case 1.2", metricList1, 1, [][]Metric{
{
{Tags: new(Set).Add("tag1", "tag2")},
{Tags: new(Set)},
{Tags: new(Set).Add("tag3", "tag4", "tag5")},
{Tags: new(Set).Add("tag6")},
},
}},
{"case 1.3", metricList1, 2, [][]Metric{
{
{Tags: new(Set).Add("tag1", "tag2")},
{Tags: new(Set)},
{Tags: new(Set).Add("tag3", "tag4", "tag5")},
},
{
{Tags: new(Set).Add("tag6")},
},
}},
Expand All @@ -101,8 +98,9 @@ func TestCutMetricsIntoParts(t *testing.T) {
{Tags: new(Set).Add("tag1", "tag2")},
},
{
{Tags: new(Set)},
{Tags: new(Set).Add("tag3", "tag4", "tag5")},
},
{
{Tags: new(Set).Add("tag6")},
},
}},
Expand Down Expand Up @@ -233,6 +231,8 @@ func TestCutMetricsIntoParts(t *testing.T) {
{
{Tags: new(Set).Add("tag7")},
{Tags: new(Set).Add("tag8")},
},
{
{Tags: new(Set).Add("tag9")},
},
}},
Expand All @@ -252,7 +252,6 @@ func TestCutMetricsIntoParts(t *testing.T) {
{
{Tags: new(Set).Add("tag0", "tag1")},
{Tags: new(Set).Add("tag0", "tag1")},
{Tags: new(Set)},
},
}},
{"case 6.2", metricList6, 7, [][]Metric{
Expand All @@ -277,7 +276,6 @@ func TestCutMetricsIntoParts(t *testing.T) {
},
{
{Tags: new(Set).Add("tag0", "tag1")},
{Tags: new(Set)},
},
}},
}
Expand Down

0 comments on commit 4198d77

Please sign in to comment.