Unified Storage Performance Optimizations - #11
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
|
@coderabbitai review |
✅ Actions performedReview triggered.
|
📝 WalkthroughWalkthroughResource server initialization is moved to constructor with dependencies initialized before runtime. Search index building reduces lock contention by narrowing the critical section. Tracer contexts are properly captured and propagated across Init and GetResourceStats methods. Test skips are added for postgres test environments. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
pkg/server/module_server_test.go (1)
35-38: Consider tracking the postgres test skip with an issue.The skip is a reasonable temporary workaround for CI/local environment differences. However, without an issue to track this, the TODO may be forgotten. The message "fails in Drone but works locally" suggests a potential environment configuration difference worth investigating (e.g., connection timeouts, database initialization timing, or network settings).
Would you like me to open a GitHub issue to track fixing this postgres test in Drone CI?
pkg/storage/unified/search/bleve.go (1)
99-101: TODO comment lacks detail on what RV check should accomplish.The TODO comment "check last RV so we can see if the numbers have changed" is vague. Consider clarifying the intended behavior: should this skip rebuilding if the RV hasn't changed, or log a warning, or something else?
📜 Review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
pkg/server/module_server_test.gopkg/storage/unified/resource/search.gopkg/storage/unified/resource/server.gopkg/storage/unified/search/bleve.gopkg/storage/unified/sql/backend.go
🧰 Additional context used
🧬 Code graph analysis (2)
pkg/storage/unified/sql/backend.go (1)
pkg/infra/tracing/tracing.go (1)
Start(415-417)
pkg/storage/unified/resource/search.go (1)
pkg/infra/tracing/tracing.go (1)
Start(415-417)
🔇 Additional comments (8)
pkg/storage/unified/sql/backend.go (1)
125-127: LGTM! Correct trace context propagation.Capturing the context returned from
tracer.Startand passing it tob.db.WithTxensures the span is properly propagated to downstream database operations. This enables end-to-end tracing visibility.pkg/storage/unified/search/bleve.go (1)
137-139: Good optimization: narrowed critical section for cache update.Moving the lock acquisition to just before the cache update significantly reduces lock contention during index building. This allows concurrent
BuildIndexcalls for different keys to execute in parallel.Note: If two goroutines concurrently build an index for the same key, both will complete their work but only one will persist in the cache (last writer wins). This isn't a correctness issue but could result in duplicate work. If this becomes a concern, consider using a per-key lock or
singleflightpattern.pkg/storage/unified/resource/search.go (4)
173-174: LGTM! Proper trace context propagation in init.Capturing the context from
tracer.Startensures the span is propagated toGetResourceStatsand other downstream calls during initialization.
215-219: Good observability addition.The log statement provides useful initialization metrics (duration and document count) that will help with performance monitoring and debugging.
279-281: Consistent logging approach.Using the structured logger
s.logaligns with the rest of the file and provides consistent log formatting.
309-311: LGTM! Proper trace context propagation in build.Same pattern as
init()- capturing the context ensures the span flows through toBuildIndexand storage operations.pkg/storage/unified/resource/server.go (2)
308-311: Correct ordering: search index initialized before watcher.Starting the watcher after search initialization ensures the search index is ready to process events. This prevents a race condition where events could arrive before the index is ready to handle them.
258-264: LGTM! Eager initialization ensures server is fully ready before use.Moving initialization to the constructor ensures the server is fully operational (storage, search index, watcher) before being returned. Returning
nilon initialization failure is the correct approach to prevent callers from using a partially initialized server. All call sites properly handle the error case.
|
This pull request has been automatically marked as stale because it has not had activity in the last 30 days. It will be closed in 2 weeks if no further activity occurs. Please feel free to give a status update or ping for review. Thank you for your contributions! |
|
This pull request has been automatically closed because it has not had any further activity in the last 2 weeks. Thank you for your contributions! |
Test 10nn
Summary by CodeRabbit
Bug Fixes
Tests
Chores
✏️ Tip: You can customize this high-level summary in your review settings.
nn---n*Replicated from [ai-code-review-evaluation/grafana-coderabbit#10](https://github.com/ai-code-review-evaluation/grafana-coderabbit/pull/10)*