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
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
# frozen_string_literal: true
|
|
2
|
-
|
|
3
|
-
module Smplkit
|
|
4
|
-
module Management
|
|
5
|
-
CONTEXT_REGISTRATION_LRU_SIZE = 10_000
|
|
6
|
-
CONTEXT_BATCH_FLUSH_SIZE = 100
|
|
7
|
-
FLAG_BATCH_FLUSH_SIZE = 50
|
|
8
|
-
LOGGER_BATCH_FLUSH_SIZE = 50
|
|
9
|
-
CONFIG_BATCH_FLUSH_SIZE = 50
|
|
10
|
-
|
|
11
|
-
# Thread-safe batch buffer for context registration.
|
|
12
|
-
class ContextRegistrationBuffer
|
|
13
|
-
def initialize
|
|
14
|
-
@seen = {}
|
|
15
|
-
@pending = []
|
|
16
|
-
@lock = Mutex.new
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def observe(contexts)
|
|
20
|
-
@lock.synchronize do
|
|
21
|
-
contexts.each do |ctx|
|
|
22
|
-
cache_key = [ctx.type, ctx.key]
|
|
23
|
-
next if @seen.key?(cache_key)
|
|
24
|
-
|
|
25
|
-
@seen.shift if @seen.size >= CONTEXT_REGISTRATION_LRU_SIZE
|
|
26
|
-
@seen[cache_key] = ctx.attributes
|
|
27
|
-
@pending << { "type" => ctx.type, "key" => ctx.key, "attributes" => ctx.attributes.dup }
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def drain
|
|
33
|
-
@lock.synchronize do
|
|
34
|
-
batch = @pending
|
|
35
|
-
@pending = []
|
|
36
|
-
batch
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def pending_count
|
|
41
|
-
@lock.synchronize { @pending.length }
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
# Thread-safe batch buffer for flag declarations.
|
|
46
|
-
#
|
|
47
|
-
# Use +peek+ + +commit(ids)+ for the send path so a failed POST leaves
|
|
48
|
-
# declarations queued for the next attempt. +drain+ is unconditional and
|
|
49
|
-
# used only by tests/teardown.
|
|
50
|
-
class FlagRegistrationBuffer
|
|
51
|
-
def initialize
|
|
52
|
-
@seen = {}
|
|
53
|
-
@pending = []
|
|
54
|
-
@lock = Mutex.new
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
def add(declaration)
|
|
58
|
-
@lock.synchronize do
|
|
59
|
-
next if @seen.key?(declaration.id)
|
|
60
|
-
|
|
61
|
-
@seen[declaration.id] = true
|
|
62
|
-
item = { "id" => declaration.id, "type" => declaration.type, "default" => declaration.default }
|
|
63
|
-
item["service"] = declaration.service if declaration.service
|
|
64
|
-
item["environment"] = declaration.environment if declaration.environment
|
|
65
|
-
@pending << item
|
|
66
|
-
end
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
def peek
|
|
70
|
-
@lock.synchronize { @pending.dup }
|
|
71
|
-
end
|
|
72
|
-
|
|
73
|
-
def commit(ids)
|
|
74
|
-
return if ids.nil? || ids.empty?
|
|
75
|
-
|
|
76
|
-
committed = ids.to_set
|
|
77
|
-
@lock.synchronize { @pending.reject! { |item| committed.include?(item["id"]) } }
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
def drain
|
|
81
|
-
@lock.synchronize do
|
|
82
|
-
batch = @pending
|
|
83
|
-
@pending = []
|
|
84
|
-
batch
|
|
85
|
-
end
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
def pending_count
|
|
89
|
-
@lock.synchronize { @pending.length }
|
|
90
|
-
end
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
# Thread-safe batch buffer for config declarations. Mirrors Python's
|
|
94
|
-
# +_ConfigRegistrationBuffer+: per-config metadata is retained across
|
|
95
|
-
# flushes so post-drain deltas re-attribute correctly, and items are
|
|
96
|
-
# dedup'd per +(config_id, item_key)+ so an already-sent item is
|
|
97
|
-
# never re-sent.
|
|
98
|
-
class ConfigRegistrationBuffer
|
|
99
|
-
def initialize
|
|
100
|
-
@pending = {} # config_id -> { id:, items: {}, ...meta }
|
|
101
|
-
@meta = {} # config_id -> { service:, environment:, parent:, name:, description: }
|
|
102
|
-
@sent_items = {} # "#{config_id}::#{item_key}" -> true
|
|
103
|
-
@lock = Mutex.new
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
# Idempotent — first writer's metadata wins.
|
|
107
|
-
def declare(config_id, service:, environment:, parent: nil, name: nil, description: nil)
|
|
108
|
-
@lock.synchronize do
|
|
109
|
-
next if @meta.key?(config_id)
|
|
110
|
-
|
|
111
|
-
@meta[config_id] = {
|
|
112
|
-
service: service, environment: environment,
|
|
113
|
-
parent: parent, name: name, description: description
|
|
114
|
-
}
|
|
115
|
-
@pending[config_id] = build_entry(config_id)
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
# Queue an item declaration for an already-declared config. Items
|
|
120
|
-
# already sent in a previous +drain+ are skipped.
|
|
121
|
-
def add_item(config_id, item_key, item_type, default, description = nil)
|
|
122
|
-
@lock.synchronize do
|
|
123
|
-
next unless @meta.key?(config_id)
|
|
124
|
-
next if @sent_items.key?("#{config_id}::#{item_key}")
|
|
125
|
-
|
|
126
|
-
entry = (@pending[config_id] ||= build_entry(config_id))
|
|
127
|
-
next if entry["items"].key?(item_key)
|
|
128
|
-
|
|
129
|
-
item = { "value" => default, "type" => item_type }
|
|
130
|
-
item["description"] = description unless description.nil?
|
|
131
|
-
entry["items"][item_key] = item
|
|
132
|
-
end
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
# Returns and clears the pending batch; records sent items.
|
|
136
|
-
def drain
|
|
137
|
-
@lock.synchronize do
|
|
138
|
-
entries = @pending.values
|
|
139
|
-
entries.each do |entry|
|
|
140
|
-
entry["items"].each_key { |item_key| @sent_items["#{entry["id"]}::#{item_key}"] = true }
|
|
141
|
-
end
|
|
142
|
-
@pending = {}
|
|
143
|
-
entries
|
|
144
|
-
end
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
def pending_count
|
|
148
|
-
@lock.synchronize { @pending.size }
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
private
|
|
152
|
-
|
|
153
|
-
def build_entry(config_id)
|
|
154
|
-
meta = @meta[config_id]
|
|
155
|
-
entry = { "id" => config_id, "items" => {} }
|
|
156
|
-
%i[service environment parent name description].each do |k|
|
|
157
|
-
v = meta[k]
|
|
158
|
-
entry[k.to_s] = v unless v.nil?
|
|
159
|
-
end
|
|
160
|
-
entry
|
|
161
|
-
end
|
|
162
|
-
end
|
|
163
|
-
|
|
164
|
-
# Thread-safe batch buffer for logger discovery.
|
|
165
|
-
class LoggerRegistrationBuffer
|
|
166
|
-
def initialize
|
|
167
|
-
@seen = {}
|
|
168
|
-
@pending = []
|
|
169
|
-
@lock = Mutex.new
|
|
170
|
-
end
|
|
171
|
-
|
|
172
|
-
def add(source)
|
|
173
|
-
@lock.synchronize do
|
|
174
|
-
next if @seen.key?(source.name)
|
|
175
|
-
|
|
176
|
-
@seen[source.name] = source.resolved_level
|
|
177
|
-
item = { "id" => source.name, "resolved_level" => source.resolved_level&.to_s }
|
|
178
|
-
item["level"] = source.level&.to_s if source.level
|
|
179
|
-
item["service"] = source.service if source.service
|
|
180
|
-
item["environment"] = source.environment if source.environment
|
|
181
|
-
@pending << item
|
|
182
|
-
end
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
def drain
|
|
186
|
-
@lock.synchronize do
|
|
187
|
-
batch = @pending
|
|
188
|
-
@pending = []
|
|
189
|
-
batch
|
|
190
|
-
end
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
def pending_count
|
|
194
|
-
@lock.synchronize { @pending.length }
|
|
195
|
-
end
|
|
196
|
-
end
|
|
197
|
-
end
|
|
198
|
-
end
|