Skip to content

Commit

Permalink
Use only target address for allocation in consistent-hashing strategy (
Browse files Browse the repository at this point in the history
…#2290)

Co-authored-by: Jacob Aronoff <[email protected]>
  • Loading branch information
swiatekm and jaronoff97 authored Nov 29, 2023
1 parent abaec7a commit 3e1a91f
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
16 changes: 16 additions & 0 deletions .chloggen/ta_really-consistent-hashing.yaml
Original file line number Diff line number Diff line change
@@ -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:
4 changes: 2 additions & 2 deletions cmd/otel-allocator/allocation/allocatortest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion cmd/otel-allocator/allocation/consistent_hashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package allocation

import (
"strings"
"sync"

"github.com/buraksezer/consistent"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/otel-allocator/allocation/consistent_hashing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 3e1a91f

Please sign in to comment.