teneo_microservice 1.0.3 → 1.0.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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 06570bcafbd3acbaa7f1eea2280fa73adbfde4311061040d4fde96f617ead862
|
4
|
+
data.tar.gz: ab48738dcdf280323fbcf73340fed9c873c5a1a8e3f1c4ab09822f49fd415252
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ff45882cfd370f7f8f5e23abe0be753696ce30a37df2592fe945ab580e32d1d97f4d238f7fa26d66a71e6b96abfc6a2fadb5d7b0997066a015716387f590509c
|
7
|
+
data.tar.gz: adca9acd8b6818d4952cae634365b71a7b70616c6c3ed8ddff743f6214faa6900e5a3da2070c70981e2abf9fd66258f19ecd0795410ee8bb55f9121be9ad1bd6
|
@@ -3,6 +3,7 @@
|
|
3
3
|
require_relative 'client'
|
4
4
|
require_relative 'service_orchestrator'
|
5
5
|
require_relative 'util/env'
|
6
|
+
require_relative 'util/logging'
|
6
7
|
|
7
8
|
##
|
8
9
|
# This class encapsulates both a gRPC endpoint and a list of gRPC clients.
|
@@ -16,10 +17,16 @@ class Server
|
|
16
17
|
##
|
17
18
|
# A list of clients used for communicating with all registered remote hosts.
|
18
19
|
attr_accessor :clients
|
20
|
+
##
|
21
|
+
# The logger that shows what the Server is doing.
|
22
|
+
attr_accessor :logger
|
19
23
|
|
20
24
|
def initialize
|
21
25
|
Env.valid_settings?
|
22
26
|
|
27
|
+
@standard_attributes = standard_log_attributes
|
28
|
+
@logger = GRPCLogger.new(standard_metadata: standard_log_attributes)
|
29
|
+
|
23
30
|
@socket = "#{ENV["LISTEN_ADDRESS"]}:#{ENV["PORT"]}"
|
24
31
|
remote_hosts = ENV['REMOTE_HOSTS'].split('|') unless ENV['REMOTE_HOSTS'].nil?
|
25
32
|
|
@@ -33,18 +40,31 @@ class Server
|
|
33
40
|
@orchestrator.initialize_listener
|
34
41
|
end
|
35
42
|
|
43
|
+
##
|
44
|
+
# standard_log_attributes returns a hash containing the minimum set of attributes
|
45
|
+
# needed for logs generated by this class.
|
46
|
+
def standard_log_attributes
|
47
|
+
{
|
48
|
+
'grpc.component' => 'server'
|
49
|
+
}
|
50
|
+
end
|
51
|
+
|
36
52
|
##
|
37
53
|
# register_service registers a service to the gRPC server.
|
38
54
|
#
|
39
55
|
# A service provides the actual executable methods used for communication,
|
40
56
|
# and registering these to the server makes them available for implementation.
|
41
57
|
def register_service(service:)
|
58
|
+
@logger.info(msg: "registering service '#{service.class}'")
|
59
|
+
|
42
60
|
@orchestrator.add(service)
|
43
61
|
end
|
44
62
|
|
45
63
|
##
|
46
64
|
# start_listening_for_data readies the server for accepting traffic.
|
47
65
|
def start_listening_for_data
|
66
|
+
@logger.info(msg: "accepting traffic on port ':#{ENV["PORT"]}'")
|
67
|
+
|
48
68
|
@orchestrator.start
|
49
69
|
end
|
50
70
|
end
|
@@ -1,14 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require 'logging'
|
4
3
|
require 'grpc'
|
5
4
|
|
6
5
|
require_relative 'error_classes/socket_format_error'
|
7
6
|
|
8
|
-
module GRPC
|
9
|
-
extend Logging.globally
|
10
|
-
end
|
11
|
-
|
12
7
|
##
|
13
8
|
# This class represents a gRPC endpoint with which clients can communicate.
|
14
9
|
class ServiceOrchestrator
|
@@ -18,26 +13,6 @@ class ServiceOrchestrator
|
|
18
13
|
|
19
14
|
def initialize(socket:)
|
20
15
|
@socket = socket
|
21
|
-
|
22
|
-
Logging.logger.root.appenders = Logging.appenders.stdout
|
23
|
-
Logging.logger.root.level = configured_log_level
|
24
|
-
end
|
25
|
-
|
26
|
-
##
|
27
|
-
# configured_log_level returns the correct token to be used to set the
|
28
|
-
# gRPC log level based on the configured setting.
|
29
|
-
def configured_log_level
|
30
|
-
error_level_hash = {
|
31
|
-
'DEBUG' => :debug,
|
32
|
-
'INFO' => :info,
|
33
|
-
'WARN' => :warn,
|
34
|
-
'ERROR' => :error,
|
35
|
-
'FATAL' => :fatal
|
36
|
-
}
|
37
|
-
|
38
|
-
return :info unless error_level_hash.key?(ENV['LOG_LEVEL'])
|
39
|
-
|
40
|
-
error_level_hash[ENV['LOG_LEVEL']]
|
41
16
|
end
|
42
17
|
|
43
18
|
##
|
@@ -49,7 +24,6 @@ class ServiceOrchestrator
|
|
49
24
|
|
50
25
|
@listener = GRPC::RpcServer.new
|
51
26
|
@listener.add_http2_port(@socket, :this_port_is_insecure)
|
52
|
-
GRPC.logger.info("... running insecurely on #{@socket}")
|
53
27
|
end
|
54
28
|
|
55
29
|
##
|
@@ -0,0 +1,139 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'logger'
|
4
|
+
require 'time'
|
5
|
+
|
6
|
+
##
|
7
|
+
# This module provides functionality for creating a correctly configured logger.
|
8
|
+
class GRPCLogger
|
9
|
+
def initialize(standard_metadata: {})
|
10
|
+
@logger = Logger.new($stdout)
|
11
|
+
@logger.sev_threshold = threshold_level
|
12
|
+
|
13
|
+
@logger.formatter = proc do |sev, datetime, _, msg|
|
14
|
+
"#{datetime.to_datetime.rfc3339} #{abbreviate_severity(severity: sev)} #{msg}\n"
|
15
|
+
end
|
16
|
+
|
17
|
+
@standard_metadata = standard_metadata
|
18
|
+
end
|
19
|
+
|
20
|
+
##
|
21
|
+
# construct_message constructs the message to be logged so it matches Go's zerolog's
|
22
|
+
# format (https://github.com/rs/zerolog).
|
23
|
+
#
|
24
|
+
# The message consists of the message provided by the caller appended by both
|
25
|
+
# the provided attributes and time attributes.
|
26
|
+
def construct_message(message:, attributes: {})
|
27
|
+
msg_parts = []
|
28
|
+
|
29
|
+
msg_parts.push(message)
|
30
|
+
|
31
|
+
now = Time.now
|
32
|
+
ms = (now.to_f * 1000).to_i - (now.to_i * 1000)
|
33
|
+
attributes['grpc.start_time'] = now.to_datetime.rfc3339
|
34
|
+
attributes['grpc.time_ms'] = ms
|
35
|
+
|
36
|
+
attributes.each do |key, value|
|
37
|
+
msg_parts.push("#{key}=#{value}")
|
38
|
+
end
|
39
|
+
|
40
|
+
msg_parts.join(' ')
|
41
|
+
end
|
42
|
+
|
43
|
+
##
|
44
|
+
# abbreviate_severity abbreviates the log's severity so it matches Go's zerolog's
|
45
|
+
# log severities (https://github.com/rs/zerolog).
|
46
|
+
def abbreviate_severity(severity:)
|
47
|
+
abbreviations = {
|
48
|
+
'DEBUG' => 'DBG',
|
49
|
+
'INFO' => 'INF',
|
50
|
+
'WARN' => 'WRN',
|
51
|
+
'ERROR' => 'ERR',
|
52
|
+
'FATAL' => 'FTL'
|
53
|
+
}
|
54
|
+
|
55
|
+
abbreviations[severity]
|
56
|
+
end
|
57
|
+
|
58
|
+
##
|
59
|
+
# threshold_level returns the correct logging threshold level
|
60
|
+
# based on the configured setting.
|
61
|
+
def threshold_level
|
62
|
+
error_level_hash = {
|
63
|
+
'DEBUG' => Logger::DEBUG,
|
64
|
+
'INFO' => Logger::INFO,
|
65
|
+
'WARN' => Logger::WARN,
|
66
|
+
'ERROR' => Logger::ERROR,
|
67
|
+
'FATAL' => Logger::FATAL
|
68
|
+
}
|
69
|
+
|
70
|
+
return Logger::INFO unless error_level_hash.key?(ENV['LOG_LEVEL'])
|
71
|
+
|
72
|
+
error_level_hash[ENV['LOG_LEVEL']]
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# debug logs a message with the DEBUG severity.
|
77
|
+
def debug(msg:, meta: {})
|
78
|
+
meta = meta.merge(@standard_metadata)
|
79
|
+
|
80
|
+
@logger.debug do
|
81
|
+
construct_message(
|
82
|
+
message: msg,
|
83
|
+
attributes: meta
|
84
|
+
)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
##
|
89
|
+
# info logs a message with the INFO severity.
|
90
|
+
def info(msg:, meta: {})
|
91
|
+
meta = meta.merge(@standard_metadata)
|
92
|
+
|
93
|
+
@logger.info do
|
94
|
+
construct_message(
|
95
|
+
message: msg,
|
96
|
+
attributes: meta
|
97
|
+
)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
##
|
102
|
+
# warn logs a message with the WARN severity.
|
103
|
+
def warn(msg:, meta: {})
|
104
|
+
meta = meta.merge(@standard_metadata)
|
105
|
+
|
106
|
+
@logger.warn do
|
107
|
+
construct_message(
|
108
|
+
message: msg,
|
109
|
+
attributes: meta
|
110
|
+
)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
##
|
115
|
+
# error logs a message with the ERROR severity.
|
116
|
+
def error(msg:, meta: {})
|
117
|
+
meta = meta.merge(@standard_metadata)
|
118
|
+
|
119
|
+
@logger.error do
|
120
|
+
construct_message(
|
121
|
+
message: msg,
|
122
|
+
attributes: meta
|
123
|
+
)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
##
|
128
|
+
# fatal logs a message with the FATAL severity.
|
129
|
+
def fatal(msg:, meta: {})
|
130
|
+
meta = meta.merge(@standard_metadata)
|
131
|
+
|
132
|
+
@logger.fatal do
|
133
|
+
construct_message(
|
134
|
+
message: msg,
|
135
|
+
attributes: meta
|
136
|
+
)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: teneo_microservice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ruben Vanoverschelde
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-03-
|
11
|
+
date: 2025-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grpc
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- lib/teneo_microservice/service_orchestrator.rb
|
83
83
|
- lib/teneo_microservice/util/convert.rb
|
84
84
|
- lib/teneo_microservice/util/env.rb
|
85
|
+
- lib/teneo_microservice/util/logging.rb
|
85
86
|
homepage: https://github.com/libis/teneo-microservice-ruby
|
86
87
|
licenses:
|
87
88
|
- MIT
|