infield 0.1.8 → 0.3.0

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: 2740909fa23076f115a2b77efeb50beaf0e41d94b87ea19499fb0542066a3cdb
4
- data.tar.gz: 03bcbc9f9041698357e7d761dcc1a186345ad3029a95a9b367bd13271dc2aba2
3
+ metadata.gz: 325524018c44e26d8fe8513f38604197def031b5582285f63c7c928b8c8d4b84
4
+ data.tar.gz: 3b04d9d84e329c69c0c5b3bb822253943f9d0ba12a5ce3d78721b25e12657d87
5
5
  SHA512:
6
- metadata.gz: 8185fe69d7d489ea72b2d62c4a0487dc5385be714b71a1c21ccd2b4c9f5a01ba6d6e99cc5ca3fc12648816b8e9dc15d0550c6170515a8cf406daef0c410f06bf
7
- data.tar.gz: 4f208e424bed118a16b949a54a42222bcc72f01d11352484d9d32ef783ae04c9d18ddcd9094e52a5e1863a0a53eab6e4b15fa8bda74a38cd7bf82f3cbb840a06
6
+ metadata.gz: f9179b0602fe9f755169b59af4a0e1ff10a62de52ac0c1cafaa96ac4653badd9a771b3cd3be5c73c35c12ddaf121a066c702c68b390d2ca123b687b8195bfee7
7
+ data.tar.gz: 0624c57b8417151e01dfdb1de57a10ab2b69656e565443f31ad848c584fcd4bb2a894dea8b3a661c38000ecf38ef9878c0922d95f13e2c663b2d840b336106c7
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.7.8
1
+ 3.2.3
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/README.md CHANGED
@@ -1,3 +1,40 @@
1
1
  # Infield
2
2
 
3
- This gem handles reporting deprecation warnings to Infield.
3
+ This gem handles reporting deprecation warnings to Infield from a Rails app.
4
+
5
+ ## Setup
6
+
7
+ You'll need an API key and repo environment ID to use this gem. You can find these at https://app.infield.ai/deprecations after signing up.
8
+
9
+ Add the gem to your gemfile:
10
+
11
+ gem 'infield', require: false
12
+
13
+ Then in `config/application.rb`:
14
+
15
+ if ENV['INFIELD_API_KEY']
16
+ require 'infield'
17
+ Infield.run(api_key: ENV['INFIELD_API_KEY'],
18
+ repo_environment_id: ENV['INFIELD_REPO_ENVIRONMENT_ID'])
19
+ end
20
+
21
+ And in any environment you want to profile from:
22
+
23
+ config.active_support.deprecation = :notify
24
+
25
+ ## Configuration options
26
+
27
+ The infield gem batches requests and sends them asyncronously. You can configure the following options to `Infield.run` (defaults shown here):
28
+
29
+ Infield.run(
30
+ api_key: key, # required
31
+ repo_environment_id: id, # required
32
+ sleep_interval: 5, # seconds, # how long to sleep between processing events
33
+ batch_size: 10, # how many events to batch in one API request to Infield
34
+ queue_limit: 30 # If more than this number of events come in in sleep_interval, any over are dropped
35
+ )
36
+
37
+ ## Test environment notes
38
+
39
+ If you enable this gem in test and use another gem to block all web
40
+ calls in your test environment, make sure to allow access to `app.infield.ai`.
@@ -10,5 +10,24 @@ module Infield
10
10
  end
11
11
  end
12
12
 
13
- Kernel.prepend(Core)
13
+ module InfieldWarningCapture
14
+ if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("3.0")
15
+ # Ruby 3.0+ supports warn(msg, category: nil, **kwargs)
16
+ def warn(msg, category: nil, **kwargs)
17
+ super
18
+
19
+ Infield::DeprecationWarning.log(msg, callstack: caller_locations, validated: true) if category == :deprecated
20
+ end
21
+ else
22
+ # Ruby < 3.0 only provides a single argument to warn
23
+ def warn(msg)
24
+ super
25
+
26
+ Infield::DeprecationWarning.log(msg, callstack: caller_locations, validated: false)
27
+ end
28
+ end
29
+ end
30
+
31
+ Kernel.extend(Core)
32
+ Warning.extend(InfieldWarningCapture)
14
33
  end
@@ -1,9 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'thread'
4
- require 'json'
5
- require 'net/http'
6
-
7
3
  module Infield
8
4
  # Takes in new deprecation warnings and sends them to the Infield API
9
5
  # in batches
@@ -22,7 +18,7 @@ module Infield
22
18
  ].freeze
23
19
 
24
20
  class << self
25
- attr_reader :queue
21
+ attr_reader :queue, :thread
26
22
 
27
23
  def enqueue(message)
28
24
  @queue ||= Queue.new
@@ -38,7 +34,7 @@ module Infield
38
34
  @queue_limit = queue_limit
