Show collapsible IP check cycles in the registry
This commit is contained in:
1 parent
94124747ce
commit
b58d5f5b82
16 files changed
+332
-36
No files matched your search
@@ -603,6 +603,61 @@ func lastCycleResultFromChecks(ctx context.Context, d *DB, registryID int64) (st
|
||||
}
|
||||
}
|
||||
|
||||
type RegistryCycle struct {
|
||||
CycleID int `json:"cycle_id"`
|
||||
RunID int64 `json:"run_id"`
|
||||
Verdict string `json:"verdict"`
|
||||
AggregatedAt *time.Time `json:"aggregated_at"`
|
||||
SelfCheckFailedOn []string `json:"self_check_failed_on"`
|
||||
}
|
||||
|
||||
// ListRegistryCycles adds run verdicts and self-check failures to the cycles
|
||||
// that still have queue data, checks, or events. Analytics can keep results
|
||||
// after registry history is pruned.
|
||||
func (d *DB) ListRegistryCycles(ctx context.Context, registryID int64) ([]RegistryCycle, error) {
|
||||
rows, err := d.QueryContext(ctx, `
|
||||
WITH evidence AS (
|
||||
SELECT cycle_id, run_id FROM checks WHERE registry_id=?1
|
||||
UNION ALL
|
||||
SELECT DISTINCT cycle_id, NULL FROM events WHERE registry_id=?1 AND cycle_id>0
|
||||
UNION ALL
|
||||
SELECT cycle_id, run_id FROM ip_queue WHERE registry_id=?1
|
||||
), cycles AS (
|
||||
SELECT cycle_id, MAX(run_id) AS run_id FROM evidence GROUP BY cycle_id
|
||||
)
|
||||
SELECT c.cycle_id, COALESCE(c.run_id, r.run_id, 0),
|
||||
COALESCE(CASE WHEN r.verdict_derived=0 THEN r.verdict END, ''),
|
||||
CASE WHEN r.verdict_derived=0 THEN r.aggregated_at END,
|
||||
(SELECT json_group_array(validator_id) FROM (
|
||||
SELECT DISTINCT validator_id FROM ip_self_check_failures
|
||||
WHERE registry_id=?1 AND cycle_id=c.cycle_id ORDER BY validator_id
|
||||
))
|
||||
FROM cycles c LEFT JOIN run_results r ON r.registry_id=?1 AND r.cycle_id=c.cycle_id
|
||||
ORDER BY c.cycle_id DESC
|
||||
`, registryID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
var cycles []RegistryCycle
|
||||
for rows.Next() {
|
||||
var c RegistryCycle
|
||||
var aggregatedAt sql.NullString
|
||||
var failures string
|
||||
if err := rows.Scan(&c.CycleID, &c.RunID, &c.Verdict, &aggregatedAt, &failures); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if c.AggregatedAt, err = nullStringToTimePtr(aggregatedAt); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := json.Unmarshal([]byte(failures), &c.SelfCheckFailedOn); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
cycles = append(cycles, c)
|
||||
}
|
||||
return cycles, rows.Err()
|
||||
}
|
||||
|
||||
func scanRegistryItems(rows *sql.Rows) ([]RegistryItem, error) {
|
||||
var out []RegistryItem
|
||||
for rows.Next() {
|
||||
|
||||
Reference in new issue
Block a user