smplkit 3.0.95 → 3.0.97
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/smplkit/account/client.rb +128 -0
- data/lib/smplkit/account/models.rb +71 -0
- data/lib/smplkit/api_support.rb +91 -0
- data/lib/smplkit/audit/buffer.rb +3 -1
- data/lib/smplkit/audit/categories.rb +21 -10
- data/lib/smplkit/audit/client.rb +18 -9
- data/lib/smplkit/audit/event_types.rb +26 -10
- data/lib/smplkit/audit/events.rb +93 -17
- data/lib/smplkit/{management/audit.rb → audit/forwarders.rb} +93 -85
- data/lib/smplkit/audit/models.rb +86 -32
- data/lib/smplkit/audit/resource_types.rb +21 -9
- data/lib/smplkit/buffers.rb +250 -0
- data/lib/smplkit/client.rb +161 -70
- data/lib/smplkit/config/client.rb +874 -186
- data/lib/smplkit/config/helpers.rb +44 -6
- data/lib/smplkit/config/models.rb +114 -7
- data/lib/smplkit/config_resolution.rb +17 -9
- data/lib/smplkit/errors.rb +14 -3
- data/lib/smplkit/flags/client.rb +602 -116
- data/lib/smplkit/flags/models.rb +110 -8
- data/lib/smplkit/flags/types.rb +8 -9
- data/lib/smplkit/jobs/client.rb +306 -0
- data/lib/smplkit/jobs/models.rb +47 -18
- data/lib/smplkit/logging/client.rb +755 -191
- data/lib/smplkit/logging/helpers.rb +5 -1
- data/lib/smplkit/logging/levels.rb +3 -1
- data/lib/smplkit/logging/models.rb +163 -6
- data/lib/smplkit/logging/normalize.rb +3 -1
- data/lib/smplkit/logging/resolution.rb +4 -4
- data/lib/smplkit/logging/sources.rb +1 -1
- data/lib/smplkit/platform/client.rb +597 -0
- data/lib/smplkit/platform/models.rb +282 -0
- data/lib/smplkit/{management → platform}/types.rb +21 -4
- data/lib/smplkit/transport.rb +103 -0
- data/lib/smplkit/ws.rb +1 -1
- data/lib/smplkit.rb +18 -6
- metadata +11 -7
- data/lib/smplkit/management/buffer.rb +0 -198
- data/lib/smplkit/management/client.rb +0 -1074
- data/lib/smplkit/management/jobs.rb +0 -226
- data/lib/smplkit/management/models.rb +0 -178
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
module Smplkit
|
|
4
4
|
module Logging
|
|
5
|
+
# Resource-to-model conversion helpers for the logging wrapper.
|
|
6
|
+
#
|
|
7
|
+
# @api private
|
|
5
8
|
module Helpers
|
|
6
9
|
module_function
|
|
7
10
|
|
|
@@ -18,6 +21,7 @@ module Smplkit
|
|
|
18
21
|
log_group_id: attrs["log_group_id"],
|
|
19
22
|
managed: attrs.fetch("managed", true),
|
|
20
23
|
description: attrs["description"],
|
|
24
|
+
environments: attrs["environments"],
|
|
21
25
|
created_at: attrs["created_at"],
|
|
22
26
|
updated_at: attrs["updated_at"]
|
|
23
27
|
)
|
|
@@ -32,7 +36,7 @@ module Smplkit
|
|
|
32
36
|
name: attrs["name"],
|
|
33
37
|
level: attrs["level"] && LogLevel.coerce(attrs["level"]),
|
|
34
38
|
description: attrs["description"],
|
|
35
|
-
|
|
39
|
+
group: attrs["parent_id"],
|
|
36
40
|
environments: attrs["environments"] || {},
|
|
37
41
|
created_at: attrs["created_at"],
|
|
38
42
|
updated_at: attrs["updated_at"]
|
|
@@ -6,7 +6,7 @@ require_relative "../log_level"
|
|
|
6
6
|
module Smplkit
|
|
7
7
|
module Logging
|
|
8
8
|
# Bidirectional mapping between Ruby stdlib +Logger+ levels and smplkit
|
|
9
|
-
# canonical levels
|
|
9
|
+
# canonical levels.
|
|
10
10
|
#
|
|
11
11
|
# Stdlib +Logger+ has DEBUG/INFO/WARN/ERROR/FATAL/UNKNOWN — no TRACE. The
|
|
12
12
|
# +stdlib-logger+ adapter maps smplkit TRACE to stdlib DEBUG when
|
|
@@ -14,6 +14,8 @@ module Smplkit
|
|
|
14
14
|
# discovering — there is no way to distinguish smplkit-TRACE-mapped-to-
|
|
15
15
|
# DEBUG from genuine DEBUG, which is consistent with how the Python
|
|
16
16
|
# +stdlib-logging+ adapter handles the same gap.
|
|
17
|
+
#
|
|
18
|
+
# @api private
|
|
17
19
|
module Levels
|
|
18
20
|
STDLIB_TO_SMPL = {
|
|
19
21
|
::Logger::DEBUG => LogLevel::DEBUG,
|
|
@@ -2,6 +2,60 @@
|
|
|
2
2
|
|
|
3
3
|
module Smplkit
|
|
4
4
|
module Logging
|
|
5
|
+
# Per-environment configuration on a logger or log group.
|
|
6
|
+
#
|
|
7
|
+
# Lives at +logger.environments[env_name]+ (a +Hash{String => LoggerEnvironment}+).
|
|
8
|
+
# Frozen — mutate the override via +logger.set_level(level, environment: "...")+
|
|
9
|
+
# or remove it via +logger.clear_level(environment: "...")+.
|
|
10
|
+
#
|
|
11
|
+
# Attributes:
|
|
12
|
+
# - level: Per-environment level override (+nil+ means no override).
|
|
13
|
+
LoggerEnvironment = Struct.new(:level, keyword_init: true) do
|
|
14
|
+
def initialize(level: nil)
|
|
15
|
+
super
|
|
16
|
+
freeze
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Coerce a dict input into +Hash{String => LoggerEnvironment}+.
|
|
21
|
+
#
|
|
22
|
+
# Accepts both pre-built +LoggerEnvironment+ instances and the wire-shaped
|
|
23
|
+
# +{env_id => {"level" => "ERROR"}}+ dicts.
|
|
24
|
+
#
|
|
25
|
+
# @api private
|
|
26
|
+
def self.convert_environments(value)
|
|
27
|
+
return {} if value.nil? || value.empty?
|
|
28
|
+
|
|
29
|
+
value.each_with_object({}) do |(env_id, env_data), out|
|
|
30
|
+
out[env_id] = build_logger_environment(env_data)
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# @api private
|
|
35
|
+
def self.build_logger_environment(env_data)
|
|
36
|
+
return env_data if env_data.is_a?(LoggerEnvironment)
|
|
37
|
+
return LoggerEnvironment.new unless env_data.is_a?(Hash)
|
|
38
|
+
|
|
39
|
+
level_str = env_data["level"] || env_data[:level]
|
|
40
|
+
return LoggerEnvironment.new if level_str.nil?
|
|
41
|
+
|
|
42
|
+
begin
|
|
43
|
+
LoggerEnvironment.new(level: LogLevel.coerce(level_str))
|
|
44
|
+
rescue ArgumentError
|
|
45
|
+
LoggerEnvironment.new
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
# Convert a typed environments dict to the wire-shaped dict for sending.
|
|
50
|
+
# Entries with +level=nil+ are skipped (no override to send).
|
|
51
|
+
#
|
|
52
|
+
# @api private
|
|
53
|
+
def self.environments_to_wire(environments)
|
|
54
|
+
environments.each_with_object({}) do |(env_id, env), out|
|
|
55
|
+
out[env_id] = { "level" => env.level.to_s } unless env.level.nil?
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
|
|
5
59
|
# A logger resource managed by the smplkit Logging service.
|
|
6
60
|
#
|
|
7
61
|
# Attributes:
|
|
@@ -12,13 +66,15 @@ module Smplkit
|
|
|
12
66
|
# - service, environment: provenance
|
|
13
67
|
# - log_group_id: parent log group, if any
|
|
14
68
|
# - managed: whether the SDK should apply server-driven level changes
|
|
69
|
+
# - environments: per-environment level overrides, keyed by environment
|
|
15
70
|
class SmplLogger
|
|
16
71
|
attr_accessor :id, :name, :resolved_level, :level, :service, :environment,
|
|
17
72
|
:log_group_id, :managed, :created_at, :updated_at, :description
|
|
18
73
|
|
|
19
74
|
def initialize(client = nil, name:, resolved_level:, id: nil, level: nil,
|
|
20
75
|
service: nil, environment: nil, log_group_id: nil,
|
|
21
|
-
managed: true, description: nil,
|
|
76
|
+
managed: true, description: nil, environments: nil,
|
|
77
|
+
created_at: nil, updated_at: nil)
|
|
22
78
|
@client = client
|
|
23
79
|
@id = id
|
|
24
80
|
@name = name
|
|
@@ -29,12 +85,58 @@ module Smplkit
|
|
|
29
85
|
@log_group_id = log_group_id
|
|
30
86
|
@managed = managed
|
|
31
87
|
@description = description
|
|
88
|
+
@environments = Logging.convert_environments(environments)
|
|
32
89
|
@created_at = created_at
|
|
33
90
|
@updated_at = updated_at
|
|
34
91
|
end
|
|
35
92
|
|
|
93
|
+
# Whether the SDK applies server-driven level changes to this logger.
|
|
94
|
+
#
|
|
95
|
+
# @return [Boolean] +true+ when smplkit controls this logger's level.
|
|
36
96
|
def managed? = !!@managed
|
|
37
97
|
|
|
98
|
+
# Read-only view of per-environment level overrides. Mutate via
|
|
99
|
+
# +set_level+ / +clear_level+ (with +environment: "..."+).
|
|
100
|
+
def environments
|
|
101
|
+
@environments.dup
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Set the log level.
|
|
105
|
+
#
|
|
106
|
+
# With +environment: nil+ (the default), sets the base log level used when
|
|
107
|
+
# no environment-specific override applies. With +environment: "..."+,
|
|
108
|
+
# sets the per-environment override. Changes are local until +save+.
|
|
109
|
+
def set_level(level, environment: nil)
|
|
110
|
+
if environment.nil?
|
|
111
|
+
@level = level
|
|
112
|
+
else
|
|
113
|
+
@environments[environment] = LoggerEnvironment.new(level: level)
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Remove a log level.
|
|
118
|
+
#
|
|
119
|
+
# With +environment: nil+ (the default), removes the base log level (the
|
|
120
|
+
# logger then inherits from its group / ancestor / system default). With
|
|
121
|
+
# +environment: "..."+, removes the per-environment override only. Changes
|
|
122
|
+
# are local until +save+.
|
|
123
|
+
def clear_level(environment: nil)
|
|
124
|
+
if environment.nil?
|
|
125
|
+
@level = nil
|
|
126
|
+
else
|
|
127
|
+
@environments.delete(environment)
|
|
128
|
+
end
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
# Remove all per-environment level overrides.
|
|
132
|
+
def clear_all_environment_levels
|
|
133
|
+
@environments = {}
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Persist this logger to the server (create or update).
|
|
137
|
+
#
|
|
138
|
+
# @return [self] this logger, refreshed from the server response.
|
|
139
|
+
# @raise [RuntimeError] If the logger was constructed without a client.
|
|
38
140
|
def save
|
|
39
141
|
raise "SmplLogger was constructed without a client; cannot save" if @client.nil?
|
|
40
142
|
|
|
@@ -44,6 +146,11 @@ module Smplkit
|
|
|
44
146
|
end
|
|
45
147
|
alias save! save
|
|
46
148
|
|
|
149
|
+
# Delete this logger from the server.
|
|
150
|
+
#
|
|
151
|
+
# @return [void]
|
|
152
|
+
# @raise [RuntimeError] If the logger was constructed without a client.
|
|
153
|
+
# @raise [Smplkit::NotFoundError] If the logger no longer exists.
|
|
47
154
|
def delete
|
|
48
155
|
raise "SmplLogger was constructed without a client; cannot delete" if @client.nil?
|
|
49
156
|
|
|
@@ -51,6 +158,7 @@ module Smplkit
|
|
|
51
158
|
end
|
|
52
159
|
alias delete! delete
|
|
53
160
|
|
|
161
|
+
# @api private
|
|
54
162
|
def _apply(other)
|
|
55
163
|
@id = other.id
|
|
56
164
|
@name = other.name
|
|
@@ -61,6 +169,7 @@ module Smplkit
|
|
|
61
169
|
@log_group_id = other.log_group_id
|
|
62
170
|
@managed = other.managed
|
|
63
171
|
@description = other.description
|
|
172
|
+
@environments = other.environments
|
|
64
173
|
@created_at = other.created_at
|
|
65
174
|
@updated_at = other.updated_at
|
|
66
175
|
end
|
|
@@ -69,11 +178,11 @@ module Smplkit
|
|
|
69
178
|
# A log group resource — a hierarchical bag of loggers with a shared
|
|
70
179
|
# configured level.
|
|
71
180
|
class SmplLogGroup
|
|
72
|
-
attr_accessor :id, :key, :name, :level, :description, :
|
|
181
|
+
attr_accessor :id, :key, :name, :level, :description, :group,
|
|
73
182
|
:created_at, :updated_at
|
|
74
183
|
|
|
75
184
|
def initialize(client = nil, key:, id: nil, name: nil, level: nil,
|
|
76
|
-
description: nil,
|
|
185
|
+
description: nil, group: nil, environments: nil,
|
|
77
186
|
created_at: nil, updated_at: nil)
|
|
78
187
|
@client = client
|
|
79
188
|
@id = id
|
|
@@ -81,12 +190,54 @@ module Smplkit
|
|
|
81
190
|
@name = name
|
|
82
191
|
@level = level
|
|
83
192
|
@description = description
|
|
84
|
-
@
|
|
85
|
-
@environments = environments
|
|
193
|
+
@group = group
|
|
194
|
+
@environments = Logging.convert_environments(environments)
|
|
86
195
|
@created_at = created_at
|
|
87
196
|
@updated_at = updated_at
|
|
88
197
|
end
|
|
89
198
|
|
|
199
|
+
# Read-only view of per-environment level overrides. Mutate via
|
|
200
|
+
# +set_level+ / +clear_level+ (with +environment: "..."+).
|
|
201
|
+
def environments
|
|
202
|
+
@environments.dup
|
|
203
|
+
end
|
|
204
|
+
|
|
205
|
+
# Set the log level.
|
|
206
|
+
#
|
|
207
|
+
# With +environment: nil+ (the default), sets the base log level used when
|
|
208
|
+
# no environment-specific override applies. With +environment: "..."+,
|
|
209
|
+
# sets the per-environment override. Changes are local until +save+.
|
|
210
|
+
def set_level(level, environment: nil)
|
|
211
|
+
if environment.nil?
|
|
212
|
+
@level = level
|
|
213
|
+
else
|
|
214
|
+
@environments[environment] = LoggerEnvironment.new(level: level)
|
|
215
|
+
end
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
# Remove a log level.
|
|
219
|
+
#
|
|
220
|
+
# With +environment: nil+ (the default), removes the base log level (the
|
|
221
|
+
# group then inherits from its parent group / ancestor / system default).
|
|
222
|
+
# With +environment: "..."+, removes the per-environment override only.
|
|
223
|
+
# Changes are local until +save+.
|
|
224
|
+
def clear_level(environment: nil)
|
|
225
|
+
if environment.nil?
|
|
226
|
+
@level = nil
|
|
227
|
+
else
|
|
228
|
+
@environments.delete(environment)
|
|
229
|
+
end
|
|
230
|
+
end
|
|
231
|
+
|
|
232
|
+
# Remove all per-environment level overrides.
|
|
233
|
+
def clear_all_environment_levels
|
|
234
|
+
@environments = {}
|
|
235
|
+
end
|
|
236
|
+
|
|
237
|
+
# Persist this group to the server (create or update).
|
|
238
|
+
#
|
|
239
|
+
# @return [self] this group, refreshed from the server response.
|
|
240
|
+
# @raise [RuntimeError] If the group was constructed without a client.
|
|
90
241
|
def save
|
|
91
242
|
raise "SmplLogGroup was constructed without a client; cannot save" if @client.nil?
|
|
92
243
|
|
|
@@ -101,6 +252,11 @@ module Smplkit
|
|
|
101
252
|
end
|
|
102
253
|
alias save! save
|
|
103
254
|
|
|
255
|
+
# Delete this group from the server.
|
|
256
|
+
#
|
|
257
|
+
# @return [void]
|
|
258
|
+
# @raise [RuntimeError] If the group was constructed without a client.
|
|
259
|
+
# @raise [Smplkit::NotFoundError] If the group no longer exists.
|
|
104
260
|
def delete
|
|
105
261
|
raise "SmplLogGroup was constructed without a client; cannot delete" if @client.nil?
|
|
106
262
|
|
|
@@ -108,13 +264,14 @@ module Smplkit
|
|
|
108
264
|
end
|
|
109
265
|
alias delete! delete
|
|
110
266
|
|
|
267
|
+
# @api private
|
|
111
268
|
def _apply(other)
|
|
112
269
|
@id = other.id
|
|
113
270
|
@key = other.key
|
|
114
271
|
@name = other.name
|
|
115
272
|
@level = other.level
|
|
116
273
|
@description = other.description
|
|
117
|
-
@
|
|
274
|
+
@group = other.group
|
|
118
275
|
@environments = other.environments
|
|
119
276
|
@created_at = other.created_at
|
|
120
277
|
@updated_at = other.updated_at
|
|
@@ -4,12 +4,12 @@ require "set"
|
|
|
4
4
|
|
|
5
5
|
module Smplkit
|
|
6
6
|
module Logging
|
|
7
|
-
# Client-side level resolution
|
|
7
|
+
# Client-side level resolution.
|
|
8
8
|
#
|
|
9
9
|
# The server stores raw configuration and returns it as-is; the SDK is
|
|
10
|
-
# responsible for walking the inheritance chain.
|
|
11
|
-
#
|
|
12
|
-
#
|
|
10
|
+
# responsible for walking the inheritance chain.
|
|
11
|
+
#
|
|
12
|
+
# @api private
|
|
13
13
|
module Resolution
|
|
14
14
|
FALLBACK_LEVEL = "INFO"
|
|
15
15
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
module Smplkit
|
|
4
4
|
module Logging
|
|
5
|
-
# Describes a logger to register via +
|
|
5
|
+
# Describes a logger to register via +client.logging.loggers.register+.
|
|
6
6
|
#
|
|
7
7
|
# Used both for buffered runtime discovery (called by +Smplkit::Client+ as
|
|
8
8
|
# adapters discover loggers) and for explicit registration from setup
|