-
Notifications
You must be signed in to change notification settings - Fork 28
/
05-upstream-spans.sql
74 lines (71 loc) · 1.59 KB
/
05-upstream-spans.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
-- nodes
WITH RECURSIVE x AS
(
SELECT
trace_id,
span_id,
parent_span_id,
service_name,
span_name
FROM ps_trace.span
WHERE $__timeFilter(start_time)
AND service_name = '${service}'
AND span_name = '${operation}'
UNION ALL
SELECT
s.trace_id,
s.span_id,
s.parent_span_id,
s.service_name,
s.span_name
FROM x
INNER JOIN ps_trace.span s
ON (x.trace_id = s.trace_id
AND x.parent_span_id = s.span_id)
)
SELECT
md5(service_name || '-' || span_name) as id,
span_name as title,
service_name as "subTitle",
count(distinct span_id) as "mainStat"
FROM x
GROUP BY service_name, span_name
;
-- edges
WITH RECURSIVE x AS
(
SELECT
trace_id,
span_id,
parent_span_id,
service_name,
span_name,
null::text as id,
null::text as target,
null::text as source
FROM ps_trace.span
WHERE $__timeFilter(start_time)
AND service_name = '${service}'
AND span_name = '${operation}'
UNION ALL
SELECT
s.trace_id,
s.span_id,
s.parent_span_id,
s.service_name,
s.span_name,
md5(s.service_name || '-' || s.span_name || '-' || x.service_name || '-' || x.span_name) as id,
md5(x.service_name || '-' || x.span_name) as target,
md5(s.service_name || '-' || s.span_name) as source
FROM x
INNER JOIN ps_trace.span s
ON (x.trace_id = s.trace_id
AND x.parent_span_id = s.span_id)
)
SELECT DISTINCT
x.id,
x.target,
x.source
FROM x
WHERE id is not null
;