layer1: add live namespace counts

This commit is contained in:
Naeel
2026-04-26 10:59:39 +03:00
parent b93e720e12
commit 073f2c1504
4 changed files with 28 additions and 0 deletions
@@ -0,0 +1,19 @@
# 2026-04-26 — NamespaceManager rewrite, step 48
## Цель шага
Убрать двусмысленность в `NamespaceManagerSummary`: сейчас `TotalNamespaces` включает и removed-записи.
## Что меняем
1. Добавляем `LiveNamespaces`.
2. `Summary()` считает его по `Snapshot()`.
3. `LogNamespaceManagerSummary()` пишет оба значения:
- `total_namespaces`
- `live_namespaces`
4. Обновляем unit tests.
## Что НЕ меняем
- не меняем правила хранения removed records;
- не меняем watcher behavior.
+2
View File
@@ -123,6 +123,7 @@ func LogNamespaceManagerSummary(logger *zap.Logger, message string, summary Name
}
logger.Info(message,
zap.Int("total_namespaces", summary.TotalNamespaces),
zap.Int("live_namespaces", summary.LiveNamespaces),
zap.Any("phase_counts", summary.PhaseCounts),
zap.Any("source_counts", summary.SourceCounts),
zap.Strings("subscribers", summary.Subscribers),
@@ -258,6 +259,7 @@ func (m *inMemoryNamespaceManager) Summary() NamespaceManagerSummary {
records := m.SnapshotRecords()
summary := NamespaceManagerSummary{
TotalNamespaces: len(records),
LiveNamespaces: len(m.Snapshot()),
PhaseCounts: make(map[NamespacePhase]int),
SourceCounts: make(map[NamespaceSource]int),
Subscribers: m.SnapshotSubscribers(),
+1
View File
@@ -75,6 +75,7 @@ type NamespaceEvent struct {
type NamespaceManagerSummary struct {
TotalNamespaces int
LiveNamespaces int
PhaseCounts map[NamespacePhase]int
SourceCounts map[NamespaceSource]int
Subscribers []string
+6
View File
@@ -63,6 +63,9 @@ func TestNamespaceManagerSnapshotAndGet(t *testing.T) {
if summary.TotalNamespaces != 2 {
t.Fatalf("expected summary total namespaces to be 2, got %d", summary.TotalNamespaces)
}
if summary.LiveNamespaces != 2 {
t.Fatalf("expected live namespaces to be 2, got %d", summary.LiveNamespaces)
}
if summary.SourceCounts[NamespaceSourceWatcher] != 2 {
t.Fatalf("expected watcher source count to be 2")
}
@@ -467,6 +470,9 @@ func TestNamespaceManagerSummary(t *testing.T) {
if summary.TotalNamespaces != 2 {
t.Fatalf("expected total namespaces 2, got %d", summary.TotalNamespaces)
}
if summary.LiveNamespaces != 1 {
t.Fatalf("expected one live namespace, got %d", summary.LiveNamespaces)
}
if summary.PhaseCounts[NamespacePhaseRegistering] != 1 {
t.Fatalf("expected one registering namespace")
}