Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ an example value. See `deploy/host/README.md`.

## [Unreleased]

### Added

- A "CVEs" tab after Artifacts has three views. "Staging" lists the packages to bump to clear the HIGH and CRITICAL CVEs found in the staging images, split into "Ours to bump", "Base OS" and "Not classified yet". Entries that are new since you last looked are marked, and "Mark all as seen" clears the markers; the markers are kept in your browser, and the tab shows a badge when there are new entries. "Released" shows, for each released image, how many of its CVEs the current staging image already fixes. "By image" is the CVE table that used to be on Overview.
- `GET /api/cve/report` returns the data behind the CVEs tab: the staging work list and the released-image view. It is public, like the other CVE endpoints.

### Changed

- The CVE table moved from Overview to the "By image" view of the new CVEs tab.
- After upgrading, images scanned before this version are rescanned once at startup so their findings can be classified. Until the rescan finishes, their packages appear under "Not classified yet". Entries marked as seen before that rescan finishes may show as new once more afterwards, because the rescan adds the file a library was found in.

## [0.2.10] - 2026-11-17

### Added
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ The dashboard polls OBS on a schedule and consumes RabbitMQ build events, stores
- Package cards showing live rollup state (building, failed, succeeded, published) across all PPG OBS projects.
- Per-target build event log: build started, succeeded, failed, published — filterable by tag and time window.
- Artifacts view — binary package download links and container image pull commands, browsable by version, repo, and arch; covers dev builds, releases, and PRs.
- CVEs tab — the packages to bump to clear HIGH and CRITICAL CVEs in staging images, what the current staging image already fixes for each released image, and the per-image CVE table; new entries since your last look are marked.
- Tag-based filtering (RPM, DEB, container) and version selector.
- PR build tracking: dedicated board context per OBS PR branch.
- SSE-based live updates — cards and event log update in real time without a page refresh.
Expand Down
63 changes: 63 additions & 0 deletions backend/internal/api/cache.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package api

import (
"context"
"sync"
"time"
)

// ttlCache caches one value per key for ttl, with single-flight fetches
// (mirrors releaseArtifactsCache). Failed fetches are not cached.
type ttlCache[T any] struct {
mu sync.Mutex
ttl time.Duration
entries map[string]ttlCacheEntry[T]
inflight map[string]chan struct{}
}

type ttlCacheEntry[T any] struct {
value T
expires time.Time
err error
}

func newTTLCache[T any](ttl time.Duration) *ttlCache[T] {
return &ttlCache[T]{ttl: ttl, entries: map[string]ttlCacheEntry[T]{}, inflight: map[string]chan struct{}{}}
}

func (c *ttlCache[T]) Get(ctx context.Context, key string, fetch func(context.Context) (T, error)) (T, error) {
var zero T
now := time.Now()
c.mu.Lock()
if entry, ok := c.entries[key]; ok && now.Before(entry.expires) {
c.mu.Unlock()
return entry.value, entry.err
}
if wait, ok := c.inflight[key]; ok {
c.mu.Unlock()
select {
case <-wait:
case <-ctx.Done():
return zero, ctx.Err()
}
c.mu.Lock()
entry := c.entries[key]
c.mu.Unlock()
return entry.value, entry.err
}
wait := make(chan struct{})
c.inflight[key] = wait
c.mu.Unlock()

value, err := fetch(ctx)
c.mu.Lock()
expires := time.Now()
if err == nil {
expires = expires.Add(c.ttl)
}
c.entries[key] = ttlCacheEntry[T]{value: value, expires: expires, err: err}
delete(c.inflight, key)
close(wait)
c.mu.Unlock()
return value, err
}
42 changes: 42 additions & 0 deletions backend/internal/api/cve_report.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package api

import (
"context"
"database/sql"
"encoding/json"
"log/slog"
"net/http"
"time"

"github.com/percona/obs-dashboard/internal/cvereport"
"github.com/percona/obs-dashboard/internal/store"
)

// cveReportHandler serves GET /api/cve/report: the staging work list and the
// released/staging comparison, aggregated by cvereport.
func cveReportHandler(db *sql.DB, cache *ttlCache[cvereport.Report]) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
rep, err := cache.Get(r.Context(), "report", func(ctx context.Context) (cvereport.Report, error) {
staging, err := store.QueryImageScans(db, "ppg:staging")
if err != nil {
return cvereport.Report{}, err
}
released, err := store.QueryImageScans(db, "ppg:releases")
if err != nil {
return cvereport.Report{}, err
}
versions, err := store.QueryContainerVersions(db)
if err != nil {
return cvereport.Report{}, err
}
return cvereport.Build(staging, released, versions, time.Now()), nil
})
if err != nil {
slog.Error("api: cve report", "err", err)
http.Error(w, "internal server error", http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
_ = json.NewEncoder(w).Encode(rep)
}
}
103 changes: 103 additions & 0 deletions backend/internal/api/cve_report_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package api

