Skip to content

Commit

Permalink
tmp - good idea with grouping
Browse files Browse the repository at this point in the history
  • Loading branch information
thampiotr committed Jan 30, 2025
1 parent 0c0c928 commit e30b3f4
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 246 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +0,0 @@
goos: darwin
goarch: arm64
pkg: github.com/grafana/alloy/internal/component/discovery
cpu: Apple M2
Benchmark_Targets_TypicalPipeline-8 33 34000016 ns/op 20898478 B/op 160937 allocs/op
Benchmark_Targets_TypicalPipeline-8 32 36584542 ns/op 20826227 B/op 160935 allocs/op
Benchmark_Targets_TypicalPipeline-8 30 35797154 ns/op 20827766 B/op 160935 allocs/op
Benchmark_Targets_TypicalPipeline-8 33 34531398 ns/op 20899688 B/op 160941 allocs/op
Benchmark_Targets_TypicalPipeline-8 32 35422260 ns/op 20827490 B/op 160933 allocs/op
Benchmark_Targets_TypicalPipeline-8 33 34420867 ns/op 20897838 B/op 160939 allocs/op
PASS
ok github.com/grafana/alloy/internal/component/discovery 8.385s
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
goos: darwin
goarch: arm64
pkg: github.com/grafana/alloy/internal/component/discovery
cpu: Apple M2
Benchmark_Targets_TypicalPipeline-8 36 32660016 ns/op 10841145 B/op 80541 allocs/op
Benchmark_Targets_TypicalPipeline-8 36 32693987 ns/op 10927902 B/op 80541 allocs/op
Benchmark_Targets_TypicalPipeline-8 37 35438566 ns/op 10927976 B/op 80543 allocs/op
Benchmark_Targets_TypicalPipeline-8 34 32530555 ns/op 10927663 B/op 80540 allocs/op
Benchmark_Targets_TypicalPipeline-8 30 38546656 ns/op 10840045 B/op 80538 allocs/op
Benchmark_Targets_TypicalPipeline-8 34 32129576 ns/op 10927397 B/op 80537 allocs/op
PASS
ok github.com/grafana/alloy/internal/component/discovery 9.699s
21 changes: 21 additions & 0 deletions internal/component/discovery/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ func (c *Component) runDiscovery(ctx context.Context, d DiscovererWithMetrics) {
}

func toAlloyTargets(cache map[string]*targetgroup.Group) []Target {
// logDebugInfo(cache)
targetsCount := 0
for _, group := range cache {
targetsCount += len(group.Targets)
Expand All @@ -235,4 +236,24 @@ func toAlloyTargets(cache map[string]*targetgroup.Group) []Target {
return allTargets
}

//
// var lastLogTime = time.Now()
// func logDebugInfo(c map[string]*targetgroup.Group) {
// if time.Since(lastLogTime) < time.Second*10 {
// return
// }
// numGroups := len(c)
// fmt.Printf("DEBUG ============================================\n")
// fmt.Printf("numGroups: %v\n", numGroups)
// for name, group := range c {
// fmt.Printf("group: %q, common labels: %v, targets: %v\n", name, len(group.Labels), len(group.Targets))
// avgTargetLabels := 0
// for _, target := range group.Targets {
// avgTargetLabels += len(target)
// }
// fmt.Printf("avgTargetLabels: %v\n", float32(avgTargetLabels)/float32(len(group.Targets)))
// }
// lastLogTime = time.Now()
// }

func (c *Component) LiveDebugging(_ int) {}
2 changes: 0 additions & 2 deletions internal/component/discovery/relabel/relabel.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ func (c *Component) Update(args component.Arguments) error {

targets := make([]discovery.Target, 0, len(newArgs.Targets))

// TODO(thampiotr): can do even better perhaps by relabeling all the group ones separately from all the
// individual ones
for _, t := range newArgs.Targets {
var (
relabelled discovery.Target
Expand Down
Loading

0 comments on commit e30b3f4

Please sign in to comment.