onni 3.0.1 → 3.0.2

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: 626e44cb1399fbd5fba62219a1a753b9b084b522d31461ba0a4850955f4924fd
4
- data.tar.gz: 2d9e250daeaea8f70d9f0f90f2176bbb79641a1904004e580b8cc16a32421921
3
+ metadata.gz: 7f9c399ad3c6230d8fc93a298bfe9a37a1b85ff4942995abc517b759690aa284
4
+ data.tar.gz: 6f2b3a9ab5920cdd8192c4a7eda531b58f68dacbc841c8d6c0c8c3d0c6b8a201
5
5
  SHA512:
6
- metadata.gz: 90fb2a2ad6ba9026bbcdb3e783fb8b61dd75f3d9216f5dead8157e8d00d0c197ce2de2251d3d6ab962af0e14f2e3ba16e040057b74e4680eb5f364e813d2358d
7
- data.tar.gz: 12d6c314e04b6ae3ea280e4186df8c47cc51ced61fd95d147d60c3053e5c9ee2e0e39f270b420396f51991356831f7ccc50e943c85530afa5ece3bc91e43c69b
6
+ metadata.gz: e71705e2ea444cf19417e934bf4679105f6e1f90f490a671f407c2c9402a6678b2a4a5325cb9c9de116047b5201f29d60b859a08989bd07e75895c6a47700ed1
7
+ data.tar.gz: 33dedf71445db359b03edfacff9261ce63bc2ea57020d621dad0cf8f594022810a62688d8785a6e4d22013d9fba1fc6f9c21435ec59e05cb4336ae1915e8e86c
data/CHANGELOG.md CHANGED
@@ -2,6 +2,13 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 3.0.2 (2026-11-24)
6
+
7
+ - Require `graphql` `>= 2.6.16` for the optional ActiveAdmin GraphQL operator API
8
+ - Reject non-positive stats purge batch sizes so a bad page size cannot wipe eligible rows
9
+ - Keep request and park outcomes when warning delivery fails after stats or cache cleanup
10
+ - Load runtime catalogue export gates in bulk instead of one query per flag
11
+
5
12
  ## 3.0.1 (2026-11-16)
6
13
 
7
14
  - Ship the ActiveAdmin agent-access guide inside the gem and add a host cutover checklist
data/CONTRIBUTING.md CHANGED
@@ -10,27 +10,6 @@ Never send project secrets or private context to public models.
10
10
 
11
11
  ## How to contribute
12
12
 
13
- ### Local checks and admin preview
14
-
15
- Run `bundle install`, then `make admin-assets` before request specs or a browser
16
- preview. The asset task needs Node.js 20 or newer and npm. It installs the locked
17
- test-only Tailwind tools and builds ActiveAdmin's stylesheet from its installed
18
- plugin plus the ActiveAdmin and Onni templates. Rails serves the generated CSS
19
- and JavaScript from the dummy app's public directory. Rebuild after changing
20
- view classes or updating ActiveAdmin. Generated assets are ignored by git and
21
- are excluded from the gem.
22
-
23
- Run `bundle exec rspec` for the suite and `make lint` for quality checks. CI builds
24
- the same assets before request specs; `make test` includes the asset build.
25
-
26
- System specs use a browser driver under the `:railsfi` name (Rails
27
- `driven_by :playwright` would replace the registration and float Chromium).
28
- After `make admin-assets`, install browsers once with
29
- `./spec/dummy/node_modules/.bin/playwright-core install chromium` (the dummy app
30
- pins `playwright-core` to the version expected by `playwright-ruby-client`).
31
- When the CLI or Chromium install is missing, system examples skip with that
32
- install hint.
33
-
34
13
  ### Reporting issues
35
14
 
36
15
  Verify the facts before filing. Use issue templates for goals, constraints, and reproduction steps.
data/README.md CHANGED
@@ -148,7 +148,7 @@ policy methods; `Onni.visible?` remains a rollout evaluation.
148
148
 
149
149
  For agent, CLI, MCP-adapter, curl or script clients, opt into
150
150
  `onni/active_admin_graphql` alongside `activeadmin-graphql` (`~> 0.4.1`) and
151
- `graphql` (`>= 2.6.15, < 3`) plus the host's `activeadmin-device_authorization`
151
+ `graphql` (`>= 2.6.16, < 3`) plus the host's `activeadmin-device_authorization`
152
152
  setup. The typed `onni` catalogue query and named mutations reuse the Ruby
153
153
  domain API and host page authorization. Device consent and bearer authentication
154
154
  stay in the host; unauthenticated callers must not receive introspection.
@@ -11,7 +11,7 @@ identity, device consent, token storage, authentication and authorization.
11
11
  # Gemfile
12
12
  gem "activeadmin", "4.0.0.beta23"
13
13
  gem "activeadmin-graphql", "~> 0.4.1"
14
- gem "graphql", ">= 2.6.15", "< 3"
14
+ gem "graphql", ">= 2.6.16", "< 3"
15
15
  gem "activeadmin-device_authorization", "~> 0.2.0"
16
16
  gem "onni", require: "onni/active_admin_graphql"
17
17
  ```
@@ -58,7 +58,7 @@ not register raw feature, gate or stat tables as editable resources.
58
58
  Complete these before treating missing GraphQL fields as an Onni bug.
59
59
 
60
60
  1. Gemfile floors match activation. Load `onni/active_admin_graphql` only with
61
- `activeadmin-graphql >= 0.4.1, < 0.5` and `graphql >= 2.6.15, < 3` declared in
61
+ `activeadmin-graphql >= 0.4.1, < 0.5` and `graphql >= 2.6.16, < 3` declared in
62
62
  the host Gemfile, then update the lock for those gems. The loader activates
63
63
  the same floors; an older locked `graphql` can leave two trees under
64
64
  `vendor/bundle` while Bundler still reports the stale pin.
@@ -2,7 +2,7 @@
2
2
 
3
3
  require "onni/active_admin"
4
4
  gem "activeadmin-graphql", ">= 0.4.1", "< 0.5"
5
- gem "graphql", ">= 2.6.15", "< 3"
5
+ gem "graphql", ">= 2.6.16", "< 3"
6
6
  require "activeadmin/graphql"
7
7
  require "onni/admin/graphql/access"
8
8
  require "onni/admin/graphql/field"
@@ -33,15 +33,17 @@ module Onni
33
33
  end
34
34
 
35
35
  def gates_for(key)
36
- ::Onni::Gate.where(feature_key: key.to_s).map { |gate| {"key" => gate.key, "value" => gate.value} }
36
+ ::Onni::Gate.where(feature_key: key.to_s).pluck(:key, :value).map do |gate_key, value|
37
+ {"key" => gate_key, "value" => value}
38
+ end
37
39
  end
38
40
 
39
41
  def gates_for_many(keys)
40
- keys = keys.map(&:to_s)
41
- grouped = ::Onni::Gate.where(feature_key: keys).group_by(&:feature_key)
42
- keys.each_with_object({}) do |key, loaded|
43
- loaded[key] = Array(grouped[key]).map { |gate| {"key" => gate.key, "value" => gate.value} }
42
+ loaded = keys.to_h { |key| [key.to_s, []] }
43
+ ::Onni::Gate.where(feature_key: loaded.keys).pluck(:feature_key, :key, :value).each do |feature_key, gate_key, value|
44
+ loaded.fetch(feature_key) << {"key" => gate_key, "value" => value}
44
45
  end
46
+ loaded
45
47
  end
46
48
 
47
49
  def replace_gates(key, gates)
@@ -76,12 +78,12 @@ module Onni
76
78
 
77
79
  def stats_for(key, period: "hour", from: 24.hours.ago, to: Time.current)
78
80
  ::Onni::StatBucket.where(feature_key: key.to_s, period: period, period_start: from..to)
79
- .order(:period_start).map do |bucket|
81
+ .order(:period_start).pluck(:period_start, :period, :shown_count, :skip_count).map do |starts_at, stored_period, shown, skipped|
80
82
  {
81
- "period_start" => bucket.period_start,
82
- "period" => bucket.period,
83
- "shown_count" => bucket.shown_count,
84
- "skip_count" => bucket.skip_count
83
+ "period_start" => starts_at,
84
+ "period" => stored_period,
85
+ "shown_count" => shown,
86
+ "skip_count" => skipped
85
87
  }
86
88
  end
87
89
  end
@@ -26,57 +26,49 @@ module Onni
26
26
  def stats_for(key, period: "hour", from: Time.now - 86_400, to: Time.now)
27
27
  return [] unless period == "hour"
28
28
 
29
+ requested_key = key.to_s
30
+ hours = epoch_hours(from).ceil..epoch_hours(to).floor
29
31
  @lock.synchronize do
30
- @stats.filter_map do |bucket_key, counts|
31
- feature_key, hour = bucket_key
32
- next unless feature_key == key.to_s
33
-
34
- started = Time.at(hour * 3600).utc
35
- next unless started.between?(from, to)
36
-
37
- {
38
- "period_start" => started,
39
- "period" => period,
40
- "shown_count" => counts[:shown_count],
41
- "skip_count" => counts[:skip_count]
42
- }
32
+ @stats.filter_map do |(feature_key, hour), counts|
33
+ stat_row(hour, period, counts) if feature_key == requested_key && hours.cover?(hour)
43
34
  end
44
35
  end.sort_by { |bucket| bucket.fetch("period_start") }
45
36
  end
46
37
 
47
38
  def purge_stats_batch(older_than:, batch_size:, after_id: 0)
39
+ cutoff_hour = epoch_hours(older_than).ceil
48
40
  @lock.synchronize do
49
- matching = older_stat_keys(older_than)
50
- slice = matching.first(batch_size)
51
- slice.each { |bucket_key| @stats.delete(bucket_key) }
52
- return {deleted: 0, last_id: nil} if slice.empty?
41
+ expired = @stats.each_key.lazy.select { |key| key.last < cutoff_hour }.first(batch_size)
42
+ expired.each { |bucket_key| @stats.delete(bucket_key) }
43
+ return {deleted: 0, last_id: nil} if expired.empty?
53
44
 
54
- {deleted: slice.size, last_id: (slice.size == batch_size) ? (after_id + slice.size) : nil}
45
+ {deleted: expired.size, last_id: (expired.size == batch_size) ? (after_id + expired.size) : nil}
55
46
  end
56
47
  end
57
48
 
58
49
  def stats_overview
59
50
  @lock.synchronize do
60
- starts = @stats.keys.filter_map { |bucket_key|
61
- _feature_key, hour = bucket_key
62
- Time.at(hour * 3600).utc
63
- }
51
+ oldest = @stats.each_key.min_by(&:last)
64
52
  {
65
53
  bucket_count: @stats.size,
66
- oldest_period_start: starts.min
54
+ oldest_period_start: oldest && Time.at(oldest.last * 3600).utc
67
55
  }
68
56
  end
69
57
  end
70
58
 
71
59
  private
72
60
 
73
- def older_stat_keys(older_than)
74
- @stats.keys.select { |_feature_key, hour| Time.at(hour * 3600).utc < older_than }.sort
61
+ def epoch_hours(time)
62
+ time.to_time.to_r / 3600
63
+ end
64
+
65
+ def stat_row(hour, period, counts)
66
+ {"period_start" => Time.at(hour * 3600).utc, "period" => period,
67
+ "shown_count" => counts[:shown_count], "skip_count" => counts[:skip_count]}
75
68
  end
76
69
 
77
70
  def stat_bucket_key(key)
78
- feature_key = key.is_a?(Symbol) ? key.to_s.freeze : key.to_s.dup.freeze
79
- [feature_key, Time.now.to_i / 3600]
71
+ [-key.to_s, Time.now.to_i / 3600]
80
72
  end
81
73
  end
82
74
  end
@@ -17,7 +17,7 @@ module Onni
17
17
  definitions = Registry.config
18
18
  keys = definitions.keys.sort
19
19
  names, more = page_keys(keys, first, after)
20
- gates = read_many(names)
20
+ gates = Store.gates_for_many(names)
21
21
  {items: names.map { |name| build(name, definitions.fetch(name), gates.fetch(name)) },
22
22
  next_cursor: more ? names.last : nil, total_count: keys.length}
23
23
  end
@@ -28,13 +28,6 @@ module Onni
28
28
  [names.first(first), names.length > first]
29
29
  end
30
30
 
31
- def read_many(names)
32
- adapter = Onni.adapter
33
- return adapter.gates_for_many(names) if adapter.respond_to?(:gates_for_many)
34
-
35
- names.to_h { |name| [name, adapter.gates_for(name)] }
36
- end
37
-
38
31
  def build(name, definition, gates)
39
32
  owner = Sync.synchronize { Delivery.entries[name.to_s] }
40
33
  {name: name.to_s, type: definition["type"], conditions: definition.fetch("conditions", []),
@@ -8,21 +8,22 @@ module Onni
8
8
  format = format.to_s
9
9
  raise ArgumentError, "Catalogue format must be yaml, json or csv" unless %w[yaml json csv].include?(format)
10
10
 
11
- rows = Registry.config.sort.map { |name, definition| row(name, definition, runtime: runtime) }
11
+ definitions = Registry.config
12
+ gates = Store.gates_for_many(definitions.keys) if runtime
13
+ rows = definitions.sort.map { |name, definition| row(name, definition, gates: gates&.fetch(name)) }
12
14
  output = encode(rows, format)
13
15
  io ? io.write(output) : output
14
16
  end
15
17
 
16
- def row(name, definition, runtime:)
18
+ def row(name, definition, gates:)
17
19
  owner = Sync.synchronize { Delivery.entries[name] }
18
20
  item = {"name" => name, "definition" => definition.except("expires_at_time"),
19
21
  "experiments" => owner ? owner.experiments : {}}
20
- item["runtime"] = snapshot(name, definition, owner) if runtime
22
+ item["runtime"] = snapshot(name, definition, owner, gates) if gates
21
23
  item
22
24
  end
23
25
 
24
- def snapshot(name, definition, owner)
25
- gates = Onni.adapter.gates_for(name)
26
+ def snapshot(name, definition, owner, gates)
26
27
  {"power" => Settings.power_state(gates, definition).to_s,
27
28
  "filters" => Settings.filters(definition, gates).slice(*Registry::Validation::FILTER_KEYS).compact,
28
29
  "variants" => Settings.variants(definition, gates), "stats" => Stats::Policy.settings(definition, gates),
@@ -5,7 +5,9 @@ module Onni
5
5
  attr_reader :filters, :stats
6
6
 
7
7
  def self.wrap(gates)
8
- gates.is_a?(self) ? gates : new(gates)
8
+ return gates if gates.is_a?(self)
9
+
10
+ gates.empty? ? EMPTY : new(gates)
9
11
  end
10
12
 
11
13
  def initialize(gates)
@@ -34,7 +36,8 @@ module Onni
34
36
  end
35
37
 
36
38
  def legacy_list(key)
37
- override = find { |gate| gate["key"] == "#{key}_override" }
39
+ override_key = "#{key}_override"
40
+ override = find { |gate| gate["key"] == override_key }
38
41
  return parse_list(override["value"]) if override
39
42
 
40
43
  values = select { |gate| gate["key"] == key }.map { |gate| gate["value"].dup }
@@ -58,5 +61,8 @@ module Onni
58
61
  rescue JSON::ParserError, ArgumentError
59
62
  {"groups" => []}
60
63
  end
64
+
65
+ EMPTY = new([])
66
+ private_constant :EMPTY
61
67
  end
62
68
  end
@@ -14,5 +14,11 @@ module Onni
14
14
  yield(payload)
15
15
  end
16
16
  end
17
+
18
+ def warn(message)
19
+ Onni.configuration.logger&.warn(message)
20
+ rescue
21
+ nil
22
+ end
17
23
  end
18
24
  end
@@ -13,6 +13,8 @@ module Onni
13
13
  end
14
14
 
15
15
  def initialize(older_than: nil, batch_size: DEFAULT_BATCH_SIZE, after_id: 0, processed_count: 0, enqueue: nil)
16
+ raise ArgumentError, "batch_size must be a positive integer" unless batch_size.is_a?(Integer) && batch_size.positive?
17
+
16
18
  @older_than = older_than
17
19
  @batch_size = batch_size
18
20
  @after_id = after_id
data/lib/onni/stats.rb CHANGED
@@ -27,7 +27,7 @@ module Onni
27
27
  end
28
28
  end
29
29
  rescue => error
30
- Onni.configuration.logger&.warn("Onni stats failed: #{error.class}: #{error.message}")
30
+ Instrumenter.warn("Onni stats failed: #{error.class}: #{error.message}")
31
31
  end
32
32
 
33
33
  def for(name, period: "hour", from: Time.now - 86_400, to: Time.now)
data/lib/onni/store.rb CHANGED
@@ -88,6 +88,13 @@ module Onni
88
88
  RequestStore.gates_context = context
89
89
  end
90
90
 
91
+ def gates_for_many(keys)
92
+ adapter = Onni.adapter
93
+ return adapter.gates_for_many(keys) if adapter.respond_to?(:gates_for_many)
94
+
95
+ keys.to_h { |key| [key, adapter.gates_for(key)] }
96
+ end
97
+
91
98
  def gate_read_context
92
99
  adapter = Onni.adapter
93
100
  adapter.respond_to?(:gate_read_context) ? adapter.gate_read_context : adapter
@@ -109,7 +116,7 @@ module Onni
109
116
  begin
110
117
  cache.delete(old_key)
111
118
  rescue => error
112
- Onni.configuration.logger&.warn("Onni cache cleanup failed: #{error.class}")
119
+ Instrumenter.warn("Onni cache cleanup failed: #{error.class}")
113
120
  end
114
121
  end
115
122
  RequestStore.gates&.delete(key)
data/lib/onni/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Onni
4
- VERSION = "3.0.1"
4
+ VERSION = "3.0.2"
5
5
  end
data/lib/onni.rb CHANGED
@@ -143,12 +143,7 @@ module Onni
143
143
  def preload!(*names)
144
144
  keys = names.flatten.map!(&:to_s)
145
145
  keys = Registry.config.keys.map(&:to_s) if keys.empty?
146
- loaded =
147
- if adapter.respond_to?(:gates_for_many)
148
- adapter.gates_for_many(keys)
149
- else
150
- keys.each_with_object({}) { |key, hash| hash[key] = adapter.gates_for(key) }
151
- end
146
+ loaded = Store.gates_for_many(keys)
152
147
  loaded.transform_values! { |gates| GateSnapshot.wrap(gates) }
153
148
  Store.store_preloaded!(loaded)
154
149
  loaded.size
@@ -161,7 +156,7 @@ module Onni
161
156
  def reset_request!
162
157
  Stats::Buffer.flush!
163
158
  rescue => error
164
- configuration.logger&.warn("Onni stats flush failed: #{error.class}")
159
+ Instrumenter.warn("Onni stats flush failed: #{error.class}")
165
160
  ensure
166
161
  RequestStore.clear!
167
162
  end
data/onni.gemspec CHANGED
@@ -58,10 +58,10 @@ Gem::Specification.new do |spec|
58
58
  spec.add_development_dependency "bundler-audit", "~> 0.9"
59
59
  spec.add_development_dependency "capybara", "~> 3.40"
60
60
  spec.add_development_dependency "capybara-playwright-driver", "~> 0.5"
61
- spec.add_development_dependency "graphql", ">= 2.6.15", "< 3"
61
+ spec.add_development_dependency "graphql", ">= 2.6.16", "< 3"
62
62
  spec.add_development_dependency "importmap-rails"
63
63
  spec.add_development_dependency "polyrun", ">= 3.0.0"
64
- spec.add_development_dependency "puma", ">= 5.0"
64
+ spec.add_development_dependency "puma", ">= 8.1.2"
65
65
  spec.add_development_dependency "rails", ">= 7.2.3.2"
66
66
  spec.add_development_dependency "rake", "~> 13"
67
67
  spec.add_development_dependency "rbs", "~> 4"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onni
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.1
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrei Makarov
@@ -133,7 +133,7 @@ dependencies:
133
133
  requirements:
134
134
  - - ">="
135
135
  - !ruby/object:Gem::Version
136
- version: 2.6.15
136
+ version: 2.6.16
137
137
  - - "<"
138
138
  - !ruby/object:Gem::Version
139
139
  version: '3'
@@ -143,7 +143,7 @@ dependencies:
143
143
  requirements:
144
144
  - - ">="
145
145
  - !ruby/object:Gem::Version
146
- version: 2.6.15
146
+ version: 2.6.16
147
147
  - - "<"
148
148
  - !ruby/object:Gem::Version
149
149
  version: '3'
@@ -181,14 +181,14 @@ dependencies:
181
181
  requirements:
182
182
  - - ">="
183
183
  - !ruby/object:Gem::Version
184
- version: '5.0'
184
+ version: 8.1.2
185
185
  type: :development
186
186
  prerelease: false
187
187
  version_requirements: !ruby/object:Gem::Requirement
188
188
  requirements:
189
189
  - - ">="
190
190
  - !ruby/object:Gem::Version
191
- version: '5.0'
191
+ version: 8.1.2
192
192
  - !ruby/object:Gem::Dependency
193
193
  name: rails
194
194
  requirement: !ruby/object:Gem::Requirement