tpt-rails 1.0.0 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +15 -3
- data/lib/generators/tpt_rails/kubernetes/templates/kubernetes/helm/values.staging.yaml.tt +1 -1
- data/lib/generators/tpt_rails/kubernetes/templates/kubernetes/helm/values.yaml.tt +7 -6
- data/lib/tpt/rails.rb +7 -0
- data/lib/tpt/rails/config.rb +3 -0
- data/lib/tpt/rails/internal/error_reporter.rb +3 -6
- data/lib/tpt/rails/puma_stats_collector.rb +86 -0
- data/lib/tpt/rails/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f8733558ff2cb637dcfad03bf25c7d163036d4c9ac4d64c2e05c5ef93139ff7f
|
4
|
+
data.tar.gz: f59d430089151aa70537970d28beb6bc012a3beb7261555d5574a28d67a6c736
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8b0a500aebf850ceaa2ad916516a5e89814319ab667f96ace1c8b5b7a1d85dc391428491c1e9f498bb4bf6ea24e41440b2130cce57b53e07d7c46ee68e248d3
|
7
|
+
data.tar.gz: 7255dd10a5ea9b263f1a977499a6b7e419a85cf1e993c229546c57f51c5adda9f6977fb20620560891b77526e19777551c873cabeb2dfcb4c8d78380c79bc8e9
|
data/README.md
CHANGED
@@ -62,8 +62,8 @@ See the documentation in [lib/tpt/rails.rb](lib/tpt/rails.rb).
|
|
62
62
|
|
63
63
|
### Error reporting (e.g. Bugsnag/Rollbar)
|
64
64
|
|
65
|
-
If you configure `rollbar_access_token` or `bugsnag_api_key` then your project
|
66
|
-
configured to report unhandled exceptions.
|
65
|
+
If you configure `rollbar_access_token` & `rollbar_enabled`, or `bugsnag_api_key` then your project
|
66
|
+
will be automatically configured to report unhandled exceptions.
|
67
67
|
|
68
68
|
To report handled exceptions:
|
69
69
|
|
@@ -100,6 +100,18 @@ 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
|
@@ -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
|
-
|
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
|
@@ -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:
|
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>
|
data/lib/tpt/rails.rb
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
+
module Tpt
|
2
|
+
module Rails
|
3
|
+
end
|
4
|
+
end
|
5
|
+
|
1
6
|
require 'tpt/rails/engine'
|
2
7
|
require 'tpt/rails/internal'
|
3
8
|
require 'tpt/rails/config'
|
9
|
+
require 'tpt/rails/puma_stats_collector'
|
4
10
|
|
5
11
|
module Tpt::Rails
|
6
12
|
class NotConfigured < StandardError; end
|
@@ -14,6 +20,7 @@ module Tpt::Rails
|
|
14
20
|
# config.app_name = '…'
|
15
21
|
# config.app_env = '…'
|
16
22
|
# config.rollbar_access_token = '…'
|
23
|
+
# config.rollbar_enabled = true/false
|
17
24
|
# config.datadog_statsd_url = '…'
|
18
25
|
# config.health_check(:foo) { … }
|
19
26
|
# …
|
data/lib/tpt/rails/config.rb
CHANGED
@@ -21,6 +21,8 @@ class Tpt::Rails::Config
|
|
21
21
|
attr_accessor :redis_url
|
22
22
|
# A project-specific access token from rollbar
|
23
23
|
attr_accessor :rollbar_access_token
|
24
|
+
# Allow enabling/disabling Rollbar. Defaults to false.
|
25
|
+
attr_accessor :rollbar_enabled
|
24
26
|
|
25
27
|
# Add a health check to the endpoint provided at `/internal/health-check` by
|
26
28
|
# Tpt::Rails::HealthChecksController.
|
@@ -64,6 +66,7 @@ class Tpt::Rails::Config
|
|
64
66
|
@error_reporter = Tpt::Rails::Internal::ErrorReporter.new(
|
65
67
|
bugsnag_api_key: bugsnag_api_key.presence,
|
66
68
|
rollbar_access_token: rollbar_access_token.presence,
|
69
|
+
rollbar_enabled: rollbar_enabled ? true : false,
|
67
70
|
)
|
68
71
|
end
|
69
72
|
|
@@ -1,7 +1,8 @@
|
|
1
1
|
class Tpt::Rails::Internal::ErrorReporter # :nodoc:
|
2
|
-
def initialize(bugsnag_api_key: nil, rollbar_access_token: nil)
|
2
|
+
def initialize(bugsnag_api_key: nil, rollbar_access_token: nil, rollbar_enabled: false)
|
3
3
|
@bugsnag_api_key = bugsnag_api_key
|
4
4
|
@rollbar_access_token = rollbar_access_token
|
5
|
+
@rollbar_enabled = rollbar_enabled
|
5
6
|
|
6
7
|
configure_bugsnag if bugsnag?
|
7
8
|
configure_rollbar if rollbar?
|
@@ -57,11 +58,7 @@ class Tpt::Rails::Internal::ErrorReporter # :nodoc:
|
|
57
58
|
|
58
59
|
Rollbar.configure do |config|
|
59
60
|
config.access_token = @rollbar_access_token
|
60
|
-
|
61
|
-
if ::Rails.env.test? || ::Rails.env.development?
|
62
|
-
config.enabled = false
|
63
|
-
end
|
64
|
-
|
61
|
+
config.enabled = @rollbar_enabled
|
65
62
|
config.environment = Tpt::Rails.app_env
|
66
63
|
end
|
67
64
|
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
|
data/lib/tpt/rails/version.rb
CHANGED
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.
|
4
|
+
version: 1.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- TpT
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -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
|
-
-
|
133
|
+
- Nonstandard
|
133
134
|
metadata: {}
|
134
135
|
post_install_message:
|
135
136
|
rdoc_options: []
|