39
35
  @batch_size = batch_size # send up to 20 messages to API at once
40
36
 
41
- Thread.new do
37
+ @thread = Thread.new do
42
38
  loop do
43
39
  sleep(@sleep_interval)
44
40
  next if @queue.empty?
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Infield
4
+ module Heartbeat
5
+ module Runner
6
+ class << self
7
+ attr_reader :thread
8
+
9
+ def run(interval: 60)
10
+ @thread = Thread.new do
11
+ loop do
12
+ if DeprecationWarning::Runner.thread&.alive?
13
+ send_heartbeat
14
+ else
15
+ stop
16
+ break
17
+ end
18
+ sleep(interval)
19
+ end
20
+ end
21
+ end
22
+
23
+ def stop
24
+ @thread&.kill
25
+ end
26
+
27
+ private
28
+
29
+ def send_heartbeat
30
+ uri = URI.parse(Infield.infield_api_url)
31
+ Net::HTTP.start(uri.host, uri.port, use_ssl: (uri.scheme == 'https')) do |http|
32
+ http.post('/api/heartbeats',
33
+ {
34
+ repo_environment_id: Infield.repo_environment_id,
35
+ environment: Infield.environment,
36
+ }.to_json,
37
+ {
38
+ 'Content-Type' => 'application/json',
39
+ 'Authorization' => "bearer #{Infield.api_key}"
40
+ })
41
+ end
42
+ rescue *DeprecationWarning::Runner::HTTP_ERRORS => e
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Infield
4
- VERSION = '0.1.8'
4
+ VERSION = '0.3.0'
5
5
  end
data/lib/infield.rb CHANGED
@@ -1,27 +1,41 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'thread'
4
+ require 'json'
5
+ require 'net/http'
6
+
3
7
  require_relative 'infield/version'
4
8
 
5
- # require_relative 'infield/core_ext'
9
+ require_relative 'infield/core_ext'
6
10
  require_relative 'infield/rails' if defined?(Rails)
7
11
 
8
12
  module Infield
9
13
  Error = Class.new(StandardError)
10
14
 
11
15
  autoload :DeprecationWarning, "#{__dir__}/infield/deprecation_warning.rb"
16
+ autoload :Heartbeat, "#{__dir__}/infield/heartbeat.rb"
12
17
 
13
18
  class << self
14
19
  attr_accessor :api_key, :repo_environment_id, :environment, :infield_api_url
15
20
 
16
- def run(api_key: nil, repo_environment_id: nil, environment: nil, sleep_interval: 5, batch_size: 10, queue_limit: 30)
21
+ def run(api_key: nil, repo_environment_id: nil, environment: nil, sleep_interval: 5, batch_size: 10, queue_limit: 30, heartbeat_interval: 600)
17
22
  @api_key = api_key || ENV['INFIELD_API_KEY']
18
23
  @repo_environment_id = repo_environment_id
19
24
  @infield_api_url = ENV['INFIELD_API_URL'] || 'https://app.infield.ai'
20
25
  raise 'API key is required' unless @api_key
21
26
  raise 'repo_environment_id is required' unless @repo_environment_id
22
27
 
23
- @environment = environment || defined?(Rails) ? Rails.env : nil
28
+ @environment = environment || (defined?(Rails) ? Rails.env : nil)
29
+
30
+ # Start the deprecation warning processor
24
31
  DeprecationWarning::Runner.run(sleep_interval: sleep_interval, batch_size: batch_size, queue_limit: queue_limit)
32
+
33
+ # Start the heartbeat
34
+ Heartbeat::Runner.run(interval: heartbeat_interval)
35
+ end
36
+
37
+ def shutdown
38
+ Heartbeat::Runner.stop
25
39
  end
26
40
  end
27
41
  end
metadata CHANGED
@@ -1,15 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infield
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Infield
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-11-08 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2025-01-09 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: webmock
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
13
41
  description:
14
42
  email:
15
43
  - support@infield.ai
@@ -21,6 +49,7 @@ files:
21
49
  - ".rubocop.yml"
22
50
  - ".ruby-version"
23
51
  - CHANGELOG.md
52
+ - Gemfile
24
53
  - LICENSE.txt
25
54
  - README.md
26
55
  - Rakefile
@@ -28,6 +57,7 @@ files:
28
57
  - lib/infield.rb
29
58
  - lib/infield/core_ext.rb
30
59
  - lib/infield/deprecation_warning.rb
60
+ - lib/infield/heartbeat.rb
31
61
  - lib/infield/rails.rb
32
62
  - lib/infield/version.rb
33
63
  homepage:
@@ -49,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
79
  - !ruby/object:Gem::Version
50
80
  version: '0'
51
81
  requirements: []
52
- rubygems_version: 3.1.6
82
+ rubygems_version: 3.4.19
53
83
  signing_key:
54
84
  specification_version: 4
55
85
  summary: Send deprecation warnings to Infield