Repository navigation
fix(cli): concurrent deploy telemetry events share an event id #2129
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 all commits
5f5485c
d359187
bee5b62
96523c5
80cac1a
b62c4e5
5f87f85
0730b0d
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 |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import { CliIoHost } from '../../../lib/cli/io-host'; | |
| import { type TelemetrySchema } from '../../../lib/cli/telemetry/schema'; | ||
| import { TelemetrySession, isValidWrapperUserAgent } from '../../../lib/cli/telemetry/session'; | ||
| import { IoHostTelemetrySink } from '../../../lib/cli/telemetry/sink/io-host-sink'; | ||
| import * as telemetryState from '../../../lib/cli/telemetry/telemetry-state'; | ||
| import { withEnv } from '../../_helpers/with-env'; | ||
|
|
||
| let ioHost: CliIoHost; | ||
|
|
@@ -34,6 +35,10 @@ describe('TelemetrySession', () => { | |
| clientFlushSpy = jest.spyOn(client, 'flush'); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| jest.restoreAllMocks(); | ||
| }); | ||
|
|
||
| test('can emit data to the client', async () => { | ||
| // WHEN | ||
| await session.emit({ | ||
|
|
@@ -114,6 +119,63 @@ describe('TelemetrySession', () => { | |
| })); | ||
| }); | ||
|
|
||
| test('concurrent DEPLOY events get distinct event ids', async () => { | ||
| // GIVEN | ||
| jest.spyOn(telemetryState, 'withTelemetryState').mockResolvedValue(undefined); | ||
|
|
||
| // WHEN: two stacks finish deploying at the same time, as with --concurrency | ||
| const first = session.emit({ eventType: 'DEPLOY', duration: 1234 }); | ||
| const second = session.emit({ eventType: 'DEPLOY', duration: 1234 }); | ||
| await first; | ||
| await second; | ||
|
|
||
| // THEN | ||
| const sequenceNumbers = clientEmitSpy.mock.calls.map(([e]) => e.identifiers.eventId.split(':').pop()); | ||
| expect(sequenceNumbers.sort()).toEqual(['1', '2']); | ||
| }); | ||
|
|
||
| test('concurrent failed DEPLOY events count every sequential failure', async () => { | ||
| // GIVEN: an in-memory state file that yields between read and write, so updates can overlap | ||
| let state: telemetryState.TelemetryState = {}; | ||
| jest.spyOn(telemetryState, 'withTelemetryState').mockImplementation(async (block) => { | ||
| const copy = { ...state }; | ||
| await Promise.resolve(); | ||
| const ret = block(copy); | ||
| state = copy; | ||
| return ret; | ||
| }); | ||
|
|
||
| // WHEN | ||
| const error = { name: ToolkitError.name }; | ||
| const first = session.emit({ eventType: 'DEPLOY', duration: 1234, error }); | ||
| const second = session.emit({ eventType: 'DEPLOY', duration: 1234, error }); | ||
| const third = session.emit({ eventType: 'DEPLOY', duration: 1234, error }); | ||
| await first; | ||
| await second; | ||
| await third; | ||
|
|
||
| // THEN | ||
| const failures = clientEmitSpy.mock.calls.map(([e]) => e.counters?.sequentialDeploymentFailures); | ||
| expect(failures).toEqual([1, 2, 3]); | ||
| expect(state.sequentialDeploymentFailures).toEqual(3); | ||
| }); | ||
|
|
||
| test('DEPLOY event is still sent when the state file cannot be updated, and later ones are counted', async () => { | ||
| // GIVEN | ||
| jest.spyOn(telemetryState, 'withTelemetryState') | ||
| .mockRejectedValueOnce(new Error('EACCES')) | ||
| .mockImplementation(async (block) => block({})); | ||
|
|
||
| // WHEN | ||
| await session.emit({ eventType: 'DEPLOY', duration: 1234 }); | ||
| await session.emit({ eventType: 'DEPLOY', duration: 1234, error: { name: ToolkitError.name } }); | ||
|
|
||
| // THEN | ||
| expect(clientEmitSpy).toHaveBeenCalledTimes(2); | ||
| expect(clientEmitSpy.mock.calls[0][0].counters?.sequentialDeploymentFailures).toBeUndefined(); | ||
| expect(clientEmitSpy.mock.calls[1][0].counters?.sequentialDeploymentFailures).toEqual(1); | ||
| }); | ||
|
|
||
|
Comment on lines
+135
to
+178
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. ⚪ Optional — Both new tests install a Suggested change: Restore mocks in a guaranteed path: add |
||
| test('calling end more than once results in no-op', async () => { | ||
| // GIVEN | ||
| const spanEndSpy = jest.spyOn(session.commandSpan!, 'end'); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.