graphql-hive 0.1.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 734441600a775933bd1250151b0234b7b8293d4ee49e087a86f80684fe116e74
4
- data.tar.gz: fe27f880db8cd0d75856fd8586363b6913f445feac2b7f7041a245eb03f49270
3
+ metadata.gz: be9427b081e7a486adf0537b3afa6e073c6c31eba88acae351589d0e1f708c87
4
+ data.tar.gz: de06ee85feb0ddd539a248534fdfe642aab8a8bb693f0cb66f0519f53ab95e11
5
5
  SHA512:
6
- metadata.gz: 967bd101bad2140070d198d8b98ae92e4cb7a2716d4709c30b33862683ea35b7b3970c6c32f8727b57619698e7af43c039e79747d5f46a931ef345c2b44d54a7
7
- data.tar.gz: 9013380ae8c596b015571cc05cf0430658d984ee548c9fb21cc3d423d2a3b7459c298816dc765c053f33a49e41318916d665fd77aa4c5eae0a76fc5d7c81f1f6
6
+ metadata.gz: eae35b3398dfbf84327efcca83c3ccc206e50698b64646359b6134143b516f2c50a51504cd6a8165ced58487b526d7c019aa95235cb2ba6132146e61e75694af
7
+ data.tar.gz: 96377bff1cf7c9f7e4e69847f68dc8143bc68702cfedfc6359f0147c16e534e660dcb871f3464a361ec082910a75db2b7ae8410cd6926a6df387ba0143c05cb4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- graphql-hive (0.1.4)
4
+ graphql-hive (0.3.0)
5
5
  graphql (~> 2.0.9)
6
6
 
7
7
  GEM
@@ -9,7 +9,7 @@ GEM
9
9
  specs:
10
10
  ast (2.4.2)
11
11
  diff-lcs (1.5.0)
12
- graphql (2.0.9)
12
+ graphql (2.0.16)
13
13
  parallel (1.22.1)
14
14
  parser (3.1.2.0)
15
15
  ast (~> 2.4.1)
data/README.md CHANGED
@@ -64,6 +64,44 @@ If you only want to use the operations monitoring, replace the `reporting` optio
64
64
 
65
65
  <br/>
66
66
 
