Skip to content

Commit

Permalink
Add node name to Collector struct
Browse files Browse the repository at this point in the history
Signed-off-by: Matej Gera <matejgera@gmail.com>
  • Loading branch information
matej-g committed Dec 11, 2023
1 parent 540e0c4 commit 9f22bec
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/otel-allocator/allocation/consistent_hashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func (c *consistentHashingAllocator) handleCollectors(diff diff.Changes[*Collect
}
// Insert the new collectors
for _, i := range diff.Additions() {
c.collectors[i.Name] = NewCollector(i.Name)
c.collectors[i.Name] = NewCollector(i.Name, i.Node)
c.consistentHasher.Add(c.collectors[i.Name])
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/otel-allocator/allocation/least_weighted.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func (allocator *leastWeightedAllocator) handleCollectors(diff diff.Changes[*Col
}
// Insert the new collectors
for _, i := range diff.Additions() {
allocator.collectors[i.Name] = NewCollector(i.Name)
allocator.collectors[i.Name] = NewCollector(i.Name, i.Node)
}
if allocateTargets {
for _, item := range allocator.targetItems {
Expand Down
9 changes: 7 additions & 2 deletions cmd/otel-allocator/allocation/strategy.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ var _ consistent.Member = Collector{}
// This struct can be extended with information like annotations and labels in the future.
type Collector struct {
Name string
Node string
NumTargets int
}

Expand All @@ -117,8 +118,8 @@ func (c Collector) String() string {
return c.Name
}

func NewCollector(name string) *Collector {
return &Collector{Name: name}
func NewCollector(name, node string) *Collector {
return &Collector{Name: name, Node: node}
}

func init() {
Expand All @@ -130,4 +131,8 @@ func init() {
if err != nil {
panic(err)
}
err = Register(perNodeStrategyName, newPerNodeAllocator)
if err != nil {
panic(err)
}
}
10 changes: 5 additions & 5 deletions cmd/otel-allocator/allocation/strategy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,11 @@ func Benchmark_Setting(b *testing.B) {
}

func TestCollectorDiff(t *testing.T) {
collector0 := NewCollector("collector-0")
collector1 := NewCollector("collector-1")
collector2 := NewCollector("collector-2")
collector3 := NewCollector("collector-3")
collector4 := NewCollector("collector-4")
collector0 := NewCollector("collector-0", "")
collector1 := NewCollector("collector-1", "")
collector2 := NewCollector("collector-2", "")
collector3 := NewCollector("collector-3", "")
collector4 := NewCollector("collector-4", "")
type args struct {
current map[string]*Collector
new map[string]*Collector
Expand Down
4 changes: 2 additions & 2 deletions cmd/otel-allocator/collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (k *Client) Watch(ctx context.Context, labelMap map[string]string, fn func(
for i := range pods.Items {
pod := pods.Items[i]
if pod.GetObjectMeta().GetDeletionTimestamp() == nil {
collectorMap[pod.Name] = allocation.NewCollector(pod.Name)
collectorMap[pod.Name] = allocation.NewCollector(pod.Name, pod.Spec.NodeName)
}
}

Expand Down Expand Up @@ -130,7 +130,7 @@ func runWatch(ctx context.Context, k *Client, c <-chan watch.Event, collectorMap

switch event.Type { //nolint:exhaustive
case watch.Added:
collectorMap[pod.Name] = allocation.NewCollector(pod.Name)
collectorMap[pod.Name] = allocation.NewCollector(pod.Name, pod.Spec.NodeName)
case watch.Deleted:
delete(collectorMap, pod.Name)
}
Expand Down

0 comments on commit 9f22bec

Please sign in to comment.