-
Notifications
You must be signed in to change notification settings - Fork 63
Separate telemetry handling between CLI and the app #2780
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 53 commits
87ff9fe
81d1bcd
773f2ee
2cf25ef
7707212
fb7be26
57bfb0e
535a343
760b4b2
0786acf
2ba7ede
81c92d1
07ae336
bccdb50
bdce54e
e55cc43
d39b8b4
2da2890
8455b4d
6eacd2d
e060e40
45c5bb1
b677102
bcb1fa4
8301ec6
6b756c5
9bbd8bb
1d02ed6
fd74c4d
dbcb0ee
8c11f7f
d902e60
0b3b46a
81e1f66
508ef54
b140592
479e8b9
0328355
2684826
be9c5e7
cfb3213
7e77f61
1396884
2515bf2
66eab06
ddb03c8
3193be8
6908bec
03e99d0
2edd6dd
197a919
d097274
888ae05
7b0a05a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,5 @@ | ||
| declare const __ENABLE_STUDIO_AI__: boolean; | ||
| declare const __ENABLE_AGENT_SUITE__: boolean; | ||
| declare const __ENABLE_CLI_TELEMETRY__: boolean; | ||
| declare const __ENABLE_STUDIO_AI__: boolean; | ||
| declare const __IS_PACKAGED_FOR_NPM__: boolean; | ||
| declare const __STUDIO_CLI_VERSION__: string; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,11 +7,11 @@ import { lockFileAsync, unlockFileAsync } from '@studio/common/lib/lockfile'; | |
| import { getAuthenticationUrl } from '@studio/common/lib/oauth'; | ||
| import { siteDetailsSchema } from '@studio/common/lib/site-events'; | ||
| import { snapshotSchema } from '@studio/common/types/snapshot'; | ||
| import { StatsMetric } from '@studio/common/types/stats'; | ||
| import { __, sprintf } from '@wordpress/i18n'; | ||
| import { readFile, writeFile } from 'atomically'; | ||
| import { z } from 'zod'; | ||
| import { validateAccessToken } from 'cli/lib/api'; | ||
| import { StatsMetric } from 'cli/lib/types/bump-stats'; | ||
| import { LoggerError } from 'cli/logger'; | ||
| import type { AiProviderId } from 'cli/ai/providers'; | ||
|
|
||
|
|
@@ -44,9 +44,7 @@ const userDataSchema = z | |
| } ) | ||
| .loose() | ||
| .optional(), | ||
| lastBumpStats: z | ||
| .record( z.string(), z.partialRecord( z.enum( StatsMetric ), z.number() ) ) | ||
| .optional(), | ||
| lastBumpStats: z.record( z.string(), z.record( z.string(), z.number() ) ).optional(), | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I previously advocated for the stricter schema here (#2394 (review)), but it actually causes more trouble than it fixes, given the other changes in this PR. Strictness in runtime types makes sense (i.e., for the function arguments to `bumpStat), but strictness in the appdata schema introduces the risk of runtime exceptions if the config file contains unknown bump stats. That isn't really needed, since we only use this object to check when we last bumped a particular stat. Anyway, with this change, it's safe to land this PR to trunk even before the config file PR train (#2807 etc) has landed. |
||
| betaFeatures: betaFeaturesSchema.optional(), | ||
| } ) | ||
| .loose(); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| import { | ||
| __bumpAggregatedUniqueStat, | ||
| __bumpStat, | ||
| AggregateInterval, | ||
| LastBumpStatsProvider, | ||
| } from '@studio/common/lib/bump-stat'; | ||
| import { lockAppdata, readAppdata, saveAppdata, unlockAppdata } from 'cli/lib/appdata'; | ||
| import { StatsGroup, StatsMetric } from 'cli/lib/types/bump-stats'; | ||
|
|
||
| const lastBumpStatsProvider: LastBumpStatsProvider = { | ||
| load: async () => { | ||
| const { lastBumpStats } = await readAppdata(); | ||
| return lastBumpStats ?? {}; | ||
| }, | ||
| lock: lockAppdata, | ||
| unlock: unlockAppdata, | ||
| save: async ( lastBumpStats ) => { | ||
| const appdata = await readAppdata(); | ||
| appdata.lastBumpStats = lastBumpStats; | ||
| // Locking is handled in `@studio/common/lib/bump-stat` | ||
| // eslint-disable-next-line studio/require-lock-before-save | ||
| await saveAppdata( appdata ); | ||
| }, | ||
| }; | ||
|
|
||
| export function bumpStat( group: StatsGroup, stat: StatsMetric, bumpInDev = false ) { | ||
| return __bumpStat( group, stat, bumpInDev ); | ||
| } | ||
|
|
||
| export async function bumpAggregatedUniqueStat( | ||
| group: StatsGroup, | ||
| stat: StatsMetric, | ||
| aggregateBy: AggregateInterval, | ||
| bumpInDev = false | ||
| ) { | ||
| return __bumpAggregatedUniqueStat( group, stat, aggregateBy, lastBumpStatsProvider, bumpInDev ); | ||
| } | ||
|
|
||
| export function getPlatformMetric(): StatsMetric { | ||
| switch ( process.platform ) { | ||
| case 'darwin': | ||
| return StatsMetric.DARWIN; | ||
| case 'linux': | ||
| return StatsMetric.LINUX; | ||
| case 'win32': | ||
| return StatsMetric.WINDOWS; | ||
| default: | ||
| return StatsMetric.UNKNOWN_PLATFORM; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| export enum StatsGroup { | ||
| STUDIO_CLI_USAGE_UNIQUE = 'studio-cli-usage-unique', | ||
| STUDIO_CLI_WEEKLY_UNIQUE_NPM = 'studio-cli-weekly-unq-npm', | ||
| STUDIO_CLI_WEEKLY_UNIQUE_APP = 'studio-cli-weekly-unq-app', | ||
| } | ||
|
|
||
| export enum StatsMetric { | ||
| SUCCESS = 'success', | ||
| FAILURE = 'failure', | ||
| // Platforms | ||
| DARWIN = 'darwin', | ||
| LINUX = 'linux', | ||
| WINDOWS = 'win32', | ||
| UNKNOWN_PLATFORM = 'unknown-platform', | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { defineConfig, mergeConfig } from 'vite'; | ||
| import { baseConfig } from './vite.config.base'; | ||
|
|
||
| export default mergeConfig( | ||
| baseConfig, | ||
| defineConfig( { | ||
| define: { | ||
| __IS_PACKAGED_FOR_NPM__: false, | ||
| __ENABLE_CLI_TELEMETRY__: false, | ||
| }, | ||
| } ) | ||
| ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused import here, it should be safe to remove.