feat: add SkipMetricsTracking property to DbSettings#11515
feat: add SkipMetricsTracking property to DbSettings#11515cbermudez97 wants to merge 1 commit intomasterfrom
Conversation
- Introduced SkipMetricsTracking property in DbSettings to control metrics tracking for specific databases. - Updated FullPruningInnerDbFactory to set SkipMetricsTracking to true for inner databases to prevent stale references after pruning. - Added unit tests to verify the behavior of metrics tracking based on the new property. - Enhanced DbMonitoringModule to respect the SkipMetricsTracking setting when adding databases to the tracker.
|
Claude finished @cbermudez97's task in 3m 42s —— View job PR Review:
|
| Severity | Count |
|---|---|
| Critical | 0 |
| High | 0 |
| Medium | 0 |
| Low | 3 |
Low — SkipMetricsTracking lacks XML docs (DbSettings.cs:15)
The coding style guide requires <summary> on all public APIs. The semantics here are non-obvious (callers don't know what it affects), so a one-liner doc would help. Other properties in the same class are also undocumented, so this is consistent with the existing pattern.
Low — TryAdd silently drops duplicate registrations (WorldStateModule.cs:45)
Not a production issue (singletons aren't recreated), but worth being aware of in test teardown/rebuild scenarios.
Low — No end-to-end regression test for the stale-reference bug (DbTrackerTests.cs:81)
TestSkipMetricsTracking validates the mechanism, but there's no test that exercises the full scenario: create FullPruningDb → trigger pruning cycle via TryStartPruning/Commit → assert tracker still reads from the new inner DB. The unit test is sufficient to merge, but an integration test would give stronger confidence.
Verdict: ready to merge. All findings are low-severity and none block correctness.
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds a SkipMetricsTracking flag to DbSettings and updates DB monitoring to avoid tracking ephemeral inner DB instances created during full pruning, preventing stale references and improving resilience when metric gathering fails.
Changes:
- Add
DbSettings.SkipMetricsTrackingand honor it inDbMonitoringModule’s DB factory interceptor. - Mark full-pruning inner DB instances as skipped, and register the stable
FullPruningDbwrapper with the tracker. - Add unit tests for skip-tracking behavior and for per-DB metric gather exception isolation.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Nethermind/Nethermind.Init/Modules/WorldStateModule.cs | Registers the FullPruningDb wrapper in the tracker to keep metrics tied to the active inner DB across prune cycles. |
| src/Nethermind/Nethermind.Init/Modules/DbMonitoringModule.cs | Skips tracking based on SkipMetricsTracking and makes metric updates resilient to per-DB exceptions. |
| src/Nethermind/Nethermind.Db/FullPruning/FullPruningInnerDbFactory.cs | Sets SkipMetricsTracking = true for indexed inner DB instances. |
| src/Nethermind/Nethermind.Db/DbSettings.cs | Introduces the SkipMetricsTracking property. |
| src/Nethermind/Nethermind.Db.Test/Nethermind.Db.Test.csproj | Adds test dependency on Nethermind.Init to access DbMonitoringModule/tracker types. |
| src/Nethermind/Nethermind.Db.Test/DbTrackerTests.cs | Adds tests for skip-tracking and exception isolation during metrics update. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // inner DB, even across full-pruning cycles. Inner DBs are excluded from tracking | ||
| // via SkipMetricsTracking (set by FullPruningInnerDbFactory) to avoid stale entries. |
| try | ||
| { | ||
| // Note: At the moment, the metric for a columns db is combined across column. | ||
| IDbMeta.DbMetric dbMetric = kv.Value.GatherMetric(); | ||
| Db.Metrics.DbSize[kv.Key] = dbMetric.Size; | ||
| Db.Metrics.DbBlockCacheSize[kv.Key] = dbMetric.CacheSize; | ||
| Db.Metrics.DbMemtableSize[kv.Key] = dbMetric.MemtableSize; | ||
| Db.Metrics.DbIndexFilterSize[kv.Key] = dbMetric.IndexSize; | ||
| Db.Metrics.DbReads[kv.Key] = dbMetric.TotalReads; | ||
| Db.Metrics.DbWrites[kv.Key] = dbMetric.TotalWrites; | ||
| } | ||
| catch (Exception e) | ||
| { | ||
| if (_logger.IsWarn) _logger.Warn($"Failed to gather metrics for DB '{kv.Key}': {e}"); | ||
| } |
| Metrics.DbReads["GoodDb"] = 0; | ||
|
|
||
| updateAction!(); | ||
|
|
||
| Assert.That(Metrics.DbReads.ContainsKey("GoodDb"), Is.True); | ||
| Assert.That(Metrics.DbReads["GoodDb"], Is.EqualTo(42)); |
| tracker.GetAllDbMeta().Count().Should().Be(1); | ||
| tracker.GetAllDbMeta().First().Key.Should().Be("TrackedDb"); |
|
|
||
| public bool DeleteOnStart { get; set; } | ||
| public bool CanDeleteFolder { get; set; } = true; | ||
| public bool SkipMetricsTracking { get; set; } |
There was a problem hiding this comment.
Low: Missing XML documentation on this public property. The coding style guide (coding-style.md) requires <summary> docs on all public APIs. Consider:
| public bool SkipMetricsTracking { get; set; } | |
| /// <summary>When true, this database will not be registered with the metrics tracker.</summary> | |
| public bool SkipMetricsTracking { get; set; } |
(Other properties in this file are also undocumented — consistent with the existing pattern, but worth fixing here since this one has non-obvious semantics.)
| // Register the outer wrapper so GatherMetric() always reflects the currently active | ||
| // inner DB, even across full-pruning cycles. Inner DBs are excluded from tracking | ||
| // via SkipMetricsTracking (set by FullPruningInnerDbFactory) to avoid stale entries. | ||
| ctx.ResolveOptional<DbMonitoringModule.DbTracker>()?.AddDb(stateDbSettings.DbName, db); |
There was a problem hiding this comment.
Low: AddDb uses TryAdd internally, which silently discards duplicate names. If this lambda ever re-runs (unlikely for a singleton, but possible in test teardown/rebuild cycles), the stale FullPruningDb instance remains in the tracker. Not a problem in practice, but worth noting if the FullPruningDb instance is ever recreated under the same name.
| } | ||
|
|
||
| [Test] | ||
| public void TestSkipMetricsTracking() |
There was a problem hiding this comment.
Low: This test verifies the SkipMetricsTracking flag mechanism, but there's no test for the actual bug scenario: create a FullPruningDb, trigger a pruning cycle (via TryStartPruning → Commit), then assert that the tracker's GatherMetric() reads from the new inner DB and not the discarded one. The unit test is good, but an integration test would close the loop on correctness.
Changes
Types of changes
What types of changes does your code introduce?
Testing
Requires testing
If yes, did you write tests?