layer1: log namespace summary active flag
This commit is contained in:
@@ -2,6 +2,21 @@
|
|||||||
|
|
||||||
## Цель шага
|
## Цель шага
|
||||||
|
|
||||||
|
Довести `HasActiveNamespaces()` до реального use-site, чтобы helper не оставался чисто декларативным.
|
||||||
|
|
||||||
|
## Что изменено
|
||||||
|
|
||||||
|
1. `LogNamespaceManagerSummary()` теперь пишет флаг `has_active_namespaces`.
|
||||||
|
2. Добавлен unit test на presence и значение этого поля в structured log.
|
||||||
|
|
||||||
|
## Почему это безопасно
|
||||||
|
|
||||||
|
- watcher behavior не меняется;
|
||||||
|
- изменён только debug/logging contract;
|
||||||
|
- покрыто `go test ./pkg/utils/...`.# 2026-04-26 — NamespaceManager rewrite, step 49
|
||||||
|
|
||||||
|
## Цель шага
|
||||||
|
|
||||||
Собрать `prepare + start` managed namespace watcher в один общий entrypoint.
|
Собрать `prepare + start` managed namespace watcher в один общий entrypoint.
|
||||||
|
|
||||||
## Что меняем
|
## Что меняем
|
||||||
|
|||||||
@@ -143,6 +143,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.Int("live_namespaces", summary.LiveNamespaces),
|
||||||
|
zap.Bool("has_active_namespaces", summary.HasActiveNamespaces()),
|
||||||
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),
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
|
"go.uber.org/zap/zaptest/observer"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
k8sfake "k8s.io/client-go/kubernetes/fake"
|
k8sfake "k8s.io/client-go/kubernetes/fake"
|
||||||
k8sCache "k8s.io/client-go/tools/cache"
|
k8sCache "k8s.io/client-go/tools/cache"
|
||||||
@@ -570,7 +571,7 @@ func TestLogNamespaceManagerSummary(t *testing.T) {
|
|||||||
TotalNamespaces: 2,
|
TotalNamespaces: 2,
|
||||||
LiveNamespaces: 1,
|
LiveNamespaces: 1,
|
||||||
PhaseCounts: map[NamespacePhase]int{
|
PhaseCounts: map[NamespacePhase]int{
|
||||||
NamespacePhaseActive: 1,
|
NamespacePhaseActive: 1,
|
||||||
NamespacePhaseRemoved: 1,
|
NamespacePhaseRemoved: 1,
|
||||||
},
|
},
|
||||||
SourceCounts: map[NamespaceSource]int{
|
SourceCounts: map[NamespaceSource]int{
|
||||||
@@ -583,6 +584,31 @@ func TestLogNamespaceManagerSummary(t *testing.T) {
|
|||||||
LogNamespaceManagerSummary(logger, "namespace summary", summary)
|
LogNamespaceManagerSummary(logger, "namespace summary", summary)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestLogNamespaceManagerSummaryIncludesHasActiveNamespaces(t *testing.T) {
|
||||||
|
core, logs := observer.New(zap.InfoLevel)
|
||||||
|
logger := zap.New(core)
|
||||||
|
|
||||||
|
LogNamespaceManagerSummary(logger, "namespace summary", NamespaceManagerSummary{
|
||||||
|
LiveNamespaces: 1,
|
||||||
|
PhaseCounts: map[NamespacePhase]int{},
|
||||||
|
SourceCounts: map[NamespaceSource]int{},
|
||||||
|
Subscribers: []string{},
|
||||||
|
})
|
||||||
|
|
||||||
|
entries := logs.AllUntimed()
|
||||||
|
if len(entries) != 1 {
|
||||||
|
t.Fatalf("expected one log entry, got %d", len(entries))
|
||||||
|
}
|
||||||
|
fields := entries[0].ContextMap()
|
||||||
|
active, ok := fields["has_active_namespaces"].(bool)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("expected has_active_namespaces field in log context")
|
||||||
|
}
|
||||||
|
if !active {
|
||||||
|
t.Fatalf("expected has_active_namespaces=true in log context")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestNamespaceManagerSummaryEmptyContract(t *testing.T) {
|
func TestNamespaceManagerSummaryEmptyContract(t *testing.T) {
|
||||||
manager := NewNamespaceManager()
|
manager := NewNamespaceManager()
|
||||||
summary := manager.Summary()
|
summary := manager.Summary()
|
||||||
|
|||||||
Reference in New Issue
Block a user