graphql-metrics 4.0.5 → 4.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -1
- data/Gemfile.lock +1 -1
- data/README.md +1 -0
- data/lib/graphql/metrics.rb +2 -0
- data/lib/graphql/metrics/instrumentation.rb +1 -0
- data/lib/graphql/metrics/tracer.rb +43 -23
- data/lib/graphql/metrics/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 794d916d7f0b35ed8c50814c7cee54af5881a9fa5102eb361d1486fde665b413
|
4
|
+
data.tar.gz: 831cd8c26e771fc5e97e483f5cda86bce63311c0a31a9d12a020cdf5be808241
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: aed42769f9dcbcb445e0e9b8ec9858d05c917542fa0c588bcc587d19c2fbc8bafd2d1fcf65f4d7742cd498a2ac1d39b66c6955827efa4da3582a44980f2346e1
|
7
|
+
data.tar.gz: 908bc4cf5d126d71e715379cd2346308b5e7ed17230ad4733eff2614827625768d0ec1186da282628c91c6ab3fe7dd3a92adc6b6e9e548b202eb3b9507f6a8fd
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
|
+
4.0.6
|
2
|
+
-----
|
3
|
+
- [35](https://github.com/Shopify/graphql-metrics/pull/35) Fix query start time, start time offset bugs.
|
4
|
+
|
1
5
|
4.0.5
|
2
6
|
-----
|
3
|
-
- [34] Fix default of pre-parsed query `parsing_duration` to be Float (`0.0`) rather than Integer (`0`).
|
7
|
+
- [34](https://github.com/Shopify/graphql-metrics/pull/34) Fix default of pre-parsed query `parsing_duration` to be Float (`0.0`) rather than Integer (`0`).
|
4
8
|
|
5
9
|
4.0.4
|
6
10
|
-----
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -80,6 +80,7 @@ parsing and validation runtime metrics will not be added to the `metrics` hash.
|
|
80
80
|
# validation_duration: 0.01704599999357015,
|
81
81
|
# analysis_start_time_offset: 0.0010339999571442604,
|
82
82
|
# analysis_duration: 0.0008190000080503523,
|
83
|
+
# multiplex_start_time: 0.0008190000080503523,
|
83
84
|
# }
|
84
85
|
#
|
85
86
|
# You can use these metrics to track high-level query performance, along with any other details you wish to
|
data/lib/graphql/metrics.rb
CHANGED
@@ -22,6 +22,8 @@ module GraphQL
|
|
22
22
|
ANALYZER_INSTANCE_KEY = :analyzer_instance
|
23
23
|
|
24
24
|
# Context keys to store timings for query phases of execution, field resolver timings.
|
25
|
+
MULTIPLEX_START_TIME = :multiplex_start_time
|
26
|
+
MULTIPLEX_START_TIME_MONOTONIC = :multiplex_start_time_monotonic
|
25
27
|
QUERY_START_TIME = :query_start_time
|
26
28
|
QUERY_START_TIME_MONOTONIC = :query_start_time_monotonic
|
27
29
|
PARSING_START_TIME_OFFSET = :parsing_start_time_offset
|
@@ -47,6 +47,7 @@ module GraphQL
|
|
47
47
|
validation_duration: ns[GraphQL::Metrics::VALIDATION_DURATION],
|
48
48
|
analysis_start_time_offset: ns[GraphQL::Metrics::ANALYSIS_START_TIME_OFFSET],
|
49
49
|
analysis_duration: ns[GraphQL::Metrics::ANALYSIS_DURATION],
|
50
|
+
multiplex_start_time: ns[GraphQL::Metrics::MULTIPLEX_START_TIME],
|
50
51
|
}
|
51
52
|
|
52
53
|
analyzer.extract_fields
|
@@ -4,11 +4,12 @@ module GraphQL
|
|
4
4
|
module Metrics
|
5
5
|
class Tracer
|
6
6
|
# NOTE: These constants come from the graphql ruby gem.
|
7
|
-
GRAPHQL_GEM_LEX_KEY = 'lex'
|
8
7
|
GRAPHQL_GEM_EXECUTE_MULTIPLEX_KEY = 'execute_multiplex'
|
9
8
|
GRAPHQL_GEM_PARSING_KEY = 'parse'
|
10
9
|
GRAPHQL_GEM_VALIDATION_KEY = 'validate'
|
11
|
-
|
10
|
+
GRAPHQL_GEM_ANALYZE_MULTIPLEX_KEY = 'analyze_multiplex'
|
11
|
+
GRAPHQL_GEM_ANALYZE_QUERY_KEY = 'analyze_query'
|
12
|
+
GRAPHQL_GEM_EXECUTE_QUERY_KEY = 'execute_query'
|
12
13
|
GRAPHQL_GEM_TRACING_FIELD_KEYS = [
|
13
14
|
GRAPHQL_GEM_TRACING_FIELD_KEY = 'execute_field',
|
14
15
|
GRAPHQL_GEM_TRACING_LAZY_FIELD_KEY = 'execute_field_lazy'
|
@@ -24,19 +25,24 @@ module GraphQL
|
|
24
25
|
# NOTE: Not all tracing events are handled here, but those that are are handled in this case statement in
|
25
26
|
# chronological order.
|
26
27
|
case key
|
27
|
-
when GRAPHQL_GEM_LEX_KEY
|
28
|
-
return setup_tracing(&block)
|
29
28
|
when GRAPHQL_GEM_EXECUTE_MULTIPLEX_KEY
|
30
|
-
return
|
29
|
+
return capture_multiplex_start_time(&block)
|
31
30
|
when GRAPHQL_GEM_PARSING_KEY
|
32
31
|
return capture_parsing_time(&block)
|
33
32
|
when GRAPHQL_GEM_VALIDATION_KEY
|
34
33
|
context = possible_context
|
35
34
|
return capture_validation_time(context, &block)
|
36
|
-
when
|
35
|
+
when GRAPHQL_GEM_ANALYZE_MULTIPLEX_KEY
|
36
|
+
# Ensures that we reset potentially long-lived PreContext objects between multiplexs. We reset at this point
|
37
|
+
# since all parsing and validation will be done by this point, and a GraphQL::Query::Context will exist.
|
38
|
+
pre_context.reset
|
39
|
+
return yield
|
40
|
+
when GRAPHQL_GEM_ANALYZE_QUERY_KEY
|
37
41
|
context = possible_context
|
38
42
|
return capture_analysis_time(context, &block)
|
39
|
-
|
43
|
+
when GRAPHQL_GEM_EXECUTE_QUERY_KEY
|
44
|
+
context = possible_context
|
45
|
+
capture_query_start_time(context, &block)
|
40
46
|
when *GRAPHQL_GEM_TRACING_FIELD_KEYS
|
41
47
|
return yield if data[:query].context[SKIP_FIELD_AND_ARGUMENT_METRICS]
|
42
48
|
return yield unless GraphQL::Metrics.timings_capture_enabled?(data[:query].context)
|
@@ -57,12 +63,14 @@ module GraphQL
|
|
57
63
|
private
|
58
64
|
|
59
65
|
PreContext = Struct.new(
|
60
|
-
:
|
61
|
-
:
|
66
|
+
:multiplex_start_time,
|
67
|
+
:multiplex_start_time_monotonic,
|
62
68
|
:parsing_start_time_offset,
|
63
69
|
:parsing_duration
|
64
70
|
) do
|
65
|
-
def
|
71
|
+
def reset
|
72
|
+
self[:multiplex_start_time] = nil
|
73
|
+
self[:multiplex_start_time_monotonic] = nil
|
66
74
|
self[:parsing_start_time_offset] = nil
|
67
75
|
self[:parsing_duration] = nil
|
68
76
|
end
|
@@ -75,17 +83,18 @@ module GraphQL
|
|
75
83
|
@pre_context.value
|
76
84
|
end
|
77
85
|
|
78
|
-
def
|
79
|
-
|
80
|
-
|
81
|
-
pre_context.query_start_time = GraphQL::Metrics.current_time
|
82
|
-
pre_context.query_start_time_monotonic = GraphQL::Metrics.current_time_monotonic
|
86
|
+
def capture_multiplex_start_time
|
87
|
+
pre_context.multiplex_start_time = GraphQL::Metrics.current_time
|
88
|
+
pre_context.multiplex_start_time_monotonic = GraphQL::Metrics.current_time_monotonic
|
83
89
|
|
84
90
|
yield
|
85
91
|
end
|
86
92
|
|
87
93
|
def capture_parsing_time
|
88
|
-
|
94
|
+
# GraphQL::Query#result fires `parse` before the `execute_multiplex` event, so sometimes
|
95
|
+
# `pre_context.multiplex_start_time_monotonic` isn't set.
|
96
|
+
parsing_offset_time = pre_context.multiplex_start_time_monotonic || GraphQL::Metrics.current_time_monotonic
|
97
|
+
timed_result = GraphQL::Metrics.time(parsing_offset_time) { yield }
|
89
98
|
|
90
99
|
pre_context.parsing_start_time_offset = timed_result.start_time
|
91
100
|
pre_context.parsing_duration = timed_result.duration
|
@@ -93,32 +102,35 @@ module GraphQL
|
|
93
102
|
timed_result.result
|
94
103
|
end
|
95
104
|
|
105
|
+
# Also consolidates parsing timings (if any) from the `pre_context`
|
96
106
|
def capture_validation_time(context)
|
97
107
|
if pre_context.parsing_duration.nil?
|
98
|
-
|
108
|
+
# Queries may already be parsed before execution (whether a single query or multiplex).
|
109
|
+
# If we don't have a parsing start time, use the multiplex start time.
|
110
|
+
pre_context.parsing_start_time_offset = pre_context.multiplex_start_time
|
111
|
+
|
112
|
+
# If we don't have a duration, consider parsing to have been instantaneous.
|
99
113
|
pre_context.parsing_duration = 0.0
|
100
114
|
end
|
101
115
|
|
102
|
-
timed_result = GraphQL::Metrics.time(pre_context.
|
116
|
+
timed_result = GraphQL::Metrics.time(pre_context.multiplex_start_time_monotonic) { yield }
|
103
117
|
|
104
118
|
ns = context.namespace(CONTEXT_NAMESPACE)
|
105
119
|
|
106
|
-
ns[
|
107
|
-
ns[
|
120
|
+
ns[MULTIPLEX_START_TIME] = pre_context.multiplex_start_time
|
121
|
+
ns[MULTIPLEX_START_TIME_MONOTONIC] = pre_context.multiplex_start_time_monotonic
|
108
122
|
ns[PARSING_START_TIME_OFFSET] = pre_context.parsing_start_time_offset
|
109
123
|
ns[PARSING_DURATION] = pre_context.parsing_duration
|
110
124
|
ns[VALIDATION_START_TIME_OFFSET] = timed_result.time_since_offset
|
111
125
|
ns[VALIDATION_DURATION] = timed_result.duration
|
112
126
|
|
113
|
-
pre_context.reset_parsing_timings
|
114
|
-
|
115
127
|
timed_result.result
|
116
128
|
end
|
117
129
|
|
118
130
|
def capture_analysis_time(context)
|
119
131
|
ns = context.namespace(CONTEXT_NAMESPACE)
|
120
132
|
|
121
|
-
timed_result = GraphQL::Metrics.time(ns[
|
133
|
+
timed_result = GraphQL::Metrics.time(ns[MULTIPLEX_START_TIME_MONOTONIC]) { yield }
|
122
134
|
|
123
135
|
ns[ANALYSIS_START_TIME_OFFSET] = timed_result.time_since_offset
|
124
136
|
ns[ANALYSIS_DURATION] = timed_result.duration
|
@@ -126,6 +138,14 @@ module GraphQL
|
|
126
138
|
timed_result.result
|
127
139
|
end
|
128
140
|
|
141
|
+
def capture_query_start_time(context)
|
142
|
+
ns = context.namespace(CONTEXT_NAMESPACE)
|
143
|
+
ns[QUERY_START_TIME] = GraphQL::Metrics.current_time
|
144
|
+
ns[QUERY_START_TIME_MONOTONIC] = GraphQL::Metrics.current_time_monotonic
|
145
|
+
|
146
|
+
yield
|
147
|
+
end
|
148
|
+
|
129
149
|
def trace_field(context_key, data)
|
130
150
|
ns = data[:query].context.namespace(CONTEXT_NAMESPACE)
|
131
151
|
query_start_time_monotonic = ns[GraphQL::Metrics::QUERY_START_TIME_MONOTONIC]
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphql-metrics
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Butcher
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-08-
|
11
|
+
date: 2020-08-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: graphql
|