From 02aad36dbf6a019209e49e8778258b106d99f551 Mon Sep 17 00:00:00 2001 From: baurine <2008.hbl@gmail.com> Date: Mon, 24 Oct 2022 14:03:09 +0800 Subject: [PATCH 1/2] feat: add telemetry for cluster info --- .../tidb-dashboard-for-dbaas/public/index.html | 7 ++++++- .../tidb-dashboard-for-dbaas/src/index.tsx | 15 ++++++++++++++- .../src/utils/global-config.ts | 8 ++++++++ .../tidb-dashboard-lib/src/utils/telemetry.ts | 8 ++++++-- 4 files changed, 34 insertions(+), 4 deletions(-) diff --git a/ui/packages/tidb-dashboard-for-dbaas/public/index.html b/ui/packages/tidb-dashboard-for-dbaas/public/index.html index 3516c0a169..c7e0109782 100644 --- a/ui/packages/tidb-dashboard-for-dbaas/public/index.html +++ b/ui/packages/tidb-dashboard-for-dbaas/public/index.html @@ -122,12 +122,17 @@ } const promBaseUrl = localStorage.getItem('dbaas.cluster_prom_base_url') + const clusterInfo = JSON.parse( + localStorage.getItem('dbaas.cluster_info') ?? '{}' + ) + startDashboard({ apiPathBase, apiToken, mixpanelUser, timezone, - promBaseUrl + promBaseUrl, + clusterInfo }) diff --git a/ui/packages/tidb-dashboard-for-dbaas/src/index.tsx b/ui/packages/tidb-dashboard-for-dbaas/src/index.tsx index 5db06b59ea..5147c7b0db 100644 --- a/ui/packages/tidb-dashboard-for-dbaas/src/index.tsx +++ b/ui/packages/tidb-dashboard-for-dbaas/src/index.tsx @@ -49,12 +49,25 @@ function start(globalConfig: IGlobalConfig) { setupClient(apiPathBase, apiToken) loadWhoAmI() loadAppInfo() + // telemetry telemetry.init( process.env.REACT_APP_MIXPANEL_HOST, process.env.REACT_APP_MIXPANEL_TOKEN ) - telemetry.enable(`tidb-dashboard-for-dbaas-${process.env.REACT_APP_VERSION}`) + const { + clusterInfo: { orgId, tenantPlan, projectId, clusterId, deployType } + } = globalConfig + telemetry.enable( + `tidb-dashboard-for-dbaas-${process.env.REACT_APP_VERSION}`, + { + tenant_id: orgId, + tenant_plan: tenantPlan, + project_id: projectId, + cluster_id: clusterId, + deploy_type: deployType + } + ) if (mixpanelUser) { telemetry.identifyUser(mixpanelUser) } diff --git a/ui/packages/tidb-dashboard-for-dbaas/src/utils/global-config.ts b/ui/packages/tidb-dashboard-for-dbaas/src/utils/global-config.ts index 87a4b80233..bb1c87c214 100644 --- a/ui/packages/tidb-dashboard-for-dbaas/src/utils/global-config.ts +++ b/ui/packages/tidb-dashboard-for-dbaas/src/utils/global-config.ts @@ -6,6 +6,14 @@ export interface IGlobalConfig { mixpanelUser: string timezone: number | null promBaseUrl: string + + clusterInfo: { + orgId: string + tenantPlan: string // FREE_TRIAL / POC / ON_DEMAND + projectId: string + clusterId: string + deployType: string // Dedicated / Dev Tier + } } export const GlobalConfigContext = createContext(null) diff --git a/ui/packages/tidb-dashboard-lib/src/utils/telemetry.ts b/ui/packages/tidb-dashboard-lib/src/utils/telemetry.ts index 51b8ef352e..d671de21dd 100644 --- a/ui/packages/tidb-dashboard-lib/src/utils/telemetry.ts +++ b/ui/packages/tidb-dashboard-lib/src/utils/telemetry.ts @@ -25,10 +25,14 @@ function init(apiHost?: string, token?: string) { mixpanel.opt_out_tracking() } -function enable(dashboardVersion: string) { +function enable( + dashboardVersion: string, + extraData: { [k: string]: any } = {} +) { mixpanel.register({ $current_url: getPathInLocationHash(), - dashboard_version: dashboardVersion + dashboard_version: dashboardVersion, + ...extraData }) mixpanel.opt_in_tracking() } From 914dce1a4ae9b4e56545d6838bdaabfb30561616 Mon Sep 17 00:00:00 2001 From: baurine <2008.hbl@gmail.com> Date: Mon, 24 Oct 2022 14:26:10 +0800 Subject: [PATCH 2/2] bump tidb-dashboard-for-dbaas to 0.0.45 --- ui/packages/tidb-dashboard-for-dbaas/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ui/packages/tidb-dashboard-for-dbaas/package.json b/ui/packages/tidb-dashboard-for-dbaas/package.json index 94264e0e9c..392057b13b 100644 --- a/ui/packages/tidb-dashboard-for-dbaas/package.json +++ b/ui/packages/tidb-dashboard-for-dbaas/package.json @@ -1,6 +1,6 @@ { "name": "@pingcap/tidb-dashboard-for-dbaas", - "version": "0.0.44", + "version": "0.0.45", "main": "dist/main.js", "module": "dist/main.js", "files": [