smplkit 1.0.5

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.
Files changed (39) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +5 -0
  3. data/LICENSE +21 -0
  4. data/README.md +105 -0
  5. data/lib/smplkit/client.rb +218 -0
  6. data/lib/smplkit/config/client.rb +238 -0
  7. data/lib/smplkit/config/helpers.rb +108 -0
  8. data/lib/smplkit/config/models.rb +192 -0
  9. data/lib/smplkit/config_resolution.rb +202 -0
  10. data/lib/smplkit/context.rb +68 -0
  11. data/lib/smplkit/debug.rb +50 -0
  12. data/lib/smplkit/errors.rb +114 -0
  13. data/lib/smplkit/flags/client.rb +480 -0
  14. data/lib/smplkit/flags/helpers.rb +76 -0
  15. data/lib/smplkit/flags/models.rb +258 -0
  16. data/lib/smplkit/flags/types.rb +233 -0
  17. data/lib/smplkit/generators/install_generator.rb +42 -0
  18. data/lib/smplkit/helpers.rb +15 -0
  19. data/lib/smplkit/log_level.rb +57 -0
  20. data/lib/smplkit/logging/adapters/base.rb +63 -0
  21. data/lib/smplkit/logging/adapters/semantic_logger_adapter.rb +88 -0
  22. data/lib/smplkit/logging/adapters/stdlib_logger_adapter.rb +143 -0
  23. data/lib/smplkit/logging/client.rb +142 -0
  24. data/lib/smplkit/logging/helpers.rb +69 -0
  25. data/lib/smplkit/logging/levels.rb +86 -0
  26. data/lib/smplkit/logging/models.rb +124 -0
  27. data/lib/smplkit/logging/normalize.rb +16 -0
  28. data/lib/smplkit/logging/sources.rb +44 -0
  29. data/lib/smplkit/management/buffer.rb +111 -0
  30. data/lib/smplkit/management/client.rb +623 -0
  31. data/lib/smplkit/management/models.rb +133 -0
  32. data/lib/smplkit/management/types.rb +65 -0
  33. data/lib/smplkit/metrics.rb +78 -0
  34. data/lib/smplkit/railtie.rb +48 -0
  35. data/lib/smplkit/version.rb +5 -0
  36. data/lib/smplkit/ws.rb +92 -0
  37. data/lib/smplkit.rb +43 -0
  38. data/sig/smplkit.rbs +141 -0
  39. metadata +139 -0
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Smplkit
4
+ module Logging
5
+ # Describes a logger to register via +Smplkit::ManagementClient#loggers#register+.
6
+ #
7
+ # Used both for buffered runtime discovery (called by +Smplkit::Client+ as
8
+ # adapters discover loggers) and for explicit registration from setup
9
+ # scripts that already know the +(service, environment)+ they belong to.
10
+ #
11
+ # Args:
12
+ # - name: Logger name (e.g. +"sqlalchemy.engine"+). Normalized to
13
+ # lowercase with slashes and colons replaced by dots before sending to
14
+ # the API.
15
+ # - resolved_level: Effective log level for this source.
16
+ # - level: Explicit (configured) log level, if different from
17
+ # +resolved_level+. Pass +nil+ when the level is inherited.
18
+ # - service: Service name this source belongs to (optional).
19
+ # - environment: Environment name this source belongs to (optional).
20
+ class LoggerSource
21
+ attr_reader :name, :resolved_level, :level, :service, :environment
22
+
23
+ def initialize(name:, resolved_level:, level: nil, service: nil, environment: nil)
24
+ @name = name
25
+ @resolved_level = resolved_level
26
+ @level = level
27
+ @service = service
28
+ @environment = environment
29
+ freeze
30
+ end
31
+
32
+ def ==(other)
33
+ other.is_a?(LoggerSource) && name == other.name && resolved_level == other.resolved_level &&
34
+ level == other.level && service == other.service && environment == other.environment
35
+ end
36
+ alias eql? ==
37
+
38
+ def hash = [name, resolved_level, level, service, environment].hash
39
+ end
40
+ end
41
+
42
+ # Top-level re-export.
43
+ LoggerSource = Logging::LoggerSource
44
+ end
@@ -0,0 +1,111 @@
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
+
10
+ # Thread-safe batch buffer for context registration.
11
+ class ContextRegistrationBuffer
12
+ def initialize
13
+ @seen = {}
14
+ @pending = []
15
+ @lock = Mutex.new
16
+ end
17
+
18
+ def observe(contexts)
19
+ @lock.synchronize do
20
+ contexts.each do |ctx|
21
+ cache_key = [ctx.type, ctx.key]
22
+ next if @seen.key?(cache_key)
23
+
24
+ @seen.shift if @seen.size >= CONTEXT_REGISTRATION_LRU_SIZE
25
+ @seen[cache_key] = ctx.attributes
26
+ @pending << { "type" => ctx.type, "key" => ctx.key, "attributes" => ctx.attributes.dup }
27
+ end
28
+ end
29
+ end
30
+
31
+ def drain
32
+ @lock.synchronize do
33
+ batch = @pending
34
+ @pending = []
35
+ batch
36
+ end
37
+ end
38
+
39
+ def pending_count
40
+ @lock.synchronize { @pending.length }
41
+ end
42
+ end
43
+
44
+ # Thread-safe batch buffer for flag declarations.
45
+ class FlagRegistrationBuffer
46
+ def initialize
47
+ @seen = {}
48
+ @pending = []
49
+ @lock = Mutex.new
50
+ end
51
+
52
+ def add(declaration)
53
+ @lock.synchronize do
54
+ next if @seen.key?(declaration.id)
55
+
56
+ @seen[declaration.id] = true
57
+ item = { "id" => declaration.id, "type" => declaration.type, "default" => declaration.default }
58
+ item["service"] = declaration.service if declaration.service
59
+ item["environment"] = declaration.environment if declaration.environment
60
+ @pending << item
61
+ end
62
+ end
63
+
64
+ def drain
65
+ @lock.synchronize do
66
+ batch = @pending
67
+ @pending = []
68
+ batch
69
+ end
70
+ end
71
+
72
+ def pending_count
73
+ @lock.synchronize { @pending.length }
74
+ end
75
+ end
76
+
77
+ # Thread-safe batch buffer for logger discovery.
78
+ class LoggerRegistrationBuffer
79
+ def initialize
80
+ @seen = {}
81
+ @pending = []
82
+ @lock = Mutex.new
83
+ end
84
+
85
+ def add(source)
86
+ @lock.synchronize do
87
+ next if @seen.key?(source.name)
88
+
89
+ @seen[source.name] = source.resolved_level
90
+ item = { "id" => source.name, "resolved_level" => source.resolved_level&.to_s }
91
+ item["level"] = source.level&.to_s if source.level
92
+ item["service"] = source.service if source.service
93
+ item["environment"] = source.environment if source.environment
94
+ @pending << item
95
+ end
96
+ end
97
+
98
+ def drain
99
+ @lock.synchronize do
100
+ batch = @pending
101
+ @pending = []
102
+ batch
103
+ end
104
+ end
105
+
106
+ def pending_count
107
+ @lock.synchronize { @pending.length }
108
+ end
109
+ end
110
+ end
111
+ end