service_skeleton 0.0.0.3.g1269800.1.gaaa2fa1 → 0.0.0.3.g1269800.1.gaaa2fa1.6.gf4e308e
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -6
- data/lib/service_skeleton/config.rb +1 -1
- data/lib/service_skeleton/logging_helpers.rb +5 -0
- data/lib/service_skeleton/signal_handler.rb +5 -5
- data/lib/service_skeleton.rb +10 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18784bb11dd6bbc8127fa41afde5f70bb6eaba45
|
4
|
+
data.tar.gz: cdce481c5d0f3f30d71b4909814cb08fd188591c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52fd258fda63cd6f9e6437720dc7b22bde7c8c2de3b5ba8353efdff5c7438de3b215327b82c0c076c16a0a51b451b90f8f2caf49e5df441e4e43482a18b9f6a3
|
7
|
+
data.tar.gz: 5cfebd77c0522f6171b73c71ee4fa0a835c89a085e4b6b42c3ca4264b7aa28c445e782af967b6275efc80d1b32c06c89d670cf92bd7e0d05afcc4a40fed56540
|
data/README.md
CHANGED
@@ -489,9 +489,6 @@ metrics](https://www.rubydoc.info/gems/frankenstein/Frankenstein/RubyGCMetrics),
|
|
489
489
|
and [Ruby VM
|
490
490
|
metrics](https://www.rubydoc.info/gems/frankenstein/Frankenstein/RubyVMMetrics).
|
491
491
|
|
492
|
-
If, for some reason, you *don't* want any default metrics in your bundle of
|
493
|
-
metrics, call `no_default_metrics` in your service class definition.
|
494
|
-
|
495
492
|
|
496
493
|
### Metrics Server Configuration
|
497
494
|
|
@@ -520,9 +517,8 @@ behaviours for common signals.
|
|
520
517
|
|
521
518
|
### Default Signals
|
522
519
|
|
523
|
-
|
524
|
-
|
525
|
-
behaviour:
|
520
|
+
When the `#run` method on your service instance is called, the following
|
521
|
+
signals will be hooked with the following behaviour:
|
526
522
|
|
527
523
|
* **`SIGUSR1`** -- increase the default minimum severity for messages which
|
528
524
|
will be emitted by the logger. The default severity only applies to log
|
@@ -84,7 +84,7 @@ class ServiceSkeleton
|
|
84
84
|
end
|
85
85
|
|
86
86
|
def start
|
87
|
-
logger.info(
|
87
|
+
logger.info(logloc) { "Starting signal handler with #{@signal_registry.length} hooks" }
|
88
88
|
|
89
89
|
@r, @w = IO.pipe
|
90
90
|
|
@@ -95,14 +95,14 @@ class ServiceSkeleton
|
|
95
95
|
if ios = IO.select([@r])
|
96
96
|
if ios.first.include?(@r)
|
97
97
|
if ios.first.first.eof?
|
98
|
-
logger.info(
|
98
|
+
logger.info(logloc) { "Signal pipe closed; shutting down" }
|
99
99
|
break
|
100
100
|
else
|
101
101
|
c = ios.first.first.read_nonblock(1)
|
102
102
|
handle_signal(c)
|
103
103
|
end
|
104
104
|
else
|
105
|
-
logger.error(
|
105
|
+
logger.error(logloc) { "Mysterious return from select: #{ios.inspect}" }
|
106
106
|
end
|
107
107
|
end
|
108
108
|
rescue StandardError => ex
|
@@ -127,7 +127,7 @@ class ServiceSkeleton
|
|
127
127
|
handler = @signal_registry[char.ord]
|
128
128
|
|
129
129
|
if handler
|
130
|
-
logger.debug(
|
130
|
+
logger.debug(logloc) { "#{handler[:signal]} received" }
|
131
131
|
@signal_counter.increment(signal: handler[:signal].to_s)
|
132
132
|
begin
|
133
133
|
handler[:callback].call
|
@@ -135,7 +135,7 @@ class ServiceSkeleton
|
|
135
135
|
log_exception(ex) { "Exception in signal handler" }
|
136
136
|
end
|
137
137
|
else
|
138
|
-
logger.error(
|
138
|
+
logger.error(logloc) { "Unrecognised signal character: #{char.inspect}" }
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
data/lib/service_skeleton.rb
CHANGED
@@ -38,14 +38,17 @@ class ServiceSkeleton
|
|
38
38
|
@logger = @config.logger
|
39
39
|
@op_mutex = Mutex.new
|
40
40
|
|
41
|
-
|
42
|
-
|
41
|
+
initialize_metrics
|
42
|
+
initialize_signals
|
43
43
|
end
|
44
44
|
|
45
45
|
def start
|
46
46
|
@op_mutex.synchronize { @thread = Thread.current }
|
47
47
|
|
48
48
|
begin
|
49
|
+
logger.info(logloc) { "Starting service #{service_name}" }
|
50
|
+
logger.info(logloc) { (["Environment:"] + config.env.map { |k, v| "#{k}=#{v.inspect}" }).join("\n ") }
|
51
|
+
|
49
52
|
start_metrics_server
|
50
53
|
start_signal_handler
|
51
54
|
run
|
@@ -112,7 +115,7 @@ class ServiceSkeleton
|
|
112
115
|
#:nocov:
|
113
116
|
end
|
114
117
|
|
115
|
-
def
|
118
|
+
def initialize_metrics
|
116
119
|
@metrics = Prometheus::Client::Registry.new
|
117
120
|
|
118
121
|
Frankenstein::RubyGCMetrics.register(@metrics)
|
@@ -126,7 +129,7 @@ class ServiceSkeleton
|
|
126
129
|
|
127
130
|
def start_metrics_server
|
128
131
|
if config.metrics_port
|
129
|
-
logger.info(
|
132
|
+
logger.info(logloc) { "Starting metrics server on port #{config.metrics_port}" }
|
130
133
|
|
131
134
|
@metrics_server = Frankenstein::Server.new(
|
132
135
|
port: config.metrics_port,
|
@@ -138,8 +141,9 @@ class ServiceSkeleton
|
|
138
141
|
end
|
139
142
|
end
|
140
143
|
|
141
|
-
def
|
142
|
-
|
144
|
+
def initialize_signals
|
145
|
+
metrics.counter(:"#{self.service_name}_signals_handled_total", "How many of each type of signal have been handled")
|
146
|
+
@signal_handler = ServiceSkeleton::SignalHandler.new(logger: logger, service: self, signal_counter: metrics.signals_handled_total)
|
143
147
|
|
144
148
|
@signal_handler.hook_signal("USR1") do
|
145
149
|
logger.level -= 1 unless logger.level == Logger::DEBUG
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: service_skeleton
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.0.3.g1269800.1.gaaa2fa1
|
4
|
+
version: 0.0.0.3.g1269800.1.gaaa2fa1.6.gf4e308e
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Palmer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-12-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: frankenstein
|