Registry: trend chart, always-pass indicator, subnet columns in the address list dialog
- Registry: "Динамика по запускам" chart (Chart.js 4.5.1, vendored) over finalized runs per target or site, % or count, subnet and calendar period filters; GET /admin/registry/trend - Registry: clickable "Всегда проходили" indicator with the address list and CSV; GET /admin/registry/always-pass and /always-pass/list - Address list dialog: "Подсеть" and "Метка подсети" columns from the administrator's subnet list (shared db.SubnetMatcher), per-subnet summary chips with a client-side filter; "прочие" renamed to "вне списка подсетей" - Rebuild control-api and admin-dashboard binaries; plans and summaries in docs/changes, README, API and USAGE updated Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
c13139cd41
commit
1536723196
50 files changed
+3560
-154
No files matched your search
@@ -232,7 +232,7 @@ func TestAnalyticsCompareEndpoints(t *testing.T) {
|
||||
}
|
||||
resp, body = fc.do(http.MethodGet, cmp+"/lists/changed"+q, nil)
|
||||
if resp.StatusCode != http.StatusOK || json.Unmarshal(body, &l) != nil || l.Group != "changed" || len(l.Rows) != 1 ||
|
||||
l.Rows[0][0] != "9.9.9.2" || !strings.HasPrefix(l.Rows[0][2], "partial → pass") {
|
||||
l.Rows[0][0] != "9.9.9.2" || !strings.HasPrefix(l.Rows[0][3], "partial → pass") {
|
||||
t.Fatalf("changed list: %d %s", resp.StatusCode, body)
|
||||
}
|
||||
resp, body = fc.do(http.MethodGet, cmp+"/lists/new"+q+"&indicator=verdict_partial", nil)
|
||||
@@ -535,7 +535,7 @@ func TestRegistryBreakdownEndpoints(t *testing.T) {
|
||||
if err := json.Unmarshal(body, &l); err != nil || resp.StatusCode != http.StatusOK || len(l.Rows) != 2 || len(l.Rows[0]) != len(l.Columns) {
|
||||
t.Fatalf("list: %d %s", resp.StatusCode, body)
|
||||
}
|
||||
if r := l.Rows[0]; r[0] != "9.9.9.2" || r[1] != "провал" || r[3] != "rxmsk" || r[5] != "dial tcp: i/o timeout" {
|
||||
if r := l.Rows[0]; r[0] != "9.9.9.2" || r[1] != "9.9.9.0/24" || r[3] != "провал" || r[5] != "rxmsk" || r[7] != "dial tcp: i/o timeout" {
|
||||
t.Errorf("failure must come first: %v", r)
|
||||
}
|
||||
resp, body = fc.do(http.MethodGet, listURL+"&format=csv", nil)
|
||||
@@ -547,3 +547,68 @@ func TestRegistryBreakdownEndpoints(t *testing.T) {
|
||||
t.Errorf("unknown key: %d, want 404", resp.StatusCode)
|
||||
}
|
||||
}
|
||||
|
||||
// The trend endpoint: 400 without a direction, with a malformed or reversed
|
||||
// period, and the shape of the series (site names, run list).
|
||||
func TestRegistryTrendEndpoint(t *testing.T) {
|
||||
fc, d, _, _ := newConfigTestHarness(t)
|
||||
fc.do(http.MethodPut, "/api/v1/admin/config/sites/1", putSiteRequest{SiteID: "rxmsk"})
|
||||
id := finishedRun(t, d)
|
||||
const base = "/api/v1/admin/registry/trend"
|
||||
|
||||
for _, bad := range []string{"", "?protocol=ssh", "?direction=up", "?direction=egress&from=2026-13-01", "?direction=egress&from=2026-10-02&to=2026-10-01"} {
|
||||
if resp, _ := fc.do(http.MethodGet, base+bad, nil); resp.StatusCode != http.StatusBadRequest {
|
||||
t.Errorf("%q: %d, want 400", bad, resp.StatusCode)
|
||||
}
|
||||
}
|
||||
resp, body := fc.do(http.MethodGet, base+"?direction=ingress&protocol=ssh&run=999", nil)
|
||||
var tr registryTrendDTO
|
||||
if err := json.Unmarshal(body, &tr); err != nil || resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("trend: %d %s", resp.StatusCode, body)
|
||||
}
|
||||
if tr.Group != "site" || tr.Direction != "ingress" || tr.Protocol != "ssh" || tr.Truncated || len(tr.Runs) != 1 || tr.Runs[0].ID != id || tr.Runs[0].Addresses != 2 ||
|
||||
len(tr.Series) != 1 || tr.Series[0].Label != "rxmsk" || !reflect.DeepEqual(tr.Series[0].Points, []trendPointDTO{{RunID: id, Total: 2, OK: 1}}) {
|
||||
t.Errorf("trend = %+v", tr)
|
||||
}
|
||||
if resp, body = fc.do(http.MethodGet, base+"?direction=egress&from=2000-01-01&to=2000-01-02", nil); resp.StatusCode != http.StatusOK ||
|
||||
!strings.Contains(string(body), `"runs":[]`) || !strings.Contains(string(body), `"series":[]`) {
|
||||
t.Errorf("empty period: %d %s", resp.StatusCode, body)
|
||||
}
|
||||
}
|
||||
|
||||
// The always-pass endpoints: 400 without a direction or with a bad period, the
|
||||
// shape of the counts, and the list and its CSV by ascending IP.
|
||||
func TestRegistryAlwaysPassEndpoint(t *testing.T) {
|
||||
fc, d, _, _ := newConfigTestHarness(t)
|
||||
id := finishedRun(t, d)
|
||||
const base = "/api/v1/admin/registry/always-pass"
|
||||
|
||||
for _, bad := range []string{"", "?protocol=ssh", "?direction=egress&from=2026-13-01", "?direction=egress&from=2026-10-02&to=2026-10-01"} {
|
||||
for _, p := range []string{base, base + "/list"} {
|
||||
if resp, _ := fc.do(http.MethodGet, p+bad, nil); resp.StatusCode != http.StatusBadRequest {
|
||||
t.Errorf("%s%q: %d, want 400", p, bad, resp.StatusCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
resp, body := fc.do(http.MethodGet, base+"?direction=ingress&protocol=ssh&run=999&status=fail", nil)
|
||||
var ap registryAlwaysPassDTO
|
||||
if err := json.Unmarshal(body, &ap); err != nil || resp.StatusCode != http.StatusOK {
|
||||
t.Fatalf("always-pass: %d %s", resp.StatusCode, body)
|
||||
}
|
||||
if ap.Direction != "ingress" || ap.Protocol != "ssh" || ap.Runs != 1 || ap.Addresses != 2 || ap.AlwaysPass != 1 || ap.FirstRunAt == nil || ap.LastRunAt == nil || ap.Truncated {
|
||||
t.Errorf("always-pass = %+v (run %d)", ap, id)
|
||||
}
|
||||
resp, body = fc.do(http.MethodGet, base+"/list?direction=ingress&protocol=ssh", nil)
|
||||
var l struct {
|
||||
Columns []string `json:"columns"`
|
||||
Rows [][]string `json:"rows"`
|
||||
}
|
||||
if err := json.Unmarshal(body, &l); err != nil || resp.StatusCode != http.StatusOK || len(l.Columns) != 8 || len(l.Rows) != 1 || l.Rows[0][0] != "9.9.9.1" || l.Rows[0][1] != "9.9.9.0/24" || l.Rows[0][3] != "1" {
|
||||
t.Errorf("list: %d %s", resp.StatusCode, body)
|
||||
}
|
||||
resp, body = fc.do(http.MethodGet, base+"/list?direction=egress&format=csv", nil)
|
||||
if !strings.HasPrefix(string(body), "\xef\xbb\xbf") || !strings.Contains(string(body), "9.9.9.1") || !strings.Contains(string(body), "9.9.9.2") ||
|
||||
!strings.Contains(resp.Header.Get("Content-Disposition"), "registry_always_pass_egress_.csv") {
|
||||
t.Errorf("csv: %v %q", resp.Header, body)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user