startback 0.10.1 → 0.11.4
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 +4 -4
- data/lib/startback/audit/prometheus.rb +2 -9
- data/lib/startback/audit/shared.rb +17 -0
- data/lib/startback/audit/trailer.rb +5 -9
- data/lib/startback/audit.rb +1 -0
- data/lib/startback/support/log_formatter.rb +2 -0
- data/lib/startback/support/robustness.rb +2 -0
- data/lib/startback/version.rb +2 -2
- data/lib/startback/web/api.rb +1 -0
- data/spec/unit/audit/test_trailer.rb +18 -1
- data/spec/unit/support/test_robusteness.rb +11 -1
- metadata +8 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 929e1ab2d7ab916eadc828ecf2d1695c14c9a43d117198457e03c70c8b479ba4
|
4
|
+
data.tar.gz: 2f3d212acd31e00b1910aca3c3c1154a5e8a130962aeb002c184c6a70da17ab2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90d448f505406727db9cd5c1db1d2fdb14b5df6ed546566ae9f3db4e573dbe43e43968f5885c9602c5ca198ceb8a7801aca769e499ef4d10acaaf2be318f779f
|
7
|
+
data.tar.gz: 01b21d439cc5b7d1c8ff218620b7eec13a8496919c941863df25d8d01f4d2c6d11b727a6c4269015ef61d1d8063ebe1487909c3b238c84c06c5211eccc568423
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require_relative 'shared'
|
1
2
|
require 'prometheus/client'
|
2
3
|
|
3
4
|
module Startback
|
@@ -23,6 +24,7 @@ module Startback
|
|
23
24
|
# input at construction time.
|
24
25
|
#
|
25
26
|
class Prometheus
|
27
|
+
include Shared
|
26
28
|
|
27
29
|
def initialize(options = {})
|
28
30
|
@prefix = options[:prefix] || "startback"
|
@@ -62,7 +64,6 @@ module Startback
|
|
62
64
|
def ignore_safely
|
63
65
|
yield
|
64
66
|
rescue => ex
|
65
|
-
puts ex.class.to_s + "\n" + ex.message + "\n" + ex.backtrace.join("\n")
|
66
67
|
nil
|
67
68
|
end
|
68
69
|
|
@@ -81,14 +82,6 @@ module Startback
|
|
81
82
|
Startback::VERSION
|
82
83
|
end
|
83
84
|
|
84
|
-
def op_name(op)
|
85
|
-
case op
|
86
|
-
when String then op
|
87
|
-
when Class then op.name
|
88
|
-
else op.class.name
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
85
|
end # class Prometheus
|
93
86
|
end # module Audit
|
94
87
|
end # module Startback
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Startback
|
2
|
+
module Audit
|
3
|
+
module Shared
|
4
|
+
|
5
|
+
def op_name(op)
|
6
|
+
return op.op_name if op.respond_to?(:op_name)
|
7
|
+
|
8
|
+
case op
|
9
|
+
when String then op
|
10
|
+
when Class then op.name
|
11
|
+
else op.class.name
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end # module Shared
|
16
|
+
end # module Audit
|
17
|
+
end # module Startback
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require_relative 'shared'
|
1
2
|
require 'forwardable'
|
2
3
|
module Startback
|
3
4
|
module Audit
|
@@ -45,6 +46,7 @@ module Startback
|
|
45
46
|
# input at construction time.
|
46
47
|
#
|
47
48
|
class Trailer
|
49
|
+
include Shared
|
48
50
|
extend Forwardable
|
49
51
|
def_delegators :@logger, :debug, :info, :warn, :error, :fatal
|
50
52
|
|
@@ -85,20 +87,14 @@ module Startback
|
|
85
87
|
log_msg
|
86
88
|
end
|
87
89
|
|
88
|
-
def op_name(op)
|
89
|
-
case op
|
90
|
-
when String then op
|
91
|
-
when Class then op.name
|
92
|
-
else op.class.name
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
90
|
def op_context(op)
|
97
91
|
sanitize(op.respond_to?(:context, false) ? op.context.to_h : {})
|
98
92
|
end
|
99
93
|
|
100
94
|
def op_data(op)
|
101
|
-
data = if op.respond_to?(:
|
95
|
+
data = if op.respond_to?(:op_data, false)
|
96
|
+
op.op_data
|
97
|
+
elsif op.respond_to?(:to_trail, false)
|
102
98
|
op.to_trail
|
103
99
|
elsif op.respond_to?(:input, false)
|
104
100
|
op.input
|
data/lib/startback/audit.rb
CHANGED
@@ -67,6 +67,8 @@ module Startback
|
|
67
67
|
log_msg.dup
|
68
68
|
elsif log_msg.is_a?(String)
|
69
69
|
log_msg = { op: "#{log_msg}#{method.nil? ? '' : '#'+method.to_s}" }
|
70
|
+
elsif log_msg.is_a?(Exception)
|
71
|
+
log_msg = { error: log_msg }
|
70
72
|
else
|
71
73
|
log_msg = log_msg.class unless log_msg.is_a?(Module)
|
72
74
|
log_msg = { op: "#{log_msg.name}##{method}" }
|
data/lib/startback/version.rb
CHANGED
data/lib/startback/web/api.rb
CHANGED
@@ -8,13 +8,30 @@ module Startback
|
|
8
8
|
Trailer.new("/tmp/trail.log")
|
9
9
|
}
|
10
10
|
|
11
|
+
describe "op_name" do
|
12
|
+
|
13
|
+
def op_name(op, trailer = self.trailer)
|
14
|
+
trailer.send(:op_name, op)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'uses op_name in priority if provided' do
|
18
|
+
op = OpenStruct.new(op_name: "foo")
|
19
|
+
expect(op_name(op)).to eql("foo")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
11
23
|
describe "op_data" do
|
12
24
|
|
13
25
|
def op_data(op, trailer = self.trailer)
|
14
26
|
trailer.send(:op_data, op)
|
15
27
|
end
|
16
28
|
|
17
|
-
it 'uses
|
29
|
+
it 'uses op_data in priority if provided' do
|
30
|
+
op = OpenStruct.new(op_data: { foo: "bar" }, input: 12, request: 13)
|
31
|
+
expect(op_data(op)).to eql({ foo: "bar" })
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'uses to_trail then' do
|
18
35
|
op = OpenStruct.new(to_trail: { foo: "bar" }, input: 12, request: 13)
|
19
36
|
expect(op_data(op)).to eql({ foo: "bar" })
|
20
37
|
end
|
@@ -135,6 +135,16 @@ module Startback
|
|
135
135
|
expect(logger).to be_a(::Logger)
|
136
136
|
end
|
137
137
|
|
138
|
+
it 'works fine with a Exception only' do
|
139
|
+
exception = StandardError.new('hello')
|
140
|
+
expected = {
|
141
|
+
error: exception
|
142
|
+
}
|
143
|
+
log_msg, logger = parse_args(exception)
|
144
|
+
expect(log_msg).to eql(expected)
|
145
|
+
expect(logger).to be_a(::Logger)
|
146
|
+
end
|
147
|
+
|
138
148
|
it 'works fine with a string and a context with logger' do
|
139
149
|
expected = {
|
140
150
|
op: "a message"
|
@@ -216,4 +226,4 @@ module Startback
|
|
216
226
|
|
217
227
|
end
|
218
228
|
end
|
219
|
-
end
|
229
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: startback
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.11.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Lambeau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -270,20 +270,20 @@ dependencies:
|
|
270
270
|
requirements:
|
271
271
|
- - ">="
|
272
272
|
- !ruby/object:Gem::Version
|
273
|
-
version: 0.
|
273
|
+
version: 0.19.0
|
274
274
|
- - "<"
|
275
275
|
- !ruby/object:Gem::Version
|
276
|
-
version: 0.
|
276
|
+
version: 0.20.0
|
277
277
|
type: :runtime
|
278
278
|
prerelease: false
|
279
279
|
version_requirements: !ruby/object:Gem::Requirement
|
280
280
|
requirements:
|
281
281
|
- - ">="
|
282
282
|
- !ruby/object:Gem::Version
|
283
|
-
version: 0.
|
283
|
+
version: 0.19.0
|
284
284
|
- - "<"
|
285
285
|
- !ruby/object:Gem::Version
|
286
|
-
version: 0.
|
286
|
+
version: 0.20.0
|
287
287
|
- !ruby/object:Gem::Dependency
|
288
288
|
name: tzinfo
|
289
289
|
requirement: !ruby/object:Gem::Requirement
|
@@ -383,6 +383,7 @@ files:
|
|
383
383
|
- lib/startback.rb
|
384
384
|
- lib/startback/audit.rb
|
385
385
|
- lib/startback/audit/prometheus.rb
|
386
|
+
- lib/startback/audit/shared.rb
|
386
387
|
- lib/startback/audit/trailer.rb
|
387
388
|
- lib/startback/bus.rb
|
388
389
|
- lib/startback/bus/bunny.rb
|
@@ -472,7 +473,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
472
473
|
- !ruby/object:Gem::Version
|
473
474
|
version: '0'
|
474
475
|
requirements: []
|
475
|
-
rubygems_version: 3.
|
476
|
+
rubygems_version: 3.3.7
|
476
477
|
signing_key:
|
477
478
|
specification_version: 4
|
478
479
|
summary: Got Your Ruby Back
|