import (
"database/sql"
"encoding/json"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"

"github.com/percona/obs-dashboard/internal/cvereport"
"github.com/percona/obs-dashboard/internal/model"
"github.com/percona/obs-dashboard/internal/store"
)

func seedReportScan(t *testing.T, db *sql.DB, project string, ids ...string) {
t.Helper()
var findings []model.CveFinding
for _, id := range ids {
findings = append(findings, model.CveFinding{
ID: id, PkgName: "openssl", InstalledVersion: "1", FixedVersion: "2",
Severity: "HIGH", Class: "os-pkgs", Vendor: "Red Hat, Inc.", Src: "openssl",
})
}
scan := model.CveScan{
Repo: "ubi9", Arch: "x86_64", ImageRef: "img", ScannedAt: time.Now().UTC(),
HighCount: len(ids), Findings: findings,
}
if err := store.UpsertCveScan(db, project, "pg", scan); err != nil {
t.Fatalf("UpsertCveScan: %v", err)
}
}

func TestCveReportHandler(t *testing.T) {
db, err := store.Open(":memory:")
if err != nil {
t.Fatalf("store.Open: %v", err)
}
t.Cleanup(func() { db.Close() })
h := cveReportHandler(db, newTTLCache[cvereport.Report](time.Minute))

// Empty DB: arrays are never null.
rec := httptest.NewRecorder()
h(rec, httptest.NewRequest(http.MethodGet, "/api/cve/report", nil))
if rec.Code != http.StatusOK {
t.Fatalf("empty: expected 200, got %d", rec.Code)
}
body := rec.Body.String()
if strings.Contains(body, "null") {
t.Fatalf("empty: body contains null: %s", body)
}
for _, want := range []string{`"ours":[]`, `"released":[]`} {
if !strings.Contains(body, want) {
t.Fatalf("empty: body missing %s: %s", want, body)
}
}

seedReportScan(t, db, "ppg:staging:18:containers", "CVE-1")
seedReportScan(t, db, "ppg:releases:18:containers", "CVE-1", "CVE-2")
h = cveReportHandler(db, newTTLCache[cvereport.Report](time.Minute))
rec = httptest.NewRecorder()
h(rec, httptest.NewRequest(http.MethodGet, "/api/cve/report", nil))
if rec.Code != http.StatusOK {
t.Fatalf("expected 200, got %d", rec.Code)
}
var rep cvereport.Report
if err := json.NewDecoder(rec.Body).Decode(&rep); err != nil {
t.Fatalf("decode: %v", err)
}
if len(rep.Staging.BaseOS) != 1 {
t.Fatalf("staging.base_os: expected 1 row, got %d", len(rep.Staging.BaseOS))
}
if len(rep.Released) != 1 || rep.Released[0].Total != 2 || rep.Released[0].FixedInStaging != 1 {
t.Fatalf("released: unexpected %+v", rep.Released)
}
}

func TestCveReportHandlerStoreError(t *testing.T) {
db, err := store.Open(":memory:")
if err != nil {
t.Fatalf("store.Open: %v", err)
}
db.Close()
h := cveReportHandler(db, newTTLCache[cvereport.Report](time.Minute))
rec := httptest.NewRecorder()
h(rec, httptest.NewRequest(http.MethodGet, "/api/cve/report", nil))
if rec.Code != http.StatusInternalServerError {
t.Fatalf("expected 500, got %d", rec.Code)
}
}

func TestCveReportRoute(t *testing.T) {
router := setupTestServer(t)
rec := httptest.NewRecorder()
router.ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/api/cve/report", nil))
if rec.Code != http.StatusOK {
t.Fatalf("expected 200, got %d", rec.Code)
}
if ct := rec.Header().Get("Content-Type"); ct != "application/json" {
t.Fatalf("expected JSON, got %q", ct)
}
}
58 changes: 1 addition & 57 deletions backend/internal/api/overview.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"net/http"
"sort"
"strings"
"sync"
"time"

"github.com/percona/obs-dashboard/internal/store"
Expand Down Expand Up @@ -294,61 +293,6 @@ func buildOverviewSnapshot(window string, now time.Time,
return snap
}

// ── cache (mirrors releaseArtifactsCache: TTL + singleflight) ──

type overviewCache struct {
mu sync.Mutex
ttl time.Duration
entries map[string]overviewCacheEntry
inflight map[string]chan struct{}
}

type overviewCacheEntry struct {
snapshot OverviewSnapshot
expires time.Time
err error
}

func newOverviewCache(ttl time.Duration) *overviewCache {
return &overviewCache{ttl: ttl, entries: map[string]overviewCacheEntry{}, inflight: map[string]chan struct{}{}}
}

