layer1: add live namespace counts
This commit is contained in:
@@ -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.
|
||||||
@@ -123,6 +123,7 @@ func LogNamespaceManagerSummary(logger *zap.Logger, message string, summary Name
|
|||||||
}
|
}
|
||||||
logger.Info(message,
|
logger.Info(message,
|
||||||
zap.Int("total_namespaces", summary.TotalNamespaces),
|
zap.Int("total_namespaces", summary.TotalNamespaces),
|
||||||
|
zap.Int("live_namespaces", summary.LiveNamespaces),
|
||||||
zap.Any("phase_counts", summary.PhaseCounts),
|
zap.Any("phase_counts", summary.PhaseCounts),
|
||||||
zap.Any("source_counts", summary.SourceCounts),
|
zap.Any("source_counts", summary.SourceCounts),
|
||||||
zap.Strings("subscribers", summary.Subscribers),
|
zap.Strings("subscribers", summary.Subscribers),
|
||||||
@@ -258,6 +259,7 @@ func (m *inMemoryNamespaceManager) Summary() NamespaceManagerSummary {
|
|||||||
records := m.SnapshotRecords()
|
records := m.SnapshotRecords()
|
||||||
summary := NamespaceManagerSummary{
|
summary := NamespaceManagerSummary{
|
||||||
TotalNamespaces: len(records),
|
TotalNamespaces: len(records),
|
||||||
|
LiveNamespaces: len(m.Snapshot()),
|
||||||
PhaseCounts: make(map[NamespacePhase]int),
|
PhaseCounts: make(map[NamespacePhase]int),
|
||||||
SourceCounts: make(map[NamespaceSource]int),
|
SourceCounts: make(map[NamespaceSource]int),
|
||||||
Subscribers: m.SnapshotSubscribers(),
|
Subscribers: m.SnapshotSubscribers(),
|
||||||
|
|||||||
@@ -75,6 +75,7 @@ type NamespaceEvent struct {
|
|||||||
|
|
||||||
type NamespaceManagerSummary struct {
|
type NamespaceManagerSummary struct {
|
||||||
TotalNamespaces int
|
TotalNamespaces int
|
||||||
|
LiveNamespaces int
|
||||||
PhaseCounts map[NamespacePhase]int
|
PhaseCounts map[NamespacePhase]int
|
||||||
SourceCounts map[NamespaceSource]int
|
SourceCounts map[NamespaceSource]int
|
||||||
Subscribers []string
|
Subscribers []string
|
||||||
|
|||||||
@@ -63,6 +63,9 @@ func TestNamespaceManagerSnapshotAndGet(t *testing.T) {
|
|||||||
if summary.TotalNamespaces != 2 {
|
if summary.TotalNamespaces != 2 {
|
||||||
t.Fatalf("expected summary total namespaces to be 2, got %d", summary.TotalNamespaces)
|
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 {
|
if summary.SourceCounts[NamespaceSourceWatcher] != 2 {
|
||||||
t.Fatalf("expected watcher source count to be 2")
|
t.Fatalf("expected watcher source count to be 2")
|
||||||
}
|
}
|
||||||
@@ -467,6 +470,9 @@ func TestNamespaceManagerSummary(t *testing.T) {
|
|||||||
if summary.TotalNamespaces != 2 {
|
if summary.TotalNamespaces != 2 {
|
||||||
t.Fatalf("expected total namespaces 2, got %d", summary.TotalNamespaces)
|
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 {
|
if summary.PhaseCounts[NamespacePhaseRegistering] != 1 {
|
||||||
t.Fatalf("expected one registering namespace")
|
t.Fatalf("expected one registering namespace")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user