yabeda-graphql 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +19 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/gemfiles/graphql_1.10.gemfile.lock +1 -1
- data/gemfiles/graphql_1.9.gemfile.lock +1 -1
- data/lib/yabeda/graphql.rb +7 -1
- data/lib/yabeda/graphql/instrumentation.rb +27 -0
- data/lib/yabeda/graphql/tracing.rb +10 -6
- data/lib/yabeda/graphql/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a08157e5e641a56c7ca1a966c76c2e468571871a38bc3662fc4be6fa9f1301f2
|
4
|
+
data.tar.gz: 463081c19996433cea8a02d8226b1375bafc2cbc5ef2738c5dafce873553362f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bfb1be162dd40907f2ad7229602e8a844f8fb5edb578e2d93fef93411c4a20d33a631c4560e071b5c025a5bd019ea62b0488b7dcc4bc86a76e46e17873ac5e37
|
7
|
+
data.tar.gz: 2aab2eb5e7e9ed55cc16611ec372107c4d3316deb7eb630ddf1422106a8574f4737b0a7a3aafdfad11074aff68a34f0eaedb4bd19ec3880ae2b955171869037a
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Changelog
|
2
|
+
|
3
|
+
All notable changes to this project will be documented in this file.
|
4
|
+
|
5
|
+
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
6
|
+
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
|
7
|
+
|
8
|
+
## 0.2.0 - 2020-03-21
|
9
|
+
|
10
|
+
### Changed
|
11
|
+
|
12
|
+
- Method of hooking gem into schema. BREAKING CHANGE! [@Envek]
|
13
|
+
- Sum durations of lazy and non-lazy resolvings for every field. [@Envek]
|
14
|
+
|
15
|
+
## 0.1.0 - 2020-03-17
|
16
|
+
|
17
|
+
- Initial release of yabeda-graphql gem. [@Envek]
|
18
|
+
|
19
|
+
[@Envek]: https://github.com/Envek "Andrey Novikov"
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
data/lib/yabeda/graphql.rb
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
require "yabeda"
|
2
2
|
require "yabeda/graphql/version"
|
3
3
|
require "yabeda/graphql/tracing"
|
4
|
+
require "yabeda/graphql/instrumentation"
|
4
5
|
|
5
6
|
module Yabeda
|
6
7
|
module GraphQL
|
7
8
|
class Error < StandardError; end
|
8
9
|
|
9
10
|
REQUEST_BUCKETS = [
|
10
|
-
0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10,
|
11
|
+
0.001, 0.005, 0.01, 0.025, 0.05, 0.1, 0.25, 0.5, 1, 2.5, 5, 10,
|
11
12
|
].freeze
|
12
13
|
|
13
14
|
Yabeda.configure do
|
@@ -27,5 +28,10 @@ module Yabeda
|
|
27
28
|
counter :mutation_fields_count, comment: "A counter for mutation root fields",
|
28
29
|
tags: %i[name deprecated]
|
29
30
|
end
|
31
|
+
|
32
|
+
def self.use(schema)
|
33
|
+
schema.instrument(:query, Instrumentation.new)
|
34
|
+
schema.use Tracing, trace_scalars: true
|
35
|
+
end
|
30
36
|
end
|
31
37
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Yabeda
|
2
|
+
module GraphQL
|
3
|
+
class Instrumentation
|
4
|
+
def before_query(query)
|
5
|
+
reset_cache!(query)
|
6
|
+
end
|
7
|
+
|
8
|
+
def after_query(query)
|
9
|
+
cache(query).each do |_path, tags:, duration:|
|
10
|
+
Yabeda.graphql.field_resolve_runtime.measure(tags, duration)
|
11
|
+
Yabeda.graphql.fields_request_count.increment(tags)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def cache(query)
|
18
|
+
query.context.namespace(Yabeda::GraphQL)[:field_call_cache]
|
19
|
+
end
|
20
|
+
|
21
|
+
def reset_cache!(query)
|
22
|
+
query.context.namespace(Yabeda::GraphQL)[:field_call_cache] =
|
23
|
+
Hash.new { |h,k| h[k] = { tags: {}, duration: 0.0 } }
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -26,10 +26,10 @@ module Yabeda
|
|
26
26
|
when "execute_field", "execute_field_lazy"
|
27
27
|
field, path, query = extract_field_trace_data(data)
|
28
28
|
|
29
|
-
return result if key == "execute_field" && query.schema.lazy?(result)
|
30
|
-
|
31
29
|
tags = extract_field_tags(field)
|
32
30
|
if path.length == 1
|
31
|
+
return result if key == "execute_field" && query.schema.lazy?(result)
|
32
|
+
|
33
33
|
if query.query?
|
34
34
|
instrument_query_execution(tags)
|
35
35
|
elsif query.mutation?
|
@@ -38,7 +38,7 @@ module Yabeda
|
|
38
38
|
# Not implemented yet
|
39
39
|
end
|
40
40
|
else
|
41
|
-
instrument_field_execution(tags, duration)
|
41
|
+
instrument_field_execution(query, path, tags, duration)
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
@@ -63,9 +63,9 @@ module Yabeda
|
|
63
63
|
}
|
64
64
|
end
|
65
65
|
|
66
|
-
def instrument_field_execution(tags, duration)
|
67
|
-
|
68
|
-
|
66
|
+
def instrument_field_execution(query, path, tags, duration)
|
67
|
+
cache(query)[path][:tags] = tags
|
68
|
+
cache(query)[path][:duration] += duration
|
69
69
|
end
|
70
70
|
|
71
71
|
def instrument_mutation_execution(tags)
|
@@ -78,6 +78,10 @@ module Yabeda
|
|
78
78
|
Yabeda.graphql.query_fields_count.increment(tags)
|
79
79
|
end
|
80
80
|
|
81
|
+
def cache(query)
|
82
|
+
query.context.namespace(Yabeda::GraphQL)[:field_call_cache]
|
83
|
+
end
|
84
|
+
|
81
85
|
def platform_field_key(type, field)
|
82
86
|
"#{type.graphql_name}.#{field.graphql_name}"
|
83
87
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yabeda-graphql
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrey Novikov
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yabeda
|
@@ -106,6 +106,7 @@ files:
|
|
106
106
|
- ".rspec"
|
107
107
|
- ".travis.yml"
|
108
108
|
- Appraisals
|
109
|
+
- CHANGELOG.md
|
109
110
|
- Gemfile
|
110
111
|
- Gemfile.lock
|
111
112
|
- LICENSE.txt
|
@@ -119,6 +120,7 @@ files:
|
|
119
120
|
- gemfiles/graphql_1.9.gemfile
|
120
121
|
- gemfiles/graphql_1.9.gemfile.lock
|
121
122
|
- lib/yabeda/graphql.rb
|
123
|
+
- lib/yabeda/graphql/instrumentation.rb
|
122
124
|
- lib/yabeda/graphql/tracing.rb
|
123
125
|
- lib/yabeda/graphql/version.rb
|
124
126
|
- yabeda-graphql.gemspec
|