materialized view and a bit better ui
Build and Publish / Metadata (push) Successful in 2s
Build and Publish / BuildAndDeployAmd64 (push) Successful in 1m3s

This commit is contained in:
mats committed 2026-09-19 12:43:17 +02:00
1 parent 26b677154b
commit 49f9bb3458
30 files changed
+2184 -106

No files matched your search

+28 -4
View File
@@ -198,7 +198,7 @@ func (s *ClickHouseStore) initSchema(ctx context.Context) error {
// empty until this succeeds.
fmt.Printf("clickhouse: failed to create rollup view (stats endpoints stay empty): %v\n", err)
}
return nil
return s.initTraceSchema(ctx)
}
// chPayload extracts rollup columns from the marshaled OTLP JSON. Field
@@ -326,17 +326,41 @@ func extractHead(data []byte) (service string, isErr bool, release, traceID stri
func (s *ClickHouseStore) Append(ctx context.Context, entry websocket.HistoryEntry) error {
service, isErr, release, traceID := extractHead(entry.Data)
// A batch routinely holds several traces, so keep every trace id (the
// scalar trace_id column only records the first) for indexed lookups.
var facts []spanFact
var traceIDs []string
switch entry.Type {
case "traces":
facts = extractSpanFacts(entry.Data)
seen := make(map[string]struct{}, len(facts))
for _, f := range facts {
if _, ok := seen[f.TraceID]; !ok {
seen[f.TraceID] = struct{}{}
traceIDs = append(traceIDs, f.TraceID)
}
}
case "logs":
traceIDs = allTraceIDs(entry.Data)
}
if traceIDs == nil {
traceIDs = []string{}
}
ts := time.Unix(0, entry.Timestamp).UTC()
err := s.conn.AsyncInsert(ctx, fmt.Sprintf(
`INSERT INTO %s.entries
(timestamp, type, service, is_error, release, trace_id, data)
VALUES (?, ?, ?, ?, ?, ?, ?)`, s.db),
(timestamp, type, service, is_error, release, trace_id, trace_ids, data)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, s.db),
false,
ts, entry.Type, service, boolToUint8(isErr), release, traceID, string(entry.Data),
ts, entry.Type, service, boolToUint8(isErr), release, traceID, traceIDs, string(entry.Data),
)
if err != nil {
return fmt.Errorf("clickhouse append: %w", err)
}
if err := s.appendSpanFacts(ctx, ts, facts); err != nil {
return fmt.Errorf("clickhouse span facts: %w", err)
}
return nil
}