Repository navigation
feat: implement error normalizer with similarity detection for reporting - #6248
Conversation
47872d0 to
955678c
Compare
8c3f724 to
65d351e
Compare
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #6248 +/- ##
==========================================
+ Coverage 76.88% 77.01% +0.13%
==========================================
Files 522 524 +2
Lines 70856 71117 +261
==========================================
+ Hits 54477 54774 +297
+ Misses 13492 13464 -28
+ Partials 2887 2879 -8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
9635837 to
9090e89
Compare
|
@koladilip What's the aim of this PR ? Is it only to limit the number of rows we are adding to With current implementation it looks like, we are skipping reporting if a similar error message is already reported. With this, we'll loose the information about how many times an error has occurred. We won't be able to figure out the top error messages (?) |
This is to reduce the reports we store in rudder-server error_detail_reports, goal of this PR is not solve complete reduction of error cardinality from reporting service perceptive, it might reduce a bit but it is not guaranteed. we'll loose the information about how many times an error has occurred -> I can fix this by returning the similar error already stored instead of skipping. |
72fef0b to
d5b295a
Compare
Based on LCS, can we get the "template" of the common string and store that, along with the diverged words replaced with "__", this way the messages can also be as human readable as possible? Example: "UserId 1234567 is missing, please provide correct id" |
d5b295a to
64b0827
Compare
575c727 to
e01b325
Compare
e01b325 to
fb46c9d
Compare
4ebdbfe to
5f2ce42
Compare
There was a problem hiding this comment.
I am getting better results when using a sorted slice when I have to cleanup 1000 error groups with 20 errors each, even taking into account the write delay (1000 writes in between), please feel free to experiment too
-test.shuffle 1756383638044817000
goos: darwin
goarch: arm64
pkg: github.com/rudderlabs/rudder-server/enterprise/reporting
cpu: Apple M1 Pro
BenchmarkErrorNormalizer
BenchmarkErrorNormalizer/map_20
BenchmarkErrorNormalizer/map_20-10 1798 654185 ns/op 1 B/op 0 allocs/op
BenchmarkErrorNormalizer/sorted_slice_20
BenchmarkErrorNormalizer/sorted_slice_20-10 7554 156696 ns/op 0 B/op 0 allocs/op
BenchmarkErrorNormalizer/map_100
BenchmarkErrorNormalizer/map_100-10 412 3011142 ns/op 25 B/op 0 allocs/op
BenchmarkErrorNormalizer/sorted_slice_100
BenchmarkErrorNormalizer/sorted_slice_100-10 1056 1162006 ns/op 12 B/op 0 allocs/op
PASS
ok github.com/rudderlabs/rudder-server/enterprise/reporting 5.825s
package reporting
import (
"strconv"
"testing"
"time"
"github.com/samber/lo"
)
const maxErrorsPerGroup = 20
func BenchmarkErrorNormalizer(b *testing.B) {
const addLoops = 100
const cleanupLoops = 1000
runBenchmark := func(b *testing.B, num int, sortedSlice bool) {
var errors []string
for i := range num {
errors = append(errors, "test error message "+strconv.Itoa(i))
}
eg := &errGroup{
errors: make(map[string]time.Time),
errorsAlt: make(map[string]struct{}),
errorsArr: make([]lo.Tuple2[string, time.Time], 0, maxErrorsPerGroup),
}
switch sortedSlice {
case true:
b.Run("sorted slice "+strconv.Itoa(num), func(b *testing.B) {
for b.Loop() {
for range addLoops {
for j := 0; j < num; j++ {
eg.addErrorAlt(errors[j])
}
}
for range cleanupLoops {
eg.cleanupAlt()
}
}
})
case false:
b.Run("map "+strconv.Itoa(num), func(b *testing.B) {
for b.Loop() {
for range addLoops {
for j := range num {
eg.addError(errors[j])
}
}
for range cleanupLoops {
eg.cleanup()
}
}
})
}
}
runBenchmark(b, 20, false)
runBenchmark(b, 20, true)
runBenchmark(b, 100, false)
runBenchmark(b, 100, true)
}
type errGroup struct {
errors map[string]time.Time
errorsAlt map[string]struct{}
errorsArr []lo.Tuple2[string, time.Time]
}
func (eg *errGroup) addError(err string) {
eg.errors[err] = time.Now()
}
func (eg *errGroup) addErrorAlt(err string) {
if _, ok := eg.errorsAlt[err]; ok {
for i, t := range eg.errorsArr {
if t.A == err {
t.B = time.Now()
eg.errorsArr[i] = t
// Move element to end
eg.errorsArr = append(eg.errorsArr[:i], eg.errorsArr[i+1:]...)
eg.errorsArr = append(eg.errorsArr, t)
break
}
}
} else {
eg.errorsAlt[err] = struct{}{}
eg.errorsArr = append(eg.errorsArr, lo.T2(err, time.Now()))
}
}
func (eg *errGroup) cleanup() {
for err, t := range eg.errors {
if time.Since(t) > time.Minute {
delete(eg.errors, err)
}
}
}
func (eg *errGroup) cleanupAlt() {
var delIdx int
for i := 0; i < len(eg.errorsArr); i++ {
if time.Since(eg.errorsArr[i].B) > time.Minute {
delIdx = i + 1
delete(eg.errorsAlt, eg.errorsArr[i].A)
} else {
break
}
}
if delIdx > 0 {
eg.errorsArr = eg.errorsArr[delIdx:]
}
}|
I did benmark and sorted is better for cleanup at least 10x times. |
8a8a589 to
4e02895
Compare
4e02895 to
1fe0d51
Compare
- Add ErrorRateLimiter struct with configurable rate limiting per source/destination/event/reporter - Implement similarity-based error message filtering using LCS algorithm - Add configurable error message truncation to prevent oversized messages - Integrate rate limiter into error reporting pipeline with early bucket checks - Add comprehensive test coverage for all rate limiting scenarios - Support configurable cleanup intervals to prevent memory leaks feat: trigger cleanup in background when maxCounters reached - Add atomic flag to prevent multiple cleanup processes running simultaneously - Trigger cleanup asynchronously instead of blocking the main flow - Add comprehensive tests for concurrent cleanup scenarios - Improve performance by avoiding lock contention during cleanup fix: use defer for mutex unlock in IsBucketFull method - Replace manual mutex unlock calls with defer pattern - Ensures mutex is always unlocked regardless of return path - Prevents potential deadlocks from forgotten unlock calls - Improves code safety and maintainability refactor: apply defer pattern for mutex unlocking in ShouldReport method - Replace manual mutex unlock calls with defer pattern in ShouldReport - Ensures mutex is always unlocked regardless of return path - Maintains manual unlock in StartCleanup loop (defer not suitable for loops) - Improves code safety and consistency across the codebase feat: implement non-blocking behavior during cleanup - Add atomic flag to track cleanup in progress - IsBucketFull returns true when cleanup is running (safe assumption) - ShouldReport returns false when cleanup is running (safe assumption) - Prevents blocking of rate limiting operations during cleanup - Improves performance by avoiding mutex contention - Add comprehensive tests for non-blocking behavior fix: update mockgen and gotestsum to resolve golang.org/x/tools tokeninternal error
- Add getSampleWithEventSamplingForEDReportsDB function to handle error sampling - Extract common event sampling logic into getSampleWithEventSamplingCore - Add NewLabelSetFromEDReportsDB function for error hash generation - Separate test cases for metrics and errors in label_set_test.go - Add comprehensive tests for new error sampling functionality - Update error reporting to use new event sampling function test: add comprehensive table-driven tests for NewLabelSetFromEDReportsDB - Add TestNewLabelSetFromEDReportsDB with multiple test cases - Test different error scenarios and field mappings - Fix incomplete NewLabelSetFromEDReportsDB implementation - Ensure all LabelSet fields are properly mapped from EDReportsDB test: enhance TestGenerateHashForErrors with comprehensive field testing - Add more parameters to createErrorObject for flexible test data creation - Test hash generation for different error messages, codes, status codes - Test hash generation for different event types, names, and PUs - Test hash generation for different workspaces, sources, destinations - Test hash generation for different buckets - Ensure all EDReportsDB fields are properly tested for hash uniqueness refactor: merge and simplify EDReportsDB tests - Merge TestGenerateHashForErrors into TestNewLabelSetFromEDReportsDB - Remove createErrorObject helper function with too many parameters - Use EDReportsDB struct literals directly for better readability - Organize tests into field mapping and hash generation subtests - Reduce code duplication and improve test maintainability refactor: simplify TestNewLabelSetFromEDReportsDB to single test structure - Remove nested t.Run structure for cleaner test organization - Combine field mapping and hash verification in single test cases - Add expectedLabelSet field to optionally verify field mapping - Use nil expectedLabelSet to skip field mapping verification - Maintain comprehensive test coverage with simpler structure
- Create ErrorReportingStats struct to centralize all error reporting stats - Move cleanupTimeStat from error normalizer to stats manager - Cache stats during initialization instead of creating new ones every time - Update error normalizer to use centralized stats manager - Fix all test files to use new constructor signature - Improve performance by avoiding repeated stat creation
- Add table-driven tests for all boundedErrorSet methods - Test exact and similarity-based message matching - Test LRU behavior and time-based cleanup - Test edge cases including empty sets and duplicates - Follow warehouse testing guidelines with parallel execution - Ensure 100% test coverage for boundedErrorSet functionality
1fe0d51 to
3e29680
Compare
🤖 I have created a release *beep* *boop* --- ## [1.58.0-rc.1](v1.57.0...v1.58.0-rc.1) (2025-09-01) ### Features * implement error normalizer with similarity detection for reporting ([#6248](#6248)) ([b4653d3](b4653d3)) * **router:** delivery throttler ([#6225](#6225)) ([f55c7a8](f55c7a8)) ### Bug Fixes * cron tracker query causing master restarts ([#6252](#6252)) ([51437b9](51437b9)) * snowpipe events getting duplicated if status API fails ([#6211](#6211)) ([#6244](#6244)) ([8d6838d](8d6838d)) * transformation metrics count amplification ([#6258](#6258)) ([fded7b3](fded7b3)) * update table schema local repository ([#6255](#6255)) ([2ec9a9f](2ec9a9f)) * update table schema local repository ([#6255](#6255)) ([4446e5b](4446e5b)) * use source-id for getting cached schemas ([#6268](#6268)) ([2ec9a9f](2ec9a9f)) * use source-id for getting cached schemas ([#6268](#6268)) ([90e4191](90e4191)) * warehouse migrations from master only ([#6282](#6282)) ([2309507](2309507)) ### Miscellaneous * add alert for stuck snowpipe pipeline ([#6271](#6271)) ([2ec9a9f](2ec9a9f)) * add context information on ut http error logs ([#6278](#6278)) ([424f22c](424f22c)) * bump amannn/action-semantic-pull-request from 5 to 6 ([#6237](#6237)) ([41c1548](41c1548)) * bump the go-deps group with 15 updates ([#6247](#6247)) ([8d6838d](8d6838d)) * bump the go-deps group with 3 updates ([#6254](#6254)) ([02a0263](02a0263)) * cleanup for schema snapshoting ([#6257](#6257)) ([4f3a68f](4f3a68f)) * remove flaky GooglePubSub retry configuration tests ([#6260](#6260)) ([6c48784](6c48784)) * remove null handling of upload id in load files ([#6241](#6241)) ([8d6838d](8d6838d)) * remove unused network code ([#6266](#6266)) ([f7cbc94](f7cbc94)) * **router:** rename endpointLabel to endpointPath ([#6279](#6279)) ([c933525](c933525)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
🤖 I have created a release *beep* *boop* --- ## [1.58.0-rc.2](v1.57.0...v1.58.0-rc.2) (2025-09-02) ### Features * implement error normalizer with similarity detection for reporting ([#6248](#6248)) ([b4653d3](b4653d3)) * **router:** delivery throttler ([#6225](#6225)) ([f55c7a8](f55c7a8)) ### Bug Fixes * cron tracker query causing master restarts ([#6252](#6252)) ([51437b9](51437b9)) * snowpipe events getting duplicated if status API fails ([#6211](#6211)) ([#6244](#6244)) ([8d6838d](8d6838d)) * transformation metrics count amplification ([#6258](#6258)) ([fded7b3](fded7b3)) * update table schema local repository ([#6255](#6255)) ([2ec9a9f](2ec9a9f)) * update table schema local repository ([#6255](#6255)) ([4446e5b](4446e5b)) * use getStringifiedSampleEvent for consistent sample event handling ([#6290](#6290)) ([526975c](526975c)) * use source-id for getting cached schemas ([#6268](#6268)) ([2ec9a9f](2ec9a9f)) * use source-id for getting cached schemas ([#6268](#6268)) ([90e4191](90e4191)) * warehouse migrations from master only ([#6282](#6282)) ([2309507](2309507)) ### Miscellaneous * add alert for stuck snowpipe pipeline ([#6271](#6271)) ([2ec9a9f](2ec9a9f)) * add context information on ut http error logs ([#6278](#6278)) ([424f22c](424f22c)) * bump amannn/action-semantic-pull-request from 5 to 6 ([#6237](#6237)) ([41c1548](41c1548)) * bump the go-deps group with 15 updates ([#6247](#6247)) ([8d6838d](8d6838d)) * bump the go-deps group with 3 updates ([#6254](#6254)) ([02a0263](02a0263)) * cleanup for schema snapshoting ([#6257](#6257)) ([4f3a68f](4f3a68f)) * remove flaky GooglePubSub retry configuration tests ([#6260](#6260)) ([6c48784](6c48784)) * remove null handling of upload id in load files ([#6241](#6241)) ([8d6838d](8d6838d)) * remove unused network code ([#6266](#6266)) ([f7cbc94](f7cbc94)) * **router:** rename endpointLabel to endpointPath ([#6279](#6279)) ([c933525](c933525)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
🤖 I have created a release *beep* *boop* --- ## [1.58.0](v1.57.0...v1.58.0) (2025-09-02) ### Features * implement error normalizer with similarity detection for reporting ([#6248](#6248)) ([b4653d3](b4653d3)) * **router:** delivery throttler ([#6225](#6225)) ([f55c7a8](f55c7a8)) ### Bug Fixes * cron tracker query causing master restarts ([#6252](#6252)) ([51437b9](51437b9)) * snowpipe events getting duplicated if status API fails ([#6211](#6211)) ([#6244](#6244)) ([8d6838d](8d6838d)) * transformation metrics count amplification ([#6258](#6258)) ([fded7b3](fded7b3)) * update table schema local repository ([#6255](#6255)) ([2ec9a9f](2ec9a9f)) * update table schema local repository ([#6255](#6255)) ([4446e5b](4446e5b)) * use getStringifiedSampleEvent for consistent sample event handling ([#6290](#6290)) ([526975c](526975c)) * use source-id for getting cached schemas ([#6268](#6268)) ([2ec9a9f](2ec9a9f)) * use source-id for getting cached schemas ([#6268](#6268)) ([90e4191](90e4191)) * warehouse migrations from master only ([#6282](#6282)) ([2309507](2309507)) ### Miscellaneous * add alert for stuck snowpipe pipeline ([#6271](#6271)) ([2ec9a9f](2ec9a9f)) * add context information on ut http error logs ([#6278](#6278)) ([424f22c](424f22c)) * bump amannn/action-semantic-pull-request from 5 to 6 ([#6237](#6237)) ([41c1548](41c1548)) * bump the go-deps group with 15 updates ([#6247](#6247)) ([8d6838d](8d6838d)) * bump the go-deps group with 3 updates ([#6254](#6254)) ([02a0263](02a0263)) * cleanup for schema snapshoting ([#6257](#6257)) ([4f3a68f](4f3a68f)) * remove flaky GooglePubSub retry configuration tests ([#6260](#6260)) ([6c48784](6c48784)) * remove null handling of upload id in load files ([#6241](#6241)) ([8d6838d](8d6838d)) * remove unused network code ([#6266](#6266)) ([f7cbc94](f7cbc94)) * **router:** rename endpointLabel to endpointPath ([#6279](#6279)) ([c933525](c933525)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
Description
This PR implements error normalization for enterprise error reporting to prevent error message spam while preserving error occurrence counts. The implementation uses a configurable error normalizer that groups similar errors and applies rate limiting per connection group.
Key Features
🔍 Error Normalization
sourceId:destinationId:eventType:pucombination🚀 Rate Limiting
sourceId:destinationId:eventType:pu)🧹 Memory Management
🔧 Interface-based Design
Configuration
Implementation Details
Error Normalization Process
sourceId:destinationId:eventType:puIntegration with Error Reporting
Error Group Structure
Each error group maintains:
Testing
Breaking Changes
None. This is a new feature that can be enabled/disabled via configuration.
Performance Impact
Linear Ticket
INT-4021: Create error rate limiter with configurable truncation