From 3bf96987816ee44ad71f3b3222db3f51e3ce82e6 Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Thu, 12 Oct 2023 16:56:07 -0600 Subject: [PATCH 01/31] Adding scarf pixel --- superset-frontend/src/features/home/RightMenu.tsx | 1 + superset/config.py | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/features/home/RightMenu.tsx b/superset-frontend/src/features/home/RightMenu.tsx index b79ebb65f888..b4f7df4bd4e2 100644 --- a/superset-frontend/src/features/home/RightMenu.tsx +++ b/superset-frontend/src/features/home/RightMenu.tsx @@ -341,6 +341,7 @@ const RightMenu = ({ return ( + {canDatabase && ( Date: Thu, 19 Oct 2023 15:04:15 -0600 Subject: [PATCH 02/31] faux query variables --- superset-frontend/src/features/home/RightMenu.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/src/features/home/RightMenu.tsx b/superset-frontend/src/features/home/RightMenu.tsx index b4f7df4bd4e2..91e8bc4a7cf3 100644 --- a/superset-frontend/src/features/home/RightMenu.tsx +++ b/superset-frontend/src/features/home/RightMenu.tsx @@ -341,7 +341,7 @@ const RightMenu = ({ return ( - + {canDatabase && ( Date: Thu, 16 Nov 2023 14:44:02 -0700 Subject: [PATCH 03/31] Adding pixel component and FF --- RESOURCES/FEATURE_FLAGS.md | 1 + superset-frontend/package.json | 2 +- .../src/utils/featureFlags.ts | 1 + .../TelemetryPixel/TelemetryPixel.test.tsx | 43 +++++++++++++++++++ .../src/components/TelemetryPixel/index.tsx | 33 ++++++++++++++ .../src/features/home/RightMenu.tsx | 7 +-- superset/config.py | 2 + 7 files changed, 85 insertions(+), 4 deletions(-) create mode 100644 superset-frontend/src/components/TelemetryPixel/TelemetryPixel.test.tsx create mode 100644 superset-frontend/src/components/TelemetryPixel/index.tsx diff --git a/RESOURCES/FEATURE_FLAGS.md b/RESOURCES/FEATURE_FLAGS.md index d029ca6c3cbd..e271c8894a1a 100644 --- a/RESOURCES/FEATURE_FLAGS.md +++ b/RESOURCES/FEATURE_FLAGS.md @@ -72,6 +72,7 @@ These features flags are **safe for production**. They have been tested and will - DRUID_JOINS - EMBEDDABLE_CHARTS - EMBEDDED_SUPERSET +- ENABLE_TELEMETRY - ENABLE_TEMPLATE_PROCESSING - ESCAPE_MARKDOWN_HTML - LISTVIEWS_DEFAULT_CARD_VIEW diff --git a/superset-frontend/package.json b/superset-frontend/package.json index 3b6310fa718c..b4e17bd0d33d 100644 --- a/superset-frontend/package.json +++ b/superset-frontend/package.json @@ -259,7 +259,7 @@ "@types/js-levenshtein": "^1.1.0", "@types/json-bigint": "^1.0.1", "@types/mousetrap": "^1.6.11", - "@types/react": "^16.9.43", + "@types/react": "^16.9.53", "@types/react-dom": "^16.9.8", "@types/react-gravatar": "^2.6.8", "@types/react-json-tree": "^0.6.11", diff --git a/superset-frontend/packages/superset-ui-core/src/utils/featureFlags.ts b/superset-frontend/packages/superset-ui-core/src/utils/featureFlags.ts index 6bc77e0e87a1..e13e06d9f04e 100644 --- a/superset-frontend/packages/superset-ui-core/src/utils/featureFlags.ts +++ b/superset-frontend/packages/superset-ui-core/src/utils/featureFlags.ts @@ -44,6 +44,7 @@ export enum FeatureFlag { ENABLE_ADVANCED_DATA_TYPES = 'ENABLE_ADVANCED_DATA_TYPES', ENABLE_EXPLORE_DRAG_AND_DROP = 'ENABLE_EXPLORE_DRAG_AND_DROP', ENABLE_JAVASCRIPT_CONTROLS = 'ENABLE_JAVASCRIPT_CONTROLS', + ENABLE_TELEMETRY = 'ENABLE_TELEMETRY', ENABLE_TEMPLATE_PROCESSING = 'ENABLE_TEMPLATE_PROCESSING', ENABLE_TEMPLATE_REMOVE_FILTERS = 'ENABLE_TEMPLATE_REMOVE_FILTERS', ESCAPE_MARKDOWN_HTML = 'ESCAPE_MARKDOWN_HTML', diff --git a/superset-frontend/src/components/TelemetryPixel/TelemetryPixel.test.tsx b/superset-frontend/src/components/TelemetryPixel/TelemetryPixel.test.tsx new file mode 100644 index 000000000000..96445624c161 --- /dev/null +++ b/superset-frontend/src/components/TelemetryPixel/TelemetryPixel.test.tsx @@ -0,0 +1,43 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +import React from 'react'; +import { render, screen } from 'spec/helpers/testing-library'; +import { FeatureFlag } from '@superset-ui/core'; +import TelemetryPixel from '.'; + +test('should render', () => { + const { container } = render(); + expect(container).toBeInTheDocument(); +}); + +test('should render the pixel link when FF is on', () => { + window.featureFlags = { + [FeatureFlag.ENABLE_TELEMETRY]: true, + }; + render(); + expect(screen.getByText('scarf.sh')).toBeInTheDocument(); +}); + +test('should NOT render the pixel link when FF is off', () => { + window.featureFlags = { + [FeatureFlag.ENABLE_TELEMETRY]: false, + }; + render(); + expect(screen.getByText('scarf.sh')).not.toBeInTheDocument(); +}); diff --git a/superset-frontend/src/components/TelemetryPixel/index.tsx b/superset-frontend/src/components/TelemetryPixel/index.tsx new file mode 100644 index 000000000000..0d209a72da89 --- /dev/null +++ b/superset-frontend/src/components/TelemetryPixel/index.tsx @@ -0,0 +1,33 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import React from 'react'; +import { isFeatureEnabled, FeatureFlag } from '@superset-ui/core'; + +const TelemetryPixel = () => { + console.log('TelemetryPixel', isFeatureEnabled(FeatureFlag.ENABLE_TELEMETRY)) + return isFeatureEnabled(FeatureFlag.ENABLE_TELEMETRY) ? ( + // eslint-disable-next-line jsx-a11y/alt-text + + ) : null; + } +export default TelemetryPixel; diff --git a/superset-frontend/src/features/home/RightMenu.tsx b/superset-frontend/src/features/home/RightMenu.tsx index 91e8bc4a7cf3..2fb2d0f967f1 100644 --- a/superset-frontend/src/features/home/RightMenu.tsx +++ b/superset-frontend/src/features/home/RightMenu.tsx @@ -46,6 +46,7 @@ import { import { RootState } from 'src/dashboard/types'; import DatabaseModal from 'src/features/databases/DatabaseModal'; import { uploadUserPerms } from 'src/views/CRUD/utils'; +import TelemetryPixel from 'src/components/TelemetryPixel'; import LanguagePicker from './LanguagePicker'; import { ExtensionConfigs, @@ -210,7 +211,7 @@ const RightMenu = ({ }, { label: t('SQL query'), - url: '/sqllab?new=true', + url: '/superset/sqllab?new=true', icon: 'fa-fw fa-search', perm: 'can_sqllab', view: 'Superset', @@ -341,7 +342,7 @@ const RightMenu = ({ return ( - + {canDatabase && ( {navbarRight.user_profile_url && ( - {t('Profile')} + {t('Profile')} )} {navbarRight.user_info_url && ( diff --git a/superset/config.py b/superset/config.py index 5584968e2f9a..93f0a3da9ed6 100644 --- a/superset/config.py +++ b/superset/config.py @@ -420,6 +420,8 @@ class D3Format(TypedDict, total=False): # make GET request to explore_json. explore_json accepts both GET and POST request. # See `PR 7935 `_ for more details. "ENABLE_EXPLORE_JSON_CSRF_PROTECTION": False, # deprecated + # Enables telemetry using Scarf.sh (to help measure Superset's adoption and the impact security concerns or other issues might have on the community) + "ENABLE_TELEMETRY": True, "ENABLE_TEMPLATE_PROCESSING": False, "ENABLE_TEMPLATE_REMOVE_FILTERS": True, # deprecated # Allow for javascript controls components From f876364290cf87f75163f65a0f8e5b407c1c853d Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Thu, 16 Nov 2023 15:19:24 -0700 Subject: [PATCH 04/31] bumping react types to allow referrer policy --- superset-frontend/package-lock.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/package-lock.json b/superset-frontend/package-lock.json index c4e771b25975..36edf82056ac 100644 --- a/superset-frontend/package-lock.json +++ b/superset-frontend/package-lock.json @@ -194,7 +194,7 @@ "@types/js-levenshtein": "^1.1.0", "@types/json-bigint": "^1.0.1", "@types/mousetrap": "^1.6.11", - "@types/react": "^16.9.43", + "@types/react": "^16.9.53", "@types/react-dom": "^16.9.8", "@types/react-gravatar": "^2.6.8", "@types/react-json-tree": "^0.6.11", From 960d6fbb34ee26bc21a735d4e45e58121d8e0e39 Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Thu, 16 Nov 2023 15:19:37 -0700 Subject: [PATCH 05/31] Passing version/sha/build to pixel --- .../src/components/TelemetryPixel/index.tsx | 11 +++++++++-- superset-frontend/src/features/home/RightMenu.tsx | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/superset-frontend/src/components/TelemetryPixel/index.tsx b/superset-frontend/src/components/TelemetryPixel/index.tsx index 0d209a72da89..b426a539e800 100644 --- a/superset-frontend/src/components/TelemetryPixel/index.tsx +++ b/superset-frontend/src/components/TelemetryPixel/index.tsx @@ -20,13 +20,20 @@ import React from 'react'; import { isFeatureEnabled, FeatureFlag } from '@superset-ui/core'; -const TelemetryPixel = () => { +interface TelemetryPixelProps { + version?: string; + sha?: string; + build?: string; +} + +const TelemetryPixel = ({version, sha, build}: TelemetryPixelProps) => { console.log('TelemetryPixel', isFeatureEnabled(FeatureFlag.ENABLE_TELEMETRY)) + var pixelPath = `https://apachesuperset.gateway.scarf.sh/pixel.png?x-pxid=0d3461e1-abb1-4691-a0aa-5ed50de66af0&version=${version}&sha=${sha}&build=${build}`; return isFeatureEnabled(FeatureFlag.ENABLE_TELEMETRY) ? ( // eslint-disable-next-line jsx-a11y/alt-text ) : null; } diff --git a/superset-frontend/src/features/home/RightMenu.tsx b/superset-frontend/src/features/home/RightMenu.tsx index 2fb2d0f967f1..9cbc54b2c628 100644 --- a/superset-frontend/src/features/home/RightMenu.tsx +++ b/superset-frontend/src/features/home/RightMenu.tsx @@ -342,7 +342,7 @@ const RightMenu = ({ return ( - + {canDatabase && ( Date: Thu, 16 Nov 2023 21:45:11 -0700 Subject: [PATCH 06/31] more bump action --- superset-frontend/package-lock.json | 40 +++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/superset-frontend/package-lock.json b/superset-frontend/package-lock.json index 36edf82056ac..0b5f07781c2c 100644 --- a/superset-frontend/package-lock.json +++ b/superset-frontend/package-lock.json @@ -19619,12 +19619,13 @@ "devOptional": true }, "node_modules/@types/react": { - "version": "16.9.43", - "resolved": "https://registry.npmjs.org/@types/react/-/react-16.9.43.tgz", - "integrity": "sha512-PxshAFcnJqIWYpJbLPriClH53Z2WlJcVZE+NP2etUtWQs2s7yIMj3/LDKZT/5CHJ/F62iyjVCDu2H3jHEXIxSg==", + "version": "16.14.51", + "resolved": "https://registry.npmjs.org/@types/react/-/react-16.14.51.tgz", + "integrity": "sha512-4T/wsDXStA5OUGTj6w2INze3ZCz22IwQiWcApgqqNRU2A6vNUIPXpNkjAMUFxx6diYPVkvz+d7gEtU7AZ+0Xqg==", "dependencies": { "@types/prop-types": "*", - "csstype": "^2.2.0" + "@types/scheduler": "*", + "csstype": "^3.0.2" } }, "node_modules/@types/react-dom": { @@ -19766,6 +19767,11 @@ "@types/react": "*" } }, + "node_modules/@types/react/node_modules/csstype": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.2.tgz", + "integrity": "sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==" + }, "node_modules/@types/redux-localstorage": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/@types/redux-localstorage/-/redux-localstorage-1.0.8.tgz", @@ -19807,6 +19813,11 @@ "resolved": "https://registry.npmjs.org/@types/rison/-/rison-0.0.6.tgz", "integrity": "sha512-mE3eRK0fpTN/GnNBOIg2tGq2cFhchQXF6fCbrLxus75TgnoOECbdHikr948FGO/UAml7/ZhLMa5FbGkF5PKvmw==" }, + "node_modules/@types/scheduler": { + "version": "0.16.6", + "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.6.tgz", + "integrity": "sha512-Vlktnchmkylvc9SnwwwozTv04L/e1NykF5vgoQ0XTmI8DD+wxfjQuHuvHS3p0r2jz2x2ghPs2h1FVeDirIteWA==" + }, "node_modules/@types/seedrandom": { "version": "2.4.30", "resolved": "https://registry.npmjs.org/@types/seedrandom/-/seedrandom-2.4.30.tgz", @@ -79578,12 +79589,20 @@ "devOptional": true }, "@types/react": { - "version": "16.9.43", - "resolved": "https://registry.npmjs.org/@types/react/-/react-16.9.43.tgz", - "integrity": "sha512-PxshAFcnJqIWYpJbLPriClH53Z2WlJcVZE+NP2etUtWQs2s7yIMj3/LDKZT/5CHJ/F62iyjVCDu2H3jHEXIxSg==", + "version": "16.14.51", + "resolved": "https://registry.npmjs.org/@types/react/-/react-16.14.51.tgz", + "integrity": "sha512-4T/wsDXStA5OUGTj6w2INze3ZCz22IwQiWcApgqqNRU2A6vNUIPXpNkjAMUFxx6diYPVkvz+d7gEtU7AZ+0Xqg==", "requires": { "@types/prop-types": "*", - "csstype": "^2.2.0" + "@types/scheduler": "*", + "csstype": "^3.0.2" + }, + "dependencies": { + "csstype": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.2.tgz", + "integrity": "sha512-I7K1Uu0MBPzaFKg4nI5Q7Vs2t+3gWWW648spaF+Rg7pI9ds18Ugn+lvg4SHczUdKlHI5LWBXyqfS8+DufyBsgQ==" + } } }, "@types/react-dom": { @@ -79768,6 +79787,11 @@ "resolved": "https://registry.npmjs.org/@types/rison/-/rison-0.0.6.tgz", "integrity": "sha512-mE3eRK0fpTN/GnNBOIg2tGq2cFhchQXF6fCbrLxus75TgnoOECbdHikr948FGO/UAml7/ZhLMa5FbGkF5PKvmw==" }, + "@types/scheduler": { + "version": "0.16.6", + "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.6.tgz", + "integrity": "sha512-Vlktnchmkylvc9SnwwwozTv04L/e1NykF5vgoQ0XTmI8DD+wxfjQuHuvHS3p0r2jz2x2ghPs2h1FVeDirIteWA==" + }, "@types/seedrandom": { "version": "2.4.30", "resolved": "https://registry.npmjs.org/@types/seedrandom/-/seedrandom-2.4.30.tgz", From ee2191415946273a9e557d2387f3b602df947394 Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Thu, 16 Nov 2023 21:45:30 -0700 Subject: [PATCH 07/31] fiddling with pixel/package path --- superset-frontend/src/components/TelemetryPixel/index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/superset-frontend/src/components/TelemetryPixel/index.tsx b/superset-frontend/src/components/TelemetryPixel/index.tsx index b426a539e800..f5c6f52fe28d 100644 --- a/superset-frontend/src/components/TelemetryPixel/index.tsx +++ b/superset-frontend/src/components/TelemetryPixel/index.tsx @@ -28,7 +28,8 @@ interface TelemetryPixelProps { const TelemetryPixel = ({version, sha, build}: TelemetryPixelProps) => { console.log('TelemetryPixel', isFeatureEnabled(FeatureFlag.ENABLE_TELEMETRY)) - var pixelPath = `https://apachesuperset.gateway.scarf.sh/pixel.png?x-pxid=0d3461e1-abb1-4691-a0aa-5ed50de66af0&version=${version}&sha=${sha}&build=${build}`; + var pixelPath = `https://static.scarf.sh/a.png?x-pxid=0d3461e1-abb1-4691-a0aa-5ed50de66af0&version=${version}&sha=${sha}&build=${build}`; + // var pixelPath = `https://apachesuperset.gateway.scarf.sh/pixel.png?x-pxid=0d3461e1-abb1-4691-a0aa-5ed50de66af0&version=${version}&sha=${sha}&build=${build}`; return isFeatureEnabled(FeatureFlag.ENABLE_TELEMETRY) ? ( // eslint-disable-next-line jsx-a11y/alt-text Date: Thu, 16 Nov 2023 22:05:30 -0700 Subject: [PATCH 08/31] touchups --- .../src/components/TelemetryPixel/index.tsx | 16 ++++++---------- .../src/features/home/RightMenu.tsx | 6 +++++- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/superset-frontend/src/components/TelemetryPixel/index.tsx b/superset-frontend/src/components/TelemetryPixel/index.tsx index f5c6f52fe28d..5b6ac9af1a9d 100644 --- a/superset-frontend/src/components/TelemetryPixel/index.tsx +++ b/superset-frontend/src/components/TelemetryPixel/index.tsx @@ -26,16 +26,12 @@ interface TelemetryPixelProps { build?: string; } -const TelemetryPixel = ({version, sha, build}: TelemetryPixelProps) => { - console.log('TelemetryPixel', isFeatureEnabled(FeatureFlag.ENABLE_TELEMETRY)) - var pixelPath = `https://static.scarf.sh/a.png?x-pxid=0d3461e1-abb1-4691-a0aa-5ed50de66af0&version=${version}&sha=${sha}&build=${build}`; - // var pixelPath = `https://apachesuperset.gateway.scarf.sh/pixel.png?x-pxid=0d3461e1-abb1-4691-a0aa-5ed50de66af0&version=${version}&sha=${sha}&build=${build}`; - return isFeatureEnabled(FeatureFlag.ENABLE_TELEMETRY) ? ( +const TelemetryPixel = ({ version, sha, build }: TelemetryPixelProps) => { + const pixelPath = `https://static.scarf.sh/a.png?x-pxid=0d3461e1-abb1-4691-a0aa-5ed50de66af0&version=${version}&sha=${sha}&build=${build}`; + // const pixelPath = `https://apachesuperset.gateway.scarf.sh/pixel.png?x-pxid=0d3461e1-abb1-4691-a0aa-5ed50de66af0&version=${version}&sha=${sha}&build=${build}`; + return isFeatureEnabled(FeatureFlag.ENABLE_TELEMETRY) ? ( // eslint-disable-next-line jsx-a11y/alt-text - + ) : null; - } +}; export default TelemetryPixel; diff --git a/superset-frontend/src/features/home/RightMenu.tsx b/superset-frontend/src/features/home/RightMenu.tsx index 9cbc54b2c628..2879c8c106de 100644 --- a/superset-frontend/src/features/home/RightMenu.tsx +++ b/superset-frontend/src/features/home/RightMenu.tsx @@ -342,7 +342,11 @@ const RightMenu = ({ return ( - + {canDatabase && ( Date: Thu, 16 Nov 2023 22:14:05 -0700 Subject: [PATCH 09/31] more linting --- superset/config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/superset/config.py b/superset/config.py index 93f0a3da9ed6..cfcfa1de85a2 100644 --- a/superset/config.py +++ b/superset/config.py @@ -1428,7 +1428,7 @@ def EMAIL_HEADER_MUTATOR( # pylint: disable=invalid-name,unused-argument TALISMAN_CONFIG = { "content_security_policy": { "default-src": ["'self'"], - "img-src": ["'self'", "blob:", "data:","https://static.scarf.sh"], + "img-src": ["'self'", "blob:", "data:", "https://static.scarf.sh"], "worker-src": ["'self'", "blob:"], "connect-src": [ "'self'", @@ -1450,7 +1450,7 @@ def EMAIL_HEADER_MUTATOR( # pylint: disable=invalid-name,unused-argument TALISMAN_DEV_CONFIG = { "content_security_policy": { "default-src": ["'self'"], - "img-src": ["'self'", "blob:", "data:","https://static.scarf.sh"], + "img-src": ["'self'", "blob:", "data:", "https://static.scarf.sh"], "worker-src": ["'self'", "blob:"], "connect-src": [ "'self'", From db5c2df0574ed527477b4d698a2471fe72960e88 Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Mon, 20 Nov 2023 13:06:34 -0700 Subject: [PATCH 10/31] fixing talisman config --- superset/config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/superset/config.py b/superset/config.py index cfcfa1de85a2..97814dc132d6 100644 --- a/superset/config.py +++ b/superset/config.py @@ -1428,7 +1428,7 @@ def EMAIL_HEADER_MUTATOR( # pylint: disable=invalid-name,unused-argument TALISMAN_CONFIG = { "content_security_policy": { "default-src": ["'self'"], - "img-src": ["'self'", "blob:", "data:", "https://static.scarf.sh"], + "img-src": ["'self'", "blob:", "data:", "https://apachesuperset.gateway.scarf.sh"], "worker-src": ["'self'", "blob:"], "connect-src": [ "'self'", @@ -1450,7 +1450,7 @@ def EMAIL_HEADER_MUTATOR( # pylint: disable=invalid-name,unused-argument TALISMAN_DEV_CONFIG = { "content_security_policy": { "default-src": ["'self'"], - "img-src": ["'self'", "blob:", "data:", "https://static.scarf.sh"], + "img-src": ["'self'", "blob:", "data:", "https://apachesuperset.gateway.scarf.sh"], "worker-src": ["'self'", "blob:"], "connect-src": [ "'self'", From 8d6f19d40e58e43dee5d25cc8c56129524065327 Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Mon, 20 Nov 2023 13:06:38 -0700 Subject: [PATCH 11/31] linting --- .../src/components/TelemetryPixel/index.tsx | 10 +++++++--- superset-frontend/src/features/home/RightMenu.tsx | 10 +++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/superset-frontend/src/components/TelemetryPixel/index.tsx b/superset-frontend/src/components/TelemetryPixel/index.tsx index 5b6ac9af1a9d..c9c3a55dbbbc 100644 --- a/superset-frontend/src/components/TelemetryPixel/index.tsx +++ b/superset-frontend/src/components/TelemetryPixel/index.tsx @@ -26,9 +26,13 @@ interface TelemetryPixelProps { build?: string; } -const TelemetryPixel = ({ version, sha, build }: TelemetryPixelProps) => { - const pixelPath = `https://static.scarf.sh/a.png?x-pxid=0d3461e1-abb1-4691-a0aa-5ed50de66af0&version=${version}&sha=${sha}&build=${build}`; - // const pixelPath = `https://apachesuperset.gateway.scarf.sh/pixel.png?x-pxid=0d3461e1-abb1-4691-a0aa-5ed50de66af0&version=${version}&sha=${sha}&build=${build}`; +const TelemetryPixel = ({ = + version = 'unknownVersion', + sha = 'unknownSHA', + build = 'unknownBuild' +}: TelemetryPixelProps) => { + const pixelId = '0d3461e1-abb1-4691-a0aa-5ed50de66af0'; + const pixelPath = `https://apachesuperset.gateway.scarf.sh/pixel/${pixelId}/${version}/${sha}/${build}`; return isFeatureEnabled(FeatureFlag.ENABLE_TELEMETRY) ? ( // eslint-disable-next-line jsx-a11y/alt-text diff --git a/superset-frontend/src/features/home/RightMenu.tsx b/superset-frontend/src/features/home/RightMenu.tsx index 2879c8c106de..caf937e30a19 100644 --- a/superset-frontend/src/features/home/RightMenu.tsx +++ b/superset-frontend/src/features/home/RightMenu.tsx @@ -342,11 +342,6 @@ const RightMenu = ({ return ( - {canDatabase && ( )} + ); }; From a80de0c62f3ca887249623b6f09ea6d3f3ced560 Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Mon, 20 Nov 2023 13:14:35 -0700 Subject: [PATCH 12/31] line too long... seems like the linter could just fix this :/ --- superset/config.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/superset/config.py b/superset/config.py index 97814dc132d6..c4776143dda2 100644 --- a/superset/config.py +++ b/superset/config.py @@ -420,7 +420,8 @@ class D3Format(TypedDict, total=False): # make GET request to explore_json. explore_json accepts both GET and POST request. # See `PR 7935 `_ for more details. "ENABLE_EXPLORE_JSON_CSRF_PROTECTION": False, # deprecated - # Enables telemetry using Scarf.sh (to help measure Superset's adoption and the impact security concerns or other issues might have on the community) + # Enables telemetry using Scarf.sh (to help measure Superset's adoption of patches + # and the impact security concerns or other issues might have on the community) "ENABLE_TELEMETRY": True, "ENABLE_TEMPLATE_PROCESSING": False, "ENABLE_TEMPLATE_REMOVE_FILTERS": True, # deprecated From bd97de73721c853751f706d72cddc849ca7c59db Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Mon, 20 Nov 2023 17:43:44 -0700 Subject: [PATCH 13/31] more linting?! --- superset/config.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/superset/config.py b/superset/config.py index c4776143dda2..dc4709e94219 100644 --- a/superset/config.py +++ b/superset/config.py @@ -1429,7 +1429,12 @@ def EMAIL_HEADER_MUTATOR( # pylint: disable=invalid-name,unused-argument TALISMAN_CONFIG = { "content_security_policy": { "default-src": ["'self'"], - "img-src": ["'self'", "blob:", "data:", "https://apachesuperset.gateway.scarf.sh"], + "img-src": [ + "'self'", + "blob:", + "data:", + "https://apachesuperset.gateway.scarf.sh", + ], "worker-src": ["'self'", "blob:"], "connect-src": [ "'self'", @@ -1451,7 +1456,12 @@ def EMAIL_HEADER_MUTATOR( # pylint: disable=invalid-name,unused-argument TALISMAN_DEV_CONFIG = { "content_security_policy": { "default-src": ["'self'"], - "img-src": ["'self'", "blob:", "data:", "https://apachesuperset.gateway.scarf.sh"], + "img-src": [ + "'self'", + "blob:", + "data:", + "https://apachesuperset.gateway.scarf.sh", + ], "worker-src": ["'self'", "blob:"], "connect-src": [ "'self'", From f4292e3d8e4f224d12d3a593ce9766fa1daefc12 Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Mon, 27 Nov 2023 10:18:43 -0700 Subject: [PATCH 14/31] fixing linting, adding docstrings --- .../src/components/TelemetryPixel/index.tsx | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/superset-frontend/src/components/TelemetryPixel/index.tsx b/superset-frontend/src/components/TelemetryPixel/index.tsx index c9c3a55dbbbc..2ab9496d8622 100644 --- a/superset-frontend/src/components/TelemetryPixel/index.tsx +++ b/superset-frontend/src/components/TelemetryPixel/index.tsx @@ -26,11 +26,22 @@ interface TelemetryPixelProps { build?: string; } -const TelemetryPixel = ({ = +/** + * Renders a telemetry pixel component to capture anonymous, agregated telemetry via Scarf. + * This can be disabled with the ENABLE_TELEMETRY feature flag + * + * @component + * @param {TelemetryPixelProps} props - The props for the TelemetryPixel component. + * @param {string} props.version - The version of Superset that's currently in use. + * @param {string} props.sha - The SHA of Superset that's currently in use. + * @param {string} props.build - The build of Superset that's currently in use. + * @returns {JSX.Element | null} The rendered TelemetryPixel component. + */ +const TelemetryPixel = ({ version = 'unknownVersion', sha = 'unknownSHA', - build = 'unknownBuild' -}: TelemetryPixelProps) => { + build = 'unknownBuild', +}: TelemetryPixelProps): JSX.Element | null => { const pixelId = '0d3461e1-abb1-4691-a0aa-5ed50de66af0'; const pixelPath = `https://apachesuperset.gateway.scarf.sh/pixel/${pixelId}/${version}/${sha}/${build}`; return isFeatureEnabled(FeatureFlag.ENABLE_TELEMETRY) ? ( From 2fabe99f4cbb9c2c99be25e2db3cca1ee0ae25b6 Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Mon, 27 Nov 2023 10:40:16 -0700 Subject: [PATCH 15/31] hide the darn image --- superset-frontend/src/components/TelemetryPixel/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/src/components/TelemetryPixel/index.tsx b/superset-frontend/src/components/TelemetryPixel/index.tsx index 2ab9496d8622..93a165f7b426 100644 --- a/superset-frontend/src/components/TelemetryPixel/index.tsx +++ b/superset-frontend/src/components/TelemetryPixel/index.tsx @@ -46,7 +46,7 @@ const TelemetryPixel = ({ const pixelPath = `https://apachesuperset.gateway.scarf.sh/pixel/${pixelId}/${version}/${sha}/${build}`; return isFeatureEnabled(FeatureFlag.ENABLE_TELEMETRY) ? ( // eslint-disable-next-line jsx-a11y/alt-text - + ) : null; }; export default TelemetryPixel; From e08ef7739fcd0c4d435e53e5d6e78163aa4dc893 Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Mon, 27 Nov 2023 10:57:59 -0700 Subject: [PATCH 16/31] linting --- superset-frontend/src/components/TelemetryPixel/index.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/superset-frontend/src/components/TelemetryPixel/index.tsx b/superset-frontend/src/components/TelemetryPixel/index.tsx index 93a165f7b426..5b43ba9cd543 100644 --- a/superset-frontend/src/components/TelemetryPixel/index.tsx +++ b/superset-frontend/src/components/TelemetryPixel/index.tsx @@ -46,7 +46,12 @@ const TelemetryPixel = ({ const pixelPath = `https://apachesuperset.gateway.scarf.sh/pixel/${pixelId}/${version}/${sha}/${build}`; return isFeatureEnabled(FeatureFlag.ENABLE_TELEMETRY) ? ( // eslint-disable-next-line jsx-a11y/alt-text - + ) : null; }; export default TelemetryPixel; From a8e3bf9a1282b7e616089047a05c479952516cf2 Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Mon, 27 Nov 2023 14:05:39 -0700 Subject: [PATCH 17/31] fixing RTL tests --- .../components/TelemetryPixel/TelemetryPixel.test.tsx | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/superset-frontend/src/components/TelemetryPixel/TelemetryPixel.test.tsx b/superset-frontend/src/components/TelemetryPixel/TelemetryPixel.test.tsx index 96445624c161..576c5c22da6c 100644 --- a/superset-frontend/src/components/TelemetryPixel/TelemetryPixel.test.tsx +++ b/superset-frontend/src/components/TelemetryPixel/TelemetryPixel.test.tsx @@ -17,7 +17,7 @@ * under the License. */ import React from 'react'; -import { render, screen } from 'spec/helpers/testing-library'; +import { render } from 'spec/helpers/testing-library'; import { FeatureFlag } from '@superset-ui/core'; import TelemetryPixel from '.'; @@ -31,7 +31,9 @@ test('should render the pixel link when FF is on', () => { [FeatureFlag.ENABLE_TELEMETRY]: true, }; render(); - expect(screen.getByText('scarf.sh')).toBeInTheDocument(); + + const image = document.querySelector('img[src*="scarf.sh"]'); + expect(image).toBeInTheDocument(); }); test('should NOT render the pixel link when FF is off', () => { @@ -39,5 +41,7 @@ test('should NOT render the pixel link when FF is off', () => { [FeatureFlag.ENABLE_TELEMETRY]: false, }; render(); - expect(screen.getByText('scarf.sh')).not.toBeInTheDocument(); + + const image = document.querySelector('img[src*="scarf.sh"]'); + expect(image).not.toBeInTheDocument(); }); From 64a60357f6176103ce38a17cc35b645f64d51eeb Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Tue, 28 Nov 2023 11:59:00 -0700 Subject: [PATCH 18/31] questionable shim update --- superset-frontend/spec/helpers/shim.tsx | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/superset-frontend/spec/helpers/shim.tsx b/superset-frontend/spec/helpers/shim.tsx index 152fcc370cfc..1913b5654658 100644 --- a/superset-frontend/spec/helpers/shim.tsx +++ b/superset-frontend/spec/helpers/shim.tsx @@ -48,15 +48,17 @@ if (defaultView != null) { } const g = global as any; -g.window = g.window || {}; -g.window.location = { href: 'about:blank' }; -g.window.performance = { now: () => new Date().getTime() }; -g.window.Worker = Worker; -g.window.IntersectionObserver = IntersectionObserver; -g.window.ResizeObserver = ResizeObserver; -g.window.featureFlags = {}; -g.URL.createObjectURL = () => ''; -g.caches = new CacheStorage(); +if (typeof window == 'undefined') { + g.window = {}; + g.window.location = { href: 'about:blank' }; + g.window.performance = { now: () => new Date().getTime() }; + g.window.Worker = Worker; + g.window.IntersectionObserver = IntersectionObserver; + g.window.ResizeObserver = ResizeObserver; + g.window.featureFlags = {}; + g.URL.createObjectURL = () => ''; + g.caches = new CacheStorage(); +} Object.defineProperty(window, 'matchMedia', { writable: true, From 766e2dd588702e5d5f30d2cacd31438a9948cc95 Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Tue, 28 Nov 2023 11:59:20 -0700 Subject: [PATCH 19/31] making tests pass - but how are they not failing everywhere? --- superset-frontend/src/features/home/RightMenu.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/src/features/home/RightMenu.tsx b/superset-frontend/src/features/home/RightMenu.tsx index caf937e30a19..48dec48cb463 100644 --- a/superset-frontend/src/features/home/RightMenu.tsx +++ b/superset-frontend/src/features/home/RightMenu.tsx @@ -211,7 +211,7 @@ const RightMenu = ({ }, { label: t('SQL query'), - url: '/superset/sqllab?new=true', + url: '/sqllab?new=true', icon: 'fa-fw fa-search', perm: 'can_sqllab', view: 'Superset', From c7995c3a4384f3247b957820bc3edf9a4b5dfd6d Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Tue, 28 Nov 2023 12:13:35 -0700 Subject: [PATCH 20/31] linting the shim fix --- superset-frontend/spec/helpers/shim.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/spec/helpers/shim.tsx b/superset-frontend/spec/helpers/shim.tsx index 1913b5654658..810df292a05a 100644 --- a/superset-frontend/spec/helpers/shim.tsx +++ b/superset-frontend/spec/helpers/shim.tsx @@ -48,7 +48,7 @@ if (defaultView != null) { } const g = global as any; -if (typeof window == 'undefined') { +if (typeof window === 'undefined') { g.window = {}; g.window.location = { href: 'about:blank' }; g.window.performance = { now: () => new Date().getTime() }; From 9e7a8daaecf48663fa98efe76f20c1cc5db23b2a Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Tue, 28 Nov 2023 13:16:52 -0700 Subject: [PATCH 21/31] =?UTF-8?q?restoring=20shim=20=C2=AF\=5F(=E3=83=84)?= =?UTF-8?q?=5F/=C2=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- superset-frontend/spec/helpers/shim.tsx | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/superset-frontend/spec/helpers/shim.tsx b/superset-frontend/spec/helpers/shim.tsx index 810df292a05a..152fcc370cfc 100644 --- a/superset-frontend/spec/helpers/shim.tsx +++ b/superset-frontend/spec/helpers/shim.tsx @@ -48,17 +48,15 @@ if (defaultView != null) { } const g = global as any; -if (typeof window === 'undefined') { - g.window = {}; - g.window.location = { href: 'about:blank' }; - g.window.performance = { now: () => new Date().getTime() }; - g.window.Worker = Worker; - g.window.IntersectionObserver = IntersectionObserver; - g.window.ResizeObserver = ResizeObserver; - g.window.featureFlags = {}; - g.URL.createObjectURL = () => ''; - g.caches = new CacheStorage(); -} +g.window = g.window || {}; +g.window.location = { href: 'about:blank' }; +g.window.performance = { now: () => new Date().getTime() }; +g.window.Worker = Worker; +g.window.IntersectionObserver = IntersectionObserver; +g.window.ResizeObserver = ResizeObserver; +g.window.featureFlags = {}; +g.URL.createObjectURL = () => ''; +g.caches = new CacheStorage(); Object.defineProperty(window, 'matchMedia', { writable: true, From 925ef36d8f91d3302405bda80094f0bb4d701b51 Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Thu, 30 Nov 2023 12:08:58 -0700 Subject: [PATCH 22/31] =?UTF-8?q?John=20=E2=9D=A4=EF=B8=8F=20JS?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- superset-frontend/src/features/home/RightMenu.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/src/features/home/RightMenu.tsx b/superset-frontend/src/features/home/RightMenu.tsx index 48dec48cb463..a37214b66bb0 100644 --- a/superset-frontend/src/features/home/RightMenu.tsx +++ b/superset-frontend/src/features/home/RightMenu.tsx @@ -475,7 +475,7 @@ const RightMenu = ({ {navbarRight.user_profile_url && ( - {t('Profile')} + {t('Profile')} )} {navbarRight.user_info_url && ( From 2e3a76458085778ac00d48ea8c2032831bc6778e Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Thu, 30 Nov 2023 12:12:05 -0700 Subject: [PATCH 23/31] fixing the window shim so it runs on problematic node versions --- superset-frontend/spec/helpers/shim.tsx | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/superset-frontend/spec/helpers/shim.tsx b/superset-frontend/spec/helpers/shim.tsx index 152fcc370cfc..23dd0024b903 100644 --- a/superset-frontend/spec/helpers/shim.tsx +++ b/superset-frontend/spec/helpers/shim.tsx @@ -48,15 +48,15 @@ if (defaultView != null) { } const g = global as any; -g.window = g.window || {}; -g.window.location = { href: 'about:blank' }; -g.window.performance = { now: () => new Date().getTime() }; -g.window.Worker = Worker; -g.window.IntersectionObserver = IntersectionObserver; -g.window.ResizeObserver = ResizeObserver; -g.window.featureFlags = {}; -g.URL.createObjectURL = () => ''; -g.caches = new CacheStorage(); +g.window ??= Object.create(window); +g.window.location ??= { href: 'about:blank' }; +g.window.performance ??= { now: () => new Date().getTime() }; +g.window.Worker ??= Worker; +g.window.IntersectionObserver ??= IntersectionObserver; +g.window.ResizeObserver ??= ResizeObserver; +g.window.featureFlags ??= {}; +g.URL.createObjectURL ??= () => ''; +g.caches ??= new CacheStorage(); Object.defineProperty(window, 'matchMedia', { writable: true, From 920bf8a35c8efcf7a688d2066367013d1a6eff1b Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Thu, 30 Nov 2023 14:49:18 -0700 Subject: [PATCH 24/31] c'mon, tests! --- superset-frontend/spec/helpers/shim.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superset-frontend/spec/helpers/shim.tsx b/superset-frontend/spec/helpers/shim.tsx index 23dd0024b903..8270c5631718 100644 --- a/superset-frontend/spec/helpers/shim.tsx +++ b/superset-frontend/spec/helpers/shim.tsx @@ -56,7 +56,7 @@ g.window.IntersectionObserver ??= IntersectionObserver; g.window.ResizeObserver ??= ResizeObserver; g.window.featureFlags ??= {}; g.URL.createObjectURL ??= () => ''; -g.caches ??= new CacheStorage(); +g.caches = new CacheStorage(); Object.defineProperty(window, 'matchMedia', { writable: true, From cb606ab4c0dc2391bf81a4d1674074163a3d3d80 Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Mon, 11 Dec 2023 14:46:41 -0700 Subject: [PATCH 25/31] Now using env var rather than a feature flag --- RESOURCES/FEATURE_FLAGS.md | 1 - docker-compose.yml | 2 + .../TelemetryPixel/TelemetryPixel.test.tsx | 45 ++++++++++--------- .../src/components/TelemetryPixel/index.tsx | 23 ++++++---- superset-frontend/webpack.config.js | 1 + superset/config.py | 5 +-- 6 files changed, 45 insertions(+), 32 deletions(-) diff --git a/RESOURCES/FEATURE_FLAGS.md b/RESOURCES/FEATURE_FLAGS.md index e271c8894a1a..d029ca6c3cbd 100644 --- a/RESOURCES/FEATURE_FLAGS.md +++ b/RESOURCES/FEATURE_FLAGS.md @@ -72,7 +72,6 @@ These features flags are **safe for production**. They have been tested and will - DRUID_JOINS - EMBEDDABLE_CHARTS - EMBEDDED_SUPERSET -- ENABLE_TELEMETRY - ENABLE_TEMPLATE_PROCESSING - ESCAPE_MARKDOWN_HTML - LISTVIEWS_DEFAULT_CARD_VIEW diff --git a/docker-compose.yml b/docker-compose.yml index b2c9196b0098..a2dfc26dba40 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -124,6 +124,8 @@ services: command: ["/app/docker/docker-frontend.sh"] env_file: docker/.env depends_on: *superset-depends-on + environment: + SCARF_ANALYTICS: "${SCARF_ANALYTICS}" volumes: *superset-volumes superset-worker: diff --git a/superset-frontend/src/components/TelemetryPixel/TelemetryPixel.test.tsx b/superset-frontend/src/components/TelemetryPixel/TelemetryPixel.test.tsx index 576c5c22da6c..7e6477971419 100644 --- a/superset-frontend/src/components/TelemetryPixel/TelemetryPixel.test.tsx +++ b/superset-frontend/src/components/TelemetryPixel/TelemetryPixel.test.tsx @@ -18,30 +18,35 @@ */ import React from 'react'; import { render } from 'spec/helpers/testing-library'; -import { FeatureFlag } from '@superset-ui/core'; import TelemetryPixel from '.'; -test('should render', () => { - const { container } = render(); - expect(container).toBeInTheDocument(); -}); +describe('environmental variables', () => { + const OLD_ENV = process.env; -test('should render the pixel link when FF is on', () => { - window.featureFlags = { - [FeatureFlag.ENABLE_TELEMETRY]: true, - }; - render(); + // restor the process after messing with it! + afterAll(() => { + process.env = OLD_ENV; + }); - const image = document.querySelector('img[src*="scarf.sh"]'); - expect(image).toBeInTheDocument(); -}); + test('should render', () => { + const { container } = render(); + expect(container).toBeInTheDocument(); + }); + + test('should render the pixel link when FF is on', () => { + process.env.SCARF_ANALYTICS = 'true'; + render(); + + const image = document.querySelector('img[src*="scarf.sh"]'); + expect(image).toBeInTheDocument(); + }); + + test('should NOT render the pixel link when FF is off', () => { + process.env.SCARF_ANALYTICS = 'false'; + render(); -test('should NOT render the pixel link when FF is off', () => { - window.featureFlags = { - [FeatureFlag.ENABLE_TELEMETRY]: false, - }; - render(); + const image = document.querySelector('img[src*="scarf.sh"]'); + expect(image).not.toBeInTheDocument(); + }); - const image = document.querySelector('img[src*="scarf.sh"]'); - expect(image).not.toBeInTheDocument(); }); diff --git a/superset-frontend/src/components/TelemetryPixel/index.tsx b/superset-frontend/src/components/TelemetryPixel/index.tsx index 5b43ba9cd543..cc3876e6d75a 100644 --- a/superset-frontend/src/components/TelemetryPixel/index.tsx +++ b/superset-frontend/src/components/TelemetryPixel/index.tsx @@ -18,7 +18,6 @@ */ import React from 'react'; -import { isFeatureEnabled, FeatureFlag } from '@superset-ui/core'; interface TelemetryPixelProps { version?: string; @@ -27,8 +26,8 @@ interface TelemetryPixelProps { } /** - * Renders a telemetry pixel component to capture anonymous, agregated telemetry via Scarf. - * This can be disabled with the ENABLE_TELEMETRY feature flag + * Renders a telemetry pixel component to capture anonymous, aggregated telemetry via Scarf. + * This can be disabled by setting the SCARF_ANALYTICS environment variable to false. * * @component * @param {TelemetryPixelProps} props - The props for the TelemetryPixel component. @@ -37,20 +36,28 @@ interface TelemetryPixelProps { * @param {string} props.build - The build of Superset that's currently in use. * @returns {JSX.Element | null} The rendered TelemetryPixel component. */ + const TelemetryPixel = ({ version = 'unknownVersion', sha = 'unknownSHA', build = 'unknownBuild', -}: TelemetryPixelProps): JSX.Element | null => { +}: TelemetryPixelProps): React.ReactElement | null => { const pixelId = '0d3461e1-abb1-4691-a0aa-5ed50de66af0'; const pixelPath = `https://apachesuperset.gateway.scarf.sh/pixel/${pixelId}/${version}/${sha}/${build}`; - return isFeatureEnabled(FeatureFlag.ENABLE_TELEMETRY) ? ( - // eslint-disable-next-line jsx-a11y/alt-text + + console.warn( + 'scarf', + process.env.SCARF_ANALYTICS, + typeof process.env.SCARF_ANALYTICS, + ); + + return JSON.stringify(process.env.SCARF_ANALYTICS) !== 'false' ? ( ) : null; }; diff --git a/superset-frontend/webpack.config.js b/superset-frontend/webpack.config.js index dea99be2cffe..6b1753009a0a 100644 --- a/superset-frontend/webpack.config.js +++ b/superset-frontend/webpack.config.js @@ -117,6 +117,7 @@ const plugins = [ 'process.env.WEBPACK_MODE': JSON.stringify(mode), 'process.env.REDUX_DEFAULT_MIDDLEWARE': process.env.REDUX_DEFAULT_MIDDLEWARE, + 'process.env.SCARF_ANALYTICS': process.env.SCARF_ANALYTICS, }), new CopyPlugin({ diff --git a/superset/config.py b/superset/config.py index dc4709e94219..6819ec8f10fa 100644 --- a/superset/config.py +++ b/superset/config.py @@ -420,9 +420,6 @@ class D3Format(TypedDict, total=False): # make GET request to explore_json. explore_json accepts both GET and POST request. # See `PR 7935 `_ for more details. "ENABLE_EXPLORE_JSON_CSRF_PROTECTION": False, # deprecated - # Enables telemetry using Scarf.sh (to help measure Superset's adoption of patches - # and the impact security concerns or other issues might have on the community) - "ENABLE_TELEMETRY": True, "ENABLE_TEMPLATE_PROCESSING": False, "ENABLE_TEMPLATE_REMOVE_FILTERS": True, # deprecated # Allow for javascript controls components @@ -1434,6 +1431,7 @@ def EMAIL_HEADER_MUTATOR( # pylint: disable=invalid-name,unused-argument "blob:", "data:", "https://apachesuperset.gateway.scarf.sh", + "https://static.scarf.sh/", ], "worker-src": ["'self'", "blob:"], "connect-src": [ @@ -1461,6 +1459,7 @@ def EMAIL_HEADER_MUTATOR( # pylint: disable=invalid-name,unused-argument "blob:", "data:", "https://apachesuperset.gateway.scarf.sh", + "https://static.scarf.sh/", ], "worker-src": ["'self'", "blob:"], "connect-src": [ From 96589f049d85bbb5c2b49d85611ca2bd832b8fda Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Mon, 11 Dec 2023 14:53:18 -0700 Subject: [PATCH 26/31] cleaning up... --- .../src/utils/featureFlags.ts | 1 - .../TelemetryPixel/TelemetryPixel.test.tsx | 43 +++++++++---------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/superset-frontend/packages/superset-ui-core/src/utils/featureFlags.ts b/superset-frontend/packages/superset-ui-core/src/utils/featureFlags.ts index e13e06d9f04e..6bc77e0e87a1 100644 --- a/superset-frontend/packages/superset-ui-core/src/utils/featureFlags.ts +++ b/superset-frontend/packages/superset-ui-core/src/utils/featureFlags.ts @@ -44,7 +44,6 @@ export enum FeatureFlag { ENABLE_ADVANCED_DATA_TYPES = 'ENABLE_ADVANCED_DATA_TYPES', ENABLE_EXPLORE_DRAG_AND_DROP = 'ENABLE_EXPLORE_DRAG_AND_DROP', ENABLE_JAVASCRIPT_CONTROLS = 'ENABLE_JAVASCRIPT_CONTROLS', - ENABLE_TELEMETRY = 'ENABLE_TELEMETRY', ENABLE_TEMPLATE_PROCESSING = 'ENABLE_TEMPLATE_PROCESSING', ENABLE_TEMPLATE_REMOVE_FILTERS = 'ENABLE_TEMPLATE_REMOVE_FILTERS', ESCAPE_MARKDOWN_HTML = 'ESCAPE_MARKDOWN_HTML', diff --git a/superset-frontend/src/components/TelemetryPixel/TelemetryPixel.test.tsx b/superset-frontend/src/components/TelemetryPixel/TelemetryPixel.test.tsx index 7e6477971419..4e3b3c9332f8 100644 --- a/superset-frontend/src/components/TelemetryPixel/TelemetryPixel.test.tsx +++ b/superset-frontend/src/components/TelemetryPixel/TelemetryPixel.test.tsx @@ -20,33 +20,30 @@ import React from 'react'; import { render } from 'spec/helpers/testing-library'; import TelemetryPixel from '.'; -describe('environmental variables', () => { - const OLD_ENV = process.env; +const OLD_ENV = process.env; - // restor the process after messing with it! - afterAll(() => { - process.env = OLD_ENV; - }); - - test('should render', () => { - const { container } = render(); - expect(container).toBeInTheDocument(); - }); +// restor the process after messing with it! +afterAll(() => { + process.env = OLD_ENV; +}); - test('should render the pixel link when FF is on', () => { - process.env.SCARF_ANALYTICS = 'true'; - render(); +test('should render', () => { + const { container } = render(); + expect(container).toBeInTheDocument(); +}); - const image = document.querySelector('img[src*="scarf.sh"]'); - expect(image).toBeInTheDocument(); - }); +test('should render the pixel link when FF is on', () => { + process.env.SCARF_ANALYTICS = 'true'; + render(); - test('should NOT render the pixel link when FF is off', () => { - process.env.SCARF_ANALYTICS = 'false'; - render(); + const image = document.querySelector('img[src*="scarf.sh"]'); + expect(image).toBeInTheDocument(); +}); - const image = document.querySelector('img[src*="scarf.sh"]'); - expect(image).not.toBeInTheDocument(); - }); +test('should NOT render the pixel link when FF is off', () => { + process.env.SCARF_ANALYTICS = 'false'; + render(); + const image = document.querySelector('img[src*="scarf.sh"]'); + expect(image).not.toBeInTheDocument(); }); From a3b91cd6706860322135d30bb9e721724f069e8f Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Mon, 11 Dec 2023 14:54:43 -0700 Subject: [PATCH 27/31] moving const --- superset-frontend/src/components/TelemetryPixel/index.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/components/TelemetryPixel/index.tsx b/superset-frontend/src/components/TelemetryPixel/index.tsx index cc3876e6d75a..660a6dd7ffd6 100644 --- a/superset-frontend/src/components/TelemetryPixel/index.tsx +++ b/superset-frontend/src/components/TelemetryPixel/index.tsx @@ -37,13 +37,14 @@ interface TelemetryPixelProps { * @returns {JSX.Element | null} The rendered TelemetryPixel component. */ +const PIXEL_ID = '0d3461e1-abb1-4691-a0aa-5ed50de66af0'; + const TelemetryPixel = ({ version = 'unknownVersion', sha = 'unknownSHA', build = 'unknownBuild', }: TelemetryPixelProps): React.ReactElement | null => { - const pixelId = '0d3461e1-abb1-4691-a0aa-5ed50de66af0'; - const pixelPath = `https://apachesuperset.gateway.scarf.sh/pixel/${pixelId}/${version}/${sha}/${build}`; + const pixelPath = `https://apachesuperset.gateway.scarf.sh/pixel/${PIXEL_ID}/${version}/${sha}/${build}`; console.warn( 'scarf', From d2b935552b3667fc75ffe05934f96b4b4fa67202 Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Mon, 11 Dec 2023 15:05:24 -0700 Subject: [PATCH 28/31] Improved docs --- CONTRIBUTING.md | 2 +- docs/docs/frequently-asked-questions.mdx | 6 ++++-- .../installing-superset-using-docker-compose.mdx | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a955f123dbf5..d96fcbfca267 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -622,7 +622,7 @@ cd superset-frontend npm ci ``` -Note that Superset uses [Scarf](https://docs.scarf.sh) to capture telemetry/analytics about versions being installed, including the `scarf-js` npm package. As noted elsewhere in this documentation, Scarf gathers aggregated stats for the sake of security/release strategy, and does not capture/retain PII. [You can read here](https://docs.scarf.sh/package-analytics/) about the package, and various means to opt out of it, but one easy way to opt out is to add this setting in `superset-frontent/package.json`: +Note that Superset uses [Scarf](https://docs.scarf.sh) to capture telemetry/analytics about versions being installed, including the `scarf-js` npm package and an analytics pixel. As noted elsewhere in this documentation, Scarf gathers aggregated stats for the sake of security/release strategy, and does not capture/retain PII. [You can read here](https://docs.scarf.sh/package-analytics/) about the `scarf-js` package, and various means to opt out of it, but you can opt out of the npm package _and_ the pixel by setting the `SCARF_ANALYTICS` envinronment variable to `false` or opt out of the pixel by adding this setting in `superset-frontent/package.json`: ```json // your-package/package.json diff --git a/docs/docs/frequently-asked-questions.mdx b/docs/docs/frequently-asked-questions.mdx index df4ee7a44251..e370c599610a 100644 --- a/docs/docs/frequently-asked-questions.mdx +++ b/docs/docs/frequently-asked-questions.mdx @@ -268,8 +268,10 @@ This can be used, for example, to convert UTC time to local time. ### Does Superset collect any telemetry data? Superset uses [Scarf](https://about.scarf.sh/) by default to collect basic telemetry data upon installing and/or running Superset. This data helps the maintainers of Superset better understand which versions of Superset are being used, in order to prioritize patch/minor releases and security fixes. -We use the [Scarf Gateway](https://docs.scarf.sh/gateway/) to sit in front of container registries, and the [scarf-js](https://about.scarf.sh/package-sdks) package to track `npm` installations. -Scarf purges PII and provides aggregated statistics. Superset users can easily opt out of analytics in various ways documented [here](https://docs.scarf.sh/gateway/#do-not-track) and [here](https://docs.scarf.sh/package-analytics/#as-a-user-of-a-package-using-scarf-js-how-can-i-opt-out-of-analytics). Additional opt-out instructions for Docker users are available on the [Docker Installation](https://superset.apache.org/docs/installation/installing-superset-using-docker-compose) page. +We use the [Scarf Gateway](https://docs.scarf.sh/gateway/) to sit in front of container registries, the [scarf-js](https://about.scarf.sh/package-sdks) package to track `npm` installations, and a Scarf pixel to gather anonymous analytics on Superset page views. +Scarf purges PII and provides aggregated statistics. Superset users can easily opt out of analytics in various ways documented [here](https://docs.scarf.sh/gateway/#do-not-track) and [here](https://docs.scarf.sh/package-analytics/#as-a-user-of-a-package-using-scarf-js-how-can-i-opt-out-of-analytics). +Superset maintainers can also opt out of telemetry data collection by setting the `SCARF_ANALYTICS` environment variable to `false` in the Superset container (or anywhere Superset/webpack are run). +Additional opt-out instructions for Docker users are available on the [Docker Installation](https://superset.apache.org/docs/installation/installing-superset-using-docker-compose) page. ### Does Superset have an archive panel or trash bin from which a user can recover deleted assets? diff --git a/docs/docs/installation/installing-superset-using-docker-compose.mdx b/docs/docs/installation/installing-superset-using-docker-compose.mdx index 4611466ca30f..7b6d9757398c 100644 --- a/docs/docs/installation/installing-superset-using-docker-compose.mdx +++ b/docs/docs/installation/installing-superset-using-docker-compose.mdx @@ -124,7 +124,9 @@ Users often want to connect to other databases from Superset. Currently, the eas :::note Superset uses [Scarf Gateway](https://about.scarf.sh/scarf-gateway) to collect telemetry data. Knowing the installation counts for different Superset versions informs the project's decisions about patching and long-term support. Scarf purges personally identifiable information (PII) and provides only aggregated statistics. -To opt-out of this data collection in your docker compose based installation, edit the `x-superset-image:` line in your `docker-compose.yml` and `docker-compose-non-dev.yml` files, replacing `apachesuperset.docker.scarf.sh/apache/superset` with `apache/superset` to pull the image directly from Docker Hub. +To opt-out of this data collection for packages downloaded through the Scarf Gateway by your docker compose based installation, edit the `x-superset-image:` line in your `docker-compose.yml` and `docker-compose-non-dev.yml` files, replacing `apachesuperset.docker.scarf.sh/apache/superset` with `apache/superset` to pull the image directly from Docker Hub. + +To disable the Scarf telemetry pixel, set the `SCARF_ANALYTICS` environment variable to `False` in your terminal and/or in your `docker/.env` and `docker/.env-non-dev` files. ::: ### 4. Log in to Superset From 3f3751f6fa580e130ad8dbc5d7e6450916e57720 Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Mon, 11 Dec 2023 15:10:57 -0700 Subject: [PATCH 29/31] lint --- docs/docs/frequently-asked-questions.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/frequently-asked-questions.mdx b/docs/docs/frequently-asked-questions.mdx index e370c599610a..954c0f86c34c 100644 --- a/docs/docs/frequently-asked-questions.mdx +++ b/docs/docs/frequently-asked-questions.mdx @@ -269,7 +269,7 @@ This can be used, for example, to convert UTC time to local time. Superset uses [Scarf](https://about.scarf.sh/) by default to collect basic telemetry data upon installing and/or running Superset. This data helps the maintainers of Superset better understand which versions of Superset are being used, in order to prioritize patch/minor releases and security fixes. We use the [Scarf Gateway](https://docs.scarf.sh/gateway/) to sit in front of container registries, the [scarf-js](https://about.scarf.sh/package-sdks) package to track `npm` installations, and a Scarf pixel to gather anonymous analytics on Superset page views. -Scarf purges PII and provides aggregated statistics. Superset users can easily opt out of analytics in various ways documented [here](https://docs.scarf.sh/gateway/#do-not-track) and [here](https://docs.scarf.sh/package-analytics/#as-a-user-of-a-package-using-scarf-js-how-can-i-opt-out-of-analytics). +Scarf purges PII and provides aggregated statistics. Superset users can easily opt out of analytics in various ways documented [here](https://docs.scarf.sh/gateway/#do-not-track) and [here](https://docs.scarf.sh/package-analytics/#as-a-user-of-a-package-using-scarf-js-how-can-i-opt-out-of-analytics). Superset maintainers can also opt out of telemetry data collection by setting the `SCARF_ANALYTICS` environment variable to `false` in the Superset container (or anywhere Superset/webpack are run). Additional opt-out instructions for Docker users are available on the [Docker Installation](https://superset.apache.org/docs/installation/installing-superset-using-docker-compose) page. From 352256e9bdb229b2ee77331c69b9b4a2f562953e Mon Sep 17 00:00:00 2001 From: Evan Rusackas Date: Wed, 13 Dec 2023 16:14:47 -0700 Subject: [PATCH 30/31] tests should pass now (and the pixel should hide) whether the env var comes through as a string or a boolean. --- superset-frontend/src/components/TelemetryPixel/index.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/superset-frontend/src/components/TelemetryPixel/index.tsx b/superset-frontend/src/components/TelemetryPixel/index.tsx index 660a6dd7ffd6..c73e7247510c 100644 --- a/superset-frontend/src/components/TelemetryPixel/index.tsx +++ b/superset-frontend/src/components/TelemetryPixel/index.tsx @@ -52,7 +52,8 @@ const TelemetryPixel = ({ typeof process.env.SCARF_ANALYTICS, ); - return JSON.stringify(process.env.SCARF_ANALYTICS) !== 'false' ? ( + return process.env.SCARF_ANALYTICS === 'false' || + process.env.SCARF_ANALYTICS === 'false' ? null : ( - ) : null; + ); }; export default TelemetryPixel; From f5fae76c0566bc89dc65d5eb5cf20d3928e30ceb Mon Sep 17 00:00:00 2001 From: "Michael S. Molina" <70410625+michael-s-molina@users.noreply.github.com> Date: Thu, 14 Dec 2023 14:21:35 -0300 Subject: [PATCH 31/31] Removes console warning --- superset-frontend/src/components/TelemetryPixel/index.tsx | 7 ------- 1 file changed, 7 deletions(-) diff --git a/superset-frontend/src/components/TelemetryPixel/index.tsx b/superset-frontend/src/components/TelemetryPixel/index.tsx index c73e7247510c..6bfe1d20b9a3 100644 --- a/superset-frontend/src/components/TelemetryPixel/index.tsx +++ b/superset-frontend/src/components/TelemetryPixel/index.tsx @@ -45,13 +45,6 @@ const TelemetryPixel = ({ build = 'unknownBuild', }: TelemetryPixelProps): React.ReactElement | null => { const pixelPath = `https://apachesuperset.gateway.scarf.sh/pixel/${PIXEL_ID}/${version}/${sha}/${build}`; - - console.warn( - 'scarf', - process.env.SCARF_ANALYTICS, - typeof process.env.SCARF_ANALYTICS, - ); - return process.env.SCARF_ANALYTICS === 'false' || process.env.SCARF_ANALYTICS === 'false' ? null : (