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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 217daf5c11dec98416acbde668b1dc611aa33858
4
- data.tar.gz: df99d97d1611db368e17a970d0306522532ddb82
3
+ metadata.gz: 18784bb11dd6bbc8127fa41afde5f70bb6eaba45
4
+ data.tar.gz: cdce481c5d0f3f30d71b4909814cb08fd188591c
5
5
  SHA512:
6
- metadata.gz: 95be950d0c0d0f3163386eff63509d771b11c279886e28095780836235f78d446a117df2468f3f56c0cdae342febec97398611ed00eb475797afa48dad17307f
7
- data.tar.gz: d9c5fb3b6662c245006cb1c7887d6e681ae2c41542aa1f7c5469539b50ff24e277eaf54020a7370d64ae696412ae1699fef8b275c31503eb9f07ed76c7879985
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
- Unless told otherwise, by calling the `no_default_signals` class method in your
524
- service class' definition, the following signals will be hooked with the following
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
@@ -6,7 +6,7 @@ require "loggerstash"
6
6
 
7
7
  class ServiceSkeleton
8
8
  class Config
9
- attr_reader :logger
9
+ attr_reader :logger, :env
10
10
 
11
11
  def initialize(env, svc)
12
12
  @env = env.to_hash.dup.freeze
@@ -17,5 +17,10 @@ class ServiceSkeleton
17
17
  (["#{explanation}#{explanation ? ": " : ""}#{ex.message} (#{ex.class})"] + ex.backtrace).join("\n ")
18
18
  end
19
19
  end
20
+
21
+ def logloc
22
+ loc = caller_locations.first
23
+ "#{self.class}##{loc.label}"
24
+ end
20
25
  end
21
26
  end
@@ -84,7 +84,7 @@ class ServiceSkeleton
84
84
  end
85
85
 
86
86
  def start
87
- logger.info("SignalHandler#start") { "Starting signal handler with #{@signal_registry.length} hooks" }
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("SignalHandler#run") { "Signal pipe closed; shutting down" }
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("SignalHandler#run") { "Mysterious return from select: #{ios.inspect}" }
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("SignalHandler#handle_signal") { "#{handler[:signal]} received" }
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("SignalHandler#handle_signal") { "Unrecognised signal character: #{char.inspect}" }
138
+ logger.error(logloc) { "Unrecognised signal character: #{char.inspect}" }
139
139
  end
140
140
  end
141
141
 
@@ -38,14 +38,17 @@ class ServiceSkeleton
38
38
  @logger = @config.logger
39
39
  @op_mutex = Mutex.new
40
40
 
41
- setup_metrics
42
- setup_signals
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 setup_metrics
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(self.class.to_s) { "Starting metrics server on port #{config.metrics_port}" }
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 setup_signals
142
- @signal_handler = ServiceSkeleton::SignalHandler.new(logger: logger, service: self, signal_counter: metrics.counter(:"#{self.service_name}_signals_handled_total", "How many of each type of signal have been handled"))
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-17 00:00:00.000000000 Z
11
+ date: 2018-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: frankenstein