service_skeleton 0.0.0.3.g1269800 → 0.0.0.3.g1269800.1.gaaa2fa1
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/README.md +13 -0
- data/lib/service_skeleton/config.rb +9 -1
- data/lib/service_skeleton.rb +7 -1
- data/service_skeleton.gemspec +1 -0
- metadata +16 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 217daf5c11dec98416acbde668b1dc611aa33858
|
4
|
+
data.tar.gz: df99d97d1611db368e17a970d0306522532ddb82
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95be950d0c0d0f3163386eff63509d771b11c279886e28095780836235f78d446a117df2468f3f56c0cdae342febec97398611ed00eb475797afa48dad17307f
|
7
|
+
data.tar.gz: d9c5fb3b6662c245006cb1c7887d6e681ae2c41542aa1f7c5469539b50ff24e277eaf54020a7370d64ae696412ae1699fef8b275c31503eb9f07ed76c7879985
|
data/README.md
CHANGED
@@ -304,6 +304,10 @@ using Unix signals or the admin HTTP interface (if enabled), you can tell the
|
|
304
304
|
logger to increase or decrease logging verbosity *without interrupting
|
305
305
|
service*. We are truly living in the future.
|
306
306
|
|
307
|
+
Finally, if you're a devotee of the ELK stack, we can automagically send log
|
308
|
+
entries straight into logstash, rather than you having to do it in some
|
309
|
+
more roundabout fashion.
|
310
|
+
|
307
311
|
|
308
312
|
### Logging Configuration
|
309
313
|
|
@@ -342,6 +346,15 @@ All are all-uppercase, and the `<SERVICENAME>_` portion is the all-uppercase
|
|
342
346
|
Logging levels can be changed at runtime, via [signals](#default-signals) or
|
343
347
|
[the HTTP admin interface](#http-admin-interface).
|
344
348
|
|
349
|
+
* **`<SERVICENAME>_LOGSTASH_SERVER`** (string; default `""`) -- if set to a
|
350
|
+
non-empty string, we will engage the services of the [loggerstash
|
351
|
+
gem](https://github.com/discourse/loggerstash) on your behalf to send all log
|
352
|
+
entries to the logstash server you specify (as [an `address:port`,
|
353
|
+
`hostname:port`, or SRV
|
354
|
+
record](https://github.com/discourse/logstash_writer#usage). Just be sure
|
355
|
+
and [configure logstash
|
356
|
+
appropriately](https://github.com/discourse/loggerstash#logstash-configuration).
|
357
|
+
|
345
358
|
* **`<SERVICENAME>_LOG_ENABLE_TIMESTAMPS`** (boolean; default: `"no"`) -- if
|
346
359
|
set to a true-ish value (`yes`/`y`/`on`/`true`/`1`), then the log entries
|
347
360
|
emitted by the logger will have the current time (to the nearest nanosecond)
|
@@ -2,12 +2,14 @@ require "to_regexp"
|
|
2
2
|
|
3
3
|
require_relative "./filtering_logger"
|
4
4
|
|
5
|
+
require "loggerstash"
|
6
|
+
|
5
7
|
class ServiceSkeleton
|
6
8
|
class Config
|
7
9
|
attr_reader :logger
|
8
10
|
|
9
11
|
def initialize(env, svc)
|
10
|
-
@env = env.to_hash.freeze
|
12
|
+
@env = env.to_hash.dup.freeze
|
11
13
|
@svc = svc
|
12
14
|
|
13
15
|
parse_registered_variables(env)
|
@@ -46,6 +48,12 @@ class ServiceSkeleton
|
|
46
48
|
|
47
49
|
@logger = Logger.new(log_file || $stderr, shift_age, shift_size)
|
48
50
|
|
51
|
+
if self.logstash_server && !self.logstash_server.empty?
|
52
|
+
loggerstash = Loggerstash.new(logstash_server: logstash_server, logger: @logger)
|
53
|
+
loggerstash.metrics_registry = @svc.metrics
|
54
|
+
loggerstash.attach(@logger)
|
55
|
+
end
|
56
|
+
|
49
57
|
if log_enable_timestamps
|
50
58
|
@logger.formatter = ->(s, t, p, m) { "#{t.utc.strftime("%FT%T.%NZ")} #{s[0]} [#{p}] #{m}\n" }
|
51
59
|
else
|
data/lib/service_skeleton.rb
CHANGED
@@ -63,11 +63,13 @@ class ServiceSkeleton
|
|
63
63
|
|
64
64
|
def stop(force = false)
|
65
65
|
if force
|
66
|
+
#:nocov:
|
66
67
|
@op_mutex.synchronize do
|
67
68
|
if @thread
|
68
69
|
@thread.raise(ServiceSkeleton::Terminate)
|
69
70
|
end
|
70
71
|
end
|
72
|
+
#:nocov:
|
71
73
|
else
|
72
74
|
shutdown
|
73
75
|
end
|
@@ -99,6 +101,7 @@ class ServiceSkeleton
|
|
99
101
|
end
|
100
102
|
|
101
103
|
def shutdown
|
104
|
+
#:nocov:
|
102
105
|
@op_mutex.synchronize do
|
103
106
|
if @thread
|
104
107
|
@thread.raise(ServiceSkeleton::Terminate)
|
@@ -106,6 +109,7 @@ class ServiceSkeleton
|
|
106
109
|
@thread = nil
|
107
110
|
end
|
108
111
|
end
|
112
|
+
#:nocov:
|
109
113
|
end
|
110
114
|
|
111
115
|
def setup_metrics
|
@@ -135,7 +139,7 @@ class ServiceSkeleton
|
|
135
139
|
end
|
136
140
|
|
137
141
|
def setup_signals
|
138
|
-
@signal_handler = ServiceSkeleton::SignalHandler.new(logger: logger, service: self, signal_counter: metrics.counter(:"#{service_name}_signals_handled_total", "How many of each type of signal have been handled"))
|
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"))
|
139
143
|
|
140
144
|
@signal_handler.hook_signal("USR1") do
|
141
145
|
logger.level -= 1 unless logger.level == Logger::DEBUG
|
@@ -173,6 +177,7 @@ class ServiceSkeleton
|
|
173
177
|
|
174
178
|
@registered_variables = [
|
175
179
|
ServiceSkeleton::ConfigVariable.new(:SERVICE_SKELETON_LOG_LEVEL) { "INFO" },
|
180
|
+
ServiceSkeleton::ConfigVariable.new(:SERVICE_SKELETON_LOGSTASH_SERVER) { "" },
|
176
181
|
ServiceSkeleton::ConfigVariable.new(:SERVICE_SKELETON_LOG_ENABLE_TIMESTAMPS) { false },
|
177
182
|
ServiceSkeleton::ConfigVariable.new(:SERVICE_SKELETON_LOG_FILE) { nil },
|
178
183
|
ServiceSkeleton::ConfigVariable.new(:SERVICE_SKELETON_LOG_MAX_FILE_SIZE) { 1048576 },
|
@@ -182,6 +187,7 @@ class ServiceSkeleton
|
|
182
187
|
|
183
188
|
def self.inherited(subclass)
|
184
189
|
subclass.string(:"#{subclass.service_name.upcase}_LOG_LEVEL", default: "INFO")
|
190
|
+
subclass.string(:"#{subclass.service_name.upcase}_LOGSTASH_SERVER", default: "")
|
185
191
|
subclass.boolean(:"#{subclass.service_name.upcase}_LOG_ENABLE_TIMESTAMPS", default: false)
|
186
192
|
subclass.string(:"#{subclass.service_name.upcase}_LOG_FILE", default: nil)
|
187
193
|
subclass.integer(:"#{subclass.service_name.upcase}_LOG_MAX_FILE_SIZE", default: 1048576, range: 0..Float::INFINITY)
|
data/service_skeleton.gemspec
CHANGED
@@ -31,6 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.required_ruby_version = ">= 2.3.0"
|
32
32
|
|
33
33
|
s.add_runtime_dependency "frankenstein", "~> 1.2"
|
34
|
+
s.add_runtime_dependency "loggerstash", "~> 0.0"
|
34
35
|
# prometheus-client provides no guaranteed backwards compatibility,
|
35
36
|
# and in fact happily breaks things with no notice, so we're stuck
|
36
37
|
# with hard-coding a specific version to avoid unexpected disaster.
|
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
|
4
|
+
version: 0.0.0.3.g1269800.1.gaaa2fa1
|
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-
|
11
|
+
date: 2018-11-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: frankenstein
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: loggerstash
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: prometheus-client
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|