Skip to content

Commit

Permalink
docs: Expand feature flags docs in contributors' guide (meltano#6697)
Browse files Browse the repository at this point in the history
* Clarify feature_flags usage and implementation in contribute docs

* Clarify feature flags usage and implementation

* Prettify
  • Loading branch information
cjohnhanson committed Aug 31, 2022
1 parent 3237022 commit c22ffa7
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions docs/src/_contribute/style.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ weight: 10
Meltano uses the below tools to enforce consistent code style. Explore the [repo](https://github.com/meltano/meltano) to learn of the specific rules and settings of each.

Python:

- [isort](https://pycqa.github.io/isort/)
- [Black](https://github.com/ambv/black)
- [Flake8](https://flake8.pycqa.org/en/latest/)
Expand All @@ -24,6 +25,7 @@ and `wemake-python-styleguide` is a plugin for Flake8 that offers an extensive s
[MyPy is currently not executed in CI](https://github.com/meltano/meltano/issues/6491). It currently raises many issues when run. We intend to address them over time.

Javascript:

- [ESLint](https://eslint.org/docs/rules/)
- [ESLint Vue Plugin](https://github.com/vuejs/eslint-plugin-vue)
- [Prettier](https://prettier.io/)
Expand Down Expand Up @@ -76,31 +78,42 @@ Object properties and methods are alphabetical where `Vuex` stores are the excep
### Feature Flags

Sometimes it is useful to be able to make preview features available or allow deprecated features to be used for backwards compatibility.

To accomplish this, Meltano implements feature flags.
For new, deprecated, or experimental features, the relevant code path can be wrapped in a feature flag context.

For example:
For new, deprecated, or experimental features, the relevant code path can be wrapped in a feature flag context. The process for adding new feature flags is as follows:

1. Determine a descriptive name for the feature flag and add it as a [`FeatureFlags` Enum value](https://github.com/meltano/meltano/blob/3237022624c9594852abe69acb4da3dbf1ce5c05/src/meltano/core/settings_service.py#L30)
1. Wrap your code blocks in a `ProjectSettingsService.feature_flag()` context as demonstrated below.
1. Add documentation about the new feature flag to the [Feature Flags section of the settings reference docs](/reference/settings#feature-flags)
1. In any documentation about the feature, note that the feature is experimental and link to the [Feature Flags section of the settings reference docs](/reference/settings#feature-flags). This note should be something similar to:
> This feature is experimental and must be enabled using feature flags. See the docs here: ...
1. Add your feature flag metadata to [settings.yml](https://github.com/meltano/meltano/blob/3237022624c9594852abe69acb4da3dbf1ce5c05/src/meltano/core/bundle/settings.yml#L189) so that it is recognized as a project-wide configuration setting.

```python
# Example feature flag usage
from meltano.core.project import Project
from meltano.core.project_settings_service import ProjectSettingsService
from meltano.core.settings_service import EXPERIMENTAL
from meltano.core.settings_service import FeatureFlags

class ExistingClass:

def __init__(self):
self.project = Project.find()
self.settings_service = ProjectSettingsService(self.project)

# If this method is called elsewhere in the code and experimental features are
# not allowed, it will throw an error:
# If this method is called elsewhere in the code and the NEW_BEHAVIOR
# feature flag is not set to 'true' it will throw an error:
def experimental_method(self):
with self.settings_service.feature_flag(EXPERIMENTAL):
print("Doing experimental behavior...")
with self.settings_service.feature_flag(FeatureFlags.NEW_BEHAVIOR):
print("Doing new behavior...")

# If this method is called elsewhere, its behavior will vary based on whether
# the feature flag is set in the project
# The same pattern can be used to deprecate existing behavior
# Notice the "raise_error=False" in the feature_flag method call
def existing_method_with_new_behavior(self):
with self.settings_service.feature_flag("new_behavior") as new_behavior:
with self.settings_service.feature_flag(FeatureFlags.NEW_BEHAVIOR, raise_error=False) as new_behavior:
if new_behavior:
print("Doing the new behavior...")
else:
Expand Down

0 comments on commit c22ffa7

Please sign in to comment.