Skip to content

Commit b9f4499

Browse files
fix: bound the service map to the recent window (#41)
Both service-map queries scanned the entire spans table (now 447k rows after expanding tracing): a DISTINCT-service full scan and a child↔parent self-join over everything. A service map is current topology, so bound both to the last hour — ~640x less data, an index scan instead of a full self-join. Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 8f96fd3 commit b9f4499

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

server/src/api.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,8 +864,12 @@ pub struct ServiceMap {
864864
/// GET /api/servicemap — service dependency graph derived from span parent/child links.
865865
#[tracing::instrument(skip_all)]
866866
pub async fn service_map(State(pool): State<PgPool>) -> Result<Json<ServiceMap>, ApiError> {
867+
// Current topology only: bound to the recent window so this is a tiny
868+
// index scan, not a self-join over the whole (retention-deep) spans table.
867869
let nodes: Vec<String> = sqlx::query_scalar(
868-
"SELECT DISTINCT service FROM spans WHERE service IS NOT NULL ORDER BY 1",
870+
"SELECT DISTINCT service FROM spans
871+
WHERE service IS NOT NULL AND start_time > now() - interval '1 hour'
872+
ORDER BY 1",
869873
)
870874
.fetch_all(&pool)
871875
.await
@@ -877,7 +881,8 @@ pub async fn service_map(State(pool): State<PgPool>) -> Result<Json<ServiceMap>,
877881
JOIN spans parent
878882
ON child.parent_span_id = parent.span_id
879883
AND child.trace_id = parent.trace_id
880-
WHERE parent.service IS NOT NULL
884+
WHERE child.start_time > now() - interval '1 hour'
885+
AND parent.service IS NOT NULL
881886
AND child.service IS NOT NULL
882887
AND parent.service IS DISTINCT FROM child.service
883888
GROUP BY parent.service, child.service

0 commit comments

Comments
 (0)