forked from apache/superset
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(telemetry): Adding Scarf based telemetry to Superset (apache#26011)
Co-authored-by: Michael S. Molina <[email protected]>
- Loading branch information
1 parent
67468c4
commit 8437a23
Showing
12 changed files
with
181 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
superset-frontend/src/components/TelemetryPixel/TelemetryPixel.test.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/** | ||
* 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 } from 'spec/helpers/testing-library'; | ||
import TelemetryPixel from '.'; | ||
|
||
const OLD_ENV = process.env; | ||
|
||
// restor the process after messing with it! | ||
afterAll(() => { | ||
process.env = OLD_ENV; | ||
}); | ||
|
||
test('should render', () => { | ||
const { container } = render(<TelemetryPixel />); | ||
expect(container).toBeInTheDocument(); | ||
}); | ||
|
||
test('should render the pixel link when FF is on', () => { | ||
process.env.SCARF_ANALYTICS = 'true'; | ||
render(<TelemetryPixel />); | ||
|
||
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(<TelemetryPixel />); | ||
|
||
const image = document.querySelector('img[src*="scarf.sh"]'); | ||
expect(image).not.toBeInTheDocument(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/** | ||
* 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'; | ||
|
||
interface TelemetryPixelProps { | ||
version?: string; | ||
sha?: string; | ||
build?: string; | ||
} | ||
|
||
/** | ||
* 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. | ||
* @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 PIXEL_ID = '0d3461e1-abb1-4691-a0aa-5ed50de66af0'; | ||
|
||
const TelemetryPixel = ({ | ||
version = 'unknownVersion', | ||
sha = 'unknownSHA', | ||
build = 'unknownBuild', | ||
}: TelemetryPixelProps): React.ReactElement | null => { | ||
const pixelPath = `https://apachesuperset.gateway.scarf.sh/pixel/${PIXEL_ID}/${version}/${sha}/${build}`; | ||
return process.env.SCARF_ANALYTICS === 'false' || | ||
process.env.SCARF_ANALYTICS === 'false' ? null : ( | ||
<img | ||
referrerPolicy="no-referrer-when-downgrade" | ||
src={pixelPath} | ||
width={0} | ||
height={0} | ||
alt="" | ||
/> | ||
); | ||
}; | ||
export default TelemetryPixel; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters