mirror of
https://github.com/MoonshotAI/kimi-code.git
synced 2026-07-09 17:29:12 +00:00
feat(telemetry): add system metrics collection (#1435)
* feat(telemetry): add system metrics collection Add periodic CPU and memory telemetry sampling with warmup capture, lifecycle cleanup, and tests. * fix(telemetry): attach prompt session to system metrics
This commit is contained in:
parent
578f7d334c
commit
10922fc70f
9 changed files with 278 additions and 0 deletions
|
|
@ -179,6 +179,7 @@ export async function runPrompt(
|
|||
version,
|
||||
uiMode: PROMPT_UI_MODE,
|
||||
model: telemetryModel,
|
||||
sessionId: session.id,
|
||||
});
|
||||
setCrashPhase('runtime');
|
||||
|
||||
|
|
|
|||
|
|
@ -32,6 +32,7 @@ export interface InitializeCliTelemetryOptions {
|
|||
readonly version: string;
|
||||
readonly uiMode: string;
|
||||
readonly model?: string;
|
||||
readonly sessionId?: string;
|
||||
}
|
||||
|
||||
export function createCliTelemetryBootstrap(): CliTelemetryBootstrap {
|
||||
|
|
@ -54,6 +55,7 @@ export function initializeCliTelemetry(options: InitializeCliTelemetryOptions):
|
|||
version: options.version,
|
||||
uiMode: options.uiMode,
|
||||
model: options.model ?? options.config.defaultModel,
|
||||
sessionId: options.sessionId,
|
||||
getAccessToken: async () =>
|
||||
(await options.harness.auth.getCachedAccessToken(KIMI_CODE_PROVIDER_NAME)) ?? null,
|
||||
});
|
||||
|
|
|
|||
|
|
@ -412,6 +412,7 @@ describe('kimi export', () => {
|
|||
version: expect.any(String),
|
||||
uiMode: 'shell',
|
||||
model: 'k2',
|
||||
sessionId: undefined,
|
||||
getAccessToken: expect.any(Function),
|
||||
});
|
||||
expect(mocks.initializeTelemetry.mock.invocationCallOrder[0]).toBeLessThan(
|
||||
|
|
|
|||
|
|
@ -217,6 +217,9 @@ describe('runPrompt', () => {
|
|||
expect(mocks.session.prompt).toHaveBeenCalledWith('say hello');
|
||||
expect(stdout.text()).toBe('• hello world\n\n');
|
||||
expect(stderr.text()).toBe('To resume this session: kimi -r ses_prompt\n');
|
||||
expect(mocks.initializeTelemetry).toHaveBeenCalledWith(
|
||||
expect.objectContaining({ sessionId: 'ses_prompt' }),
|
||||
);
|
||||
expect(mocks.shutdownTelemetry).toHaveBeenCalled();
|
||||
expect(mocks.harnessClose).toHaveBeenCalled();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -213,6 +213,7 @@ describe('runShell', () => {
|
|||
version: '1.2.3-test',
|
||||
uiMode: 'shell',
|
||||
model: 'k2',
|
||||
sessionId: undefined,
|
||||
getAccessToken: expect.any(Function),
|
||||
});
|
||||
expect(mocks.setCrashPhase).toHaveBeenCalledWith('runtime');
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue