diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-10-21 10:08:36 +0300 |
commit | 48aff82709769b098321c738f3444b9bdaa694c6 (patch) | |
tree | e00c7c43e2d9b603a5a6af576b1685e400410dee /lib/feature | |
parent | 879f5329ee916a948223f8f43d77fba4da6cd028 (diff) |
Add latest changes from gitlab-org/gitlab@13-5-stable-eev13.5.0-rc42
Diffstat (limited to 'lib/feature')
-rw-r--r-- | lib/feature/definition.rb | 33 | ||||
-rw-r--r-- | lib/feature/shared.rb | 12 |
2 files changed, 28 insertions, 17 deletions
diff --git a/lib/feature/definition.rb b/lib/feature/definition.rb index ee779a86952..0ba1bdc4799 100644 --- a/lib/feature/definition.rb +++ b/lib/feature/definition.rb @@ -84,17 +84,14 @@ class Feature end def definitions - @definitions ||= {} + # We lazily load all definitions + # The hot reloading might request a feature flag + # before we can properly call `load_all!` + @definitions ||= load_all! end - def load_all! - definitions.clear - - paths.each do |glob_path| - load_all_from_path!(glob_path) - end - - definitions + def reload! + @definitions = load_all! end def valid_usage!(key, type:, default_enabled:) @@ -110,9 +107,7 @@ class Feature def register_hot_reloader! # Reload feature flags on change of this file or any `.yml` file_watcher = Rails.configuration.file_watcher.new(reload_files, reload_directories) do - # We use `Feature::Definition` as on Ruby code-reload - # a new class definition is created - Feature::Definition.load_all! + Feature::Definition.reload! end Rails.application.reloaders << file_watcher @@ -123,6 +118,16 @@ class Feature private + def load_all! + # We currently do not load feature flag definitions + # in production environments + return [] unless Gitlab.dev_or_test_env? + + paths.each_with_object({}) do |glob_path, definitions| + load_all_from_path!(definitions, glob_path) + end + end + def load_from_file(path) definition = File.read(path) definition = YAML.safe_load(definition) @@ -133,7 +138,7 @@ class Feature raise Feature::InvalidFeatureFlagError, "Invalid definition for `#{path}`: #{e.message}" end - def load_all_from_path!(glob_path) + def load_all_from_path!(definitions, glob_path) Dir.glob(glob_path).each do |path| definition = load_from_file(path) @@ -146,7 +151,7 @@ class Feature end def reload_files - [File.expand_path(__FILE__)] + [] end def reload_directories diff --git a/lib/feature/shared.rb b/lib/feature/shared.rb index c06f699ef27..9ec56ee6b52 100644 --- a/lib/feature/shared.rb +++ b/lib/feature/shared.rb @@ -9,12 +9,14 @@ class Feature # optional: defines if a on-disk definition is required for this feature flag type # rollout_issue: defines if `bin/feature-flag` asks for rollout issue # default_enabled: defines a default state of a feature flag when created by `bin/feature-flag` + # ee_only: defines that a feature flag can only be created in a context of EE # example: usage being shown when exception is raised TYPES = { development: { description: 'Short lived, used to enable unfinished code to be deployed', - optional: true, + optional: false, rollout_issue: true, + ee_only: false, default_enabled: false, example: <<-EOS Feature.enabled?(:my_feature_flag, project) @@ -26,6 +28,7 @@ class Feature description: "Long-lived feature flags that control operational aspects of GitLab's behavior", optional: true, rollout_issue: false, + ee_only: false, default_enabled: false, example: <<-EOS Feature.enabled?(:my_ops_flag, type: ops) @@ -36,6 +39,7 @@ class Feature description: 'Permanent feature flags used to temporarily disable licensed features.', optional: true, rollout_issue: false, + ee_only: true, default_enabled: true, example: <<-EOS project.feature_available?(:my_licensed_feature) @@ -44,13 +48,15 @@ class Feature } }.freeze + # The ordering of PARAMS defines an order in YAML + # This is done to ease the file comparison PARAMS = %i[ name - default_enabled - type introduced_by_url rollout_issue_url + type group + default_enabled ].freeze end end |