Skip to content

Commit

Permalink
Merge pull request #28 from lucasmafra/consumer-execution-boxes
Browse files Browse the repository at this point in the history
Create execution boxes for consumer spans
  • Loading branch information
davicorreiajr authored Apr 2, 2020
2 parents 251b2d6 + abbbdbe commit f24cc73
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 44 deletions.
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"
: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

0 comments on commit f24cc73

Please sign in to comment.