-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tail/log): dedup same log string in scanner (#165)
* test(query/log/tail): more unit tests for scan Signed-off-by: Gyuho Lee <[email protected]> * feat(query/log/tail): simplify scan line processing logic Signed-off-by: Gyuho Lee <[email protected]> * test(query/log/tail): add benchmarks Signed-off-by: Gyuho Lee <[email protected]> * feat(query/log/tail): support dedup in scanner Signed-off-by: Gyuho Lee <[email protected]> * test(log/tail): add more unit tests Signed-off-by: Gyuho Lee <[email protected]> * feat(diagnose): scan logs with dedup Signed-off-by: Gyuho Lee <[email protected]> * feat(dmesg, diagnose): dedup by default Signed-off-by: Gyuho Lee <[email protected]> * fix imports Signed-off-by: Gyuho Lee <[email protected]> --------- Signed-off-by: Gyuho Lee <[email protected]>
- Loading branch information
Showing
8 changed files
with
810 additions
and
46 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
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
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
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,113 @@ | ||
package tail | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
query_log_common "github.com/leptonai/gpud/components/query/log/common" | ||
|
||
"k8s.io/utils/ptr" | ||
) | ||
|
||
// go test -bench=BenchmarkScan -benchmem | ||
// go test -bench=BenchmarkScan_DmesgLog -benchmem | ||
func BenchmarkScan_DmesgLog(b *testing.B) { | ||
ctx := context.Background() | ||
|
||
benchmarks := []struct { | ||
name string | ||
linesToTail int | ||
withFilter bool | ||
dedup bool | ||
}{ | ||
{"Tail100NoFilter", 100, false, false}, | ||
{"Tail1000NoFilter", 1000, false, false}, | ||
{"Tail100WithFilter", 100, true, false}, | ||
{"Tail1000WithFilter", 1000, true, false}, | ||
|
||
{"Tail100NoFilterWithDedup", 100, false, true}, | ||
{"Tail1000NoFilterWithDedup", 1000, false, true}, | ||
{"Tail100WithFilterWithDedup", 100, true, true}, | ||
{"Tail1000WithFilterWithDedup", 1000, true, true}, | ||
} | ||
|
||
for _, bm := range benchmarks { | ||
b.Run(bm.name, func(b *testing.B) { | ||
var opts []OpOption | ||
opts = append(opts, | ||
WithFile("testdata/dmesg.0.log"), | ||
WithLinesToTail(bm.linesToTail), | ||
WithParseTime(func(line []byte) (time.Time, error) { | ||
return time.Time{}, nil | ||
}), | ||
WithProcessMatched(func(line []byte, _ time.Time, _ *query_log_common.Filter) {}), | ||
) | ||
|
||
if bm.withFilter { | ||
opts = append(opts, WithSelectFilter(&query_log_common.Filter{ | ||
Substring: ptr.To("error"), | ||
})) | ||
} | ||
|
||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_, err := Scan(ctx, opts...) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
|
||
// go test -bench=BenchmarkScan -benchmem | ||
// go test -bench=BenchmarkScan_KubeletLog -benchmem | ||
func BenchmarkScan_KubeletLog(b *testing.B) { | ||
ctx := context.Background() | ||
|
||
benchmarks := []struct { | ||
name string | ||
linesToTail int | ||
withFilter bool | ||
dedup bool | ||
}{ | ||
{"Tail100NoFilter", 100, false, false}, | ||
{"Tail1000NoFilter", 1000, false, false}, | ||
{"Tail100WithFilter", 100, true, false}, | ||
{"Tail1000WithFilter", 1000, true, false}, | ||
|
||
{"Tail100NoFilterWithDedup", 100, false, true}, | ||
{"Tail1000NoFilterWithDedup", 1000, false, true}, | ||
{"Tail100WithFilterWithDedup", 100, true, true}, | ||
{"Tail1000WithFilterWithDedup", 1000, true, true}, | ||
} | ||
|
||
for _, bm := range benchmarks { | ||
b.Run(bm.name, func(b *testing.B) { | ||
var opts []OpOption | ||
opts = append(opts, | ||
WithFile("testdata/kubelet.0.log"), | ||
WithLinesToTail(bm.linesToTail), | ||
WithParseTime(func(line []byte) (time.Time, error) { | ||
return time.Time{}, nil | ||
}), | ||
WithProcessMatched(func(line []byte, _ time.Time, _ *query_log_common.Filter) {}), | ||
) | ||
|
||
if bm.withFilter { | ||
opts = append(opts, WithSelectFilter(&query_log_common.Filter{ | ||
Substring: ptr.To("error"), | ||
})) | ||
} | ||
|
||
b.ResetTimer() | ||
for i := 0; i < b.N; i++ { | ||
_, err := Scan(ctx, opts...) | ||
if err != nil { | ||
b.Fatal(err) | ||
} | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.