standard_flags 0.1.0 → 0.2.0

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 (71) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +229 -0
  3. data/README.md +837 -33
  4. data/lib/generators/standard_flags/admin/admin_generator.rb +115 -0
  5. data/lib/generators/standard_flags/admin/templates/controller.rb.tt +103 -0
  6. data/lib/generators/standard_flags/admin/templates/index.tsx.tt +64 -0
  7. data/lib/generators/standard_flags/admin/templates/show.tsx.tt +275 -0
  8. data/lib/generators/standard_flags/install/install_generator.rb +16 -1
  9. data/lib/generators/standard_flags/install/templates/flags.rb.tt +3 -2
  10. data/lib/generators/standard_flags/install/templates/initializer.rb.tt +10 -0
  11. data/lib/generators/standard_flags/migrations/migrations_generator.rb +57 -0
  12. data/lib/generators/standard_flags/migrations/templates/create_standard_flags_tables.rb.tt +78 -0
  13. data/lib/standard_flags/actor.rb +50 -0
  14. data/lib/standard_flags/audit_trail.rb +56 -0
  15. data/lib/standard_flags/config.rb +78 -0
  16. data/lib/standard_flags/context.rb +5 -1
  17. data/lib/standard_flags/definition.rb +85 -13
  18. data/lib/standard_flags/diagnostics.rb +35 -3
  19. data/lib/standard_flags/engine.rb +10 -2
  20. data/lib/standard_flags/env_pin.rb +15 -4
  21. data/lib/standard_flags/errors.rb +4 -0
  22. data/lib/standard_flags/evaluation.rb +5 -4
  23. data/lib/standard_flags/evaluator.rb +14 -1
  24. data/lib/standard_flags/events.rb +49 -0
  25. data/lib/standard_flags/health_check.rb +12 -2
  26. data/lib/standard_flags/health_contribution.rb +65 -0
  27. data/lib/standard_flags/mcp/cohorts.rb +65 -0
  28. data/lib/standard_flags/mcp/flags.rb +143 -0
  29. data/lib/standard_flags/mcp/members.rb +154 -0
  30. data/lib/standard_flags/mcp/writes.rb +98 -0
  31. data/lib/standard_flags/mcp.rb +238 -0
  32. data/lib/standard_flags/memo.rb +15 -1
  33. data/lib/standard_flags/notifiers/logger.rb +14 -0
  34. data/lib/standard_flags/open_feature/provider.rb +232 -0
  35. data/lib/standard_flags/open_feature.rb +26 -0
  36. data/lib/standard_flags/operations/audit.rb +218 -0
  37. data/lib/standard_flags/operations/base.rb +290 -0
  38. data/lib/standard_flags/operations/cohorts.rb +80 -0
  39. data/lib/standard_flags/operations/failure.rb +16 -0
  40. data/lib/standard_flags/operations/members.rb +164 -0
  41. data/lib/standard_flags/operations/restore.rb +330 -0
  42. data/lib/standard_flags/operations/restore_target.rb +197 -0
  43. data/lib/standard_flags/operations/rules.rb +233 -0
  44. data/lib/standard_flags/operations/validation.rb +154 -0
  45. data/lib/standard_flags/operations.rb +43 -0
  46. data/lib/standard_flags/parser.rb +16 -0
  47. data/lib/standard_flags/purge_job.rb +14 -0
  48. data/lib/standard_flags/registry.rb +38 -5
  49. data/lib/standard_flags/reporting.rb +51 -7
  50. data/lib/standard_flags/resolvers.rb +14 -7
  51. data/lib/standard_flags/result.rb +43 -0
  52. data/lib/standard_flags/rspec.rb +67 -13
  53. data/lib/standard_flags/runtime/active_record_store.rb +428 -0
  54. data/lib/standard_flags/runtime/cache.rb +98 -0
  55. data/lib/standard_flags/runtime/evaluation_tracker.rb +93 -0
  56. data/lib/standard_flags/runtime/memory_store.rb +408 -0
  57. data/lib/standard_flags/runtime/models.rb +43 -0
  58. data/lib/standard_flags/runtime/resolver.rb +256 -0
  59. data/lib/standard_flags/runtime/rule_snapshot.rb +60 -0
  60. data/lib/standard_flags/runtime/store.rb +161 -0
  61. data/lib/standard_flags/runtime/values.rb +181 -0
  62. data/lib/standard_flags/runtime.rb +266 -0
  63. data/lib/standard_flags/sensor.rb +12 -5
  64. data/lib/standard_flags/subscribers.rb +6 -0
  65. data/lib/standard_flags/testing.rb +100 -1
  66. data/lib/standard_flags/tooling/changes.rb +196 -0
  67. data/lib/standard_flags/tooling.rb +232 -19
  68. data/lib/standard_flags/version.rb +1 -1
  69. data/lib/standard_flags.rb +33 -5
  70. data/lib/tasks/standard_flags.rake +45 -1
  71. metadata +41 -1
@@ -2,32 +2,43 @@ require "date"
2
2
  require "json"
3
3
  require "pathname"
4
4
  require "active_support/core_ext/string/inflections"
5
+ require "standard_flags/tooling/changes"
5
6
 
6
7
  module StandardFlags
7
8
  # The logic behind the rake tasks, kept out of the rake file so it can be
8
9
  # tested without booting an app.
9
10
  module Tooling
10
11
  # `flags:list`: every flag, its value here, and where the value came from.
11
- # A permanent flag shows `permanent` in the remove_by column.
12
+ # A permanent flag shows `permanent` in the remove_by column. With
13
+ # runtime rules on, a `rule` column shows each flag's rule status, and a
14
+ # header line the snapshot's revision and age.
12
15
  class List
13
16
  HEADERS = %w[key kind value reason env_var remove_by].freeze
17
+ RUNTIME_HEADERS = (HEADERS + %w[rule]).freeze
14
18
 
15
19
  def initialize(registry: StandardFlags.registry)
16
20
  @registry = registry
17
21
  end
18
22
 
23
+ def headers
24
+ Runtime.enabled? ? RUNTIME_HEADERS : HEADERS
25
+ end
26
+
19
27
  def rows
28
+ runtime = Runtime.enabled?
20
29
  @registry.definitions.sort_by(&:key).map do |definition|
21
30
  evaluation = Evaluator.evaluate(@registry, definition.key, Context.empty)
22
- [ definition.key.to_s, definition.kind.to_s, evaluation.value.to_s, evaluation.reason,
23
- evaluation.source_env_var || "-", lifecycle(definition) ]
31
+ row = [ definition.key.to_s, definition.kind.to_s, evaluation.value.to_s, evaluation.reason,
32
+ evaluation.source_env_var || "-", lifecycle(definition) ]
33
+ runtime ? row << (Runtime.snapshot.rule(definition.key)&.status || "-") : row
24
34
  end
25
35
  end
26
36
 
27
37
  def render
28
- table = [ HEADERS ] + rows
29
- widths = HEADERS.each_index.map { |i| table.map { |row| row[i].length }.max }
30
- table.map { |row| row.each_with_index.map { |cell, i| cell.ljust(widths[i]) }.join(" ").rstrip }.join("\n")
38
+ table = [ headers ] + rows
39
+ widths = headers.each_index.map { |i| table.map { |row| row[i].length }.max }
40
+ lines = table.map { |row| row.each_with_index.map { |cell, i| cell.ljust(widths[i]) }.join(" ").rstrip }
41
+ ([ runtime_line ].compact + lines).join("\n")
31
42
  end
32
43
 
33
44
  private
@@ -37,15 +48,37 @@ module StandardFlags
37
48
 
38
49
  definition.remove_by&.iso8601 || "-"
39
50
  end
51
+
52
+ def runtime_line
53
+ return unless Runtime.enabled?
54
+
55
+ snapshot = Runtime.snapshot
56
+ return "runtime rules: not loaded (serving code defaults)" unless snapshot.loaded
57
+
58
+ orphans = snapshot.rules.keys.reject { |key| @registry.key?(key) }
59
+ line = "runtime rules: revision #{snapshot.revision}, #{snapshot.age}s old#{', stale' if snapshot.stale}"
60
+ orphans.empty? ? line : "#{line}; rules for undeclared keys: #{orphans.sort.join(', ')}"
61
+ end
40
62
  end
41
63
 
42
- # `flags:stale`: flags past their remove_by date. Each one's `final:`
43
- # value says which branch to keep when deleting it. Permanent flags have
44
- # no remove_by date, so they never appear.
64
+ # `flags:stale`: flags and modes past their remove_by date. Each one's
65
+ # `final:` value says which branch to keep when deleting it. Permanent
66
+ # flags have no remove_by date, so they never appear.
67
+ #
68
+ # With runtime rules on it also lists rules worth cleaning up: at 100%
69
+ # or stopped for 30 days or more, not evaluated in 14 days (when
70
+ # `config.track_evaluations` is on), and rules for undeclared or
71
+ # tombstoned keys; and memberships past `config.membership_retention`
72
+ # that `flags:purge` would delete.
45
73
  class Stale
46
- def initialize(registry: StandardFlags.registry, today: Date.today)
74
+ SETTLED_AFTER = 30 * 86_400
75
+ UNUSED_AFTER = 14 * 86_400
76
+
77
+ def initialize(registry: StandardFlags.registry, today: Date.today, now: Time.now.utc, store: nil)
47
78
  @registry = registry
48
79
  @today = today
80
+ @now = now
81
+ @store = store
49
82
  end
50
83
 
51
84
  def definitions
@@ -54,13 +87,67 @@ module StandardFlags
54
87
 
55
88
  def render
56
89
  stale = definitions
57
- return "No flags are past their remove_by date." if stale.empty?
90
+ lines =
91
+ if stale.empty?
92
+ [ "No flags are past their remove_by date." ]
93
+ else
94
+ stale.map do |definition|
95
+ final = definition.final.nil? ? "" : ", final: #{definition.final.inspect}"
96
+ "#{definition.key} (#{definition.kind}, owner: #{definition.owner}) " \
97
+ "was due for removal on #{definition.remove_by.iso8601}#{final}"
98
+ end
99
+ end
100
+ lines.concat(runtime_lines) if Runtime.enabled?
101
+ lines.join("\n")
102
+ end
103
+
104
+ # Findings about stored rules and memberships, one String each.
105
+ def runtime_findings
106
+ loaded = store.load
107
+ findings = loaded.rules.sort_by(&:key).flat_map { |rule| rule_findings(rule) }
108
+ due = store.purgeable(before: @now - StandardFlags.config.membership_retention)
109
+ unless (due[:removed] + due[:expired]).zero?
110
+ findings << "#{due[:removed]} removed and #{due[:expired]} expired memberships are past retention; run flags:purge"
111
+ end
112
+ findings
113
+ end
114
+
115
+ private
116
+
117
+ def store
118
+ @store || Runtime.store
119
+ end
120
+
121
+ def runtime_lines
122
+ findings = runtime_findings
123
+ findings.empty? ? [ "No stale runtime rules." ] : findings
124
+ rescue StandardError => e
125
+ [ "runtime rules: could not read the store (#{(e.cause_class if e.is_a?(Runtime::StoreError)) || e.class})" ]
126
+ end
127
+
128
+ def rule_findings(rule)
129
+ findings = []
130
+ if @registry.tombstoned?(rule.key)
131
+ findings << "rule :#{rule.key} is for a tombstoned flag"
132
+ elsif !@registry.key?(rule.key)
133
+ findings << "rule :#{rule.key} is for an undeclared flag"
134
+ end
135
+ if rule.percentage_bps == Bucket::BUCKETS && rule.full_since && rule.full_since <= @now - SETTLED_AFTER
136
+ findings << "rule :#{rule.key} has served 100% since #{day(rule.full_since)}; remove the flag or Stop it"
137
+ end
138
+ if rule.stopped? && rule.updated_at && rule.updated_at <= @now - SETTLED_AFTER
139
+ findings << "rule :#{rule.key} has been stopped since #{day(rule.updated_at)}; remove the flag"
140
+ end
141
+ last = rule.last_evaluated_at || rule.updated_at
142
+ if StandardFlags.config.track_evaluations && last && last <= @now - UNUSED_AFTER
143
+ seen = rule.last_evaluated_at ? "since #{day(last)}" : "since it changed on #{day(last)}"
144
+ findings << "rule :#{rule.key} has not been evaluated #{seen}"
145
+ end
146
+ findings
147
+ end
58
148
 
