Unverified Commit 8bc2a65f authored by Jude Gao's avatar Jude Gao Committed by GitHub

track persistent caching usage (#76996)

parent 3e5e6dba
...@@ -206,6 +206,7 @@ import { ...@@ -206,6 +206,7 @@ import {
} from '../server/lib/router-utils/build-prefetch-segment-data-route' } from '../server/lib/router-utils/build-prefetch-segment-data-route'
import { turbopackBuild } from './turbopack-build' import { turbopackBuild } from './turbopack-build'
import { isPersistentCachingEnabled } from '../shared/lib/turbopack/utils'
import { inlineStaticEnv, populateStaticEnv } from '../lib/inline-static-env' import { inlineStaticEnv, populateStaticEnv } from '../lib/inline-static-env'
type Fallback = null | boolean | string type Fallback = null | boolean | string
...@@ -2476,6 +2477,10 @@ export default async function build( ...@@ -2476,6 +2477,10 @@ export default async function build(
featureName: 'experimental/ppr', featureName: 'experimental/ppr',
invocationCount: config.experimental.ppr ? 1 : 0, invocationCount: config.experimental.ppr ? 1 : 0,
}, },
{
featureName: 'turbopackPersistentCaching',
invocationCount: isPersistentCachingEnabled(config) ? 1 : 0,
},
] ]
telemetry.record( telemetry.record(
features.map((feature) => { features.map((feature) => {
......
...@@ -26,7 +26,10 @@ import type { Telemetry } from '../../../telemetry/storage' ...@@ -26,7 +26,10 @@ import type { Telemetry } from '../../../telemetry/storage'
import type { IncomingMessage, ServerResponse } from 'http' import type { IncomingMessage, ServerResponse } from 'http'
import loadJsConfig from '../../../build/load-jsconfig' import loadJsConfig from '../../../build/load-jsconfig'
import { createValidFileMatcher } from '../find-page-file' import { createValidFileMatcher } from '../find-page-file'
import { eventCliSession } from '../../../telemetry/events' import {
EVENT_BUILD_FEATURE_USAGE,
eventCliSession,
} from '../../../telemetry/events'
import { getDefineEnv } from '../../../build/webpack/plugins/define-env-plugin' import { getDefineEnv } from '../../../build/webpack/plugins/define-env-plugin'
import { getSortedRoutes } from '../../../shared/lib/router/utils' import { getSortedRoutes } from '../../../shared/lib/router/utils'
import { import {
...@@ -73,6 +76,7 @@ import { createEnvDefinitions } from '../experimental/create-env-definitions' ...@@ -73,6 +76,7 @@ import { createEnvDefinitions } from '../experimental/create-env-definitions'
import { JsConfigPathsPlugin } from '../../../build/webpack/plugins/jsconfig-paths-plugin' import { JsConfigPathsPlugin } from '../../../build/webpack/plugins/jsconfig-paths-plugin'
import { store as consoleStore } from '../../../build/output/store' import { store as consoleStore } from '../../../build/output/store'
import { import {
isPersistentCachingEnabled,
ModuleBuildError, ModuleBuildError,
TurbopackInternalError, TurbopackInternalError,
} from '../../../shared/lib/turbopack/utils' } from '../../../shared/lib/turbopack/utils'
...@@ -996,6 +1000,16 @@ export async function setupDevBundler(opts: SetupOpts) { ...@@ -996,6 +1000,16 @@ export async function setupDevBundler(opts: SetupOpts) {
} }
) )
) )
// Track build features for dev server here:
opts.telemetry.record({
eventName: EVENT_BUILD_FEATURE_USAGE,
payload: {
featureName: 'turbopackPersistentCaching',
invocationCount: isPersistentCachingEnabled(opts.nextConfig) ? 1 : 0,
},
})
return result return result
} }
......
...@@ -178,6 +178,7 @@ export type EventBuildFeatureUsage = { ...@@ -178,6 +178,7 @@ export type EventBuildFeatureUsage = {
| 'esmExternals' | 'esmExternals'
| 'webpackPlugins' | 'webpackPlugins'
| UseCacheTrackerKey | UseCacheTrackerKey
| 'turbopackPersistentCaching'
invocationCount: number invocationCount: number
} }
export function eventBuildFeatureUsage( export function eventBuildFeatureUsage(
......
module.exports = {
experimental: {
turbo: {
unstablePersistentCaching: true
}
}
}
\ No newline at end of file
...@@ -6,10 +6,10 @@ import { ...@@ -6,10 +6,10 @@ import {
launchApp, launchApp,
nextBuild, nextBuild,
nextLint, nextLint,
waitFor,
} from 'next-test-utils' } from 'next-test-utils'
import fs from 'fs-extra' import fs from 'fs-extra'
import path from 'path' import path from 'path'
const appDir = path.join(__dirname, '..') const appDir = path.join(__dirname, '..')
describe('config telemetry', () => { describe('config telemetry', () => {
...@@ -761,6 +761,81 @@ describe('config telemetry', () => { ...@@ -761,6 +761,81 @@ describe('config telemetry', () => {
}) })
} }
) )
it('emits telemetry for persistent cache in build mode', async () => {
await fs.rename(
path.join(appDir, 'next.config.persistent-cache'),
path.join(appDir, 'next.config.js')
)
try {
const { stderr } = await nextBuild(appDir, [], {
stderr: true,
env: { NEXT_TELEMETRY_DEBUG: 1 },
})
try {
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toContainEqual({
featureName: 'turbopackPersistentCaching',
invocationCount: 1,
})
} catch (err) {
require('console').error('failing stderr', stderr, err)
throw err
}
} finally {
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.persistent-cache')
)
}
})
it('emits telemetry for persistent cache in dev mode', async () => {
await fs.rename(
path.join(appDir, 'next.config.persistent-cache'),
path.join(appDir, 'next.config.js')
)
let app
let stderr = ''
try {
app = await launchApp(appDir, await findPort(), {
env: { NEXT_TELEMETRY_DEBUG: 1 },
onStderr(msg) {
stderr += msg || ''
},
})
await waitFor(2000)
const featureUsageEvents = findAllTelemetryEvents(
stderr,
'NEXT_BUILD_FEATURE_USAGE'
)
expect(featureUsageEvents).toContainEqual({
featureName: 'turbopackPersistentCaching',
invocationCount: 1,
})
} catch (err) {
require('console').error('failing stderr', err)
throw err
} finally {
if (app) {
await killApp(app)
}
await fs.rename(
path.join(appDir, 'next.config.js'),
path.join(appDir, 'next.config.persistent-cache')
)
}
})
} }
) )
}) })
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment