From 4cbf4821940d1680734fe032e01f41205b6a2fc4 Mon Sep 17 00:00:00 2001 From: Grace Guo Date: Wed, 25 Nov 2020 11:47:18 -0800 Subject: [PATCH] fix: add feature flag for domain sharding (#11797) * fix: add feature flag for domain sharding * fix review comment * add comment for speical case --- superset-frontend/src/featureFlags.ts | 5 ++++- superset-frontend/src/utils/hostNamesConfig.js | 11 +++++++++++ superset/config.py | 4 ++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/superset-frontend/src/featureFlags.ts b/superset-frontend/src/featureFlags.ts index 1bac02dcbd..8183cfa877 100644 --- a/superset-frontend/src/featureFlags.ts +++ b/superset-frontend/src/featureFlags.ts @@ -19,6 +19,7 @@ // We can codegen the enum definition based on a list of supported flags that we // check into source control. We're hardcoding the supported flags for now. export enum FeatureFlag { + ALLOW_DASHBOARD_DOMAIN_SHARDING = 'ALLOW_DASHBOARD_DOMAIN_SHARDING', OMNIBAR = 'OMNIBAR', CLIENT_CACHE = 'CLIENT_CACHE', SCHEDULED_QUERIES = 'SCHEDULED_QUERIES', @@ -49,7 +50,9 @@ declare global { } export function initFeatureFlags(featureFlags: FeatureFlagMap) { - window.featureFlags = featureFlags || {}; + if (!window.featureFlags) { + window.featureFlags = featureFlags || {}; + } } export function isFeatureEnabled(feature: FeatureFlag) { diff --git a/superset-frontend/src/utils/hostNamesConfig.js b/superset-frontend/src/utils/hostNamesConfig.js index a216cbee1f..8a9f208cc3 100644 --- a/superset-frontend/src/utils/hostNamesConfig.js +++ b/superset-frontend/src/utils/hostNamesConfig.js @@ -16,6 +16,12 @@ * specific language governing permissions and limitations * under the License. */ +import { + initFeatureFlags, + isFeatureEnabled, + FeatureFlag, +} from 'src/featureFlags'; + function getDomainsConfig() { const appContainer = document.getElementById('app'); if (!appContainer) { @@ -23,8 +29,13 @@ function getDomainsConfig() { } const bootstrapData = JSON.parse(appContainer.getAttribute('data-bootstrap')); + // this module is a little special, it may be loaded before index.jsx, + // where window.featureFlags get initialized + // eslint-disable-next-line camelcase + initFeatureFlags(bootstrapData?.common?.feature_flags); const availableDomains = new Set([window.location.hostname]); if ( + isFeatureEnabled(FeatureFlag.ALLOW_DASHBOARD_DOMAIN_SHARDING) && bootstrapData && bootstrapData.common && bootstrapData.common.conf && diff --git a/superset/config.py b/superset/config.py index fa5b3857f8..d469b047b5 100644 --- a/superset/config.py +++ b/superset/config.py @@ -298,6 +298,10 @@ LANGUAGES = {} # and FEATURE_FLAGS = { 'BAR': True, 'BAZ': True } in superset_config.py # will result in combined feature flags of { 'FOO': True, 'BAR': True, 'BAZ': True } DEFAULT_FEATURE_FLAGS: Dict[str, bool] = { + # allow dashboard to use sub-domains to send chart request + # you also need ENABLE_CORS and + # SUPERSET_WEBSERVER_DOMAINS for list of domains + "ALLOW_DASHBOARD_DOMAIN_SHARDING": True, # Experimental feature introducing a client (browser) cache "CLIENT_CACHE": False, "ENABLE_EXPLORE_JSON_CSRF_PROTECTION": False,