Skip to content

Commit

Permalink
fix(@cubejs-client/playground): telemetry (#2727)
Browse files Browse the repository at this point in the history
  • Loading branch information
vasilev-alex committed May 13, 2021
1 parent d472bcd commit 366435a
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions packages/cubejs-backend-shared/src/env.ts
Expand Up @@ -241,6 +241,9 @@ const variables: Record<string, (...args: any) => any> = {
livePreview: () => get('CUBEJS_LIVE_PREVIEW')
.default('false')
.asBoolStrict(),
telemetry: () => get('CUBEJS_TELEMETRY')
.default('true')
.asBoolStrict(),
};

type Vars = typeof variables;
Expand Down
4 changes: 3 additions & 1 deletion packages/cubejs-playground/src/App.tsx
Expand Up @@ -8,7 +8,7 @@ import { RouteComponentProps, withRouter } from 'react-router';
import Header from './components/Header';
import GlobalStyles from './components/GlobalStyles';
import { CubeLoader } from './atoms';
import { event, setAnonymousId } from './events';
import { event, setAnonymousId, setTelemetry } from './events';
import './index.less';

const selectedTab = (pathname) => {
Expand Down Expand Up @@ -52,6 +52,8 @@ class App extends Component<RouteComponentProps, TAppState> {

const res = await fetch('/playground/context');
const context = await res.json();

setTelemetry(context.telemetry);
setAnonymousId(context.anonymousId, {
coreServerVersion: context.coreServerVersion,
projectFingerprint: context.projectFingerprint,
Expand Down
8 changes: 8 additions & 0 deletions packages/cubejs-playground/src/events.ts
Expand Up @@ -7,8 +7,15 @@ let trackEvents: BaseEvent[] = [];
let baseProps = {
sentFrom: 'frontend'
};
let telemetry: boolean | undefined;

export const setTelemetry = (isAllowed) => telemetry = isAllowed;

const track = async (event) => {
if (telemetry !== true) {
return;
}

if (!cookie('playground_anonymous')) {
cookie('playground_anonymous', uuidv4());
}
Expand Down Expand Up @@ -38,6 +45,7 @@ const track = async (event) => {
body: JSON.stringify(toFlush.map((r) => ({ ...r, sentAt }))),
headers: { 'Content-Type': 'application/json' },
});

if (result.status !== 200 && retries > 0) {
return flush(toFlush, retries - 1);
}
Expand Down
3 changes: 2 additions & 1 deletion packages/cubejs-playground/src/index.tsx
Expand Up @@ -16,7 +16,8 @@ import { SecurityContextProvider } from './components/SecurityContext/SecurityCo

const history = createHashHistory();
history.listen((location) => {
page(location);
const { search, ...props } = location;
page(props);
});

async function getToken(payload: string = '') {
Expand Down
3 changes: 2 additions & 1 deletion packages/cubejs-server-core/src/core/DevServer.ts
Expand Up @@ -82,7 +82,8 @@ export class DevServer {
projectFingerprint: this.cubejsServer.projectFingerprint,
shouldStartConnectionWizardFlow: !this.cubejsServer.configFileExists(),
livePreview: options.livePreview,
isDocker: isDocker()
isDocker: isDocker(),
telemetry: options.telemetry,
});
}));

Expand Down
2 changes: 1 addition & 1 deletion packages/cubejs-server-core/src/core/server.ts
Expand Up @@ -400,7 +400,7 @@ export class CubejsServerCore {
externalDriverFactory,
externalDialectFactory,
apiSecret: process.env.CUBEJS_API_SECRET,
telemetry: process.env.CUBEJS_TELEMETRY !== 'false',
telemetry: getEnv('telemetry'),
scheduledRefreshTimeZones: process.env.CUBEJS_SCHEDULED_REFRESH_TIMEZONES &&
process.env.CUBEJS_SCHEDULED_REFRESH_TIMEZONES.split(',').map(t => t.trim()),
scheduledRefreshContexts: async () => [null],
Expand Down

0 comments on commit 366435a

Please sign in to comment.