-
Notifications
You must be signed in to change notification settings - Fork 250
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
79 changed files
with
1,617 additions
and
500 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package relabel | ||
|
||
// TODO(thampiotr): write comment | ||
// TODO(thampiotr): port the test | ||
|
||
import ( | ||
"crypto/md5" | ||
"encoding/binary" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/prometheus/common/model" | ||
) | ||
|
||
type LabelBuilder interface { | ||
Get(label string) string | ||
// TODO(thampiotr): test that Set and Del can be called while iterating. | ||
Range(f func(label string, value string)) | ||
Set(label string, val string) | ||
Del(ns ...string) | ||
} | ||
|
||
// ProcessBuilder is like Process, but the caller passes a labels.Builder | ||
// containing the initial set of labels, which is mutated by the rules. | ||
func ProcessBuilder(lb LabelBuilder, cfgs ...*Config) (keep bool) { | ||
for _, cfg := range cfgs { | ||
keep = doRelabel(cfg, lb) | ||
if !keep { | ||
return false | ||
} | ||
} | ||
return true | ||
} | ||
|
||
func doRelabel(cfg *Config, lb LabelBuilder) (keep bool) { | ||
var va [16]string | ||
values := va[:0] | ||
if len(cfg.SourceLabels) > cap(values) { | ||
values = make([]string, 0, len(cfg.SourceLabels)) | ||
} | ||
for _, ln := range cfg.SourceLabels { | ||
values = append(values, lb.Get(string(ln))) | ||
} | ||
val := strings.Join(values, cfg.Separator) | ||
|
||
switch cfg.Action { | ||
case Drop: | ||
if cfg.Regex.MatchString(val) { | ||
return false | ||
} | ||
case Keep: | ||
if !cfg.Regex.MatchString(val) { | ||
return false | ||
} | ||
case DropEqual: | ||
if lb.Get(cfg.TargetLabel) == val { | ||
return false | ||
} | ||
case KeepEqual: | ||
if lb.Get(cfg.TargetLabel) != val { | ||
return false | ||
} | ||
case Replace: | ||
indexes := cfg.Regex.FindStringSubmatchIndex(val) | ||
// If there is no match no replacement must take place. | ||
if indexes == nil { | ||
break | ||
} | ||
target := model.LabelName(cfg.Regex.ExpandString([]byte{}, cfg.TargetLabel, val, indexes)) | ||
if !target.IsValid() { | ||
break | ||
} | ||
res := cfg.Regex.ExpandString([]byte{}, cfg.Replacement, val, indexes) | ||
if len(res) == 0 { | ||
lb.Del(string(target)) | ||
break | ||
} | ||
lb.Set(string(target), string(res)) | ||
case Lowercase: | ||
lb.Set(cfg.TargetLabel, strings.ToLower(val)) | ||
case Uppercase: | ||
lb.Set(cfg.TargetLabel, strings.ToUpper(val)) | ||
case HashMod: | ||
hash := md5.Sum([]byte(val)) | ||
// Use only the last 8 bytes of the hash to give the same result as earlier versions of this code. | ||
mod := binary.BigEndian.Uint64(hash[8:]) % cfg.Modulus | ||
lb.Set(cfg.TargetLabel, fmt.Sprintf("%d", mod)) | ||
case LabelMap: | ||
lb.Range(func(name, value string) { | ||
if cfg.Regex.MatchString(name) { | ||
res := cfg.Regex.ReplaceAllString(name, cfg.Replacement) | ||
lb.Set(res, value) | ||
} | ||
}) | ||
case LabelDrop: | ||
lb.Range(func(name, value string) { | ||
if cfg.Regex.MatchString(name) { | ||
lb.Del(name) | ||
} | ||
}) | ||
case LabelKeep: | ||
lb.Range(func(name, value string) { | ||
if !cfg.Regex.MatchString(name) { | ||
lb.Del(value) | ||
} | ||
}) | ||
default: | ||
panic(fmt.Errorf("relabel: unknown relabel action type %q", cfg.Action)) | ||
} | ||
|
||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
internal/component/discovery/benchmark_data/01_typical_pipeline_targets_as_maps.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
goos: darwin | ||
goarch: arm64 | ||
pkg: github.com/grafana/alloy/internal/component/discovery | ||
cpu: Apple M2 | ||
Benchmark_Targets_TypicalPipeline-8 30 38546436 ns/op 64963036 B/op 241805 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 28 38647682 ns/op 64953672 B/op 241803 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 28 38550351 ns/op 64967889 B/op 241822 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 30 38803608 ns/op 64960262 B/op 241807 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 27 38605718 ns/op 64965312 B/op 241814 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 28 38427967 ns/op 64958167 B/op 241812 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 28 38815302 ns/op 64961392 B/op 241810 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 28 39033807 ns/op 64964683 B/op 241812 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 26 39444696 ns/op 64963500 B/op 241818 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 26 38543861 ns/op 64961057 B/op 241808 allocs/op | ||
PASS | ||
ok github.com/grafana/alloy/internal/component/discovery 23.807s |
16 changes: 16 additions & 0 deletions
16
internal/component/discovery/benchmark_data/02_typical_pipeline_targets_as_capsule.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
goos: darwin | ||
goarch: arm64 | ||
pkg: github.com/grafana/alloy/internal/component/discovery | ||
cpu: Apple M2 | ||
Benchmark_Targets_TypicalPipeline-8 24 45995441 ns/op 66573585 B/op 241368 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 25 44810203 ns/op 66532546 B/op 241380 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 24 44766747 ns/op 66531254 B/op 241373 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 25 45150108 ns/op 66530506 B/op 241367 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 25 47782998 ns/op 66576992 B/op 241376 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 25 47254332 ns/op 66576284 B/op 241378 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 24 44567898 ns/op 66536935 B/op 241394 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 24 44572594 ns/op 66574589 B/op 241369 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 25 44610702 ns/op 66532897 B/op 241375 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 25 44945075 ns/op 66575368 B/op 241376 allocs/op | ||
PASS | ||
ok github.com/grafana/alloy/internal/component/discovery 23.817s |
12 changes: 12 additions & 0 deletions
12
internal/component/discovery/benchmark_data/03_typical_pipeline_optimised.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 72 15278984 ns/op 20085046 B/op 60435 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 75 14940728 ns/op 20085236 B/op 60436 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 75 15123676 ns/op 20085305 B/op 60437 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 74 15007377 ns/op 20085855 B/op 60439 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 75 15170948 ns/op 20085227 B/op 60436 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 75 15316376 ns/op 20084762 B/op 60435 allocs/op | ||
PASS | ||
ok github.com/grafana/alloy/internal/component/discovery 13.170s |
12 changes: 12 additions & 0 deletions
12
internal/component/discovery/benchmark_data/04_typical_pipeline_cached_labels.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 48 22740573 ns/op 21467362 B/op 100933 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 45 23141183 ns/op 21466235 B/op 100932 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 48 24125997 ns/op 21466766 B/op 100936 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 46 22152172 ns/op 21469613 B/op 100944 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 46 26163378 ns/op 21466312 B/op 100928 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 38 41765575 ns/op 21539059 B/op 100944 allocs/op | ||
PASS | ||
ok github.com/grafana/alloy/internal/component/discovery 8.729s |
Empty file.
12 changes: 12 additions & 0 deletions
12
internal/component/discovery/benchmark_data/06_typical_pipeline_grouping.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 33 35633138 ns/op 10840681 B/op 80539 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 34 32671718 ns/op 10840274 B/op 80535 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 37 33207543 ns/op 10927221 B/op 80541 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 34 33105222 ns/op 10840144 B/op 80529 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 36 32274262 ns/op 10927934 B/op 80541 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 37 32763682 ns/op 10840785 B/op 80536 allocs/op | ||
PASS | ||
ok github.com/grafana/alloy/internal/component/discovery 8.826s |
12 changes: 12 additions & 0 deletions
12
internal/component/discovery/benchmark_data/07_typical_pipeline_cleanup.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 40 29411972 ns/op 10927567 B/op 80537 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 40 29447266 ns/op 10927386 B/op 80537 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 40 29141625 ns/op 10840319 B/op 80536 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 40 29083859 ns/op 10840952 B/op 80541 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 40 36991749 ns/op 10927696 B/op 80541 allocs/op | ||
Benchmark_Targets_TypicalPipeline-8 39 29443703 ns/op 10927869 B/op 80538 allocs/op | ||
PASS | ||
ok github.com/grafana/alloy/internal/component/discovery 9.926s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.