func (c *overviewCache) Get(ctx context.Context, key string, fetch func(context.Context) (OverviewSnapshot, error)) (OverviewSnapshot, error) {
now := time.Now()
c.mu.Lock()
if entry, ok := c.entries[key]; ok && now.Before(entry.expires) {
c.mu.Unlock()
return entry.snapshot, entry.err
}
if wait, ok := c.inflight[key]; ok {
c.mu.Unlock()
select {
case <-wait:
case <-ctx.Done():
return OverviewSnapshot{}, ctx.Err()
}
c.mu.Lock()
entry := c.entries[key]
c.mu.Unlock()
return entry.snapshot, entry.err
}
wait := make(chan struct{})
c.inflight[key] = wait
c.mu.Unlock()

snapshot, err := fetch(ctx)
c.mu.Lock()
expires := time.Now()
if err == nil {
expires = expires.Add(c.ttl)
}
c.entries[key] = overviewCacheEntry{snapshot: snapshot, expires: expires, err: err}
delete(c.inflight, key)
close(wait)
c.mu.Unlock()
return snapshot, err
}

// ── handler ──

// mergeInstanceCounts folds unstamped (pre-migration) targets into the
Expand Down Expand Up @@ -379,7 +323,7 @@ func mergeInstanceCounts(counts []store.InstanceTargetCounts, defaultSlug string
}

// overviewHandler serves GET /api/overview?window=24h|48h|7d.
func overviewHandler(db *sql.DB, defaultSlug string, cache *overviewCache) http.HandlerFunc {
func overviewHandler(db *sql.DB, defaultSlug string, cache *ttlCache[OverviewSnapshot]) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
window := r.URL.Query().Get("window")
if window == "" {
Expand Down
6 changes: 3 additions & 3 deletions backend/internal/api/overview_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ func TestOverviewHandlerWindowValidation(t *testing.T) {
t.Fatal(err)
}
defer db.Close()
h := overviewHandler(db, "opensuse", newOverviewCache(time.Minute))
h := overviewHandler(db, "opensuse", newTTLCache[OverviewSnapshot](time.Minute))

for _, tc := range []struct {
q string
Expand Down Expand Up @@ -225,7 +225,7 @@ func TestOverviewHandlerByInstance(t *testing.T) {
}
}

h := overviewHandler(db, "opensuse", newOverviewCache(time.Minute))
h := overviewHandler(db, "opensuse", newTTLCache[OverviewSnapshot](time.Minute))
w := httptest.NewRecorder()
h(w, httptest.NewRequest(http.MethodGet, "/api/overview", nil))
if w.Code != http.StatusOK {
Expand Down Expand Up @@ -255,7 +255,7 @@ func TestOverviewHandlerCaches(t *testing.T) {
t.Fatal(err)
}
defer db.Close()
h := overviewHandler(db, "opensuse", newOverviewCache(time.Minute))
h := overviewHandler(db, "opensuse", newTTLCache[OverviewSnapshot](time.Minute))

w := httptest.NewRecorder()
h(w, httptest.NewRequest(http.MethodGet, "/api/overview", nil))
Expand Down
5 changes: 4 additions & 1 deletion backend/internal/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/go-chi/chi/v5"
"github.com/go-chi/chi/v5/middleware"
"github.com/percona/obs-dashboard/internal/auth"
"github.com/percona/obs-dashboard/internal/cvereport"
"github.com/percona/obs-dashboard/internal/hub"
"github.com/percona/obs-dashboard/internal/obs"
"github.com/percona/obs-dashboard/internal/upgrade"
Expand Down Expand Up @@ -61,7 +62,8 @@ func NewRouter(db *sql.DB, h *hub.Hub, fleet *obs.Fleet, ws Statter, telemetryEn
r.Get("/healthz", healthzHandler)
releaseArtifacts := newReleaseArtifactsCache(10 * time.Minute)
metadataCache := newBinaryListCache(5 * time.Minute)
overview := newOverviewCache(60 * time.Second)
overview := newTTLCache[OverviewSnapshot](60 * time.Second)
cveReport := newTTLCache[cvereport.Report](30 * time.Second)

r.Route("/api/products/{product}/{tier}/{version}", func(r chi.Router) {
r.Get("/packages", packagesHandler(db))
Expand Down Expand Up @@ -97,6 +99,7 @@ func NewRouter(db *sql.DB, h *hub.Hub, fleet *obs.Fleet, ws Statter, telemetryEn
r.Get("/api/overview", overviewHandler(db, fleet.Default().Slug, overview))
r.Get("/api/cve/scans", cveScansHandler(db))
r.Get("/api/cve/findings", cveFindingsHandler(db))
r.Get("/api/cve/report", cveReportHandler(db, cveReport))

// State-changing actions: signed-in, allowlisted users only.
r.Group(func(r chi.Router) {
Expand Down
Loading
Loading