graphql-metrics 4.0.5 → 4.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e35ba7c6756d4d431a32911e2bf8452f8f825ed1ff6d90c17ad0a0cb13f4d5f9
4
- data.tar.gz: 1bb21be1384170bca7151a05ae36299c70193ca570bece6a7cdeb59f67e9ed57
3
+ metadata.gz: 794d916d7f0b35ed8c50814c7cee54af5881a9fa5102eb361d1486fde665b413
4
+ data.tar.gz: 831cd8c26e771fc5e97e483f5cda86bce63311c0a31a9d12a020cdf5be808241
5
5
  SHA512:
6
- metadata.gz: ba5a5d9fe0b038410260a9fc7d05472a2a7b3012194bc727226429920225f93f617ce353f8121e07b0a27b6f13899c8895ef26bf37e9856df05482c692042603
7
- data.tar.gz: baec02caa8599a575912c7e3e6696d11ac9bc0e88ebc5ed270eeaf7c0d8cf800bb5d1d48276f513a69c8921c43ef821a9f1239290a86027b9c104495e79c1ca3
6
+ metadata.gz: aed42769f9dcbcb445e0e9b8ec9858d05c917542fa0c588bcc587d19c2fbc8bafd2d1fcf65f4d7742cd498a2ac1d39b66c6955827efa4da3582a44980f2346e1
7
+ data.tar.gz: 908bc4cf5d126d71e715379cd2346308b5e7ed17230ad4733eff2614827625768d0ec1186da282628c91c6ab3fe7dd3a92adc6b6e9e548b202eb3b9507f6a8fd
@@ -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
  -----
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphql-metrics (4.0.5)
4
+ graphql-metrics (4.0.6)
5
5
  concurrent-ruby (~> 1.1.0)
6
6
  graphql (>= 1.10.8)
7
7
 
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
@@ -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
- GRAPHQL_GEM_ANALYZE_KEY = 'analyze_query'
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 setup_tracing(&block)
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 GRAPHQL_GEM_ANALYZE_KEY
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
- :query_start_time,
61
- :query_start_time_monotonic,
66
+ :multiplex_start_time,
67
+ :multiplex_start_time_monotonic,
62
68
  :parsing_start_time_offset,
63
69
  :parsing_duration
64
70
  ) do
65
- def reset_parsing_timings
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 setup_tracing
79
- return yield if pre_context.query_start_time
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
- timed_result = GraphQL::Metrics.time { yield }
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
- pre_context.parsing_start_time_offset = 0.0
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.query_start_time_monotonic) { yield }
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[QUERY_START_TIME] = pre_context.query_start_time
107
- ns[QUERY_START_TIME_MONOTONIC] = pre_context.query_start_time_monotonic
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[QUERY_START_TIME_MONOTONIC]) { yield }
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]
@@ -2,6 +2,6 @@
2
2
 
3
3
  module GraphQL
4
4
  module Metrics
5
- VERSION = "4.0.5"
5
+ VERSION = "4.0.6"
6
6
  end
7
7
  end
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.5
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-10 00:00:00.000000000 Z
11
+ date: 2020-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql