Skip to content

Commit

Permalink
add telemetry and log for build and provisioning step times
Browse files Browse the repository at this point in the history
  • Loading branch information
Roy Razon committed Nov 28, 2023
1 parent 560c8f0 commit f889431
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
9 changes: 8 additions & 1 deletion packages/core/src/commands/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import { Logger } from '../log'
import { BuildSpec, generateBuild } from '../build'
import { gitContext } from '../git'
import { childProcessPromise } from '../child-process'
import { telemetryEmitter } from '../telemetry'
import { measureTime } from '../timing'

const buildCommand = async ({
log,
Expand Down Expand Up @@ -43,7 +45,12 @@ const buildCommand = async ({
]

log.info(`Running: docker ${dockerArgs.join(' ')}`)
await childProcessPromise(spawn('docker', dockerArgs, { stdio: 'inherit', cwd, env }))
const { elapsedTimeSec } = await measureTime(() => childProcessPromise(spawn('docker', dockerArgs, { stdio: 'inherit', cwd, env })))
telemetryEmitter().capture('build success', {
elapsed_sec: elapsedTimeSec,
has_registry: Boolean(buildSpec.registry),
})
log.info(`Elapsed time for build step: ${elapsedTimeSec.toLocaleString(undefined, { maximumFractionDigits: 2 })} sec`)

return { buildModel, deployModel }
}
Expand Down
11 changes: 10 additions & 1 deletion packages/core/src/commands/up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { BuildSpec } from '../build'
import modelCommand from './model'
import buildCommand from './build'
import { CommandExecuter } from '../command-executer'
import { telemetryEmitter } from '../telemetry'
import { measureTime } from '../timing'

const uploadFiles = async ({
log,
Expand Down Expand Up @@ -143,7 +145,14 @@ const up = async ({
log.info(`Running: docker compose up ${composeArgs.join(' ')}`)

await using dockerContext = await dockerEnvContext({ connection, log })
await compose.spawnPromise(composeArgs, { stdio: 'inherit', env: dockerContext.env })

const { elapsedTimeSec } = await measureTime(() => compose.spawnPromise(composeArgs, { stdio: 'inherit', env: dockerContext.env }))
telemetryEmitter().capture('provisioning success', {
elapsed_sec: elapsedTimeSec,
with_build: Boolean(buildSpec),
has_registry: Boolean(buildSpec?.registry),
})
log.info(`Elapsed time for provisioning step: ${elapsedTimeSec.toLocaleString(undefined, { maximumFractionDigits: 2 })} sec`)

return { composeModel, projectLocalDataDir }
}
Expand Down
6 changes: 6 additions & 0 deletions packages/core/src/timing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export const measureTime = async <T>(f: () => Promise<T>) => {
const startTime = Date.now()
const result = await f()
const elapsedTimeSec = (new Date().getTime() - startTime) / 1000
return { result, elapsedTimeSec }
}

0 comments on commit f889431

Please sign in to comment.