-
Notifications
You must be signed in to change notification settings - Fork 0
Automated Test: unified-storage-enhancements #329
Automated Test: unified-storage-enhancements #329
Conversation
…#97529) * dont lazy init unified storage * Inits index when creating new resource server. Fixes trace propagation by passing span ctx. Update some logging. * Use finer grained cache locking when building indexes to speed things up. Locking the whole function was slowing things down. * formatting * linter fix * go mod * make update-workspace * fix workspaces check error * update dependency owner in mod file * wait 1 second before querying metrics * try with big timeout, see if fixes CI. Wont fail locally. * skips postgres integration test. Only fails in drone. Will fix later. * put delay back to 500 ms
📝 WalkthroughWalkthroughThese changes refactor the resource server to perform initialization once at startup rather than lazily on each operation, update tracing context propagation across multiple modules to use context-returning tracer calls, modify search index cache synchronization behavior, and add a PostgreSQL skip to a test. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@pkg/storage/unified/sql/backend.go`:
- Around line 126-127: The span name concatenation double-dot bug occurs because
tracePrefix is "sql.resource." and the code appends ".GetResourceStats"
producing "sql.resource..GetResourceStats"; update the span creation in
GetResourceStats (tracePrefix+".GetResourceStats") to remove the extra leading
dot by either appending "GetResourceStats" (tracePrefix+"GetResourceStats") or
trimming the trailing dot from tracePrefix before concatenation, and apply the
same fix to the other occurrences that use ".Read" so all span names follow the
same pattern as WriteEvent/Create/Update.
🧹 Nitpick comments (4)
pkg/server/module_server_test.go (1)
35-38: Tracking the TODO to fix this test for PostgreSQL.With both sqlite3 and postgres skipped, this integration test now only runs against MySQL. Consider creating a tracking issue so this doesn't remain skipped indefinitely.
Would you like me to open an issue to track re-enabling this test for PostgreSQL?
pkg/storage/unified/resource/search.go (1)
186-192: Pre-existing data race ontotalBatchesIndexedwheninitWorkers > 1.This isn't introduced by this PR, but
totalBatchesIndexed++(line 189) is executed concurrently insidegroup.Gogoroutines without synchronization. Ifs.initWorkers > 1, this is a data race detectable by-race. Consider usingatomic.AddInt64or moving the count outside the goroutine.♻️ Suggested fix using atomic
- totalBatchesIndexed := 0 + var totalBatchesIndexed atomic.Int64 group := errgroup.Group{} group.SetLimit(s.initWorkers) ... for _, info := range stats { group.Go(func() error { s.log.Debug("initializing search index", "namespace", info.Namespace, "group", info.Group, "resource", info.Resource) - totalBatchesIndexed++ + totalBatchesIndexed.Add(1) _, _, err = s.build(ctx, info.NamespacedResource, info.Count, info.ResourceVersion) return err }) } ... - span.AddEvent("namespaces indexed", trace.WithAttributes(attribute.Int("namespaced_indexed", totalBatchesIndexed))) + span.AddEvent("namespaces indexed", trace.WithAttributes(attribute.Int64("namespaced_indexed", totalBatchesIndexed.Load())))pkg/storage/unified/search/bleve.go (2)
144-154: Pre-existing:TotalDocsiteratesb.cachewithout holdingcacheMu.Now that
BuildIndexwrites tob.cacheundercacheMu, reading it without a lock inTotalDocsis a data race if the two can overlap. Consider adding a read lock here.🔒 Proposed fix
func (b *bleveBackend) TotalDocs() int64 { + b.cacheMu.RLock() + defer b.cacheMu.RUnlock() var totalDocs int64 for _, v := range b.cache {
99-101: Silenced the log and left a TODO — consider checking the existing index.If
bleve.New(dir, mapper)succeeds on a path that already has data, it creates a new index (overwriting). The TODO about checking last RV to detect changes is worth tracking.Would you like me to open an issue to track the RV-based skip optimization for file-based indexes?
| ctx, span := b.tracer.Start(ctx, tracePrefix+".GetResourceStats") | ||
| defer span.End() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Double dot in span name: "sql.resource..GetResourceStats"
tracePrefix is "sql.resource." (line 27), so concatenating ".GetResourceStats" produces "sql.resource..GetResourceStats". Other methods in this file (e.g., WriteEvent, Create, Update) omit the leading dot. This also applies to the pre-existing ".Read" on line 353.
🔧 Proposed fix
- ctx, span := b.tracer.Start(ctx, tracePrefix+".GetResourceStats")
+ ctx, span := b.tracer.Start(ctx, tracePrefix+"GetResourceStats")And separately (pre-existing, line 353):
- _, span := b.tracer.Start(ctx, tracePrefix+".Read")
+ _, span := b.tracer.Start(ctx, tracePrefix+"Read")🤖 Prompt for AI Agents
In `@pkg/storage/unified/sql/backend.go` around lines 126 - 127, The span name
concatenation double-dot bug occurs because tracePrefix is "sql.resource." and
the code appends ".GetResourceStats" producing "sql.resource..GetResourceStats";
update the span creation in GetResourceStats (tracePrefix+".GetResourceStats")
to remove the extra leading dot by either appending "GetResourceStats"
(tracePrefix+"GetResourceStats") or trimming the trailing dot from tracePrefix
before concatenation, and apply the same fix to the other occurrences that use
".Read" so all span names follow the same pattern as WriteEvent/Create/Update.
This pull request was automatically created by
@coderabbitai/e2e-reviewer.Batch created pull request.
Summary by CodeRabbit
Bug Fixes
Improvements
Tests