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
@@ -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
|
||||
|
||||
@@ -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()))
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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" */
|
||||
|
||||
@@ -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}: сбор идёт с открытия карты)',
|
||||
|
||||
Reference in New Issue
Block a user