v0.7.2: empty traffic window no longer blanks the map
The flows API sent "edges": null for a window without connections (a nil Go slice); the frontend iterated it and renderMap threw after the new breadcrumbs were drawn, so the previous namespace stayed on screen under the new name. The API now sends empty lists, fetchFlows guards against null, and a failed draw reports itself in the status bar. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
1df5d3559a
commit
8b8fe341d5
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
name: cluster-map
|
name: cluster-map
|
||||||
version: 0.7.1
|
version: 0.7.2
|
||||||
dependencies:
|
dependencies:
|
||||||
- name: deckhouse_lib_helm
|
- name: deckhouse_lib_helm
|
||||||
version: 1.72.24
|
version: 1.72.24
|
||||||
|
|||||||
@@ -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:
|
v0.7.1:
|
||||||
fixes:
|
fixes:
|
||||||
- Alert rules are rendered on DKP versions without the operator-prometheus-crd module.
|
- Alert rules are rendered on DKP versions without the operator-prometheus-crd module.
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ type workloadRef struct {
|
|||||||
|
|
||||||
// Build assembles the graph from the cache. isSystem classifies namespaces.
|
// Build assembles the graph from the cache. isSystem classifies namespaces.
|
||||||
func Build(c *kube.Cache, isSystem func(string) bool) (*Graph, error) {
|
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)
|
namespaces, err := kube.List[corev1.Namespace](c.Namespaces)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -366,7 +366,8 @@ func (c *Collector) Query(namespaces map[string]bool, window time.Duration) Resu
|
|||||||
|
|
||||||
c.mu.Lock()
|
c.mu.Lock()
|
||||||
defer c.mu.Unlock()
|
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 {
|
if c.running {
|
||||||
res.CoveredSec = min(res.WindowSec, int(now.Sub(c.coveredFrom).Seconds()))
|
res.CoveredSec = min(res.WindowSec, int(now.Sub(c.coveredFrom).Seconds()))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,8 @@ limitations under the License.
|
|||||||
package traffic
|
package traffic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -163,3 +165,19 @@ func TestDisabledModeNeverStreams(t *testing.T) {
|
|||||||
t.Fatal("collector without a Hubble client must not start")
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -760,7 +760,20 @@ function focusOnMap(id) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
let renderToken = 0;
|
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() {
|
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;
|
const token = ++renderToken;
|
||||||
renderTree();
|
renderTree();
|
||||||
renderCrumbs();
|
renderCrumbs();
|
||||||
@@ -830,7 +843,11 @@ async function fetchFlows(namespaces) {
|
|||||||
const p = new URLSearchParams({ namespaces: namespaces.join(','), window: state.trafficWindow });
|
const p = new URLSearchParams({ namespaces: namespaces.join(','), window: state.trafficWindow });
|
||||||
const r = await fetch('/api/flows?' + p);
|
const r = await fetch('/api/flows?' + p);
|
||||||
if (!r.ok) throw new Error((await r.text()).trim() || 'HTTP ' + r.status);
|
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" */
|
/* hover: highlight a card's neighbourhood, like NSX "logical path" */
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ const I18N = {
|
|||||||
'node': 'node {name}',
|
'node': 'node {name}',
|
||||||
'edge.conns': '{n} conn.', 'edge.new': ', {n} new', 'edge.drop': ' · drop {n}',
|
'edge.conns': '{n} conn.', 'edge.new': ', {n} new', 'edge.drop': ' · drop {n}',
|
||||||
'status.loadingTraffic': 'loading traffic…', 'status.loadingGraph': 'loading graph…',
|
'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.noRelay': 'no connection to Hubble Relay', 'status.trafficFailed': 'traffic unavailable: {err}',
|
||||||
'status.partial': '{covered} (of {window}: collecting since start)',
|
'status.partial': '{covered} (of {window}: collecting since start)',
|
||||||
'status.onDemandPartial': '{covered} (of {window}: collecting since the map was opened)',
|
'status.onDemandPartial': '{covered} (of {window}: collecting since the map was opened)',
|
||||||
@@ -66,7 +66,7 @@ const I18N = {
|
|||||||
'node': 'нода {name}',
|
'node': 'нода {name}',
|
||||||
'edge.conns': '{n} соед.', 'edge.new': ', новых {n}', 'edge.drop': ' · drop {n}',
|
'edge.conns': '{n} соед.', 'edge.new': ', новых {n}', 'edge.drop': ' · drop {n}',
|
||||||
'status.loadingTraffic': 'загрузка трафика…', 'status.loadingGraph': 'загрузка графа…',
|
'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.noRelay': 'нет связи с Hubble Relay', 'status.trafficFailed': 'трафик недоступен: {err}',
|
||||||
'status.partial': '{covered} (из {window}: сбор идёт с запуска)',
|
'status.partial': '{covered} (из {window}: сбор идёт с запуска)',
|
||||||
'status.onDemandPartial': '{covered} (из {window}: сбор идёт с открытия карты)',
|
'status.onDemandPartial': '{covered} (из {window}: сбор идёт с открытия карты)',
|
||||||
|
|||||||
Reference in New Issue
Block a user