tpt-rails 1.1.0 → 1.4.0.rc1

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: '0669d857b54eed34690e1f47f44c7b8fde75a7ddc612dec36db7fe3cb96e7d24'
4
- data.tar.gz: 507c33fe3739bd57ff55ea7d42508f6a5394df1b7d5be1fcaf27f3beb8d792fe
3
+ metadata.gz: b14bdc3ce7ea3aedee1b055dfdb4ef8cdc6fbcae92fb3db5ec3751f3dda7a787
4
+ data.tar.gz: fd51b3732c7771868049abb884dfd37789d7199c07777f300d899d344f5ae5d4
5
5
  SHA512:
6
- metadata.gz: 6ed1fa381014e4baad4c6cd3919dc1069735c19b7ddb225ae920b6bf746bdcfa02bb21badd8967876f176ee26cd27565c4e9f67240255d024f701aaeff9ab2e8
7
- data.tar.gz: da2721a6091ecc9e49afec62450a66b576ab31a08e17a044110bee307b8218522a085f2b1b86aad65cf1d8021c0db6bafbf6c2eb238ebe22172151a261ca92f9
6
+ metadata.gz: da90f352cf93c79c434999c574279add0dd3e2af36c53f2fe8f148dfe6b981f3c83b5f454316507191c52085f1bf0fdd03c2bca5caadbb5122096cdb6b57604c
7
+ data.tar.gz: 88e4a35987347c990aacb29e80c80528f8e3859105b2afa01e11719d0b727ebf97623652b5d3b0cf8397498fb5a5c61ccdf08f2477486bcd0036c7ac7a8d85e1
data/README.md CHANGED
@@ -100,12 +100,24 @@ Tpt::Rails provides the following endpoint:
100
100
 
101
101
  This endpoint reports an error via `Tpt::Rails.report` and emits a metric to Datadog.
102
102
 
103
+ ### Puma instrumentation
104
+
105
+ Add the following to `config/puma.rb` to have Puma metrics sent to Datadog:
106
+
107
+ ```ruby
108
+ before_fork do
109
+ Tpt::Rails::PumaStatsCollector.run(metrics_client: Tpt::Rails.statsd)
110
+ end
111
+ ```
112
+
113
+ Note: this currently only collects metrics when running Puma in _clustered_ mode (i.e. w/ more than one worker)
114
+
103
115
  ## Developing this Gem
104
116
 
105
117
  ### Running tests
106
118
 
107
119
  1. Start `docker-compose up` (provides a real Redis instance for tests)
108
- 2. Run `rails test`
120
+ 2. Run `bin/test`
109
121
 
110
122
  ### Using your local version of this gem in a local app
111
123
 
@@ -119,7 +131,7 @@ gem 'tpt-rails', path: '/your/local/path/to/tpt/rails'
119
131
 
120
132
  First ensure you have permissions to publish to rubygems.org.
121
133
 
