Skip to content

Commit

Permalink
Merge pull request #332 from walmartlabs/20200828-apollo-tracing
Browse files Browse the repository at this point in the history
Convert ad-hoc timing to follow the standard for Apollo GraphQL tracing
  • Loading branch information
hlship committed Sep 3, 2020
2 parents b468926 + a642d7e commit ae0a65a
Show file tree
Hide file tree
Showing 22 changed files with 606 additions and 376 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.38.0 -- UNRELEASED

Optional request tracing is now designed to be compatible with Apollo GraphQL's implementation.

## 0.37.0 -- 30 Jun 2020

Added new function `com.walmartlabs.lacinia.util/inject-streamers`, used to
Expand Down
34 changes: 34 additions & 0 deletions dev-resources/tracing_demo.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
(ns tracing-demo
(:require
[com.walmartlabs.lacinia :as lacinia]
[com.walmartlabs.lacinia.tracing :as tracing]
[com.walmartlabs.lacinia-test :as lacinia-test]
[com.walmartlabs.lacinia.resolve :as resolve]
[com.walmartlabs.test-utils :refer [simplify]])
(:import (java.util.concurrent ThreadPoolExecutor TimeUnit SynchronousQueue)))

(def star-wars-schema lacinia-test/default-schema)

(comment
(let [queue (SynchronousQueue.)
thread-pool (ThreadPoolExecutor. 5 10 1 TimeUnit/SECONDS queue)]
;; Ensure all core thread are started and ready, however, for the tiny
;; resolvers in the example, it's hard to show parallel behavior. Need some I/O.
(while (.prestartCoreThread thread-pool))
(try
(binding [resolve/*callback-executor* thread-pool]

(simplify
(lacinia/execute
star-wars-schema "
{
luke: human(id: \"1000\") { friends { name }}
leia: human(id: \"1003\") { name }
}"
nil
(tracing/enable-tracing nil))))
(finally
(.shutdown thread-pool))))


)
2 changes: 1 addition & 1 deletion docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ pseudoxml:

live: clean html
$(SPHINXAUTOBUILD) \
-i '.git/*' \
--ignore '.git/*' \
--no-initial \
--open-browser \
-b html \
Expand Down
21 changes: 0 additions & 21 deletions docs/_examples/timings.edn

This file was deleted.

73 changes: 73 additions & 0 deletions docs/_examples/tracing.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
(require '[com.walmartlabs.lacinia :as lacinia]
[com.walmartlabs.lacinia.tracing :as tracing])

(def start-wars-schema ...)

(lacinia/execute
star-wars-schema "
{
luke: human(id: \"1000\") { friends { name }}
leia: human(id: \"1003\") { name }
}"
nil
(tracing/enable-tracing nil))
=>
{:data {:luke {:friends [{:name "Han Solo"}
{:name "Leia Organa"}
{:name "C-3PO"}
{:name "R2-D2"}]},
:leia {:name "Leia Organa"}},
:extensions {:tracing {:version 1,
:startTime "2020-08-31T22:14:25.401Z",
:endTime "2020-08-31T22:14:25.449Z",
:duration 47430231,
:parsing {:startOffset 68824, :duration 38932608},
:validation {:startOffset 39099642, :duration 1941960},
:execution {:resolvers [{:path [:luke],
:parentType :QueryRoot,
:fieldName :human,
:returnType "human!",
:startOffset 42476480,
:duration 303264}
{:path [:luke :friends],
:parentType :human,
:fieldName :friends,
:returnType "[character]",
:startOffset 43183550,
:duration 185802}
{:path [:luke :friends 0 :name],
:parentType :human,
:fieldName :name,
:returnType "String",
:startOffset 43669784,
:duration 16145}
{:path [:luke :friends 1 :name],
:parentType :human,
:fieldName :name,
:returnType "String",
:startOffset 44205401,
:duration 4629}
{:path [:luke :friends 2 :name],
:parentType :droid,
:fieldName :name,
:returnType "String",
:startOffset 44346489,
:duration 4563}
{:path [:luke :friends 3 :name],
:parentType :droid,
:fieldName :name,
:returnType "String",
:startOffset 44477160,
:duration 3971}
{:path [:leia],
:parentType :QueryRoot,
:fieldName :human,
:returnType "human!",
:startOffset 46609256,
:duration 130413}
{:path [:leia :name],
:parentType :human,
:fieldName :name,
:returnType "String",
:startOffset 46866059,
:duration 7833}]}}}}

0 comments on commit ae0a65a

Please sign in to comment.