layer1: add namespace source counts
This commit is contained in:
@@ -0,0 +1,17 @@
|
|||||||
|
# 2026-04-26 — NamespaceManager rewrite, step 47
|
||||||
|
|
||||||
|
## Цель шага
|
||||||
|
|
||||||
|
Сделать `NamespaceManagerSummary` информативнее для наблюдения за источниками namespace state.
|
||||||
|
|
||||||
|
## Что меняем
|
||||||
|
|
||||||
|
1. В summary добавляем `SourceCounts`.
|
||||||
|
2. `Summary()` считает namespace-ы по `NamespaceSource`.
|
||||||
|
3. `LogNamespaceManagerSummary()` пишет `source_counts`.
|
||||||
|
4. Обновляем unit tests.
|
||||||
|
|
||||||
|
## Что НЕ меняем
|
||||||
|
|
||||||
|
- не меняем watcher behavior;
|
||||||
|
- не меняем semantics state transitions.
|
||||||
@@ -124,6 +124,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.Any("phase_counts", summary.PhaseCounts),
|
zap.Any("phase_counts", summary.PhaseCounts),
|
||||||
|
zap.Any("source_counts", summary.SourceCounts),
|
||||||
zap.Strings("subscribers", summary.Subscribers),
|
zap.Strings("subscribers", summary.Subscribers),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -258,10 +259,12 @@ func (m *inMemoryNamespaceManager) Summary() NamespaceManagerSummary {
|
|||||||
summary := NamespaceManagerSummary{
|
summary := NamespaceManagerSummary{
|
||||||
TotalNamespaces: len(records),
|
TotalNamespaces: len(records),
|
||||||
PhaseCounts: make(map[NamespacePhase]int),
|
PhaseCounts: make(map[NamespacePhase]int),
|
||||||
|
SourceCounts: make(map[NamespaceSource]int),
|
||||||
Subscribers: m.SnapshotSubscribers(),
|
Subscribers: m.SnapshotSubscribers(),
|
||||||
}
|
}
|
||||||
for _, record := range records {
|
for _, record := range records {
|
||||||
summary.PhaseCounts[record.Phase]++
|
summary.PhaseCounts[record.Phase]++
|
||||||
|
summary.SourceCounts[record.Source]++
|
||||||
}
|
}
|
||||||
return summary
|
return summary
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ type NamespaceEvent struct {
|
|||||||
type NamespaceManagerSummary struct {
|
type NamespaceManagerSummary struct {
|
||||||
TotalNamespaces int
|
TotalNamespaces int
|
||||||
PhaseCounts map[NamespacePhase]int
|
PhaseCounts map[NamespacePhase]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.SourceCounts[NamespaceSourceWatcher] != 2 {
|
||||||
|
t.Fatalf("expected watcher source count to be 2")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNamespaceManagerUpsertIncrementsGeneration(t *testing.T) {
|
func TestNamespaceManagerUpsertIncrementsGeneration(t *testing.T) {
|
||||||
@@ -473,6 +476,9 @@ func TestNamespaceManagerSummary(t *testing.T) {
|
|||||||
if !reflect.DeepEqual([]string{"router"}, summary.Subscribers) {
|
if !reflect.DeepEqual([]string{"router"}, summary.Subscribers) {
|
||||||
t.Fatalf("expected router subscriber in summary")
|
t.Fatalf("expected router subscriber in summary")
|
||||||
}
|
}
|
||||||
|
if summary.SourceCounts[NamespaceSourceWatcher] != 2 {
|
||||||
|
t.Fatalf("expected two watcher-sourced namespaces")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLogNamespaceManagerSummaryWithNilLogger(t *testing.T) {
|
func TestLogNamespaceManagerSummaryWithNilLogger(t *testing.T) {
|
||||||
|
|||||||
Reference in New Issue
Block a user