From 363854172f740596c7e15588a09e35c225aaeda1 Mon Sep 17 00:00:00 2001 From: "gemini-cli[bot]" <218312386+gemini-cli[bot]@users.noreply.github.com> Date: Fri, 1 May 2026 12:20:02 -0700 Subject: [PATCH] Metrics updates (#26348) Co-authored-by: gemini-cli[bot] --- tools/gemini-cli-bot/metrics/index.ts | 8 +-- .../metrics/scripts/backlog_age.ts | 59 +++++++++++++++++++ 2 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 tools/gemini-cli-bot/metrics/scripts/backlog_age.ts diff --git a/tools/gemini-cli-bot/metrics/index.ts b/tools/gemini-cli-bot/metrics/index.ts index 3f18c610b8..9562033395 100644 --- a/tools/gemini-cli-bot/metrics/index.ts +++ b/tools/gemini-cli-bot/metrics/index.ts @@ -133,7 +133,7 @@ async function run() { writeFileSync(OUTPUT_FILE, results.join('\n')); console.log(`Saved metrics to ${OUTPUT_FILE}`); - // Update timeseries with rolling window (keep last 100 lines) + // Update timeseries with rolling window (keep last 5000 lines) const timestamp = new Date().toISOString(); let timeseriesLines: string[] = []; if (existsSync(TIMESERIES_FILE)) { @@ -146,10 +146,10 @@ async function run() { if (newRows.length > 0) { timeseriesLines.push(...newRows); - // Keep header + last 100 data rows - if (timeseriesLines.length > 101) { + // Keep header + last 5000 data rows + if (timeseriesLines.length > 5001) { const header = timeseriesLines[0]; - timeseriesLines = [header, ...timeseriesLines.slice(-100)]; + timeseriesLines = [header, ...timeseriesLines.slice(-5000)]; } writeFileSync(TIMESERIES_FILE, timeseriesLines.join('\n') + '\n'); diff --git a/tools/gemini-cli-bot/metrics/scripts/backlog_age.ts b/tools/gemini-cli-bot/metrics/scripts/backlog_age.ts new file mode 100644 index 0000000000..816dfbdf59 --- /dev/null +++ b/tools/gemini-cli-bot/metrics/scripts/backlog_age.ts @@ -0,0 +1,59 @@ +/** + * @license + * Copyright 2026 Google LLC + * SPDX-License-Identifier: Apache-2.0 + */ + +import { GITHUB_OWNER, GITHUB_REPO } from '../types.js'; +import { execSync } from 'node:child_process'; + +/** + * Calculates the average age of the oldest 100 open issues in days. + */ +function run() { + try { + const query = ` + query($owner: String!, $repo: String!) { + repository(owner: $owner, name: $repo) { + issues(first: 100, states: OPEN, orderBy: {field: CREATED_AT, direction: ASC}) { + nodes { + createdAt + } + } + } + } + `; + const output = execSync( + `gh api graphql -F owner=${GITHUB_OWNER} -F repo=${GITHUB_REPO} -f query='${query}'`, + { encoding: 'utf-8', stdio: ['ignore', 'pipe', 'ignore'] }, + ).trim(); + const data = JSON.parse(output).data.repository; + const issues = data.issues.nodes; + + if (issues.length === 0) { + process.stdout.write('backlog_age_days,0\n'); + return; + } + + const now = new Date().getTime(); + const totalAgeDays = issues.reduce( + (acc: number, issue: { createdAt: string }) => { + const created = new Date(issue.createdAt).getTime(); + return acc + (now - created) / (1000 * 60 * 60 * 24); + }, + 0, + ); + + const avgAgeDays = totalAgeDays / issues.length; + process.stdout.write( + `backlog_age_days,${Math.round(avgAgeDays * 100) / 100}\n`, + ); + } catch (error) { + process.stderr.write( + error instanceof Error ? error.message : String(error), + ); + process.exit(1); + } +} + +run();