fix
Build and Publish / Metadata (push) Successful in 9s
Build and Publish / BuildAndDeployAmd64 (push) Successful in 2m35s

This commit is contained in:
mats committed 2026-09-22 22:09:32 +02:00
1 parent e81b8c2fcd
commit 0052822e49
7 files changed
+94 -1

No files matched your search

+38
View File
@@ -213,6 +213,44 @@ func (s *ClickHouseStore) AppendOccurrence(ctx context.Context, occ Occurrence)
return nil
}
// RecentOccurrences returns persisted issue occurrences in chronological
// order so the in-memory issue tracker can be rebuilt after a restart.
func (s *ClickHouseStore) RecentOccurrences(ctx context.Context, limit int) ([]Occurrence, error) {
if limit <= 0 {
limit = 100000
}
rows, err := s.conn.Query(ctx, fmt.Sprintf(`
SELECT issue_id, kind, service, toUnixTimestamp64Nano(timestamp), trace_id, span_id, sample
FROM %s.issue_occurrences
ORDER BY timestamp DESC
LIMIT ?`, s.db), limit)
if err != nil {
return nil, fmt.Errorf("clickhouse recent issue occurrences: %w", err)
}
defer rows.Close()
var out []Occurrence
for rows.Next() {
var o Occurrence
var ts int64
var sample string
if err := rows.Scan(&o.IssueID, &o.Kind, &o.Service, &ts, &o.TraceID, &o.SpanID, &sample); err != nil {
return nil, fmt.Errorf("scan issue occurrence: %w", err)
}
o.Timestamp = ts
o.Sample = json.RawMessage(sample)
out = append(out, o)
}
if err := rows.Err(); err != nil {
return nil, fmt.Errorf("iterate issue occurrences: %w", err)
}
// The query is newest-first; replay oldest-first to preserve issue titles
// and trend buckets as they were originally observed.
for i, j := 0, len(out)-1; i < j; i, j = i+1, j-1 {
out[i], out[j] = out[j], out[i]
}
return out, nil
}
const maxSamplesPerIssueTrace = 20
const maxUntraced = 20