-
Notifications
You must be signed in to change notification settings - Fork 37
feat(o11y): track ingest version in session metrics + type safety and test coverage #57
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
c1904bc
feat(o11y): track ingest version in session metrics
iscekic 43bd83b
refactor(session-ingest): tighten IngestMetaKey and writeIngestMetaIf…
iscekic 9258f81
test(o11y): add unit tests for alerting evaluate helpers
iscekic 1b2a3af
test(session-ingest): add unit tests for ingest meta extractors
iscekic d70ff4e
test(session-ingest): add unit tests for getItemIdentity
iscekic 9fbb369
test(session-ingest): add unit tests for buildSharedSessionSnapshot
iscekic 88f6280
test(session-ingest): add unit tests for withDORetry
iscekic ada39d4
test(session-ingest): add edge case tests for computeSessionMetrics
iscekic d0c3068
fix(o11y): default ingestVersion to 0 for rolling deploy safety
iscekic b09667a
test(o11y): verify ingestVersion defaults to 0 when omitted
iscekic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import { describe, it, expect } from 'vitest'; | ||
| import { computeBurnRate, dimensionKey, effectiveSeverity, rowsToMap } from '../src/alerting/evaluate'; | ||
|
|
||
| describe('computeBurnRate', () => { | ||
| it('computes burn rate from bad fraction and SLO', () => { | ||
| // 1% bad with 99.9% SLO => 0.01 / 0.001 = 10 | ||
| expect(computeBurnRate(0.01, 0.999)).toBeCloseTo(10); | ||
| }); | ||
|
|
||
| it('returns 0 when bad fraction is 0', () => { | ||
| expect(computeBurnRate(0, 0.999)).toBe(0); | ||
| }); | ||
|
|
||
| it('returns Infinity when SLO is 1.0 (zero error budget)', () => { | ||
| expect(computeBurnRate(0.01, 1.0)).toBe(Infinity); | ||
| }); | ||
|
|
||
| it('returns Infinity when SLO exceeds 1.0', () => { | ||
| expect(computeBurnRate(0.01, 1.1)).toBe(Infinity); | ||
| }); | ||
|
|
||
| it('handles typical page-level burn rate threshold', () => { | ||
| // 14.4x burn rate means bad_fraction = 14.4 * (1 - 0.999) = 0.0144 | ||
| expect(computeBurnRate(0.0144, 0.999)).toBeCloseTo(14.4); | ||
| }); | ||
| }); | ||
|
|
||
| describe('dimensionKey', () => { | ||
| it('constructs provider:model:clientName key', () => { | ||
| expect(dimensionKey('openai', 'gpt-4', 'kilo-gateway')).toBe('openai:gpt-4:kilo-gateway'); | ||
| }); | ||
|
|
||
| it('handles empty strings', () => { | ||
| expect(dimensionKey('', '', '')).toBe('::'); | ||
| }); | ||
|
|
||
| it('preserves colons in values', () => { | ||
| expect(dimensionKey('a:b', 'c', 'd')).toBe('a:b:c:d'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('rowsToMap', () => { | ||
| it('converts rows to a map keyed by dimension', () => { | ||
| const rows = [ | ||
| { provider: 'openai', model: 'gpt-4', client_name: 'kilo-gateway', value: 1 }, | ||
| { provider: 'anthropic', model: 'claude-sonnet-4.5', client_name: 'cli', value: 2 }, | ||
| ]; | ||
| const map = rowsToMap(rows); | ||
| expect(map.size).toBe(2); | ||
| expect(map.get('openai:gpt-4:kilo-gateway')?.value).toBe(1); | ||
| expect(map.get('anthropic:claude-sonnet-4.5:cli')?.value).toBe(2); | ||
| }); | ||
|
|
||
| it('returns empty map for empty input', () => { | ||
| expect(rowsToMap([]).size).toBe(0); | ||
| }); | ||
|
|
||
| it('last row wins for duplicate dimensions', () => { | ||
| const rows = [ | ||
| { provider: 'openai', model: 'gpt-4', client_name: 'cli', value: 1 }, | ||
| { provider: 'openai', model: 'gpt-4', client_name: 'cli', value: 2 }, | ||
| ]; | ||
| const map = rowsToMap(rows); | ||
| expect(map.size).toBe(1); | ||
| expect(map.get('openai:gpt-4:cli')?.value).toBe(2); | ||
| }); | ||
| }); | ||
|
|
||
| describe('effectiveSeverity', () => { | ||
| const recommended = new Set(['gpt-4', 'claude-sonnet-4.5']); | ||
|
|
||
| it('keeps page for recommended model on kilo-gateway', () => { | ||
| expect(effectiveSeverity('page', 'kilo-gateway', 'gpt-4', recommended)).toBe('page'); | ||
| }); | ||
|
|
||
| it('downgrades page to ticket for non-recommended model on kilo-gateway', () => { | ||
| expect(effectiveSeverity('page', 'kilo-gateway', 'gpt-3.5-turbo', recommended)).toBe('ticket'); | ||
| }); | ||
|
|
||
| it('downgrades page to ticket for recommended model on non-gateway client', () => { | ||
| expect(effectiveSeverity('page', 'cli', 'gpt-4', recommended)).toBe('ticket'); | ||
| }); | ||
|
|
||
| it('downgrades page to ticket for non-recommended model on non-gateway client', () => { | ||
| expect(effectiveSeverity('page', 'cli', 'gpt-3.5-turbo', recommended)).toBe('ticket'); | ||
| }); | ||
|
|
||
| it('keeps ticket severity unchanged regardless of model/client', () => { | ||
| expect(effectiveSeverity('ticket', 'kilo-gateway', 'gpt-4', recommended)).toBe('ticket'); | ||
| expect(effectiveSeverity('ticket', 'cli', 'gpt-3.5-turbo', recommended)).toBe('ticket'); | ||
| }); | ||
|
|
||
| it('handles empty recommended models set', () => { | ||
| expect(effectiveSeverity('page', 'kilo-gateway', 'gpt-4', new Set())).toBe('ticket'); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.