mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-07-11 10:30:46 -07:00
Fix duplicate LOC counting due to diff_stat being passed in multiple places (#7483)
This commit is contained in:
@@ -517,28 +517,6 @@ export class ClearcutLogger {
|
||||
});
|
||||
}
|
||||
|
||||
if (event.diff_stat) {
|
||||
const metadataMapping: { [key: string]: EventMetadataKey } = {
|
||||
ai_added_lines: EventMetadataKey.GEMINI_CLI_AI_ADDED_LINES,
|
||||
ai_removed_lines: EventMetadataKey.GEMINI_CLI_AI_REMOVED_LINES,
|
||||
user_added_lines: EventMetadataKey.GEMINI_CLI_USER_ADDED_LINES,
|
||||
user_removed_lines: EventMetadataKey.GEMINI_CLI_USER_REMOVED_LINES,
|
||||
};
|
||||
|
||||
for (const [key, gemini_cli_key] of Object.entries(metadataMapping)) {
|
||||
if (
|
||||
event.diff_stat[key as keyof typeof event.diff_stat] !== undefined
|
||||
) {
|
||||
data.push({
|
||||
gemini_cli_key,
|
||||
value: JSON.stringify(
|
||||
event.diff_stat[key as keyof typeof event.diff_stat],
|
||||
),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const logEvent = this.createLogEvent(EventNames.FILE_OPERATION, data);
|
||||
this.enqueueLogEvent(logEvent);
|
||||
this.flushIfNeeded();
|
||||
|
||||
@@ -194,7 +194,6 @@ export function logFileOperation(
|
||||
event.lines,
|
||||
event.mimetype,
|
||||
event.extension,
|
||||
event.diff_stat,
|
||||
event.programming_language,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -258,37 +258,25 @@ describe('Telemetry Metrics', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should include diffStat when provided', () => {
|
||||
it('should record file operation without diffStat', () => {
|
||||
initializeMetricsModule(mockConfig);
|
||||
mockCounterAddFn.mockClear();
|
||||
|
||||
const diffStat = {
|
||||
ai_added_lines: 5,
|
||||
ai_removed_lines: 2,
|
||||
user_added_lines: 3,
|
||||
user_removed_lines: 1,
|
||||
};
|
||||
|
||||
recordFileOperationMetricModule(
|
||||
mockConfig,
|
||||
FileOperation.UPDATE,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
diffStat,
|
||||
);
|
||||
|
||||
expect(mockCounterAddFn).toHaveBeenCalledWith(1, {
|
||||
'session.id': 'test-session-id',
|
||||
operation: FileOperation.UPDATE,
|
||||
ai_added_lines: 5,
|
||||
ai_removed_lines: 2,
|
||||
user_added_lines: 3,
|
||||
user_removed_lines: 1,
|
||||
});
|
||||
});
|
||||
|
||||
it('should not include diffStat attributes when diffStat is not provided', () => {
|
||||
it('should record minimal file operation when optional parameters are undefined', () => {
|
||||
initializeMetricsModule(mockConfig);
|
||||
mockCounterAddFn.mockClear();
|
||||
|
||||
@@ -310,33 +298,21 @@ describe('Telemetry Metrics', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle diffStat with all zero values', () => {
|
||||
it('should not include diffStat attributes when diffStat is not provided', () => {
|
||||
initializeMetricsModule(mockConfig);
|
||||
mockCounterAddFn.mockClear();
|
||||
|
||||
const diffStat = {
|
||||
ai_added_lines: 0,
|
||||
ai_removed_lines: 0,
|
||||
user_added_lines: 0,
|
||||
user_removed_lines: 0,
|
||||
};
|
||||
|
||||
recordFileOperationMetricModule(
|
||||
mockConfig,
|
||||
FileOperation.UPDATE,
|
||||
undefined,
|
||||
undefined,
|
||||
undefined,
|
||||
diffStat,
|
||||
);
|
||||
|
||||
expect(mockCounterAddFn).toHaveBeenCalledWith(1, {
|
||||
'session.id': 'test-session-id',
|
||||
operation: FileOperation.UPDATE,
|
||||
ai_added_lines: 0,
|
||||
ai_removed_lines: 0,
|
||||
user_added_lines: 0,
|
||||
user_removed_lines: 0,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -21,7 +21,6 @@ import {
|
||||
METRIC_CONTENT_RETRY_FAILURE_COUNT,
|
||||
} from './constants.js';
|
||||
import type { Config } from '../config/config.js';
|
||||
import type { DiffStat } from '../tools/tools.js';
|
||||
|
||||
export enum FileOperation {
|
||||
CREATE = 'create',
|
||||
@@ -227,7 +226,6 @@ export function recordFileOperationMetric(
|
||||
lines?: number,
|
||||
mimetype?: string,
|
||||
extension?: string,
|
||||
diffStat?: DiffStat,
|
||||
programming_language?: string,
|
||||
): void {
|
||||
if (!fileOperationCounter || !isMetricsInitialized) return;
|
||||
@@ -238,12 +236,6 @@ export function recordFileOperationMetric(
|
||||
if (lines !== undefined) attributes['lines'] = lines;
|
||||
if (mimetype !== undefined) attributes['mimetype'] = mimetype;
|
||||
if (extension !== undefined) attributes['extension'] = extension;
|
||||
if (diffStat !== undefined) {
|
||||
attributes['ai_added_lines'] = diffStat.ai_added_lines;
|
||||
attributes['ai_removed_lines'] = diffStat.ai_removed_lines;
|
||||
attributes['user_added_lines'] = diffStat.user_added_lines;
|
||||
attributes['user_removed_lines'] = diffStat.user_removed_lines;
|
||||
}
|
||||
if (programming_language !== undefined) {
|
||||
attributes['programming_language'] = programming_language;
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import type { Config } from '../config/config.js';
|
||||
import type { ApprovalMode } from '../config/config.js';
|
||||
import type { CompletedToolCall } from '../core/coreToolScheduler.js';
|
||||
import { DiscoveredMCPTool } from '../tools/mcp-tool.js';
|
||||
import type { DiffStat, FileDiff } from '../tools/tools.js';
|
||||
import type { FileDiff } from '../tools/tools.js';
|
||||
import { AuthType } from '../core/contentGenerator.js';
|
||||
import {
|
||||
getDecisionFromOutcome,
|
||||
@@ -424,7 +424,6 @@ export class FileOperationEvent implements BaseTelemetryEvent {
|
||||
lines?: number;
|
||||
mimetype?: string;
|
||||
extension?: string;
|
||||
diff_stat?: DiffStat;
|
||||
programming_language?: string;
|
||||
|
||||
constructor(
|
||||
@@ -433,7 +432,6 @@ export class FileOperationEvent implements BaseTelemetryEvent {
|
||||
lines?: number,
|
||||
mimetype?: string,
|
||||
extension?: string,
|
||||
diff_stat?: DiffStat,
|
||||
programming_language?: string,
|
||||
) {
|
||||
this['event.name'] = 'file_operation';
|
||||
@@ -443,7 +441,6 @@ export class FileOperationEvent implements BaseTelemetryEvent {
|
||||
this.lines = lines;
|
||||
this.mimetype = mimetype;
|
||||
this.extension = extension;
|
||||
this.diff_stat = diff_stat;
|
||||
this.programming_language = programming_language;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user