diff --git a/Chart.yaml b/Chart.yaml index e29627f..94674c2 100644 --- a/Chart.yaml +++ b/Chart.yaml @@ -1,5 +1,5 @@ name: cluster-map -version: 0.7.1 +version: 0.7.2 dependencies: - name: deckhouse_lib_helm version: 1.72.24 diff --git a/changelog.yaml b/changelog.yaml index c5f3f91..1ff7555 100644 --- a/changelog.yaml +++ b/changelog.yaml @@ -1,3 +1,7 @@ +v0.7.2: + fixes: + - A namespace without traffic in the selected window is drawn again; the empty window was sent as null and the map kept the previous namespace on screen. + - A map that fails to draw shows an error instead of the previous view. v0.7.1: fixes: - Alert rules are rendered on DKP versions without the operator-prometheus-crd module. diff --git a/images/cluster-map/src/internal/topology/graph.go b/images/cluster-map/src/internal/topology/graph.go index e95718d..2647a54 100644 --- a/images/cluster-map/src/internal/topology/graph.go +++ b/images/cluster-map/src/internal/topology/graph.go @@ -70,7 +70,7 @@ type workloadRef struct { // Build assembles the graph from the cache. isSystem classifies namespaces. func Build(c *kube.Cache, isSystem func(string) bool) (*Graph, error) { - g := &Graph{} + g := &Graph{Nodes: []Node{}, Edges: []Edge{}} namespaces, err := kube.List[corev1.Namespace](c.Namespaces) if err != nil { return nil, err diff --git a/images/cluster-map/src/internal/traffic/collector.go b/images/cluster-map/src/internal/traffic/collector.go index ad4393d..b68b47d 100644 --- a/images/cluster-map/src/internal/traffic/collector.go +++ b/images/cluster-map/src/internal/traffic/collector.go @@ -366,7 +366,8 @@ func (c *Collector) Query(namespaces map[string]bool, window time.Duration) Resu c.mu.Lock() defer c.mu.Unlock() - res := Result{Mode: c.cfg.TrafficMode, WindowSec: int(window.Seconds()), Connected: c.connected, Error: c.lastErr} + // Empty lists, not nil: the frontend iterates them, and JSON null is not iterable. + res := Result{Mode: c.cfg.TrafficMode, WindowSec: int(window.Seconds()), Connected: c.connected, Error: c.lastErr, Endpoints: []Endpoint{}, Edges: []Edge{}} if c.running { res.CoveredSec = min(res.WindowSec, int(now.Sub(c.coveredFrom).Seconds())) } diff --git a/images/cluster-map/src/internal/traffic/collector_test.go b/images/cluster-map/src/internal/traffic/collector_test.go index 5bb0553..afbd7ba 100644 --- a/images/cluster-map/src/internal/traffic/collector_test.go +++ b/images/cluster-map/src/internal/traffic/collector_test.go @@ -17,6 +17,8 @@ limitations under the License. package traffic import ( + "encoding/json" + "strings" "testing" "time" @@ -163,3 +165,19 @@ func TestDisabledModeNeverStreams(t *testing.T) { t.Fatal("collector without a Hubble client must not start") } } + +// An empty window is sent as empty lists: the frontend iterates them, and a +// null there once left a namespace without traffic looking blank. +func TestEmptyWindowEncodesEmptyLists(t *testing.T) { + now := t0.Add(time.Minute) + c := newTestCollector(&now) + b, err := json.Marshal(c.Query(map[string]bool{"quiet": true}, 5*time.Minute)) + if err != nil { + t.Fatal(err) + } + for _, want := range []string{`"endpoints":[]`, `"edges":[]`} { + if !strings.Contains(string(b), want) { + t.Errorf("response %s lacks %s", b, want) + } + } +} diff --git a/images/cluster-map/src/web/static/app.js b/images/cluster-map/src/web/static/app.js index f8d230c..da866e9 100644 --- a/images/cluster-map/src/web/static/app.js +++ b/images/cluster-map/src/web/static/app.js @@ -760,7 +760,20 @@ function focusOnMap(id) { } let renderToken = 0; +// A failed draw must say so: otherwise the previous scope's map stays on +// screen under the new breadcrumbs, which reads as "this namespace is empty". async function renderMap() { + const token = renderToken + 1; + try { + await drawMap(); + } catch (err) { + if (token !== renderToken) return; + console.error(err); + cy.elements().remove(); + setStatus(t('status.renderFailed', { error: err.message }), true); + } +} +async function drawMap() { const token = ++renderToken; renderTree(); renderCrumbs(); @@ -830,7 +843,11 @@ async function fetchFlows(namespaces) { const p = new URLSearchParams({ namespaces: namespaces.join(','), window: state.trafficWindow }); const r = await fetch('/api/flows?' + p); if (!r.ok) throw new Error((await r.text()).trim() || 'HTTP ' + r.status); - return r.json(); + const flows = await r.json(); + // the server sends [] for an empty window since v0.7.2; up to v0.7.1 it sent null + flows.edges ??= []; + flows.endpoints ??= []; + return flows; } /* hover: highlight a card's neighbourhood, like NSX "logical path" */ diff --git a/images/cluster-map/src/web/static/i18n.js b/images/cluster-map/src/web/static/i18n.js index 6038dcb..a2641f3 100644 --- a/images/cluster-map/src/web/static/i18n.js +++ b/images/cluster-map/src/web/static/i18n.js @@ -12,7 +12,7 @@ const I18N = { 'node': 'node {name}', 'edge.conns': '{n} conn.', 'edge.new': ', {n} new', 'edge.drop': ' · drop {n}', 'status.loadingTraffic': 'loading traffic…', 'status.loadingGraph': 'loading graph…', - 'status.graphFailed': 'could not load the graph: HTTP {code}', 'status.empty': 'nothing here', + 'status.graphFailed': 'could not load the graph: HTTP {code}', 'status.renderFailed': 'could not draw the map: {error}', 'status.empty': 'nothing here', 'status.noRelay': 'no connection to Hubble Relay', 'status.trafficFailed': 'traffic unavailable: {err}', 'status.partial': '{covered} (of {window}: collecting since start)', 'status.onDemandPartial': '{covered} (of {window}: collecting since the map was opened)', @@ -66,7 +66,7 @@ const I18N = { 'node': 'нода {name}', 'edge.conns': '{n} соед.', 'edge.new': ', новых {n}', 'edge.drop': ' · drop {n}', 'status.loadingTraffic': 'загрузка трафика…', 'status.loadingGraph': 'загрузка графа…', - 'status.graphFailed': 'не удалось загрузить граф: HTTP {code}', 'status.empty': 'здесь нет объектов', + 'status.graphFailed': 'не удалось загрузить граф: HTTP {code}', 'status.renderFailed': 'не удалось нарисовать карту: {error}', 'status.empty': 'здесь нет объектов', 'status.noRelay': 'нет связи с Hubble Relay', 'status.trafficFailed': 'трафик недоступен: {err}', 'status.partial': '{covered} (из {window}: сбор идёт с запуска)', 'status.onDemandPartial': '{covered} (из {window}: сбор идёт с открытия карты)',