google-cloud-debugger 0.28.1 → 0.28.2

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
  SHA1:
3
- metadata.gz: 3c830b378b4d42961196533588aaf0c9de64d777
4
- data.tar.gz: 8c7f28747d36f7a912d91f70864450ef7d53f044
3
+ metadata.gz: 4f6c7702998c26106d5d7d8c9da1da90a23a85a9
4
+ data.tar.gz: 9e792c21da0a3224c17df88921f635eddbdd8b90
5
5
  SHA512:
6
- metadata.gz: 1f69ee4d95699271c7c03cfc34568e6110b9d43c265c89c367c88b80ce3e2709be02135185eec68fafcd1425f7b1caa70e9219136b57fb4a295f1b7242832717
7
- data.tar.gz: d60ae09e0b72d201533acd290631f18331ab9bbeefd6a963f5fc9e521732db07df6fc93aebfa54017f534084949efa6c70cb1e0ad4232c0d7c9851ce9ac4ea2e
6
+ metadata.gz: 10b6cf1fbdfa245b73e5d40f83736e5e74444060484d13a18352be3ffcbb14dc0cba4fa9502e845b82874f04bde6ccce2eb52b56e2ebcdb0ee04d57c62526754
7
+ data.tar.gz: 4e249d586c912cc55b971547268b5ab79fe975892c84ac5e24e46eb29a98749e8b4f21155815f9b735515fbf70f525eb41779c072532e80d4c7f628ab694b3b5
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # google-cloud-debugger
2
2
 
