fix
This commit is contained in:
1 parent
e81b8c2fcd
commit
0052822e49
7 files changed
+94
-1
No files matched your search
@@ -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
|
||||
|
||||
|
||||
@@ -134,6 +134,7 @@ type IssueTracesPage struct {
|
||||
// did this issue happen in" in one query (ClickHouseStore).
|
||||
type OccurrenceStore interface {
|
||||
AppendOccurrence(ctx context.Context, occ Occurrence) error
|
||||
RecentOccurrences(ctx context.Context, limit int) ([]Occurrence, error)
|
||||
IssueTraces(ctx context.Context, issueID string, opts IssueTracesOptions) (IssueTracesPage, error)
|
||||
IssueSources(ctx context.Context, issueID string) ([]IssueSource, error)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user