lamby 5.0.0 → 5.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/Gemfile.lock +6 -1
- data/lamby.gemspec +1 -0
- data/lib/lamby/cold_start_metrics.rb +83 -0
- data/lib/lamby/config.rb +18 -0
- data/lib/lamby/handler.rb +1 -0
- data/lib/lamby/rack_http.rb +1 -0
- data/lib/lamby/version.rb +1 -1
- data/lib/lamby.rb +1 -0
- metadata +17 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 98dcd67fb4bd1f352c4afde4809295882f00f98136aecf0fb59d41b926a753cb
|
4
|
+
data.tar.gz: bb842eac6ef100d94925ec34934b0f75055255f48148416763810ebe74d66481
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 715a673a6c996aea87b9639d5d130e851d9ed0c5ca005705f21edcb35a163696911f1f876ef2aced5450780a4387b2bc6270c3d5b95a811a828fa3343f49bbb6
|
7
|
+
data.tar.gz: 18e6581b89d754cf7d4360d522c31a88e6c26a8ca7731e8f644e61e7ca88fc039c53a7bd3a403f14ebb974c4e8663d99659e24329e3f2b0528917e8995d69fb2
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,18 @@
|
|
2
2
|
|
3
3
|
See this http://keepachangelog.com link for information on how we want this documented formatted.
|
4
4
|
|
5
|
+
## v5.2.0
|
6
|
+
|
7
|
+
### Fixed
|
8
|
+
|
9
|
+
- Safely Pass Percent Symbols in Paths Fixes #170
|
10
|
+
|
11
|
+
## v5.1.0
|
12
|
+
|
13
|
+
### Added
|
14
|
+
|
15
|
+
- New CloudWatch cold start metrics. Defaults to off. Enable with `config.cold_start_metrics = true`.
|
16
|
+
|
5
17
|
## v5.0.0
|
6
18
|
|
7
19
|
### Changed
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
lamby (5.
|
4
|
+
lamby (5.2.0)
|
5
5
|
lambda-console-ruby
|
6
6
|
rack
|
7
7
|
|
@@ -133,6 +133,8 @@ GEM
|
|
133
133
|
nio4r (2.5.9)
|
134
134
|
nokogiri (1.14.3-aarch64-linux)
|
135
135
|
racc (~> 1.4)
|
136
|
+
nokogiri (1.14.3-arm64-darwin)
|
137
|
+
racc (~> 1.4)
|
136
138
|
pry (0.14.2)
|
137
139
|
coderay (~> 1.1)
|
138
140
|
method_source (~> 1.0)
|
@@ -169,6 +171,7 @@ GEM
|
|
169
171
|
rake (13.0.6)
|
170
172
|
ruby2_keywords (0.0.5)
|
171
173
|
thor (1.2.1)
|
174
|
+
timecop (0.9.6)
|
172
175
|
timeout (0.3.2)
|
173
176
|
tzinfo (2.0.6)
|
174
177
|
concurrent-ruby (~> 1.0)
|
@@ -180,6 +183,7 @@ GEM
|
|
180
183
|
|
181
184
|
PLATFORMS
|
182
185
|
aarch64-linux
|
186
|
+
arm64-darwin-22
|
183
187
|
|
184
188
|
DEPENDENCIES
|
185
189
|
aws-sdk-ssm
|
@@ -192,6 +196,7 @@ DEPENDENCIES
|
|
192
196
|
pry
|
193
197
|
rails
|
194
198
|
rake
|
199
|
+
timecop
|
195
200
|
webrick
|
196
201
|
|
197
202
|
BUNDLED WITH
|
data/lamby.gemspec
CHANGED
@@ -27,5 +27,6 @@ Gem::Specification.new do |spec|
|
|
27
27
|
spec.add_development_dependency 'minitest-focus'
|
28
28
|
spec.add_development_dependency 'mocha'
|
29
29
|
spec.add_development_dependency 'pry'
|
30
|
+
spec.add_development_dependency 'timecop'
|
30
31
|
spec.add_development_dependency 'webrick'
|
31
32
|
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module Lamby
|
2
|
+
class ColdStartMetrics
|
3
|
+
NAMESPACE = 'Lamby'
|
4
|
+
|
5
|
+
@cold_start = true
|
6
|
+
@cold_start_time = (Time.now.to_f * 1000).to_i
|
7
|
+
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def instrument!
|
11
|
+
return unless @cold_start
|
12
|
+
@cold_start = false
|
13
|
+
now = (Time.now.to_f * 1000).to_i
|
14
|
+
proactive_init = (now - @cold_start_time) > 10_000
|
15
|
+
new(proactive_init).instrument!
|
16
|
+
end
|
17
|
+
|
18
|
+
def clear!
|
19
|
+
@cold_start = true
|
20
|
+
@cold_start_time = (Time.now.to_f * 1000).to_i
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize(proactive_init)
|
26
|
+
@proactive_init = proactive_init
|
27
|
+
@metrics = []
|
28
|
+
@properties = {}
|
29
|
+
end
|
30
|
+
|
31
|
+
def instrument!
|
32
|
+
name = @proactive_init ? 'ProactiveInit' : 'ColdStart'
|
33
|
+
put_metric name, 1, 'Count'
|
34
|
+
puts JSON.dump(message)
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def dimensions
|
40
|
+
[{ AppName: rails_app_name }]
|
41
|
+
end
|
42
|
+
|
43
|
+
def put_metric(name, value, unit = nil)
|
44
|
+
@metrics << { 'Name': name }.tap do |m|
|
45
|
+
m['Unit'] = unit if unit
|
46
|
+
end
|
47
|
+
set_property name, value
|
48
|
+
end
|
49
|
+
|
50
|
+
def set_property(name, value)
|
51
|
+
@properties[name] = value
|
52
|
+
self
|
53
|
+
end
|
54
|
+
|
55
|
+
def message
|
56
|
+
{
|
57
|
+
'_aws': {
|
58
|
+
'Timestamp': timestamp,
|
59
|
+
'CloudWatchMetrics': [
|
60
|
+
{
|
61
|
+
'Namespace': NAMESPACE,
|
62
|
+
'Dimensions': [dimensions.map(&:keys).flatten],
|
63
|
+
'Metrics': @metrics
|
64
|
+
}
|
65
|
+
]
|
66
|
+
}
|
67
|
+
}.tap do |m|
|
68
|
+
dimensions.each { |d| m.merge!(d) }
|
69
|
+
m.merge!(@properties)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def timestamp
|
74
|
+
Time.current.strftime('%s%3N').to_i
|
75
|
+
end
|
76
|
+
|
77
|
+
def rails_app_name
|
78
|
+
Lamby.config.metrics_app_name ||
|
79
|
+
Rails.application.class.name.split('::').first
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
end
|
data/lib/lamby/config.rb
CHANGED
@@ -41,6 +41,8 @@ module Lamby
|
|
41
41
|
|
42
42
|
def initialize_defaults
|
43
43
|
@rack_app = nil
|
44
|
+
@cold_start_metrics = false
|
45
|
+
@metrics_app_name = nil
|
44
46
|
@event_bridge_handler = lambda { |event, context| puts(event) }
|
45
47
|
end
|
46
48
|
|
@@ -64,5 +66,21 @@ module Lamby
|
|
64
66
|
@handled_proc = proc
|
65
67
|
end
|
66
68
|
|
69
|
+
def cold_start_metrics?
|
70
|
+
@cold_start_metrics
|
71
|
+
end
|
72
|
+
|
73
|
+
def cold_start_metrics=(bool)
|
74
|
+
@cold_start_metrics = bool
|
75
|
+
end
|
76
|
+
|
77
|
+
def metrics_app_name
|
78
|
+
@metrics_app_name
|
79
|
+
end
|
80
|
+
|
81
|
+
def metrics_app_name=(name)
|
82
|
+
@metrics_app_name = name
|
83
|
+
end
|
84
|
+
|
67
85
|
end
|
68
86
|
end
|
data/lib/lamby/handler.rb
CHANGED
data/lib/lamby/rack_http.rb
CHANGED
@@ -78,6 +78,7 @@ module Lamby
|
|
78
78
|
def path_info
|
79
79
|
stage = event.dig('requestContext', 'stage')
|
80
80
|
spath = event.dig('requestContext', 'http', 'path') || event.dig('requestContext', 'path')
|
81
|
+
spath = event['rawPath'] if spath != event['rawPath'] && !payload_version_one?
|
81
82
|
spath.sub /\A\/#{stage}/, ''
|
82
83
|
end
|
83
84
|
|
data/lib/lamby/version.rb
CHANGED
data/lib/lamby.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lamby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.
|
4
|
+
version: 5.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ken Collins
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-07-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -136,6 +136,20 @@ dependencies:
|
|
136
136
|
- - ">="
|
137
137
|
- !ruby/object:Gem::Version
|
138
138
|
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: timecop
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
139
153
|
- !ruby/object:Gem::Dependency
|
140
154
|
name: webrick
|
141
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -177,6 +191,7 @@ files:
|
|
177
191
|
- images/social2.png
|
178
192
|
- lamby.gemspec
|
179
193
|
- lib/lamby.rb
|
194
|
+
- lib/lamby/cold_start_metrics.rb
|
180
195
|
- lib/lamby/config.rb
|
181
196
|
- lib/lamby/debug.rb
|
182
197
|
- lib/lamby/handler.rb
|