Skip to content

Commit

Permalink
feat: Support feature flag overrides in ephemeral test envs (apache#1…
Browse files Browse the repository at this point in the history
…4008)

* Add support for feature flag overrides in ephemeral env cmd

* update docs to reference correct config

* Update ephemeral env docs
  • Loading branch information
robdiciuccio committed Apr 8, 2021
1 parent 487e308 commit 274ee0a
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 7 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/ephemeral-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ jobs:
runs-on: ubuntu-latest
outputs:
slash-command: ${{ steps.eval-body.outputs.result }}
feature-flags: ${{ steps.eval-feature-flags.outputs.result }}

steps:
- name: Debug
Expand All @@ -28,6 +29,22 @@ jobs:
const result = pattern.exec(context.payload.comment.body)
return result === null ? 'noop' : result[1]
- name: Eval comment body for feature flags
uses: actions/github-script@v3
id: eval-feature-flags
with:
script: |
const pattern = /FEATURE_(\w+)=(\w+)/g;
let results = [];
[...context.payload.comment.body.matchAll(pattern)].forEach(match => {
const config = {
name: `SUPERSET_FEATURE_${match[1]}`,
value: match[2],
};
results.push(config);
});
return results;
- name: Limit to committers
if: >
steps.eval-body.outputs.result != 'noop' &&
Expand Down Expand Up @@ -100,6 +117,10 @@ jobs:
container-name: superset-ci
image: ${{ steps.login-ecr.outputs.registry }}/superset-ci:pr-${{ github.event.issue.number }}

- name: Update env vars in the Amazon ECS task definition
run: |
cat <<< "$(jq '.containerDefinitions[0].environment += ${{ needs.ephemeral_env_comment.outputs.feature-flags }}' < ${{ steps.task-def.outputs.task-definition }})" > ${{ steps.task-def.outputs.task-definition }}
- name: Describe ECS service
id: describe-services
run: |
Expand Down
9 changes: 8 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,16 @@ Finally, never submit a PR that will put master branch in broken state. If the P

#### Test Environments

- Members of the Apache GitHub org can launch an ephemeral test environment directly on a pull request by creating a comment containing (only) the command `/testenv up`
- Members of the Apache GitHub org can launch an ephemeral test environment directly on a pull request by creating a comment containing (only) the command `/testenv up`.
- Note that org membership must be public in order for this validation to function properly.
- Feature flags may be set for a test environment by specifying the flag name (prefixed with `FEATURE_`) and value after the command.
- Format: `/testenv up FEATURE_<feature flag name>=true|false`
- Example: `/testenv up FEATURE_DASHBOARD_NATIVE_FILTERS=true`
- Multiple feature flags may be set in single command, separated by whitespace
- A comment will be created by the workflow script with the address and login information for the ephemeral environment.
- Test environments may be created once the Docker build CI workflow for the PR has completed successfully.
- Test environments do not currently update automatically when new commits are added to a pull request.
- Test environments do not currently support async workers, though this is planned.
- Running test environments will be shutdown upon closing the pull request.

#### Merging
Expand Down
2 changes: 1 addition & 1 deletion docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1570,7 +1570,7 @@ You can enable or disable features with flag from ``superset_config.py``:

.. code-block:: python
DEFAULT_FEATURE_FLAGS = {
FEATURE_FLAGS = {
'CLIENT_CACHE': False,
'ENABLE_EXPLORE_JSON_CSRF_PROTECTION': False,
'PRESTO_EXPAND_DATA': False,
Expand Down
2 changes: 1 addition & 1 deletion docs/sqllab.rst
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ can optionally specify a custom formatter. Eg:
return [{"Cost": f"US$ {cost:.2f}"}]
DEFAULT_FEATURE_FLAGS = {
FEATURE_FLAGS = {
"ESTIMATE_QUERY_COST": True,
"QUERY_COST_FORMATTERS_BY_ENGINE": {"presto": presto_query_cost_formatter},
}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/pages/docs/installation/configuring.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ functionalities in Superset, but will be only affected by a subset of users.
You can enable or disable features with flag from `superset_config.py`:

```python
DEFAULT_FEATURE_FLAGS = {
FEATURE_FLAGS = {
'CLIENT_CACHE': False,
'ENABLE_EXPLORE_JSON_CSRF_PROTECTION': False,
'PRESTO_EXPAND_DATA': False,
Expand Down
15 changes: 13 additions & 2 deletions superset/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@
import json
import logging
import os
import re
import sys
from collections import OrderedDict
from datetime import date
from distutils.util import strtobool
from typing import Any, Callable, Dict, List, Optional, Type, TYPE_CHECKING, Union

from cachelib.base import BaseCache
Expand Down Expand Up @@ -296,7 +298,7 @@ def _try_json_readsha( # pylint: disable=unused-argument
# Feature flags
# ---------------------------------------------------
# Feature flags that are set by default go here. Their values can be
# overwritten by those specified under FEATURE_FLAGS in super_config.py
# overwritten by those specified under FEATURE_FLAGS in superset_config.py
# For example, DEFAULT_FEATURE_FLAGS = { 'FOO': True, 'BAR': False } here
# and FEATURE_FLAGS = { 'BAR': True, 'BAZ': True } in superset_config.py
# will result in combined feature flags of { 'FOO': True, 'BAR': True, 'BAZ': True }
Expand Down Expand Up @@ -374,6 +376,15 @@ def _try_json_readsha( # pylint: disable=unused-argument
if DEFAULT_FEATURE_FLAGS["THUMBNAILS"]:
DEFAULT_FEATURE_FLAGS["LISTVIEWS_DEFAULT_CARD_VIEW"] = True

# Feature flags may also be set via 'SUPERSET_FEATURE_' prefixed environment vars.
DEFAULT_FEATURE_FLAGS.update(
{
k[len("SUPERSET_FEATURE_") :]: bool(strtobool(v))
for k, v in os.environ.items()
if re.search(r"^SUPERSET_FEATURE_\w+", k)
}
)

# This is merely a default.
FEATURE_FLAGS: Dict[str, bool] = {}

Expand Down Expand Up @@ -721,7 +732,7 @@ class CeleryConfig: # pylint: disable=too-few-public-methods
#
# return out
#
# DEFAULT_FEATURE_FLAGS = {
# FEATURE_FLAGS = {
# "ESTIMATE_QUERY_COST": True,
# "QUERY_COST_FORMATTERS_BY_ENGINE": {"postgresql": postgres_query_cost_formatter},
# }
Expand Down
2 changes: 1 addition & 1 deletion tests/superset_test_config_sqllab_backend_persist.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@

from .superset_test_config import *

DEFAULT_FEATURE_FLAGS = {"SQLLAB_BACKEND_PERSISTENCE": True}
FEATURE_FLAGS = {"SQLLAB_BACKEND_PERSISTENCE": True}

0 comments on commit 274ee0a

Please sign in to comment.