Skip to content

Commit

Permalink
Merge pull request #1431 from kubeshop/erdikose/fix/telemetry-updates
Browse files Browse the repository at this point in the history
chore: Telemetry reviews fixes
  • Loading branch information
erdkse authored Mar 4, 2022
2 parents a87f3b9 + 4840a26 commit ab0d0c3
Show file tree
Hide file tree
Showing 12 changed files with 48 additions and 40 deletions.
2 changes: 0 additions & 2 deletions electron/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,9 @@ const templatesDir = path.join(userDataDir, 'monokleTemplates');
const templatePacksDir = path.join(userDataDir, 'monokleTemplatePacks');
const APP_DEPENDENCIES = ['kubectl', 'helm', 'kustomize'];


let {disableErrorReports,disableTracking} = initNucleus(isDev, app);
unhandled({
logger: (error) => {
console.error(error);
if (!disableErrorReports) {
Nucleus.trackError((error && error.name) || 'Unnamed error', error);
}
Expand Down
2 changes: 1 addition & 1 deletion electron/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export function askActionConfirmation({
}

export const initNucleus = (isDev: boolean, app: any) => {
Nucleus.init('6218cf3ef5e5d2023724d89b', {
Nucleus.init(PROCESS_ENV.NUCLEUS_SH_APP_ID || '6218cf3ef5e5d2023724d89b', {
disableInDev: false,
disableTracking: Boolean(electronStore.get('appConfig.disableEventTracking')),
disableErrorReports: true,
Expand Down
31 changes: 15 additions & 16 deletions src/components/organisms/CreateProjectModal/CreateProjectModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import FileExplorer from '@components/atoms/FileExplorer';
import {useFileExplorer} from '@hooks/useFileExplorer';

import {useFocus} from '@utils/hooks';
import {trackEvent} from '@utils/telemetry';
import {CREATE_EMPTY_PROJECT, trackEvent} from '@utils/telemetry';

import Colors from '@styles/Colors';

Expand Down Expand Up @@ -105,7 +105,7 @@ const CreateProjectModal: React.FC = () => {
setFormStep(FormSteps.STEP_TWO);
}
if (!uiState.fromTemplate && values.rootFolder && values.name) {
trackEvent('CREATE_EMPTY_PROJECT');
trackEvent(CREATE_EMPTY_PROJECT);
dispatch(setCreateProject({...values}));
closeModal();
}
Expand Down Expand Up @@ -267,20 +267,19 @@ const CreateProjectModal: React.FC = () => {
<TemplateModal template={selectedTemplate} projectToCreate={formValues} onClose={onTemplateModalClose} />
)}

{Object.values(templateMap).sort((a,b) =>{
if(favoriteTemplates.includes(a.id))
return -1;
if(favoriteTemplates.includes(b.id))
return 1;
return 0;
}).map(template => (
<TemplateInformation
key={template.id}
template={template}
onClickOpenTemplate={() => onClickOpenTemplate(template)}
/>
))}

{Object.values(templateMap)
.sort((a, b) => {
if (favoriteTemplates.includes(a.id)) return -1;
if (favoriteTemplates.includes(b.id)) return 1;
return 0;
})
.map(template => (
<TemplateInformation
key={template.id}
template={template}
onClickOpenTemplate={() => onClickOpenTemplate(template)}
/>
))}
</S.TemplatesContainer>
)}

Expand Down
4 changes: 2 additions & 2 deletions src/components/organisms/PaneManager/PaneManagerLeftMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {useAppDispatch, useAppSelector} from '@redux/hooks';
import {setLeftMenuSelection, toggleLeftMenu, toggleStartProjectPane} from '@redux/reducers/ui';
import {activeProjectSelector, kustomizationsSelector} from '@redux/selectors';

import {trackEvent} from '@utils/telemetry';
import {SELECT_LEFT_TOOL_PANEL, trackEvent} from '@utils/telemetry';

import Colors from '@styles/Colors';

Expand Down Expand Up @@ -52,7 +52,7 @@ const PaneManagerLeftMenu: React.FC = () => {
if (isStartProjectPaneVisible) {
dispatch(toggleStartProjectPane());
}
trackEvent('SELECT_LEFT_TOOL_PANEL', {panelID: selectedMenu});
trackEvent(SELECT_LEFT_TOOL_PANEL, {panelID: selectedMenu});
dispatch(setLeftMenuSelection(selectedMenu));

if (!leftActive) {
Expand Down
8 changes: 4 additions & 4 deletions src/components/organisms/TemplateModal/TemplateModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {createUnsavedResourcesFromVanillaTemplate} from '@redux/services/templat

import {TemplateFormRenderer} from '@components/molecules';

import {trackEvent} from '@utils/telemetry';
import {START_FROM_A_TEMPLATE, USE_TEMPLATE, trackEvent} from '@utils/telemetry';

import * as S from './styled';

Expand Down Expand Up @@ -53,7 +53,7 @@ const TemplateModal: React.FC<TemplateModalProps> = props => {
const onClickSubmit = useCallback(
(formDataList: Record<string, Primitive>[]) => {
if (projectToCreate) {
trackEvent('START_FROM_A_TEMPLATE', {templateID: template.id});
trackEvent(START_FROM_A_TEMPLATE, {templateID: template.id});
dispatch(setCreateProject({...projectToCreate}));
onClose('PREVIEW');
}
Expand All @@ -62,7 +62,7 @@ const TemplateModal: React.FC<TemplateModalProps> = props => {
formDataList.shift();

if (isVanillaTemplate(template)) {
trackEvent('USE_TEMPLATE', {templateID: template.id});
trackEvent(USE_TEMPLATE, {templateID: template.id});
setIsLoading(true);
createUnsavedResourcesFromVanillaTemplate(template, formDataList, dispatch)
.then(({message, resources}) => {
Expand All @@ -81,7 +81,7 @@ const TemplateModal: React.FC<TemplateModalProps> = props => {
return;
}
setIsLoading(true);
trackEvent('USE_TEMPLATE', {templateID: template.id});
trackEvent(USE_TEMPLATE, {templateID: template.id});
previewReferencedHelmChart(
template.chartName,
template.chartVersion,
Expand Down
4 changes: 2 additions & 2 deletions src/redux/thunks/previewCluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {extractK8sResources, processParsedResources} from '@redux/services/resou
import {createPreviewResult, createRejectionWithAlert, getK8sObjectsAsYaml} from '@redux/thunks/utils';

import {createKubeClient} from '@utils/kubeclient';
import {trackEvent} from '@utils/telemetry';
import {CLUSTER_VIEW, trackEvent} from '@utils/telemetry';

import {getRegisteredKindHandlers, getResourceKindHandler} from '@src/kindhandlers';

Expand Down Expand Up @@ -82,7 +82,7 @@ const previewClusterHandler = async (context: string, thunkAPI: any) => {
resourceIds: customResources.map(r => r.id),
});

trackEvent('CLUSTER_VIEW', {numberOfResourcesInCluster: Object.keys(previewResult.previewResources).length});
trackEvent(CLUSTER_VIEW, {numberOfResourcesInCluster: Object.keys(previewResult.previewResources).length});

previewResult.alert.message = `Previewing ${Object.keys(previewResult.previewResources).length} resources`;
}
Expand Down
4 changes: 2 additions & 2 deletions src/redux/thunks/previewHelmValuesFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {currentConfigSelector} from '@redux/selectors';
import {createPreviewResult, createRejectionWithAlert} from '@redux/thunks/utils';

import {runHelm} from '@utils/helm';
import {trackEvent} from '@utils/telemetry';
import {DO_HELM_PREVIEW, trackEvent} from '@utils/telemetry';

/**
* Thunk to preview a Helm Chart
Expand Down Expand Up @@ -60,7 +60,7 @@ export const previewHelmValuesFile = createAsyncThunk<

const result = await runHelm(args);

trackEvent('DO_HELM_PREVIEW');
trackEvent(DO_HELM_PREVIEW);

if (result.error) {
return createRejectionWithAlert(thunkAPI, 'Helm Error', result.error);
Expand Down
4 changes: 2 additions & 2 deletions src/redux/thunks/previewKustomization.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {SetPreviewDataPayload} from '@redux/reducers/main';
import {currentConfigSelector} from '@redux/selectors';
import {createPreviewResult, createRejectionWithAlert} from '@redux/thunks/utils';

import {trackEvent} from '@utils/telemetry';
import {DO_KUSTOMIZE_PREVIEW, trackEvent} from '@utils/telemetry';

export type KustomizeCommandOptions = {
folder: string;
Expand Down Expand Up @@ -48,7 +48,7 @@ export const previewKustomization = createAsyncThunk<
log.info(`previewing ${resource.id} in folder ${folder}`);
const result = await runKustomize(folder, projectConfig);

trackEvent('DO_KUSTOMIZE_PREVIEW');
trackEvent(DO_KUSTOMIZE_PREVIEW);

if (result.error) {
return createRejectionWithAlert(thunkAPI, 'Kustomize Error', result.error);
Expand Down
4 changes: 2 additions & 2 deletions src/redux/thunks/saveUnsavedResources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {K8sResource} from '@models/k8sresource';
import {RootState} from '@models/rootstate';

import {getFileTimestamp} from '@utils/files';
import {trackEvent} from '@utils/telemetry';
import {ADD_NEW_RESOURCE, trackEvent} from '@utils/telemetry';

import {createRejectionWithAlert} from './utils';

Expand Down Expand Up @@ -47,7 +47,7 @@ const performSaveUnsavedResource = async (
throw new Error('Could not find the root folder.');
}

trackEvent('ADD_NEW_RESOURCE', {resourceKind: resource.kind});
trackEvent(ADD_NEW_RESOURCE, {resourceKind: resource.kind});

if (saveMode === 'saveToFolder') {
await writeFilePromise(absolutePath, resource.text);
Expand Down
4 changes: 2 additions & 2 deletions src/redux/thunks/setRootFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {processParsedResources} from '@redux/services/resource';
import {createRejectionWithAlert} from '@redux/thunks/utils';

import {getFileStats} from '@utils/files';
import {trackEvent} from '@utils/telemetry';
import {OPEN_EXISTING_PROJECT, trackEvent} from '@utils/telemetry';

/**
* Thunk to set the specified root folder
Expand Down Expand Up @@ -83,7 +83,7 @@ export const setRootFolder = createAsyncThunk<
type: AlertEnum.Success,
};

trackEvent('OPEN_EXISTING_PROJECT', {
trackEvent(OPEN_EXISTING_PROJECT, {
numberOfFiles: Object.values(fileMap).filter(f => !f.children).length,
numberOfResources: Object.values(resourceMap).length,
});
Expand Down
10 changes: 5 additions & 5 deletions src/utils/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as os from 'os';
// @ts-ignore
import shellPath from 'shell-path';

import {trackEvent} from './telemetry';
import {WINDOW_HELP_LINK, trackEvent} from './telemetry';

let cachedShellPath: string | undefined;

Expand All @@ -21,12 +21,12 @@ export function showItemInFolder(fullPath: string) {
}

export function openGitHub() {
trackEvent('WINDOW_HELP_LINK', {linkID: 'github'});
trackEvent(WINDOW_HELP_LINK, {linkID: 'github'});
shell.openExternal('https://github.com/kubeshop/monokle');
}

export function openDiscord() {
trackEvent('WINDOW_HELP_LINK', {linkID: 'discord'});
trackEvent(WINDOW_HELP_LINK, {linkID: 'discord'});
shell.openExternal('https://discord.gg/kMJxmuYTMu');
}

Expand All @@ -37,12 +37,12 @@ export function openUrlInExternalBrowser(url?: string) {
}

export function openDocumentation() {
trackEvent('WINDOW_HELP_LINK', {linkID: 'documentation', osType: os.type});
trackEvent(WINDOW_HELP_LINK, {linkID: 'documentation'});
shell.openExternal(`https://kubeshop.github.io/monokle?os=${os.type}`);
}

export function openKeyboardShortcuts() {
trackEvent('WINDOW_HELP_LINK', {linkID: 'shortcuts', osType: os.type});
trackEvent(WINDOW_HELP_LINK, {linkID: 'shortcuts'});
shell.openExternal(`https://kubeshop.github.io/monokle/hotkeys?os=${os.type}`);
}

Expand Down
11 changes: 11 additions & 0 deletions src/utils/telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,14 @@ export const trackEvent = (eventName: string, payload?: any) => {
export const trackError = (error: any) => {
ipcRenderer.send('track-event', {error});
};

export const CREATE_EMPTY_PROJECT = 'CREATE_EMPTY_PROJECT';
export const SELECT_LEFT_TOOL_PANEL = 'SELECT_LEFT_TOOL_PANEL';
export const START_FROM_A_TEMPLATE = 'START_FROM_A_TEMPLATE';
export const WINDOW_HELP_LINK = 'WINDOW_HELP_LINK';
export const USE_TEMPLATE = 'USE_TEMPLATE';
export const DO_HELM_PREVIEW = 'DO_HELM_PREVIEW';
export const CLUSTER_VIEW = 'CLUSTER_VIEW';
export const DO_KUSTOMIZE_PREVIEW = 'DO_KUSTOMIZE_PREVIEW';
export const OPEN_EXISTING_PROJECT = 'OPEN_EXISTING_PROJECT';
export const ADD_NEW_RESOURCE = 'ADD_NEW_RESOURCE';

0 comments on commit ab0d0c3

Please sign in to comment.