122
- Then execute:
134
+ Once you've merged, check out the `master` branch and execute:
123
135
  ```sh
124
136
  bundle exec gem bump --push --tag --version patch # patch/minor/major/X.X.X
125
137
  bundle exec gem release
@@ -9,7 +9,7 @@ image:
9
9
 
10
10
  environment:
11
11
  ENVIRONMENT: staging
12
- APP_ENV: production
12
+ APP_ENV: staging
13
13
  RAILS_ENV: production
14
14
 
15
15
  postgresql:
@@ -70,13 +70,14 @@ service:
70
70
  resources:
71
71
  # requests is guaranteed. kubernetes will only put your pod on a node where it can guarantee these
72
72
  # amounts.
73
- requests:
74
- memory: 256Mi
75
- cpu: 200m
76
- # limits is when your pod gets killed for using too many resources
77
- limits:
73
+ requests: &requests
78
74
  memory: 512Mi
79
- cpu: 1
75
+ cpu: 500m
76
+ # limits is when your pod gets killed for using too many resources. normally these should be set
77
+ # the same as the "requests" limit, but if you have a unique workload that requires burstable
78
+ # limits then consult with CloudOps
79
+ limits:
80
+ *requests
80
81
 
81
82
  app:
82
83
  # this configures your service to be available at <%= Tpt::Rails.app_name %>.<ingress_dns_name>
@@ -6,6 +6,7 @@ end
6
6
  require 'tpt/rails/engine'
7
7
  require 'tpt/rails/internal'
8
8
  require 'tpt/rails/config'
9
+ require 'tpt/rails/puma_stats_collector'
9
10
 
10
11
  module Tpt::Rails
11
12
  class NotConfigured < StandardError; end
@@ -67,5 +68,10 @@ module Tpt::Rails
67
68
  def config # :nodoc:
68
69
  configured? ? @config : raise(NotConfigured)
69
70
  end
71
+
72
+ # This should be set by the deployment tool. E.g. Jenkins: https://git.io/JJFiD
73
+ def release_version
74
+ ENV['TPT_RELEASE_VERSION'].presence
75
+ end
70
76
  end
71
77
  end
@@ -29,18 +29,21 @@ class Tpt::Rails::Internal::Datadog # :nodoc:
29
29
  url = @statsd_url || 'statsd://localhost'
30
30
  uri = URI.parse(url)
31
31
 
32
+ tags = ["env:#{Tpt::Rails.app_env}"]
33
+ tags << ["tpt_release_version:#{Tpt::Rails.release_version}"] if Tpt::Rails.release_version
34
+
32
35
  ::Datadog::Statsd.new(
33
36
  uri.host,
34
37
  uri.port || DEFAULT_STATSD_PORT,
35
- {
36
- namespace: Tpt::Rails.app_name,
37
- tags: ["env:#{Tpt::Rails.app_env}"],
38
- }
38
+ namespace: Tpt::Rails.app_name,
39
+ tags: tags,
39
40
  )
40
41
  end
41
42
 
42
43
  def configure_tracing
43
44
  uri = URI.parse(@trace_url)
45
+ tags = { 'env' => Tpt::Rails.app_env }
46
+ tags["tpt_release_version"] = Tpt::Rails.release_version if Tpt::Rails.release_version
44
47
 
45
48
  ::Datadog.configure do |c|
46
49
  # This will activate auto-instrumentation for Rails
@@ -53,8 +56,10 @@ class Tpt::Rails::Internal::Datadog # :nodoc:
53
56
  enabled: true,
54
57
  hostname: uri.host,
55
58
  port: uri.port || DEFAULT_TRACE_PORT,
56
- tags: { 'env' => Tpt::Rails.app_env },
59
+ tags: tags,
57
60
  )
61
+
62
+ c.logger.level = ::Logger::WARN
58
63
  end
59
64
 
60
65
  ::Datadog::Pipeline.before_flush(
@@ -49,6 +49,7 @@ class Tpt::Rails::Internal::ErrorReporter # :nodoc:
49
49
 
50
50
  Bugsnag.configure do |config|
51
51
  config.api_key = @bugsnag_api_key
52
+ config.app_version = Tpt::Rails.release_version if Tpt::Rails.release_version
52
53
  end
53
54
  end
54
55
 
@@ -58,8 +59,10 @@ class Tpt::Rails::Internal::ErrorReporter # :nodoc:
58
59
 
59
60
  Rollbar.configure do |config|
60
61
  config.access_token = @rollbar_access_token
62
+ config.code_version = Tpt::Rails.release_version if Tpt::Rails.release_version
61
63
  config.enabled = @rollbar_enabled
62
64
  config.environment = Tpt::Rails.app_env
65
+ config.populate_empty_backtraces = true
63
66
  end
64
67
  end
65
68
  end
@@ -0,0 +1,86 @@
1
+ module Tpt::Rails::PumaStatsCollector # :nodoc:
2
+ class PumaStats
3
+ def initialize(stats)
4
+ @stats = JSON.parse(stats, symbolize_names: true)
5
+ end
6
+
7
+ def clustered?
8
+ @stats.has_key?(:workers)
9
+ end
10
+
11
+ def workers
12
+ @stats.fetch(:workers, 1)
13
+ end
14
+
15
+ def booted_workers
16
+ @stats.fetch(:booted_workers, 1)
17
+ end
18
+
19
+ def running
20
+ get_stat(:running)
21
+ end
22
+
23
+ def backlog
24
+ get_stat(:backlog)
25
+ end
26
+
27
+ def pool_capacity
28
+ get_stat(:pool_capacity)
29
+ end
30
+
31
+ def max_threads
32
+ get_stat(:max_threads)
33
+ end
34
+
35
+ def to_s
36
+ {
37
+ workers: workers,
38
+ booted_workers: booted_workers,
39
+ running: running,
40
+ backlog: backlog,
41
+ pool_capacity: pool_capacity,
42
+ max_threads: max_threads
43
+ }.to_json
44
+ end
45
+
46
+ private
47
+ def get_stat(name)
48
+ if clustered?
49
+ @stats[:worker_status].map { |s| s[:last_status].fetch(name, 0) }.sum
50
+ else
51
+ @stats.fetch(name, 0)
52
+ end
53
+ end
54
+ end
55
+
56
+ class << self
57
+ def run(metrics_client:, start_delay: 10, collect_interval: 30)
58
+ Thread.new do
59
+ # Give Puma time to start
60
+ sleep start_delay
61
+
62
+ # Get pod name if set
63
+ pod_name = ENV["KUBE_POD"]
64
+
65
+ loop do
66
+ begin
67
+ stats = PumaStats.new(Puma.stats)
68
+
69
+ tags = []
70
+ # Add pod_name tag if set
71
+ tags << "pod_name:#{pod_name}" if pod_name
72
+
73
+ metrics_client.gauge("puma.workers", stats.workers, tags: tags)
74
+ metrics_client.gauge("puma.booted_workers", stats.booted_workers, tags: tags)
75
+ metrics_client.gauge("puma.running", stats.running, tags: tags)
76
+ metrics_client.gauge("puma.backlog", stats.backlog, tags: tags)
77
+ metrics_client.gauge("puma.pool_capacity", stats.pool_capacity, tags: tags)
78
+ metrics_client.gauge("puma.max_threads", stats.max_threads, tags: tags)
79
+ end
80
+
81
+ sleep collect_interval
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
@@ -1,5 +1,5 @@
1
1
  module Tpt
2
2
  module Rails
3
- VERSION = '1.1.0'
3
+ VERSION = '1.4.0.rc1'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tpt-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.4.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - TpT
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-28 00:00:00.000000000 Z
11
+ date: 2020-09-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 6.0.2
19
+ version: 6.0.3
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 6.0.2.1
22
+ version: 6.0.3.3
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: 6.0.2
29
+ version: 6.0.3
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 6.0.2.1
32
+ version: 6.0.3.3
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: dogstatsd-ruby
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -50,14 +50,14 @@ dependencies:
50
50
  requirements:
51
51
  - - "~>"
52
52
  - !ruby/object:Gem::Version
53
- version: '0.30'
53
+ version: '0.40'
54
54
  type: :runtime
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
58
  - - "~>"
59
59
  - !ruby/object:Gem::Version
60
- version: '0.30'
60
+ version: '0.40'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: sqlite3
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -126,10 +126,11 @@ files:
126
126
  - lib/tpt/rails/internal/datadog.rb
127
127
  - lib/tpt/rails/internal/error_reporter.rb
128
128
  - lib/tpt/rails/internal/health_checks.rb
129
+ - lib/tpt/rails/puma_stats_collector.rb
129
130
  - lib/tpt/rails/version.rb
130
131
  homepage: https://github.com/TeachersPayTeachers/tpt-rails
131
132
  licenses:
132
- - None
133
+ - Nonstandard
133
134
  metadata: {}
134
135
  post_install_message:
135
136
  rdoc_options: []
@@ -142,11 +143,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
142
143
  version: '0'
143
144
  required_rubygems_version: !ruby/object:Gem::Requirement
144
145
  requirements:
145
- - - ">="
146
+ - - ">"
146
147
  - !ruby/object:Gem::Version
147
- version: '0'
148
+ version: 1.3.1
148
149
  requirements: []
149
- rubygems_version: 3.0.3
150
+ rubygems_version: 3.1.2
150
151
  signing_key:
151
152
  specification_version: 4
152
153
  summary: Utils for TpT Rails apps