67
+ ## 3. (Optional) Configure Lifecycle Hooks
68
+
69
+ Calling these hooks are situational - it's likely that you may not need to call
70
+ them at all!
71
+
72
+ ### `on_start`
73
+
74
+ Call this hook if you are running `GraphQL::Hive` in a process that `fork`s
75
+ itself.
76
+
77
+ example: `puma` web server running in (["clustered
78
+ mode"](https://github.com/puma/puma/tree/6d8b728b42a61bcf3c1e4c698c9165a45e6071e8#clustered-mode))
79
+
80
+ ```ruby
81
+ # config/puma.rb
82
+ preload_app!
83
+
84
+ on_worker_boot do
85
+ GraphQL::Hive.instance.on_start
86
+ end
87
+ ```
88
+
89
+ ### `on_exit`
90
+
91
+ If your GraphQL API process is shut down non-gracefully but has a shutdown hook
92
+ to call into, call `on_worker_exit`.
93
+
94
+ `puma` example:
95
+
96
+ ```ruby
97
+ # config/puma.rb
98
+
99
+ on_worker_shutdown do
100
+ GraphQL::Hive.instance.on_exit
101
+ end
102
+ ```
103
+
104
+ <br />
67
105
 
68
106
  **You are all set! 🚀**
69
107
 
@@ -74,7 +112,7 @@ When deploying or starting up your GraphQL API, `graphql-hive` will immediately:
74
112
 
75
113
  <br/>
76
114
 
77
- ## 3. See how your GraphQL API is operating
115
+ ## 4. See how your GraphQL API is operating
78
116
 
79
117
  You should now see operations information (RPM, error rate, queries performed) on your [GraphQL Hive dashboard](https://app.graphql-hive.com/):
80
118
 
@@ -86,7 +124,7 @@ You should now see operations information (RPM, error rate, queries performed) o
86
124
  <br/>
87
125
 
88
126
 
89
- ## 4. Going further: use the Hive Github app
127
+ ## 5. Going further: use the Hive Github app
90
128
 
91
129
  Stay on top of your GraphQL Schema changes by installing the Hive Github Application and enabling Slack notifications about breaking changes:
92
130
 
@@ -117,6 +155,7 @@ class MySchema < GraphQL::Schema
117
155
  endpoint: 'app.graphql-hive.com', # optional
118
156
  port: 80, # optional
119
157
  buffer_size: 50, # forward the operations data to Hive every 50 requests
158
+ collect_usage_sampling: 1.0,
120
159
  reporting: { # mandatory if `report_schema: true`
121
160
  # mandatory member of `reporting`
122
161
  author: 'Author of the latest change',
@@ -41,7 +41,7 @@ end
41
41
  class Schema < GraphQL::Schema
42
42
  query QueryType
43
43
 
44
- use(GraphQL::Hive, { buffer_size: 2, token: 'c3715c1afab97070c5c5b9bce8d02c7b', debug: true, reporting: { author: 'Charly Poly', commit: '109bb1e748bae21bdfe663c0ffc7e830' }, client_info: proc { |context|
44
+ use(GraphQL::Hive, { buffer_size: 2, token: 'YOUR_TOKEN', debug: true, reporting: { author: 'Charly Poly', commit: '109bb1e748bae21bdfe663c0ffc7e830' }, client_info: proc { |context|
45
45
  { name: context[:client_name], version: context[:client_version] }
46
46
  } })
47
47
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- graphql-hive (0.1.3)
4
+ graphql-hive (0.3.0)
5
5
  graphql (~> 2.0.9)
6
6
 
7
7
  GEM
@@ -27,6 +27,31 @@ module GraphQL
27
27
 
28
28
  @options_mutex = Mutex.new
29
29
  @queue = Queue.new
30
+
31
+ start_thread
32
+ end
33
+
34
+ def add_operation(operation)
35
+ @queue.push(operation)
36
+ end
37
+
38
+ def on_exit
39
+ @queue.close
40
+ @thread.join
41
+ end
42
+
43
+ def on_start
44
+ start_thread
45
+ end
46
+
47
+ private
48
+
49
+ def start_thread
50
+ if @thread&.alive?
51
+ @options[:logger].warn('Tried to start operations flushing thread but it was already alive')
52
+ return
53
+ end
54
+
30
55
  @thread = Thread.new do
31
56
  buffer = []
32
57
  while (operation = @queue.pop(false))
@@ -47,17 +72,6 @@ module GraphQL
47
72
  end
48
73
  end
49
74
 
50
- def add_operation(operation)
51
- @queue.push(operation)
52
- end
53
-
54
- def on_exit
55
- @queue.close
56
- @thread.join
57
- end
58
-
59
- private
60
-
61
75
  def process_operations(operations)
62
76
  report = {
63
77
  size: 0,
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Graphql
4
4
  module Hive
5
- VERSION = '0.1.4'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
data/lib/graphql-hive.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'logger'
4
+ require 'securerandom'
4
5
 
5
6
  require 'graphql-hive/version'
6
7
  require 'graphql-hive/usage_reporter'
@@ -57,7 +58,8 @@ module GraphQL
57
58
  read_operations: true,
58
59
  report_schema: true,
59
60
  buffer_size: 50,
60
- logger: nil
61
+ logger: nil,
62
+ collect_usage_sampling: 1.0
61
63
  }.freeze
62
64
 
63
65
  self.platform_keys = {
@@ -114,7 +116,9 @@ module GraphQL
114
116
  elapsed = ending - starting
115
117
  duration = (elapsed.to_f * (10**9)).to_i
116
118
 
117
- report_usage(timestamp, queries, results, duration) unless queries.empty?
119
+ # rubocop:disable Layout/LineLength
120
+ report_usage(timestamp, queries, results, duration) if !queries.empty? && SecureRandom.random_number <= @options[:collect_usage_sampling]
121
+ # rubocop:enable Layout/LineLength
118
122
 
119
123
  results
120
124
  else
@@ -144,6 +148,10 @@ module GraphQL
144
148
  @usage_reporter.on_exit
145
149
  end
146
150
 
151
+ def on_start
152
+ @usage_reporter.on_start
153
+ end
154
+
147
155
  private
148
156
 
149
157
  def initialize_options!(options)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphql-hive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Charly POLY
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-06-28 00:00:00.000000000 Z
11
+ date: 2023-01-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphql