Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions apps/service/src/metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ describe('Metrics', () => {
repository,
pullNumber: 1,
headSha: 'a'.repeat(40),
trigger: { kind: 'opened' }
trigger: { kind: 'opened' },
strength: 'expert'
},
attempts: 0,
maxAttempts: 3
Expand All @@ -93,7 +94,7 @@ describe('Metrics', () => {

const jobs = (await reader.points('hansi_jobs_total')).map((p) => [p.attributes, p.value]);
expect(jobs).toEqual([
[{ type: 'review', outcome: 'done', retry: 'false' }, 1],
[{ type: 'review', strength: 'expert', outcome: 'done', retry: 'false' }, 1],

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assert strength on the job duration histogram too

This only verifies the new label on hansi_jobs_total; the separately recorded hansi_job_duration_seconds label is not asserted anywhere. A regression that drops strength from the duration histogram would leave this test passing despite that metric being part of the change.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/service/src/metrics.test.ts
Line: 97

Comment:
**Assert strength on the job duration histogram too**

This only verifies the new label on `hansi_jobs_total`; the separately recorded `hansi_job_duration_seconds` label is not asserted anywhere. A regression that drops strength from the duration histogram would leave this test passing despite that metric being part of the change.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

🟡 Minor · testing · Reply if this doesn't apply.

[{ type: 'chat', outcome: 'failed', retry: 'true' }, 1],
[{ type: 'unknown', outcome: 'invalid', retry: 'false' }, 1]
]);
Expand Down
9 changes: 6 additions & 3 deletions apps/service/src/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,18 @@ export class Metrics {
this.jobsActive.add(1, { type });
}

/** A review carries the strength it ran at, so cost per review can be read per strength. */
jobFinished(
type: string,
outcome: 'done' | 'failed' | 'invalid',
retry: boolean,
seconds?: number
seconds?: number,
strength?: Strength
): void {
if (outcome !== 'invalid') this.jobsActive.add(-1, { type });
this.jobs.add(1, { type, outcome, retry: String(retry) });
if (seconds !== undefined) this.jobDuration.record(seconds, { type, outcome });
const labels = { type, ...(strength && { strength }) };
this.jobs.add(1, { ...labels, outcome, retry: String(retry) });
Comment on lines +130 to +131

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the documented job metric labels

The README metrics table at rows 202–203 still lists the old label sets, so it no longer describes the labels emitted for review jobs. Please update those rows to note that strength is present for reviews and absent for chat/invalid jobs.

Prompt To Fix With AI
This is a comment left during a code review.
Path: apps/service/src/metrics.ts
Line: 130-131

Comment:
**Update the documented job metric labels**

The README metrics table at rows 202–203 still lists the old label sets, so it no longer describes the labels emitted for review jobs. Please update those rows to note that `strength` is present for reviews and absent for chat/invalid jobs.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.

🟡 Minor · documentation · Reply if this doesn't apply.

if (seconds !== undefined) this.jobDuration.record(seconds, { ...labels, outcome });
}

/**
Expand Down
3 changes: 2 additions & 1 deletion apps/service/src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ export class Worker {
job.type,
outcome?.outcome ?? 'failed',
outcome === undefined || (outcome.outcome === 'failed' && outcome.retry),
(performance.now() - started) / 1000
(performance.now() - started) / 1000,
job.type === 'review' ? job.strength : undefined
);
this.running--;
if (this.running === 0) this.idle.splice(0).forEach((resolve) => resolve());
Expand Down