3
- [Stackdriver Debugger](https://cloud.google.com/debugger/) ([docs](https://cloud.google.com/debugger/docs/)) lets you inspect the state of a running application at any code location in real time, without stopping or slowing down the application, and without modifying the code to add logging statements. You can use Stackdriver Debugger with any deployment of your application, including test, development, and production. The Ruby debugger adds minimal request latency, typically less than 50ms, and only when the application state is captured. In most cases, this is not noticeable by users.
3
+ [Stackdriver Debugger](https://cloud.google.com/debugger/) lets you inspect the state of a running application at any code location in real time, without stopping or slowing down the application, and without modifying the code to add logging statements. You can use Stackdriver Debugger with any deployment of your application, including test, development, and production. The Ruby debugger adds minimal request latency, typically less than 50ms, and only when the application state is captured. In most cases, this is not noticeable by users.
4
4
 
5
5
  - [google-cloud-debugger documentation](http://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-debugger/master/google/cloud/debugger)
6
6
  - [google-cloud-debugger on RubyGems](https://rubygems.org/gems/google-cloud-debugger)
@@ -8,25 +8,181 @@
8
8
 
9
9
  ## Quick Start
10
10
 
11
- Setting up Stackdriver Debugger involves three steps:
11
+ Install the gem directly:
12
12
 
13
- 1. Add the `google-cloud-debugger` library to your app.
14
- 2. Register your app's source code.
15
- 3. Deploy your app and set a breakpoint.
13
+ ```sh
14
+ $ gem install google-cloud-debugger
15
+ ```
16
16
 
17
- See the
18
- [google-cloud-debugger documentation](http://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-debugger/master/google/cloud/debugger)
19
- for a quick tutorial.
17
+ Or install through Bundler:
20
18
 
21
- ## Authentication
19
+ 1. Add the `google-cloud-debugger` gem to your Gemfile:
20
+
21
+ ```ruby
22
+ gem "google-cloud-debugger"
23
+ ```
24
+
25
+ 2. Use Bundler to install the gem:
26
+
27
+ ```sh
28
+ $ bundle install
29
+ ```
30
+
31
+ Alternatively, check out the [`stackdriver`](../stackdriver) gem that includes
32
+ the `google-cloud-debugger` gem.
33
+
34
+ ## Enable Stackdriver Debugger API
35
+
36
+ The Stackdriver Debugger agent needs the [Stackdriver Debugger
37
+ API](https://console.cloud.google.com/apis/library/clouddebugger.googleapis.com)
38
+ to be enabled on your Google Cloud project. Make sure it's enabled if not
39
+ already.
40
+
41
+ ## Enabling the Debugger agent
42
+
43
+ The Stackdriver Debugger library provides a Debugger agent that helps instrument
44
+ breakpoints in your running applications. The library also comes with a Railtie
45
+ and a Rack Middleware to help control the Debugger agent in popular Rack based
46
+ frameworks, such as Ruby on Rails and Sinatra.
47
+
48
+ ### With Ruby on Rails
49
+
50
+ You can load the Railtie that comes with the library into your Ruby
51
+ on Rails application by explicitly requiring it during the application startup:
52
+
53
+ ```ruby
54
+ # In config/application.rb
55
+ require "google/cloud/debugger/rails"
56
+ ```
57
+
58
+ If you're using the `stackdriver` gem, it automatically loads the Railtie into
59
+ your application when it starts.
60
+
61
+ ### With other Rack-based frameworks
62
+
63
+ Other Rack-based frameworks, such as Sinatra, can use the Rack Middleware
64
+ provided by the library:
65
+
66
+ ```ruby
67
+ require "google/cloud/debugger"
68
+ use Google::Cloud::Debugger::Middleware
69
+ ```
70
+
71
+ ### Without Rack-based framework
72
+
73
+ Non-rack-based applications can start the agent explicitly at the entry point of
74
+ your application:
22
75
 
23
- This library uses Service Account credentials to connect to Google Cloud services. When running on Compute Engine the credentials will be discovered automatically. When running on other environments the Service Account credentials can be specified by providing the path to the JSON file, or the JSON itself, in environment variables.
76
+ ```ruby
77
+ require "google/cloud/debugger"
78
+ Google::Cloud::Debugger.new.start
79
+ ```
24
80
 
25
- Instructions and configuration options are covered in the [Authentication Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-debugger/guides/authentication).
81
+ ### Configuring the agent
26
82
 
27
- ## Usage
83
+ You can customize the behavior of the Stackdriver Debugger agent. See the
84
+ [agent configuration](../stackdriver/docs/configuration.md) for a list of
85
+ possible configuration options.
86
+
87
+ ## Running on Google Cloud Platform
88
+
89
+ The Stackdriver Debugger agent should work without you manually providing
90
+ authentication credentials for instances running on Google Cloud Platform, as
91
+ long as the Stackdriver Debugger API access scope is enabled on that instance.
92
+
93
+ ### App Engine
94
+
95
+ On Google App Engine, the Stackdriver Debugger API access scope is enabled by
96
+ default, and the Stackdriver Debugger agent can be used without providing
97
+ credentials or a project ID.
98
+
99
+ ### Container Engine
100
+
101
+ On Google Container Engine, you must explicitly add the `cloud_debugger` OAuth
102
+ scope when creating the cluster:
103
+
104
+ ```sh
105
+ $ gcloud container clusters create example-cluster-name --scopes https://www.googleapis.com/auth/cloud_debugger
106
+ ```
107
+
108
+ You can also do this through the Google Cloud Platform Console. Select
109
+ **Enabled** in the Cloud Platform section of **Create a container cluster**.
110
+
111
+ ### Compute Engine
112
+
113
+ To use Stackdriver Debugger, Compute Engine VM instances should have one of the
114
+ following access scopes. These are only relevant when you use Compute Engine's
115
+ default service account:
116
+
117
+ * `https://www.googleapis.com/auth/cloud-platform`
118
+ * `https://www.googleapis.com/auth/cloud_debugger`
119
+
120
+ The `cloud-platform` access scope can be supplied when creating a new instance
121
+ through the Google Cloud Platform Console. Select **Allow full access to all
122
+ Cloud APIs** in the **Identity and API access** section of **Create an
123
+ instance**.
124
+
125
+ The `cloud_debugger` access scope must be supplied manually using the SDK's
126
+ `gcloud compute instances create` command or the `gcloud compute instances
127
+ set-service-account` command.
128
+
129
+ ## Running locally and elsewhere
130
+
131
+ To run the Stackdriver Debugger agent outside of Google Cloud Platform, you must
132
+ supply your GCP project ID and appropriate service account credentials directly
133
+ to the Stackdriver Debugger agent. This applies to running the agent on your own
134
+ workstation, on your datacenter's computers, or on the VM instances of another
135
+ cloud provider. See the [Authentication section](#authentication) for
136
+ instructions on how to do so.
137
+
138
+ ## Authentication
28
139
 
29
- This library provides a Stackdriver Debugger Agent that's able to work with Ruby applications. It also integrates with Ruby on Rails and other popular Rack-based frameworks. See the [Instrumentation Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-debugger/guides/instrumentation) for more details.
140
+ This library uses Service Account credentials to connect to Google Cloud
141
+ services. When running on Compute Engine the credentials will be discovered
142
+ automatically. When running on other environments the Service Account
143
+ credentials can be specified by providing in several ways.
144
+
145
+ The best way to provide authentication information if you're using Ruby on Rails
146
+ is through the Rails configuration interface:
147
+
148
+ ```ruby
149
+ # in config/environments/*.rb
150
+ Rails.application.configure do |config|
151
+ # Shared parameters
152
+ config.google_cloud.project_id = "your-project-id"
153
+ config.google_cloud.keyfile = "/path/to/key.json"
154
+ # Or Stackdriver Debugger agent specific parameters
155
+ config.google_cloud.debugger.project_id = "your-project-id"
156
+ config.google_cloud.debugger.keyfile = "/path/to/key.json"
157
+ end
158
+ ```
159
+
160
+ Other Rack-based applications that are loading the Rack Middleware directly can use
161
+ the configration interface:
162
+
163
+ ```ruby
164
+ require "google/cloud/debugger"
165
+ Google::Cloud.configure do |config|
166
+ # Shared parameters
167
+ config.project_id = "your-project-id"
168
+ config.keyfile = "/path/to/key.json"
169
+ # Or Stackdriver Debugger agent specific parameters
170
+ config.debugger.project_id = "your-project-id"
171
+ config.debugger.keyfile = "/path/to/key.json"
172
+ end
173
+ ```
174
+
175
+ Or provide the parameters to the Stackdriver Debugger agent when it starts:
176
+
177
+ ```ruby
178
+ require "google/cloud/debugger"
179
+ Google::Cloud::Debugger.new(project_id: "your-project-id",
180
+ keyfile: "/path/to/key.json").start
181
+ ```
182
+
183
+ This library also supports the other authentication methods provided by the
184
+ `google-cloud-ruby` suite. Instructions and configuration options are covered
185
+ in the [Authentication Guide](https://googlecloudplatform.github.io/google-cloud-ruby/#/docs/google-cloud-debugger/guides/authentication).
30
186
 
31
187
  ## Supported Ruby Versions
32
188
 
@@ -18,6 +18,13 @@
18
18
  #include "ruby/debug.h"
19
19
  #include "tracer.h"
20
20
 
21
+ #define FILE_TRACEPOINT_EVENTS (RUBY_EVENT_CLASS | RUBY_EVENT_CALL | RUBY_EVENT_B_CALL)
22
+ #define RETURN_TRACEPOINT_EVENTS (RUBY_EVENT_END | RUBY_EVENT_RETURN | RUBY_EVENT_B_RETURN)
23
+ #define FIBER_TRACEPOINT_EVENT RUBY_EVENT_FIBER_SWITCH
24
+
25
+ /* To prevent unused parameter warnings */
26
+ #define UNUSED(x) (void)(x)
27
+
21
28
  /**
22
29
  * hash_get_keys_callback
23
30
  * Helper callback function for hash_get_keys.
@@ -259,7 +266,7 @@ enable_line_trace_for_thread(VALUE self)
259
266
  /**
260
267
  * return_trace_callback
261
268
  * Callback function for tracer#return_tracepoint. It gets called on
262
- * RUBY_EVENT_END, RUBY_EVENT_RETURN, RUBY_EVENT_C_RETURN, and
269
+ * RUBY_EVENT_END, RUBY_EVENT_RETURN, and
263
270
  * RUBY_EVENT_B_RETURN events. It keeps line tracing consistent when Ruby
264
271
  * program counter interleaves files. Everytime called, it checks caller stack
265
272
  * frame's file path, if it matches any of the breakpoints, it turns line
@@ -375,8 +382,7 @@ enable_return_trace_for_thread(VALUE self)
375
382
  return_trace_set = rb_hash_aref(thread_variables_hash, return_trace_thread_flag);
376
383
 
377
384
  if (!RTEST(return_trace_set)) {
378
- int return_tracepoint_event = RUBY_EVENT_END | RUBY_EVENT_RETURN | RUBY_EVENT_C_RETURN | RUBY_EVENT_B_RETURN;
379
- rb_thread_add_event_hook2(current_thread, (rb_event_hook_func_t)return_trace_callback, return_tracepoint_event, self, RUBY_EVENT_HOOK_FLAG_RAW_ARG | RUBY_EVENT_HOOK_FLAG_SAFE);
385
+ rb_thread_add_event_hook2(current_thread, (rb_event_hook_func_t)return_trace_callback, RETURN_TRACEPOINT_EVENTS, self, RUBY_EVENT_HOOK_FLAG_RAW_ARG | RUBY_EVENT_HOOK_FLAG_SAFE);
380
386
  rb_hash_aset(thread_variables_hash, return_trace_thread_flag, Qtrue);
381
387
  }
382
388
 
@@ -386,7 +392,7 @@ enable_return_trace_for_thread(VALUE self)
386
392
  /**
387
393
  * file_tracepoint_callback
388
394
  * Callback function for tracer#file_tracepoint. It gets called on
389
- * RUBY_EVENT_CLASS, RUBY_EVENT_CALL, RUBY_EVENT_C_CALL, and RUBY_EVENT_B_CALL
395
+ * RUBY_EVENT_CLASS, RUBY_EVENT_CALL, and RUBY_EVENT_B_CALL
390
396
  * events. It check if any breakpoints matches current file the VM program counter
391
397
  * is in, and turn on line event tracing for that thread. Otherwise turn off
392
398
  * line tracing if in wrong file. The first time it turns on line even tracing,
@@ -523,7 +529,7 @@ rb_enable_traces(VALUE self)
523
529
  VALUE file_tracepoint;
524
530
  VALUE fiber_tracepoint;
525
531
 
526
- file_tracepoint = register_tracepoint(self, FILE_TRACEPOINT_EVENT, "@file_tracepoint", file_tracepoint_callback);
532
+ file_tracepoint = register_tracepoint(self, FILE_TRACEPOINT_EVENTS, "@file_tracepoint", file_tracepoint_callback);
527
533
  UNUSED(fiber_tracepoint);
528
534
 
529
535
  // Immediately activate file tracepoint and fiber tracepoint
@@ -19,12 +19,6 @@
19
19
 
20
20
  #include "ruby/debug.h"
21
21
 
22
- #define FILE_TRACEPOINT_EVENT (RUBY_EVENT_CLASS | RUBY_EVENT_CALL | RUBY_EVENT_C_CALL | RUBY_EVENT_B_CALL)
23
- #define FIBER_TRACEPOINT_EVENT RUBY_EVENT_FIBER_SWITCH
24
-
25
- /* To prevent unused parameter warnings */
26
- #define UNUSED(x) (void)(x)
27
-
28
22
  void
29
23
  Init_tracer(VALUE mDebugger);
30
24
 
@@ -0,0 +1,70 @@
1
+ # Copyright 2017 Google Inc. All rights reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+
16
+ module Google
17
+ module Cloud
18
+ module Debugger
19
+ ##
20
+ # @private Helps keep tracking of backoff on calling APIs in loop
21
+ class Backoff
22
+ ##
23
+ # Small interval to start with
24
+ DEFAULT_START_INTERVAL = 1
25
+
26
+ ##
27
+ # Maximum interval value to use
28
+ DEFAULT_MAX_INTERVAL = 600
29
+
30
+ ##
31
+ # Interval incremental multiplier
32
+ DEFAULT_MULTIPLIER = 2
33
+
34
+ ##
35
+ # The current time interval should wait until next iteration
36
+ attr_reader :interval
37
+
38
+ def initialize start_interval = DEFAULT_START_INTERVAL,
39
+ max_interval = DEFAULT_MAX_INTERVAL,
40
+ multiplier = DEFAULT_MULTIPLIER
41
+ @start_interval = start_interval
42
+ @max_interval = max_interval
43
+ @multiplier = multiplier
44
+ end
45
+
46
+ ##
47
+ # Resets backoff
48
+ def succeeded
49
+ @interval = nil
50
+ end
51
+
52
+ ##
53
+ # Initialize backoff or increase backoff interval
54
+ def failed
55
+ @interval = if @interval
56
+ [@max_interval, @interval * @multiplier].min
57
+ else
58
+ @start_interval
59
+ end
60
+ end
61
+
62
+ ##
63
+ # Check if a backoff delay should be applied
64
+ def backing_off?
65
+ !@interval.nil?
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -14,6 +14,7 @@
14
14
 
15
15
 
16
16
  require "digest/sha1"
17
+ require "google/cloud/debugger/backoff"
17
18
  require "google/cloud/debugger/debuggee/app_uniquifier_generator"
18
19
  require "google/cloud/debugger/version"
19
20
  require "json"
@@ -69,6 +70,7 @@ module Google
69
70
  @service_version = service_version
70
71
  @computed_uniquifier = nil
71
72
  @id = nil
73
+ @register_backoff = Google::Cloud::Debugger::Backoff.new
72
74
  end
73
75
 
74
76
  ##
@@ -76,13 +78,20 @@ module Google
76
78
  # Debuggee service.
77
79
  # @return [Boolean] True if registered sucessfully; otherwise false.
78
80
  def register
81
+ # Wait if backoff applies
82
+ sleep @register_backoff.interval if @register_backoff.backing_off?
83
+
79
84
  begin
80
85
  response = service.register_debuggee to_grpc
81
86
  @id = response.debuggee.id
82
87
  rescue
83
88
  revoke_registration
84
89
  end
85
- registered?
90
+
91
+ registered = registered?
92
+ registered ? @register_backoff.succeeded : @register_backoff.failed
93
+
94
+ registered
86
95
  end
87
96
 
88
97
  ##
@@ -16,7 +16,7 @@
16
16
  module Google
17
17
  module Cloud
18
18
  module Debugger
19
- VERSION = "0.28.1"
19
+ VERSION = "0.28.2"
20
20
  end
21
21
  end
22
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google-cloud-debugger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.28.1
4
+ version: 0.28.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Heng Xiong
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-08 00:00:00.000000000 Z
11
+ date: 2017-09-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: binding_of_caller
@@ -269,6 +269,7 @@ files:
269
269
  - lib/google-cloud-debugger.rb
270
270
  - lib/google/cloud/debugger.rb
271
271
  - lib/google/cloud/debugger/agent.rb
272
+ - lib/google/cloud/debugger/backoff.rb
272
273
  - lib/google/cloud/debugger/breakpoint.rb
273
274
  - lib/google/cloud/debugger/breakpoint/evaluator.rb
274
275
  - lib/google/cloud/debugger/breakpoint/source_location.rb