-
Notifications
You must be signed in to change notification settings - Fork 626
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(flamegraph/models): make it mandatory to handle all spyNames (#…
…1300) * chore(flamegraph/models): make it mandatory to handle all spyNames * chore(models): export spynames at runtime BREAKING CHANGE: it will throw an error if spyName is unsupported
- Loading branch information
Showing
13 changed files
with
78 additions
and
28 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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 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 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,18 @@ | ||
import { SpyNameSchema, AllSpyNames } from './spyName'; | ||
|
||
describe('SpyName', () => { | ||
it('fails when when passing an unsupported value', () => { | ||
expect(SpyNameSchema.safeParse('foo').success).toBe(false); | ||
}); | ||
|
||
it('defaults to "unknown" when absent', () => { | ||
expect(SpyNameSchema.parse('')).toBe('unknown'); | ||
}); | ||
|
||
test.each(AllSpyNames.map((a) => [a, a]))( | ||
'parse("%s") should return "%s"', | ||
(spyName) => { | ||
expect(SpyNameSchema.parse(spyName)).toBe(spyName); | ||
} | ||
); | ||
}); |
This file contains 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,30 @@ | ||
import { z } from 'zod'; | ||
|
||
export const SpyNameFirstClass = [ | ||
'dotnetspy', | ||
'ebpfspy', | ||
'gospy', | ||
'phpspy', | ||
'pyspy', | ||
'rbspy', | ||
'nodespy', | ||
'javaspy', | ||
'pyroscope-rs', | ||
] as const; | ||
|
||
export const SpyNameOther = [ | ||
'scrape', // for compability purposes, it should be golang | ||
'tracing', | ||
'unknown', | ||
] as const; | ||
|
||
export const AllSpyNames = [...SpyNameFirstClass, ...SpyNameOther] as const; | ||
|
||
export const SpyNameSchema = z.preprocess((val) => { | ||
if (!val) { | ||
return 'unknown'; | ||
} | ||
return val; | ||
}, z.enum(AllSpyNames).default('unknown')); | ||
|
||
export type SpyName = z.infer<typeof SpyNameSchema>; |