ListEnabledCheckDefs selected interval_s but never filtered on it, so every enabled check ran on every 30s pass and the declared per-check intervals were decorative. Invisible at 17 enabled checks; at ~180 it would have meant ~126 SSH connections every 30s (~363k/day) and `apt update` on every machine every 30 seconds — 14,400 mirror hits a day to answer a question that changes daily. - check_defs.last_run_at (migration 026) + a due-ness predicate in the query. A column rather than scheduler memory because this control plane restarts on every deploy, and an in-memory map would re-fire every check on each restart. - runCheck stamps last_run_at before processing the result, so a permanently failing check backs off to its interval instead of re-running every pass. - updates and backup-freshness drop to daily. Both answer questions whose answers change about once a day; 60s was just the shared ssh-script default. - last_run_at is seeded to a random offset within the interval so checks created by the same seed do not stay in lockstep — otherwise ~165 probes land in the same instant each minute instead of spread across it. Deliberately not in the upsert's DO UPDATE: a re-seed must not re-herd them. Steady state becomes ~180k SSH/day (down from ~363k) and 5 apt runs/day (down from 14,400), with each 60s check landing at its own point in the minute. Also renumbers 022→023, 023→024, 024→025: origin/main added its own 022_knowledge_revisions, and prod has already applied version 22. Left colliding, prod would have skipped the monitoring_spec migration entirely and then failed the seed on a missing column. Co-Authored-By: Claude <noreply@anthropic.com>
132 lines
3.0 KiB
Go
132 lines
3.0 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: ontology.sql
|
|
|
|
package sqlcgen
|
|
|
|
import (
|
|
"context"
|
|
)
|
|
|
|
const getLifecycleForType = `-- name: GetLifecycleForType :one
|
|
SELECT ld.id, ld.states, ld.default_state, ld.terminal_states, ld.transitions, ld.created_at FROM lifecycle_defs ld
|
|
JOIN entity_types et ON et.lifecycle_id = ld.id
|
|
WHERE et.name = $1
|
|
`
|
|
|
|
func (q *Queries) GetLifecycleForType(ctx context.Context, name string) (LifecycleDef, error) {
|
|
row := q.db.QueryRow(ctx, getLifecycleForType, name)
|
|
var i LifecycleDef
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.States,
|
|
&i.DefaultState,
|
|
&i.TerminalStates,
|
|
&i.Transitions,
|
|
&i.CreatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listEntityTypes = `-- name: ListEntityTypes :many
|
|
SELECT name, parent_type, is_abstract, domain, layer, description, lifecycle_id, attribute_schema, schema_version, status, created_at, updated_at, monitoring_spec FROM entity_types ORDER BY name
|
|
`
|
|
|
|
func (q *Queries) ListEntityTypes(ctx context.Context) ([]EntityType, error) {
|
|
rows, err := q.db.Query(ctx, listEntityTypes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []EntityType
|
|
for rows.Next() {
|
|
var i EntityType
|
|
if err := rows.Scan(
|
|
&i.Name,
|
|
&i.ParentType,
|
|
&i.IsAbstract,
|
|
&i.Domain,
|
|
&i.Layer,
|
|
&i.Description,
|
|
&i.LifecycleID,
|
|
&i.AttributeSchema,
|
|
&i.SchemaVersion,
|
|
&i.Status,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
&i.MonitoringSpec,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listLifecycleDefs = `-- name: ListLifecycleDefs :many
|
|
SELECT id, states, default_state, terminal_states, transitions, created_at FROM lifecycle_defs ORDER BY id
|
|
`
|
|
|
|
func (q *Queries) ListLifecycleDefs(ctx context.Context) ([]LifecycleDef, error) {
|
|
rows, err := q.db.Query(ctx, listLifecycleDefs)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []LifecycleDef
|
|
for rows.Next() {
|
|
var i LifecycleDef
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.States,
|
|
&i.DefaultState,
|
|
&i.TerminalStates,
|
|
&i.Transitions,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const listRelationshipTypes = `-- name: ListRelationshipTypes :many
|
|
SELECT name, inverse, source_type, target_type, cardinality, description, created_at FROM relationship_types ORDER BY name
|
|
`
|
|
|
|
func (q *Queries) ListRelationshipTypes(ctx context.Context) ([]RelationshipType, error) {
|
|
rows, err := q.db.Query(ctx, listRelationshipTypes)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []RelationshipType
|
|
for rows.Next() {
|
|
var i RelationshipType
|
|
if err := rows.Scan(
|
|
&i.Name,
|
|
&i.Inverse,
|
|
&i.SourceType,
|
|
&i.TargetType,
|
|
&i.Cardinality,
|
|
&i.Description,
|
|
&i.CreatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|