Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create execution boxes for consumer spans #28

Merged
merged 2 commits into from
Apr 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/atlas/domain/sequence_diagram.clj
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
([k tags] (->> tags (filter (match-tag? k)) first))
([k v tags] (->> tags (filter (match-tag? k v)) first)))

(def has-tag? (comp boolean find-tag))
(def has-tag? (comp boolean find-tag))

(defn- server-span? [{:keys [tags]}] (has-tag? "span.kind" "server" tags))

(defn- consumer-span? [{:keys [tags]}] (has-tag? "span.kind" "consumer" tags))

(defn- client-span? [{:keys [tags]}] (has-tag? "span.kind" "client" tags))

(defn- producer-span? [{:keys [tags]}] (has-tag? "span.kind" "producer" tags))
Expand Down Expand Up @@ -77,19 +79,20 @@
(s/defn duration-ms :- cs/PosInt
[trace :- s-jaeger/Trace]
(let [start-time (start-time trace)
end-time (->> trace :spans (map span->end-time) sort last)]
end-time (->> trace :spans (map span->end-time) sort last)]
(.toMillis (time/duration start-time end-time))))

(s/defn lifelines :- [s-sequence-diagram/Lifeline]
[trace :- s-jaeger/Trace]
(let [services (->> trace :processes (map process->lifeline))
topics (->> trace :spans (filter producer-span?) (map span->topic) (map topic->lifeline))]
[{:keys [spans processes]} :- s-jaeger/Trace]
(let [services (->> processes (map process->lifeline))
topics (->> spans (filter producer-span?) (map span->topic) (map topic->lifeline))]
(concat services topics)))

(s/defn execution-boxes :- [s-sequence-diagram/ExecutionBox]
[trace :- s-jaeger/Trace]
(let [server-spans (->> trace :spans (filter server-span?))]
(map (span->execution-box trace) server-spans)))
(let [server-spans (->> trace :spans (filter server-span?))
consumer-spans (->> trace :spans (filter consumer-span?))]
(map (span->execution-box trace) (concat server-spans consumer-spans))))

(s/defn arrows :- [s-sequence-diagram/Arrow]
[trace :- s-jaeger/Trace]
Expand Down
93 changes: 56 additions & 37 deletions test/atlas/domain/sequence_diagram_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@
:start-time 1500000000000000
:duration 1000
:references []
:tags [{:key "span.kind"
:type "string"
:value "server"}
{:key "http.method"
:type "string"
:value "GET"}
{:key "http.url"
:type "string"
:value "/api/orders/1"}]}
:tags [{:key "span.kind"
:type "string"
:value "server"}
{:key "http.method"
:type "string"
:value "GET"}
{:key "http.url"
:type "string"
:value "/api/orders/1"}]}

{:trace-id "1"
:span-id "2"
Expand All @@ -31,15 +31,15 @@
:references [{:ref-type :child-of
:trace-id "1"
:span-id "1"}]
:tags [{:key "span.kind"
:type "string"
:value "client"}
{:key "http.method"
:type "string"
:value "GET"}
{:key "http.url"
:type "string"
:value "/api/orders/1"}]}
:tags [{:key "span.kind"
:type "string"
:value "client"}
{:key "http.method"
:type "string"
:value "GET"}
{:key "http.url"
:type "string"
:value "/api/orders/1"}]}

{:trace-id "1"
:span-id "3"
Expand All @@ -50,30 +50,45 @@
:references [{:ref-type :child-of
:trace-id "1"
:span-id "2"}]
:tags [{:key "span.kind"
:type "string"
:value "server"}
{:key "http.method"
:type "string"
:value "GET"}
{:key "http.url"
:type "string"
:value "/api/orders/1"}]}
:tags [{:key "span.kind"
:type "string"
:value "server"}
{:key "http.method"
:type "string"
:value "GET"}
{:key "http.url"
:type "string"
:value "/api/orders/1"}]}
{:trace-id "1"
:span-id "4"
:process-id :p2
:operation-name "kafka.out PROCESS_ORDER"
:start-time 1500000000250000
:duration 50
:references [{:ref-type :child-of
:trace-id "1"
:span-id "3"}]
:tags [{:key "span.kind"
:type "string"
:value "producer"}
{:key "message_bus.destination"
:type "string"
:value "PROCESS_ORDER"}]}]
:duration 50
:references [{:ref-type :child-of
:trace-id "1"
:span-id "3"}]
:tags [{:key "span.kind"
:type "string"
:value "producer"}
{:key "message_bus.destination"
:type "string"
:value "PROCESS_ORDER"}]}
{:trace-id "1"
lucasmafra marked this conversation as resolved.
Show resolved Hide resolved
:span-id "5"
:process-id :p2
:operation-name "kafka.in PROCESS_ORDER"
:start-time 1500000000350000
:duration 50
:references [{:ref-type :child-of
:trace-id "1"
:span-id "4"}]
:tags [{:key "span.kind"
:type "string"
:value "consumer"}
{:key "message_bus.destination"
:type "string"
:value "PROCESS_ORDER"}]}]

:processes {:p1 {:service-name "bff"}
:p2 {:service-name "orders"}}})
Expand Down Expand Up @@ -104,6 +119,10 @@
{:id "3"
:start-time #epoch 1500000000200
:duration-ms 100
:lifeline "orders"}
{:id "5"
:start-time #epoch 1500000000350
:duration-ms 50
:lifeline "orders"}]
(nut/execution-boxes trace)))))

Expand Down
19 changes: 19 additions & 0 deletions test/flows/get_sequence_diagram.clj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,21 @@
"tags" [{"key" "span.kind"
"type" "string"
"value" "producer"}
{"key" "message_bus.destination"
"type" "string"
"value" "PROCESS_ORDER"}]}
{"traceID" "1"
"spanID" "5"
"processID" "p2"
"operationName" "kafka.in PROCESS_ORDER"
"startTime" 1500000000350000
"duration" 50
"references" [{"ref-type" "CHILD_OF"
"traceID" "1"
"spanID" "4"}]
"tags" [{"key" "span.kind"
"type" "string"
"value" "consumer"}
{"key" "message_bus.destination"
"type" "string"
"value" "PROCESS_ORDER"}]}]
Expand All @@ -97,6 +112,10 @@
{"id" "3"
"start_time" 1500000000200
"duration_ms" 100
"lifeline" "orders"}
{"id" "5"
"start_time" 1500000000350
"duration_ms" 50
"lifeline" "orders"}]
"arrows" [{"id" "2"
"from" "bff"
Expand Down