diff --git a/.chloggen/ta_really-consistent-hashing.yaml b/.chloggen/ta_really-consistent-hashing.yaml new file mode 100755 index 0000000000..c95cb800a3 --- /dev/null +++ b/.chloggen/ta_really-consistent-hashing.yaml @@ -0,0 +1,16 @@ +# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' +change_type: enhancement + +# The name of the component, or a single word describing the area of concern, (e.g. operator, target allocator, github action) +component: target allocator + +# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). +note: Use only target address for allocation in consistent-hashing strategy + +# One or more tracking issues related to the change +issues: [2280] + +# (Optional) One or more lines of additional information to render under the primary note. +# These lines will be padded with 2 spaces and then inserted directly into the document. +# Use pipe (|) for multiline entries. +subtext: diff --git a/cmd/otel-allocator/allocation/allocatortest.go b/cmd/otel-allocator/allocation/allocatortest.go index 23196ae5af..88312a80a5 100644 --- a/cmd/otel-allocator/allocation/allocatortest.go +++ b/cmd/otel-allocator/allocation/allocatortest.go @@ -39,7 +39,7 @@ func MakeNNewTargets(n int, numCollectors int, startingIndex int) map[string]*ta "i": model.LabelValue(strconv.Itoa(i)), "total": model.LabelValue(strconv.Itoa(n + startingIndex)), } - newTarget := target.NewItem(fmt.Sprintf("test-job-%d", i), "test-url", label, collector) + newTarget := target.NewItem(fmt.Sprintf("test-job-%d", i), fmt.Sprintf("test-url-%d", i), label, collector) toReturn[newTarget.Hash()] = newTarget } return toReturn @@ -64,7 +64,7 @@ func MakeNNewTargetsWithEmptyCollectors(n int, startingIndex int) map[string]*ta "i": model.LabelValue(strconv.Itoa(i)), "total": model.LabelValue(strconv.Itoa(n + startingIndex)), } - newTarget := target.NewItem(fmt.Sprintf("test-job-%d", i), "test-url", label, "") + newTarget := target.NewItem(fmt.Sprintf("test-job-%d", i), fmt.Sprintf("test-url-%d", i), label, "") toReturn[newTarget.Hash()] = newTarget } return toReturn diff --git a/cmd/otel-allocator/allocation/consistent_hashing.go b/cmd/otel-allocator/allocation/consistent_hashing.go index c455063730..d98aca72f6 100644 --- a/cmd/otel-allocator/allocation/consistent_hashing.go +++ b/cmd/otel-allocator/allocation/consistent_hashing.go @@ -15,6 +15,7 @@ package allocation import ( + "strings" "sync" "github.com/buraksezer/consistent" @@ -111,7 +112,7 @@ func (c *consistentHashingAllocator) addTargetToTargetItems(tg *target.Item) { delete(c.targetItemsPerJobPerCollector[tg.CollectorName][tg.JobName], tg.Hash()) TargetsPerCollector.WithLabelValues(previousColName.String(), consistentHashingStrategyName).Set(float64(c.collectors[previousColName.String()].NumTargets)) } - colOwner := c.consistentHasher.LocateKey([]byte(tg.Hash())) + colOwner := c.consistentHasher.LocateKey([]byte(strings.Join(tg.TargetURL, ""))) tg.CollectorName = colOwner.String() c.targetItems[tg.Hash()] = tg c.addCollectorTargetItemMapping(tg) diff --git a/cmd/otel-allocator/allocation/consistent_hashing_test.go b/cmd/otel-allocator/allocation/consistent_hashing_test.go index eb8c4894df..bbd4295202 100644 --- a/cmd/otel-allocator/allocation/consistent_hashing_test.go +++ b/cmd/otel-allocator/allocation/consistent_hashing_test.go @@ -28,7 +28,7 @@ func TestCanSetSingleTarget(t *testing.T) { actualTargetItems := c.TargetItems() assert.Len(t, actualTargetItems, 1) for _, item := range actualTargetItems { - assert.Equal(t, "collector-2", item.CollectorName) + assert.Equal(t, "collector-0", item.CollectorName) } }