opener-webservice 2.1.0 → 2.2.1

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
- SHA1:
3
- metadata.gz: 32302b9a2aac215c69670cd55e4c28d22901df9c
4
- data.tar.gz: d24fb9f1fc3113ff70685bd1c2ce440eced844c6
2
+ SHA256:
3
+ metadata.gz: e9d2c615347f8c18229b705527f0256122040331a5db76517edb5e7da0bb0ee7
4
+ data.tar.gz: 53b8a41ca1dc581f00296272c05479c62a3e671cfb416b1b4bb43fbab660e7dd
5
5
  SHA512:
6
- metadata.gz: 5c96ce12b9449ee865ee208180fed338a7bdb9077741cecc23a618cd31fe499570a0fa750f905ca1f17ebebb09294a9a431fa83d7c43910a6890a83779c68285
7
- data.tar.gz: 602204c799cca06cf486f1fb44c1f6d2ea2a8f53417916313a08e7e80a035ef2e6f4c2eb75f784ce0f3ac7389c121851b041ef8b7a628493f2e1aaec2334663a
6
+ metadata.gz: 1f8d549b4dc5535635dca23ed3950eefbe39c7ea3c26a5572aecee715724cdc1a7cca36cb8547951bf95e8ad034d38c518a3e94a489834025884abd8d4596dd5
7
+ data.tar.gz: f4760946b5cdf462346bcbf5271b428a4e56489839052af0377d9dff3190b5d4465a1ee17a7b55c3c97759c534fb45ef4b317fd85efef6498ff9741eeffd1ea7
data/README.md CHANGED
@@ -93,6 +93,8 @@ receives the following parameters:
93
93
 
94
94
  * A supported Ruby version (see below)
95
95
  * Amazon S3 (only when one wants to store ouput in S3)
96
+ * libarchive (for running the tests and such), on Debian/Ubuntu based systems
97
+ this can be installed using `sudo apt-get install libarchive-dev`
96
98
 
97
99
  The following Ruby versions are supported:
98
100
 
@@ -0,0 +1,206 @@
1
+ # Here are the settings that are common to all environments
2
+ common: &default_settings
3
+ # ============================== LICENSE KEY ===============================
4
+
5
+ # You must specify the license key associated with your New Relic
6
+ # account. This key binds your Agent's data to your account in the
7
+ # New Relic service.
8
+ license_key: <%= ENV['NEWRELIC_TOKEN'] %>
9
+
10
+ # Agent Enabled (Ruby/Rails Only)
11
+ # Use this setting to force the agent to run or not run.
12
+ # Default is 'auto' which means the agent will install and run only
13
+ # if a valid dispatcher such as Mongrel is running. This prevents
14
+ # it from running with Rake or the console. Set to false to
15
+ # completely turn the agent off regardless of the other settings.
16
+ # Valid values are true, false and auto.
17
+ #
18
+ agent_enabled: true
19
+
20
+ # Application Name Set this to be the name of your application as
21
+ # you'd like it show up in New Relic. The service will then auto-map
22
+ # instances of your application into an "application" on your
23
+ # dashboard page. If you want to map this instance into multiple
24
+ # apps, like "AJAX Requests" and "All UI" then specify a semicolon
25
+ # separated list of up to three distinct names, or a yaml list.
26
+ # Defaults to the capitalized RAILS_ENV or RACK_ENV (i.e.,
27
+ # Production, Staging, etc)
28
+ #
29
+ # Example:
30
+ #
31
+ # app_name:
32
+ # - Ajax Service
33
+ # - All Services
34
+ #
35
+ app_name: "<%= ENV['APP_NAME'] %>"
36
+
37
+ # When "true", the agent collects performance data about your
38
+ # application and reports this data to the New Relic service at
39
+ # newrelic.com. This global switch is normally overridden for each
40
+ # environment below. (formerly called 'enabled')
41
+ # monitor_mode: true
42
+
43
+ # Developer mode should be off in every environment but
44
+ # development as it has very high overhead in memory.
45
+ developer_mode: false
46
+
47
+ # The newrelic agent generates its own log file to keep its logging
48
+ # information separate from that of your application. Specify its
49
+ # log level here.
50
+ log_level: error
51
+
52
+ # Optionally set the path to the log file This is expanded from the
53
+ # root directory (may be relative or absolute, e.g. 'log/' or
54
+ # '/var/log/') The agent will attempt to create this directory if it
55
+ # does not exist.
56
+ log_file_path: STDOUT
57
+
58
+ # Optionally set the name of the log file, defaults to 'newrelic_agent.log'
59
+ #log_file_name: 'newrelic_agent.log'
60
+
61
+ # The newrelic agent communicates with the service via https by default. This
62
+ # prevents eavesdropping on the performance metrics transmitted by the agent.
63
+ # The encryption required by SSL introduces a nominal amount of CPU overhead,
64
+ # which is performed asynchronously in a background thread. If you'd prefer
65
+ # to send your metrics over http uncomment the following line.
66
+ ssl: true
67
+
68
+ #============================== Browser Monitoring ===============================
69
+ # New Relic Real User Monitoring gives you insight into the performance real users are
70
+ # experiencing with your website. This is accomplished by measuring the time it takes for
71
+ # your users' browsers to download and render your web pages by injecting a small amount
72
+ # of JavaScript code into the header and footer of each page.
73
+ browser_monitoring:
74
+ # By default the agent automatically injects the monitoring JavaScript
75
+ # into web pages. Set this attribute to false to turn off this behavior.
76
+ auto_instrument: false
77
+
78
+ # Proxy settings for connecting to the New Relic server.
79
+ #
80
+ # If a proxy is used, the host setting is required. Other settings
81
+ # are optional. Default port is 8080.
82
+ #
83
+ # proxy_host: hostname
84
+ # proxy_port: 8080
85
+ # proxy_user:
86
+ # proxy_pass:
87
+
88
+ # The agent can optionally log all data it sends to New Relic servers to a
89
+ # separate log file for human inspection and auditing purposes. To enable this
90
+ # feature, change 'enabled' below to true.
91
+ # See: https://newrelic.com/docs/ruby/audit-log
92
+ audit_log:
93
+ enabled: false
94
+
95
+ # Tells transaction tracer and error collector (when enabled)
96
+ # whether or not to capture HTTP params. When true, frameworks can
97
+ # exclude HTTP parameters from being captured.
98
+ # Rails: the RoR filter_parameter_logging excludes parameters
99
+ # Java: create a config setting called "ignored_params" and set it to
100
+ # a comma separated list of HTTP parameter names.
101
+ # ex: ignored_params: credit_card, ssn, password
102
+ capture_params: false
103
+
104
+ # Transaction tracer captures deep information about slow
105
+ # transactions and sends this to the New Relic service once a
106
+ # minute. Included in the transaction is the exact call sequence of
107
+ # the transactions including any SQL statements issued.
108
+ transaction_tracer:
109
+
110
+ # Transaction tracer is enabled by default. Set this to false to
111
+ # turn it off. This feature is only available at the Professional
112
+ # and above product levels.
113
+ enabled: true
114
+
115
+ # Threshold in seconds for when to collect a transaction
116
+ # trace. When the response time of a controller action exceeds
117
+ # this threshold, a transaction trace will be recorded and sent to
118
+ # New Relic. Valid values are any float value, or (default) "apdex_f",
119
+ # which will use the threshold for an dissatisfying Apdex
120
+ # controller action - four times the Apdex T value.
121
+ transaction_threshold: 0
122
+
123
+ # When transaction tracer is on, SQL statements can optionally be
124
+ # recorded. The recorder has three modes, "off" which sends no
125
+ # SQL, "raw" which sends the SQL statement in its original form,
126
+ # and "obfuscated", which strips out numeric and string literals.
127
+ record_sql: obfuscated
128
+
129
+ # Threshold in seconds for when to collect stack trace for a SQL
130
+ # call. In other words, when SQL statements exceed this threshold,
131
+ # then capture and send to New Relic the current stack trace. This is
132
+ # helpful for pinpointing where long SQL calls originate from.
133
+ stack_trace_threshold: 0.500
134
+
135
+ # Determines whether the agent will capture query plans for slow
136
+ # SQL queries. Only supported in mysql and postgres. Should be
137
+ # set to false when using other adapters.
138
+ # explain_enabled: true
139
+
140
+ # Threshold for query execution time below which query plans will
141
+ # not be captured. Relevant only when `explain_enabled` is true.
142
+ # explain_threshold: 0.5
143
+
144
+ # Error collector captures information about uncaught exceptions and
145
+ # sends them to New Relic for viewing
146
+ error_collector:
147
+
148
+ # Error collector is enabled by default. Set this to false to turn
149
+ # it off. This feature is only available at the Professional and above
150
+ # product levels.
151
+ enabled: false
152
+
153
+ # To stop specific errors from reporting to New Relic, set this property
154
+ # to comma-separated values. Default is to ignore routing errors,
155
+ # which are how 404's get triggered.
156
+ ignore_errors: "ActionController::RoutingError,Sinatra::NotFound"
157
+
158
+ # If you're interested in capturing memcache keys as though they
159
+ # were SQL uncomment this flag. Note that this does increase
160
+ # overhead slightly on every memcached call, and can have security
161
+ # implications if your memcached keys are sensitive
162
+ # capture_memcache_keys: true
163
+
164
+ # Application Environments
165
+ # ------------------------------------------
166
+ # Environment-specific settings are in this section.
167
+ # For Rails applications, RAILS_ENV is used to determine the environment.
168
+ # For Java applications, pass -Dnewrelic.environment <environment> to set
169
+ # the environment.
170
+
171
+ # NOTE if your application has other named environments, you should
172
+ # provide newrelic configuration settings for these environments here.
173
+
174
+ development:
175
+ <<: *default_settings
176
+ # Turn on communication to New Relic service in development mode
177
+ monitor_mode: false
178
+ app_name: "<%= ENV['APP_NAME'] %> (Development)"
179
+
180
+ test:
181
+ <<: *default_settings
182
+ # It almost never makes sense to turn on the agent when running
183
+ # unit, functional or integration tests or the like.
184
+ monitor_mode: false
185
+
186
+ # Turn on the agent in production for 24x7 monitoring. NewRelic
187
+ # testing shows an average performance impact of < 5 ms per
188
+ # transaction, you can leave this on all the time without
189
+ # incurring any user-visible performance degradation.
190
+ production:
191
+ <<: *default_settings
192
+ monitor_mode: true
193
+
194
+ error_collector:
195
+ enabled: true
196
+
197
+ # Many applications have a staging environment which behaves
198
+ # identically to production. Support for that environment is provided
199
+ # here. By default, the staging environment has the agent turned on.
200
+ staging:
201
+ <<: *default_settings
202
+ monitor_mode: true
203
+ app_name: "<%= ENV['APP_NAME'] %> (Staging)"
204
+
205
+ error_collector:
206
+ enabled: true
@@ -1,6 +1,7 @@
1
1
  require 'securerandom'
2
2
  require 'json'
3
3
 
4
+ require 'aws-sdk'
4
5
  require 'puma/cli'
5
6
  require 'slop'
6
7
  require 'sinatra/base'
@@ -17,3 +18,4 @@ require_relative 'webservice/error_handler'
17
18
  require_relative 'webservice/input_extractor'
18
19
  require_relative 'webservice/input_sanitizer'
19
20
  require_relative 'webservice/option_parser'
21
+ require_relative 'webservice/transaction'
@@ -68,6 +68,15 @@ module Opener
68
68
  return !!ENV['ROLLBAR_TOKEN']
69
69
  end
70
70
 
71
+ ##
72
+ # Returns `true` if New Relic monitoring should be enabled.
73
+ #
74
+ # @return [TrueClass|FalseClass]
75
+ #
76
+ def self.newrelic?
77
+ return !!ENV['NEWRELIC_TOKEN']
78
+ end
79
+
71
80
  ##
72
81
  # Configures Rollbar.
73
82
  #
@@ -114,8 +114,7 @@ Puma Options:
114
114
  abort
115
115
  end
116
116
 
117
- on :b=,
118
- :bucket=,
117
+ on :bucket=,
119
118
  'The S3 bucket to store output in',
120
119
  :as => String
121
120
 
@@ -159,6 +158,13 @@ Puma Options:
159
158
  GC::Profiler.enable
160
159
  end
161
160
 
161
+ if Configuration.syslog?
162
+ Core::Syslog.open(
163
+ ENV['APP_NAME'],
164
+ ::Syslog::LOG_CONS | ::Syslog::LOG_PID
165
+ )
166
+ end
167
+
162
168
  Configuration.configure_rollbar
163
169
 
164
170
  # Puma on JRuby does some weird stuff with forking/exec. As a result
@@ -56,7 +56,12 @@ module Opener
56
56
  end
57
57
 
58
58
  error do
59
- Rollbar.report_exception(env['sinatra.error'])
59
+ Rollbar.error(
60
+ env['sinatra.error'],
61
+ :parameters => Transaction.current.parameters
62
+ )
63
+
64
+ Transaction.reset_current
60
65
 
61
66
  halt(
62
67
  500,
@@ -145,6 +150,8 @@ module Opener
145
150
 
146
151
  content_type(ctype)
147
152
 
153
+ Transaction.reset_current
154
+
148
155
  return output
149
156
  end
150
157
 
@@ -159,6 +166,11 @@ module Opener
159
166
  request_id = options['request_id'] || SecureRandom.hex
160
167
  final_url = options['callbacks'].last
161
168
 
169
+ Core::Syslog.info(
170
+ "Processing asynchronous request with final URL #{final_url}",
171
+ :request_id => request_id
172
+ )
173
+
162
174
  async { analyze_async(options, request_id) }
163
175
 
164
176
  content_type :json
@@ -177,6 +189,8 @@ module Opener
177
189
  # @return [Array]
178
190
  #
179
191
  def analyze(options)
192
+ add_transaction_parameters(options)
193
+
180
194
  comp_options = InputSanitizer.new.whitelist_options(
181
195
  options,
182
196
  self.class.accepted_params
@@ -236,6 +250,11 @@ module Opener
236
250
  new_payload.delete('input')
237
251
 
238
252
  if Configuration.output_bucket
253
+ Core::Syslog.info(
254
+ "Uploading output to s3://#{Configuration.output_bucket}",
255
+ :request_id => request_id
256
+ )
257
+
239
258
  uploader = Uploader.new
240
259
  object = uploader.upload(request_id, output, options['metadata'])
241
260
 
@@ -244,9 +263,30 @@ module Opener
244
263
  new_payload['input'] = output
245
264
  end
246
265
 
266
+ Core::Syslog.info(
267
+ "Submitting output to #{next_url}",
268
+ :request_id => request_id
269
+ )
270
+
247
271
  CallbackHandler.new.post(next_url, new_payload)
248
272
  end
249
273
 
274
+ ##
275
+ # @param [Hash] options
276
+ #
277
+ def add_transaction_parameters(options)
278
+ # If raw input is given we'll trim it so the payload isn't too large for
279
+ # Rollbar/New Relic. This uses Hash#merge so we don't modify the
280
+ # original options variable.
281
+ if options['input']
282
+ options = options.merge(
283
+ 'input' => options['input'].byteslice(0, 256)
284
+ )
285
+ end
286
+
287
+ Transaction.current.add_parameters(options)
288
+ end
289
+
250
290
  ##
251
291
  # Returns a Hash containing the parameters from a JSON payload. The keys
252
292
  # of this Hash are returned as _strings_ to prevent Symbol DOS attacks.
@@ -0,0 +1,56 @@
1
+ module Opener
2
+ module Webservice
3
+ ##
4
+ # Class for storing information of a single transaction in a thread.
5
+ #
6
+ # @!attribute [r] parameters
7
+ # @return [Hash]
8
+ #
9
+ class Transaction
10
+ attr_reader :parameters
11
+
12
+ ##
13
+ # The name of the key to store the current transaction in.
14
+ #
15
+ # @return [Symbol]
16
+ #
17
+ THREAD_KEY = :opener_webservices_transaction
18
+
19
+ ##
20
+ # Returns the current transaction.
21
+ #
22
+ # @return [Opener::Daemons::Transaction]
23
+ #
24
+ def self.current
25
+ return Thread.current[THREAD_KEY] ||= new
26
+ end
27
+
28
+ ##
29
+ # Removes the current transaction
30
+ #
31
+ def self.reset_current
32
+ Thread.current[THREAD_KEY] = nil
33
+ end
34
+
35
+ def initialize
36
+ @parameters = {}
37
+ end
38
+
39
+ ##
40
+ # Merges the given parameters with the existing ones.
41
+ #
42
+ # If New Relic is enabled the parameters are also added to the current
43
+ # New Relic transaction.
44
+ #
45
+ # @param [Hash] parameters
46
+ #
47
+ def add_parameters(parameters = {})
48
+ @parameters = @parameters.merge(parameters)
49
+
50
+ if Configuration.newrelic?
51
+ NewRelic::Agent.add_custom_parameters(parameters)
52
+ end
53
+ end
54
+ end # Transaction
55
+ end # Webservice
56
+ end # Opener
@@ -1,5 +1,5 @@
1
1
  module Opener
2
2
  module Webservice
3
- VERSION = '2.1.0'
3
+ VERSION = '2.2.1'
4
4
  end # Webservice
5
5
  end # Opener
@@ -10,6 +10,7 @@ Gem::Specification.new do |spec|
10
10
  spec.license = 'Apache 2.0'
11
11
 
12
12
  spec.files = Dir.glob([
13
+ 'config/**/*',
13
14
  'lib/**/*',
14
15
  '*.gemspec',
15
16
  'README.md',
@@ -17,16 +18,16 @@ Gem::Specification.new do |spec|
17
18
  ]).select { |file| File.file?(file) }
18
19
 
19
20
  spec.add_dependency 'sinatra', '~> 1.4.3'
20
- spec.add_dependency 'uuidtools'
21
21
  spec.add_dependency 'json'
22
22
  spec.add_dependency 'opener-callback-handler', '~> 1.0'
23
23
  spec.add_dependency 'httpclient', ['~> 2.0', '>= 2.5.3.3']
24
- spec.add_dependency 'opener-core', '~> 2.0'
24
+ spec.add_dependency 'opener-core', '~> 2.3'
25
25
  spec.add_dependency 'puma'
26
26
  spec.add_dependency 'slop', '~> 3.0'
27
+ spec.add_dependency 'aws-sdk', '~> 2.0'
27
28
 
28
- spec.add_dependency 'newrelic_rpm'
29
- spec.add_dependency 'rollbar', '~> 1.0'
29
+ spec.add_dependency 'newrelic_rpm', '~> 3.0'
30
+ spec.add_dependency 'rollbar', '~> 3.0'
30
31
 
31
32
  spec.add_development_dependency 'bundler', '~> 1.3'
32
33
  spec.add_development_dependency 'rake'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opener-webservice
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - development@olery.com
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-11-21 00:00:00.000000000 Z
11
+ date: 2021-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sinatra
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: 1.4.3
27
- - !ruby/object:Gem::Dependency
28
- name: uuidtools
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: '0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: json
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -92,14 +78,14 @@ dependencies:
92
78
  requirements:
93
79
  - - "~>"
94
80
  - !ruby/object:Gem::Version
95
- version: '2.0'
81
+ version: '2.3'
96
82
  type: :runtime
97
83
  prerelease: false
98
84
  version_requirements: !ruby/object:Gem::Requirement
99
85
  requirements:
100
86
  - - "~>"
101
87
  - !ruby/object:Gem::Version
102
- version: '2.0'
88
+ version: '2.3'
103
89
  - !ruby/object:Gem::Dependency
104
90
  name: puma
105
91
  requirement: !ruby/object:Gem::Requirement
@@ -128,34 +114,48 @@ dependencies:
128
114
  - - "~>"
129
115
  - !ruby/object:Gem::Version
130
116
  version: '3.0'
117
+ - !ruby/object:Gem::Dependency
118
+ name: aws-sdk
119
+ requirement: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '2.0'
124
+ type: :runtime
125
+ prerelease: false
126
+ version_requirements: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '2.0'
131
131
  - !ruby/object:Gem::Dependency
132
132
  name: newrelic_rpm
133
133
  requirement: !ruby/object:Gem::Requirement
134
134
  requirements:
135
- - - ">="
135
+ - - "~>"
136
136
  - !ruby/object:Gem::Version
137
- version: '0'
137
+ version: '3.0'
138
138
  type: :runtime
139
139
  prerelease: false
140
140
  version_requirements: !ruby/object:Gem::Requirement
141
141
  requirements:
142
- - - ">="
142
+ - - "~>"
143
143
  - !ruby/object:Gem::Version
144
- version: '0'
144
+ version: '3.0'
145
145
  - !ruby/object:Gem::Dependency
146
146
  name: rollbar
147
147
  requirement: !ruby/object:Gem::Requirement
148
148
  requirements:
149
149
  - - "~>"
150
150
  - !ruby/object:Gem::Version
151
- version: '1.0'
151
+ version: '3.0'
152
152
  type: :runtime
153
153
  prerelease: false
154
154
  version_requirements: !ruby/object:Gem::Requirement
155
155
  requirements:
156
156
  - - "~>"
157
157
  - !ruby/object:Gem::Version
158
- version: '1.0'
158
+ version: '3.0'
159
159
  - !ruby/object:Gem::Dependency
160
160
  name: bundler
161
161
  requirement: !ruby/object:Gem::Requirement
@@ -227,13 +227,14 @@ dependencies:
227
227
  - !ruby/object:Gem::Version
228
228
  version: '0'
229
229
  description: Basic webservice hooks for the OpeNER toolchain
230
- email:
230
+ email:
231
231
  executables: []
232
232
  extensions: []
233
233
  extra_rdoc_files: []
234
234
  files:
235
235
  - LICENSE.txt
236
236
  - README.md
237
+ - config/newrelic.yml
237
238
  - lib/opener/webservice.rb
238
239
  - lib/opener/webservice/configuration.rb
239
240
  - lib/opener/webservice/error_handler.rb
@@ -241,14 +242,15 @@ files:
241
242
  - lib/opener/webservice/input_sanitizer.rb
242
243
  - lib/opener/webservice/option_parser.rb
243
244
  - lib/opener/webservice/server.rb
245
+ - lib/opener/webservice/transaction.rb
244
246
  - lib/opener/webservice/uploader.rb
245
247
  - lib/opener/webservice/version.rb
246
248
  - opener-webservice.gemspec
247
- homepage:
249
+ homepage:
248
250
  licenses:
249
251
  - Apache 2.0
250
252
  metadata: {}
251
- post_install_message:
253
+ post_install_message:
252
254
  rdoc_options: []
253
255
  require_paths:
254
256
  - lib
@@ -263,10 +265,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
263
265
  - !ruby/object:Gem::Version
264
266
  version: '0'
265
267
  requirements: []
266
- rubyforge_project:
267
- rubygems_version: 2.2.2
268
- signing_key:
268
+ rubygems_version: 3.2.14
269
+ signing_key:
269
270
  specification_version: 4
270
271
  summary: Basic webservice hooks for the OpeNER toolchain
271
272
  test_files: []
272
- has_rdoc: