Commit 2c6bce38 authored by Shinya Maeda's avatar Shinya Maeda

Merge branch 'remove-alpha-beta-feature-available' into 'master'

Remove alpha / beta feature available methods

See merge request gitlab-org/gitlab!45493
parents 7a0c681b 7f886ad8
......@@ -309,11 +309,6 @@ used as an actor for `Feature.enabled?`.
### Feature flags for licensed features
If a feature is license-gated, there's no need to add an additional
explicit feature flag check since the flag is checked as part of the
`License.feature_available?` call. Similarly, there's no need to "clean up" a
feature flag once the feature has reached general availability.
The [`Project#feature_available?`](https://gitlab.com/gitlab-org/gitlab/blob/4cc1c62918aa4c31750cb21dfb1a6c3492d71080/app/models/project_feature.rb#L63-68),
[`Namespace#feature_available?`](https://gitlab.com/gitlab-org/gitlab/blob/4cc1c62918aa4c31750cb21dfb1a6c3492d71080/ee/app/models/ee/namespace.rb#L71-85) (EE), and
[`License.feature_available?`](https://gitlab.com/gitlab-org/gitlab/blob/4cc1c62918aa4c31750cb21dfb1a6c3492d71080/ee/app/models/license.rb#L293-300) (EE) methods all implicitly check for
......@@ -328,38 +323,11 @@ Due to limitations with `feature_available?`, the YAML definition for `licensed`
flags accepts only `default_enabled: true`. This is under development as per the
[related issue](https://gitlab.com/gitlab-org/gitlab/-/issues/218667).
#### Alpha/beta licensed feature flags
This is relevant when developing the feature using
[several smaller merge requests](https://about.gitlab.com/handbook/values/#make-small-merge-requests), or when the feature is considered to be an
[alpha or beta](https://about.gitlab.com/handbook/product/gitlab-the-product/#alpha-beta-ga), and
should not be available by default.
As an example, if you were to ship the frontend half of a feature without the
backend, you'd want to disable the feature entirely until the backend half is
also ready to be shipped. To make sure this feature is disabled for both
GitLab.com and self-managed instances, you should use the
[`Namespace#alpha_feature_available?`](https://gitlab.com/gitlab-org/gitlab/blob/458749872f4a8f27abe8add930dbb958044cb926/ee/app/models/ee/namespace.rb#L113) or
[`Namespace#beta_feature_available?`](https://gitlab.com/gitlab-org/gitlab/blob/458749872f4a8f27abe8add930dbb958044cb926/ee/app/models/ee/namespace.rb#L100-112)
method, according to our [definitions](https://about.gitlab.com/handbook/product/gitlab-the-product/#alpha-beta-ga). This ensures the feature is disabled unless the feature flag is
_explicitly_ enabled.
If you want a licensed feature to be disabled by default or enabled only for a given gate, you can use a feature flag with a different name. The feature checks would then
look like:
CAUTION: **Caution:**
If `alpha_feature_available?` or `beta_feature_available?` is used, the YAML definition
for the feature flag must use `default_enabled: [false, true]`, because the usage
of the feature flag is undefined. These methods may change, as per the
[related issue](https://gitlab.com/gitlab-org/gitlab/-/issues/218667).
The resulting YAML should be similar to:
```yaml
name: scoped_labels
group: group::memory
type: licensed
# The `default_enabled:` is undefined
# as `feature_available?` uses `default_enabled: true`
# as `beta_feature_available?` uses `default_enabled: false`
default_enabled: [false, true]
```ruby
Feature.enabled?(:licensed_feature_feature_flag, project) && project.feature_available?(:licensed_feature)
```
### Feature groups
......
......@@ -118,20 +118,6 @@ module EE
project.full_path.sub(/\A#{Regexp.escape(full_path)}/, full_path_before_last_save)
end
# This makes the feature disabled by default, in contrary to how
# `#feature_available?` makes a feature enabled by default.
#
# This allows to:
# - Enable the feature flag for a given group, regardless of the license.
# This is useful for early testing a feature in production on a given group.
# - Enable the feature flag globally and still check that the license allows
# it. This is the case when we're ready to enable a feature for anyone
# with the correct license.
def beta_feature_available?(feature)
::Feature.enabled?(feature, type: :licensed) ? feature_available?(feature) : ::Feature.enabled?(feature, self, type: :licensed)
end
alias_method :alpha_feature_available?, :beta_feature_available?
# Checks features (i.e. https://about.gitlab.com/pricing/) availabily
# for a given Namespace plan. This method should consider ancestor groups
# being licensed.
......
......@@ -312,20 +312,6 @@ module EE
shared_runners_enabled? && shared_runners_limit_namespace.shared_runners_minutes_limit_enabled?
end
# This makes the feature disabled by default, in contrary to how
# `#feature_available?` makes a feature enabled by default.
#
# This allows to:
# - Enable the feature flag for a given project, regardless of the license.
# This is useful for early testing a feature in production on a given project.
# - Enable the feature flag globally and still check that the license allows
# it. This is the case when we're ready to enable a feature for anyone
# with the correct license.
def beta_feature_available?(feature)
::Feature.enabled?(feature, type: :licensed) ? feature_available?(feature) : ::Feature.enabled?(feature, self, type: :licensed)
end
alias_method :alpha_feature_available?, :beta_feature_available?
def push_audit_events_enabled?
::Feature.enabled?(:repository_push_audit_event, self)
end
......
......@@ -792,12 +792,6 @@ RSpec.describe Group do
end
end
describe '#alpha/beta_feature_available?' do
it_behaves_like 'an entity with alpha/beta feature support' do
let(:entity) { group }
end
end
describe "#insights_config" do
context 'when group has no Insights project configured' do
it 'returns the default config' do
......
......@@ -797,12 +797,6 @@ RSpec.describe Project do
end
end
describe '#alpha/beta_feature_available?' do
it_behaves_like 'an entity with alpha/beta feature support' do
let(:entity) { create(:project) }
end
end
describe '#feature_available?' do
let(:namespace) { build(:namespace) }
let(:plan_license) { nil }
......
# frozen_string_literal: true
# This needs an `entity` object: Project or Group.
RSpec.shared_examples 'an entity with alpha/beta feature support' do
where(level: %w[alpha beta])
with_them do
let(:method_name) { "#{level}_feature_available?" }
context 'when license does not allow it' do
before do
stub_licensed_features(insights: false)
end
context 'when the feature flag is enabled globally' do
before do
stub_feature_flags(insights: true)
end
it { expect(entity.public_send(method_name, :insights)).to be_falsy }
end
context 'when the feature flag is disabled globally' do
before do
stub_feature_flags(insights: false)
end
it { expect(entity.public_send(method_name, :insights)).to be_falsy }
context 'and enabled for the entity' do
before do
stub_feature_flags(insights: entity)
end
it { expect(entity.public_send(method_name, :insights)).to be_truthy }
end
end
end
context 'when license allows it' do
before do
stub_licensed_features(insights: true)
end
context 'when the feature flag is enabled globally' do
before do
stub_feature_flags(insights: true)
end
it { expect(entity.public_send(method_name, :insights)).to be_truthy }
end
context 'when the feature flag is disabled globally' do
before do
stub_feature_flags(insights: false)
end
it { expect(entity.public_send(method_name, :insights)).to be_falsy }
context 'and enabled for the entity' do
before do
stub_feature_flags(insights: entity)
end
it { expect(entity.public_send(method_name, :insights)).to be_truthy }
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment