Skip to content

armgit / Pulse

Public Imported from GitHub
0

Real-time monitoring dashboard for Proxmox VE, PBS, Docker, Kubernetes, TrueNAS and vSphere. Self-hosted, with alerts for failed backups, full disks, unhealthy containers and offline nodes.

Index unified resource timeline filters

rcourtman2bf4c8145068
diff --git a/docs/release-control/v6/internal/subsystems/unified-resources.md b/docs/release-control/v6/internal/subsystems/unified-resources.md
index 95c884ba2d..b25246b723 100644
--- a/docs/release-control/v6/internal/subsystems/unified-resources.md
+++ b/docs/release-control/v6/internal/subsystems/unified-resources.md
@@ -89,6 +89,10 @@ in memory or adapter-local state.
and `/api/resources/{id}/relationships` expose the current graph facets as
separate queryable surfaces instead of forcing consumers to parse the full
resource payload.
+Those filtered timeline reads are backed by dedicated `resource_changes`
+indexes on `canonical_id`, `kind`, `source_type`, and `observed_at`, so the
+canonical history path stays fast as the filtered timeline grows instead of
+falling back to a consumer-local scan.
The frontend now also consumes those facet reads through
`frontend-modern/src/api/resources.ts` and the dedicated resource detail
drawer, which keeps the presentation surface aligned with the governed API
diff --git a/internal/unifiedresources/code_standards_test.go b/internal/unifiedresources/code_standards_test.go
index 4fa5e41f53..0ac2fde4a2 100644
--- a/internal/unifiedresources/code_standards_test.go
+++ b/internal/unifiedresources/code_standards_test.go
@@ -260,6 +260,24 @@ func TestResourceAPIExposesDedicatedFacetReads(t *testing.T) {
}
}
+func TestResourceTimelineStoreIndexesSupportFilteredReads(t *testing.T) {
+ data, err := os.ReadFile(filepath.Join("store.go"))
+ if err != nil {
+ t.Fatalf("failed to read store.go: %v", err)
+ }
+ source := string(data)
+ requiredSnippets := []string{
+ "idx_resource_changes_kind_time",
+ "idx_resource_changes_source_type_time",
+ "ensureResourceChangesIndexes",
+ }
+ for _, snippet := range requiredSnippets {
+ if !strings.Contains(source, snippet) {
+ t.Fatalf("internal/unifiedresources/store.go must pin filtered timeline index snippet %q", snippet)
+ }
+ }
+}
+
func TestResourceFacetCountsAreCanonicalResourceFields(t *testing.T) {
typesData, err := os.ReadFile(filepath.Join("types.go"))
if err != nil {
diff --git a/internal/unifiedresources/store.go b/internal/unifiedresources/store.go
index e912bc9ccf..717aa7227f 100644
--- a/internal/unifiedresources/store.go
+++ b/internal/unifiedresources/store.go
@@ -350,6 +350,9 @@ func (s *SQLiteResourceStore) initSchema() error {
if err := s.migrateResourceChangesSchema(); err != nil {
return err
}
+ if err := s.ensureResourceChangesIndexes(); err != nil {
+ return err
+ }
return nil
}
@@ -381,6 +384,20 @@ func (s *SQLiteResourceStore) migrateResourceChangesSchema() error {
return nil
}
+func (s *SQLiteResourceStore) ensureResourceChangesIndexes() error {
+ indexes := []string{
+ `CREATE INDEX IF NOT EXISTS idx_resource_changes_canonical_time ON resource_changes(canonical_id, observed_at DESC)`,
+ `CREATE INDEX IF NOT EXISTS idx_resource_changes_kind_time ON resource_changes(kind, observed_at DESC)`,
+ `CREATE INDEX IF NOT EXISTS idx_resource_changes_source_type_time ON resource_changes(source_type, observed_at DESC)`,
+ }
+ for _, stmt := range indexes {
+ if _, err := s.db.Exec(stmt); err != nil {
+ return fmt.Errorf("ensure resource_changes index: %w", err)
+ }
+ }
+ return nil
+}
+
func (s *SQLiteResourceStore) addResourceChangesColumnIfMissing(columns map[string]struct{}, columnName, definition string) error {
if _, ok := columns[columnName]; ok {
return nil
diff --git a/internal/unifiedresources/store_test.go b/internal/unifiedresources/store_test.go
index c769a3da0a..937b543e8e 100644
--- a/internal/unifiedresources/store_test.go
+++ b/internal/unifiedresources/store_test.go
@@ -208,6 +208,47 @@ func TestNewSQLiteResourceStore_MigratesLegacyResourceChangesTable(t *testing.T)
if len(results) != 2 {
t.Fatalf("GetRecentChanges after migration write returned %d rows, want 2", len(results))
}
+
+ indexes, err := resourceChangesIndexes(store.db)
+ if err != nil {
+ t.Fatalf("resourceChangesIndexes: %v", err)
+ }
+ for _, want := range []string{
+ "idx_resource_changes_canonical_time",
+ "idx_resource_changes_kind_time",
+ "idx_resource_changes_source_type_time",
+ } {
+ if _, ok := indexes[want]; !ok {
+ t.Fatalf("expected migrated resource_changes index %q, got %#v", want, indexes)
+ }
+ }
+}
+
+func resourceChangesIndexes(db *sql.DB) (map[string]struct{}, error) {
+ rows, err := db.Query(`PRAGMA index_list(resource_changes)`)
+ if err != nil {
+ return nil, err
+ }
+ defer rows.Close()
+
+ indexes := make(map[string]struct{})
+ for rows.Next() {
+ var (
+ seq int
+ name string
+ uniq int
+ origin string
+ part int
+ )
+ if err := rows.Scan(&seq, &name, &uniq, &origin, &part); err != nil {
+ return nil, err
+ }
+ indexes[name] = struct{}{}
+ }
+ if err := rows.Err(); err != nil {
+ return nil, err
+ }
+ return indexes, nil
}
func newTestStore(t *testing.T) *SQLiteResourceStore {