59
- stale.map do |definition|
60
- final = definition.final.nil? ? "" : ", final: #{definition.final.inspect}"
61
- "#{definition.key} (#{definition.kind}, owner: #{definition.owner}) " \
62
- "was due for removal on #{definition.remove_by.iso8601}#{final}"
63
- end.join("\n")
149
+ def day(time)
150
+ time.utc.to_date.iso8601
64
151
  end
65
152
  end
66
153
 
@@ -129,9 +216,10 @@ module StandardFlags
129
216
 
130
217
  # `standard_flags:manifest`: a deterministic description of the flag set
131
218
  # (keys, wire names, kinds, values, audiences, defaults) for client CI.
132
- # Entries of kind `flag` also say whether the flag is permanent.
219
+ # Entries of kind `flag` and `mode` also say whether they are permanent.
133
220
  class Manifest
134
221
  VERSION = 1
222
+ LIFECYCLE_KINDS = %i[flag mode].freeze
135
223
 
136
224
  def initialize(registry: StandardFlags.registry)
137
225
  @registry = registry
@@ -162,7 +250,7 @@ module StandardFlags
162
250
  "default" => default(definition),
163
251
  "audiences" => definition.expose.sort.to_h { |audience, name| [ audience.to_s, name ] }
164
252
  }
165
- entry["permanent"] = definition.permanent? if definition.kind == :flag
253
+ entry["permanent"] = definition.permanent? if LIFECYCLE_KINDS.include?(definition.kind)
166
254
  entry
167
255
  end
168
256
 
@@ -180,10 +268,120 @@ module StandardFlags
180
268
  end
181
269
 
182
270
  # `standard_flags:typescript`: a `.d.ts` with one Features interface per
183
- # audience, keyed by wire name.
271
+ # audience, keyed by wire name; every flag key and its stored values; and
272
+ # the shapes of StandardFlags::MCP's results, which the admin pages
273
+ # (`standard_flags:admin`) are typed from.
184
274
  class TypeScript
185
275
  IDENTIFIER = /\A[A-Za-z_$][A-Za-z0-9_$]*\z/
186
276
 
277
+ # The JSON StandardFlags::MCP returns (and the admin controller passes
278
+ # as props). Static: the flag-specific parts are FlagKey and FlagValues.
279
+ MCP_TYPES = <<~TS.freeze
280
+ // Results of StandardFlags::MCP tools: the admin page props.
281
+ export type FlagKind = "flag" | "kill_switch" | "mode" | "experiment" | "compat";
282
+ export type RuleStatus = "draft" | "running" | "paused" | "stopped";
283
+
284
+ export interface FlagPin {
285
+ readonly env_var: string;
286
+ readonly label: string;
287
+ }
288
+
289
+ export interface FlagRuleSummary {
290
+ readonly status: RuleStatus;
291
+ readonly revision: number;
292
+ readonly percentage_bps: number | null;
293
+ readonly member_count: number;
294
+ }
295
+
296
+ export interface FlagRule {
297
+ readonly status: RuleStatus;
298
+ readonly revision: number;
299
+ readonly hash_version: number;
300
+ readonly percentage_bps: number | null;
301
+ readonly rollout_value: string | null;
302
+ readonly variant_weights: Readonly<Record<string, number>>;
303
+ readonly fallthrough_value: string | null;
304
+ readonly stop_value: string | null;
305
+ readonly conditions: Readonly<Record<string, unknown>>;
306
+ readonly cohorts: ReadonlyArray<{ readonly cohort: string; readonly value: string }>;
307
+ readonly hidden_cohorts: number;
308
+ readonly member_count: number;
309
+ readonly full_since: string | null;
310
+ readonly last_evaluated_at: string | null;
311
+ }
312
+
313
+ export interface FlagSummary {
314
+ readonly key: FlagKey;
315
+ readonly kind: FlagKind;
316
+ readonly owner: string | null;
317
+ readonly description: string | null;
318
+ readonly unit: string | null;
319
+ readonly values: ReadonlyArray<string>;
320
+ readonly value: string | null;
321
+ readonly reason: string;
322
+ readonly source: string;
323
+ readonly pinned: FlagPin | null;
324
+ readonly rule: FlagRuleSummary | null;
325
+ }
326
+
327
+ export interface FlagList {
328
+ readonly flags: ReadonlyArray<FlagSummary>;
329
+ readonly runtime_rules: boolean;
330
+ readonly store_revision: number | null;
331
+ }
332
+
333
+ export interface FlagEvaluation {
334
+ readonly unit_key: string | null;
335
+ readonly value: string | null;
336
+ readonly variant: string | null;
337
+ readonly reason: string;
338
+ readonly error_code: string | null;
339
+ readonly rule_id: string | null;
340
+ readonly source: string;
341
+ }
342
+
343
+ export interface FlagDetail {
344
+ readonly key: FlagKey;
345
+ readonly kind: FlagKind;
346
+ readonly owner: string | null;
347
+ readonly description: string | null;
348
+ readonly unit: string | null;
349
+ readonly values: ReadonlyArray<string>;
350
+ readonly default: string | null;
351
+ readonly evaluation: FlagEvaluation;
352
+ readonly pinned: FlagPin | null;
353
+ readonly runtime_rules: boolean;
354
+ readonly rule: FlagRule | null;
355
+ readonly store_revision: number | null;
356
+ }
357
+
358
+ export interface FlagMember {
359
+ readonly unit: string;
360
+ readonly unit_key: string;
361
+ readonly value: string;
362
+ readonly expires_at: string | null;
363
+ readonly expired: boolean;
364
+ readonly added_at: string | null;
365
+ }
366
+
367
+ export interface FlagMemberPage {
368
+ readonly total: number;
369
+ readonly offset: number;
370
+ readonly limit: number;
371
+ readonly next_offset: number | null;
372
+ readonly revealed: boolean;
373
+ readonly members: ReadonlyArray<FlagMember>;
374
+ }
375
+
376
+ export interface FlagAuditEntry {
377
+ readonly event: string;
378
+ readonly occurred_at: string | null;
379
+ readonly actor: string | null;
380
+ readonly reason: string | null;
381
+ readonly revision: number | null;
382
+ }
383
+ TS
384
+
187
385
  def initialize(registry: StandardFlags.registry)
188
386
  @registry = registry
189
387
  end
@@ -201,11 +399,26 @@ module StandardFlags
201
399
  out << "export type FeaturesByAudience = {"
202
400
  audiences.each { |audience| out << " #{property(audience.to_s)}: #{interface_name(audience)};" }
203
401
  out << "};" << ""
402
+ out.concat(flag_types)
403
+ out << MCP_TYPES
204
404
  out.join("\n")
205
405
  end
206
406
 
207
407
  private
208
408
 
409
+ # FlagKey (every declared key) and FlagValues (each flag's stored
410
+ # values: "on"/"off", mode values, variants).
411
+ def flag_types
412
+ definitions = @registry.definitions.sort_by(&:key)
413
+ keys = definitions.map { |definition| definition.key.to_s.to_json }
414
+ out = [ "export type FlagKey = #{keys.empty? ? 'never' : keys.join(' | ')};", "", "export type FlagValues = {" ]
415
+ definitions.each do |definition|
416
+ values = definition.allowed_values.map { |value| Runtime.wire(value).to_json }.join(" | ")
417
+ out << " readonly #{property(definition.key.to_s)}: #{values};"
418
+ end
419
+ out << "};" << ""
420
+ end
421
+
209
422
  def interface_name(audience)
210
423
  "#{audience.to_s.camelize}Features"
211
424
  end
@@ -1,3 +1,3 @@
1
1
  module StandardFlags
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -3,6 +3,9 @@ require "active_support/core_ext/object/blank"
3
3
 
4
4
  require "standard_flags/version"
5
5
  require "standard_flags/errors"
6
+ require "standard_flags/result"
7
+ require "standard_flags/actor"
8
+ require "standard_flags/events"
6
9
  require "standard_flags/reason"
7
10
  require "standard_flags/evaluation"
8
11
  require "standard_flags/mode"
@@ -14,27 +17,37 @@ require "standard_flags/reporting"
14
17
  require "standard_flags/parser"
15
18
  require "standard_flags/env_pin"
16
19
  require "standard_flags/testing"
20
+ require "standard_flags/bucket"
21
+ require "standard_flags/runtime"
17
22
  require "standard_flags/resolvers"
18
23
  require "standard_flags/evaluator"
19
24
  require "standard_flags/reader"
20
25
  require "standard_flags/snapshot"
21
26
  require "standard_flags/sensor"
22
27
  require "standard_flags/payload"
23
- require "standard_flags/bucket"
24
28
  require "standard_flags/config"
25
29
  require "standard_flags/notifiers/logger"
26
30
  require "standard_flags/notifiers/sentry"
27
31
  require "standard_flags/notifiers/metrics"
28
32
  require "standard_flags/subscribers"
29
33
  require "standard_flags/diagnostics"
34
+ require "standard_flags/audit_trail"
35
+ require "standard_flags/operations"
36
+ require "standard_flags/mcp"
30
37
  require "standard_flags/tooling"
38
+ require "standard_flags/health_contribution"
31
39
  require "standard_flags/engine" if defined?(::Rails::Engine)
32
40
 
41
+ # standard_health 0.9+ registers this check by default and lists forbidden
42
+ # pins on /diagnostics/env. Runs at require time, before app initializers.
43
+ ActiveSupport.on_load(:standard_health, &StandardFlags::HealthContribution::HOOK)
44
+
33
45
  module StandardFlags
34
- # Loaded on first reference: they need actionpack, activejob and
35
- # standard_health respectively, which the host brings.
46
+ # Loaded on first reference: they need actionpack, activejob (Job and
47
+ # PurgeJob) and standard_health respectively, which the host brings.
36
48
  autoload :Controller, "standard_flags/controller"
37
49
  autoload :Job, "standard_flags/job"
50
+ autoload :PurgeJob, "standard_flags/purge_job"
38
51
  autoload :HealthCheck, "standard_flags/health_check"
39
52
 
40
53
  class << self
@@ -45,6 +58,7 @@ module StandardFlags
45
58
  builder.instance_eval(&block)
46
59
  @registry = builder.build
47
60
  Memo.clear!
61
+ HealthContribution.refresh!(@registry)
48
62
  @registry
49
63
  end
50
64
 
@@ -80,6 +94,7 @@ module StandardFlags
80
94
  subscribers.teardown!
81
95
  @registry = nil
82
96
  @config = nil
97
+ Runtime.reset!
83
98
  Testing.reset!
84
99
  end
85
100
 
@@ -117,16 +132,29 @@ module StandardFlags
117
132
  Snapshot.build(registry, Context.wrap(binding.local_variable_get(:for)))
118
133
  end
119
134
 
120
- def sensor(key, for: nil, &block)
135
+ def sensor(key, for: nil, report: true, &block)
121
136
  raise ArgumentError, "sensor needs a block" unless block
122
137
 
123
- Sensor.run(reader(for: binding.local_variable_get(:for)), key, &block)
138
+ Sensor.run(reader(for: binding.local_variable_get(:for)), key, report: report, &block)
124
139
  end
125
140
 
126
141
  def payload(audience, for: nil)
127
142
  Payload.build(registry, audience, Context.wrap(binding.local_variable_get(:for)))
128
143
  end
129
144
 
145
+ # Reads the runtime memberships of many units in one query and memoises
146
+ # them for the current unit of work, so evaluating a flag for each record
147
+ # in a loop doesn't run a query per record:
148
+ #
149
+ # StandardFlags.preload(:organization, organizations)
150
+ # organizations.each { |org| StandardFlags.on?(:new_checkout, for: { organization: org }) }
151
+ #
152
+ # Takes records or keys. A no-op unless runtime rules are on and a unit
153
+ # of work (request, job, executor block) is open.
154
+ def preload(unit, records_or_keys)
155
+ Runtime.preload(unit, records_or_keys)
156
+ end
157
+
130
158
  def payload_digest(audience, for: nil)
131
159
  Payload.digest(payload(audience, for: binding.local_variable_get(:for)))
132
160
  end
@@ -4,11 +4,55 @@ namespace :flags do
4
4
  puts StandardFlags::Tooling::List.new.render
5
5
  end
6
6
 
7
- desc "List flags past their remove_by date"
7
+ desc "List flags past their remove_by date, and stale runtime rules and memberships"
8
8
  task stale: :environment do
9
9
  puts StandardFlags::Tooling::Stale.new.render
10
10
  end
11
11
 
12
+ desc "Show one flag (KEY=), or a cohort (KEY=cohort:<key>): declaration, value, pin and stored rule"
13
+ task show: :environment do
14
+ key = ENV["KEY"].to_s.strip
15
+ abort "flags:show: KEY= is required" if key.empty?
16
+ puts StandardFlags::Tooling::Show.new(key).render
17
+ end
18
+
19
+ # Break-glass changes from a console. Each needs REASON= (it is written to
20
+ # the audit log), runs as StandardFlags::Actor.system("rake"), and prints
21
+ # the outcome and the new revision. Pinned flags are refused.
22
+ run_change = lambda do |task|
23
+ outcome = StandardFlags::Tooling::Command.new(ENV).run(task)
24
+ outcome.ok? ? puts(outcome.message) : abort(outcome.message)
25
+ end
26
+
27
+ desc "Set a flag's fallthrough value: KEY= VALUE= REASON="
28
+ task(set: :environment) { run_change.call(:set) }
29
+
30
+ desc "Ramp a flag's percentage: KEY= BPS= (0-10000) [VALUE=] REASON="
31
+ task(ramp: :environment) { run_change.call(:ramp) }
32
+
33
+ desc "Start a draft or paused rule: KEY= REASON="
34
+ task(start: :environment) { run_change.call(:start) }
35
+
36
+ desc "Pause a running rule (the code default serves): KEY= REASON="
37
+ task(pause: :environment) { run_change.call(:pause) }
38
+
39
+ desc "Stop a rule, serving one value to everyone: KEY= SERVE= REASON="
40
+ task(stop: :environment) { run_change.call(:stop) }
41
+
42
+ namespace :members do
43
+ desc "Add members to a flag or cohort (KEY=cohort:<key>): KEY= KEYS=a,b [UNIT=] [VALUE=] [EXPIRES_AT=] REASON="
44
+ task(add: :environment) { run_change.call(:members_add) }
45
+
46
+ desc "Remove members from a flag or cohort: KEY= KEYS=a,b [UNIT=] REASON="
47
+ task(remove: :environment) { run_change.call(:members_remove) }
48
+ end
49
+
50
+ desc "Restore rules and memberships as they were at AT (from the audit log): AT= [KEYS=a,b,cohort:x] [APPLY=1] REASON="
51
+ task(restore: :environment) { run_change.call(:restore) }
52
+
53
+ desc "Delete memberships removed or expired longer ago than config.membership_retention: REASON="
54
+ task(purge: :environment) { run_change.call(:purge) }
55
+
12
56
  desc "Check flag references: fail on undeclared keys, warn on unreferenced flags"
13
57
  task refs: :environment do
14
58
  refs = StandardFlags::Tooling::Refs.new(root: Rails.root)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: standard_flags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rarebit One
@@ -90,10 +90,18 @@ files:
90
90
  - LICENSE
91
91
  - README.md
92
92
  - Rakefile
93
+ - lib/generators/standard_flags/admin/admin_generator.rb
94
+ - lib/generators/standard_flags/admin/templates/controller.rb.tt
95
+ - lib/generators/standard_flags/admin/templates/index.tsx.tt
96
+ - lib/generators/standard_flags/admin/templates/show.tsx.tt
93
97
  - lib/generators/standard_flags/install/install_generator.rb
94
98
  - lib/generators/standard_flags/install/templates/flags.rb.tt
95
99
  - lib/generators/standard_flags/install/templates/initializer.rb.tt
100
+ - lib/generators/standard_flags/migrations/migrations_generator.rb
101
+ - lib/generators/standard_flags/migrations/templates/create_standard_flags_tables.rb.tt
96
102
  - lib/standard_flags.rb
103
+ - lib/standard_flags/actor.rb
104
+ - lib/standard_flags/audit_trail.rb
97
105
  - lib/standard_flags/bucket.rb
98
106
  - lib/standard_flags/config.rb
99
107
  - lib/standard_flags/context.rb
@@ -105,26 +113,58 @@ files:
105
113
  - lib/standard_flags/errors.rb
106
114
  - lib/standard_flags/evaluation.rb
107
115
  - lib/standard_flags/evaluator.rb
116
+ - lib/standard_flags/events.rb
108
117
  - lib/standard_flags/health_check.rb
118
+ - lib/standard_flags/health_contribution.rb
109
119
  - lib/standard_flags/job.rb
120
+ - lib/standard_flags/mcp.rb
121
+ - lib/standard_flags/mcp/cohorts.rb
122
+ - lib/standard_flags/mcp/flags.rb
123
+ - lib/standard_flags/mcp/members.rb
124
+ - lib/standard_flags/mcp/writes.rb
110
125
  - lib/standard_flags/memo.rb
111
126
  - lib/standard_flags/mode.rb
112
127
  - lib/standard_flags/notifiers/logger.rb
113
128
  - lib/standard_flags/notifiers/metrics.rb
114
129
  - lib/standard_flags/notifiers/sentry.rb
130
+ - lib/standard_flags/open_feature.rb
131
+ - lib/standard_flags/open_feature/provider.rb
132
+ - lib/standard_flags/operations.rb
133
+ - lib/standard_flags/operations/audit.rb
134
+ - lib/standard_flags/operations/base.rb
135
+ - lib/standard_flags/operations/cohorts.rb
136
+ - lib/standard_flags/operations/failure.rb
137
+ - lib/standard_flags/operations/members.rb
138
+ - lib/standard_flags/operations/restore.rb
139
+ - lib/standard_flags/operations/restore_target.rb
140
+ - lib/standard_flags/operations/rules.rb
141
+ - lib/standard_flags/operations/validation.rb
115
142
  - lib/standard_flags/parser.rb
116
143
  - lib/standard_flags/payload.rb
144
+ - lib/standard_flags/purge_job.rb
117
145
  - lib/standard_flags/reader.rb
118
146
  - lib/standard_flags/reason.rb
119
147
  - lib/standard_flags/registry.rb
120
148
  - lib/standard_flags/reporting.rb
121
149
  - lib/standard_flags/resolvers.rb
150
+ - lib/standard_flags/result.rb
122
151
  - lib/standard_flags/rspec.rb
152
+ - lib/standard_flags/runtime.rb
153
+ - lib/standard_flags/runtime/active_record_store.rb
154
+ - lib/standard_flags/runtime/cache.rb
155
+ - lib/standard_flags/runtime/evaluation_tracker.rb
156
+ - lib/standard_flags/runtime/memory_store.rb
157
+ - lib/standard_flags/runtime/models.rb
158
+ - lib/standard_flags/runtime/resolver.rb
159
+ - lib/standard_flags/runtime/rule_snapshot.rb
160
+ - lib/standard_flags/runtime/store.rb
161
+ - lib/standard_flags/runtime/values.rb
123
162
  - lib/standard_flags/sensor.rb
124
163
  - lib/standard_flags/snapshot.rb
125
164
  - lib/standard_flags/subscribers.rb
126
165
  - lib/standard_flags/testing.rb
127
166
  - lib/standard_flags/tooling.rb
167
+ - lib/standard_flags/tooling/changes.rb
128
168
  - lib/standard_flags/version.rb
129
169
  - lib/tasks/standard_flags.rake
130
170
  homepage: https://github.com/rarebit-one/standard_flags