-
Notifications
You must be signed in to change notification settings - Fork 449
feat(api): accept exemplar settings on API- and agent-authored tiles #2809
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
Open
jordan-simonovski
wants to merge
6
commits into
jordansimonovski/exemplars-overlay
from
jordansimonovski/exemplars-agent-surface
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d4c31de
feat(api): accept exemplar settings on API- and agent-authored tiles
jordan-simonovski 62f79a3
fix(api): validate the exemplar trace source, not just its shape
jordan-simonovski a59288e
chore(api): raise the api lint ceiling by one for the round-trip test
jordan-simonovski 399e733
fix(api): exempt unchanged tiles from the exemplar trace-source kind …
jordan-simonovski b6cf62b
fix(api): exempt unchanged tiles from the exemplar source existence c…
jordan-simonovski be4166f
fix(api): re-validate the exemplar trace source when exemplars are sw…
jordan-simonovski 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| --- | ||
| '@hyperdx/api': minor | ||
| --- | ||
|
|
||
| feat: accept exemplar settings on API- and agent-authored dashboard tiles | ||
|
|
||
| `enableExemplars` and `exemplarTraceSourceId` are now accepted on line and | ||
| stacked-bar tiles through the external v2 API and the MCP dashboard tools, | ||
| survive the tile conversion in both directions, and are documented in the | ||
| OpenAPI spec. Previously they validated on write and were dropped before | ||
| persistence, so they could not be set through any surface. | ||
|
|
||
| `exemplarTraceSourceId` is checked three ways, because a marker's "view trace" | ||
| link is only as good as the source behind it: an ObjectId on both surfaces, the | ||
| source must exist for the team, and it must actually be a Trace source. The | ||
| existence and kind checks mirror the heatmap gate. Without them a well-formed id | ||
| for a metric source saved cleanly and left every marker linking nowhere. |
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
85 changes: 85 additions & 0 deletions
85
packages/api/src/mcp/tools/dashboards/__tests__/exemplarSettings.test.ts
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,85 @@ | ||
| import { Types } from 'mongoose'; | ||
|
|
||
| import { mcpTilesParam } from '@/mcp/tools/dashboards/schemas'; | ||
|
|
||
| /** | ||
| * `enableExemplars` and `exemplarTraceSourceId` are the two exemplar settings an | ||
| * MCP agent can put on a tile. The trace source id has to survive as something | ||
| * the source lookup can actually resolve — it is read back as a Mongo ObjectId — | ||
| * so accepting any string here would persist a tile whose markers silently never | ||
| * link to a trace. | ||
| */ | ||
| const tile = | ||
| (displayType: 'line' | 'stacked_bar') => | ||
| (config: Record<string, unknown>) => [ | ||
| { | ||
| name: 'Latency', | ||
| config: { | ||
| displayType, | ||
| sourceId: new Types.ObjectId().toString(), | ||
| select: [{ aggFn: 'count', alias: 'Requests' }], | ||
| ...config, | ||
| }, | ||
| }, | ||
| ]; | ||
|
|
||
| // The two tile types declare the exemplar fields in separate schema blocks, so | ||
| // an edit that only updates one would otherwise go unnoticed. | ||
| const lineTile = tile('line'); | ||
| const barTile = tile('stacked_bar'); | ||
|
|
||
| describe('MCP tile exemplar settings', () => { | ||
| it('accepts a valid ObjectId as the exemplar trace source', () => { | ||
| const traceSourceId = new Types.ObjectId().toString(); | ||
| const parsed = mcpTilesParam.parse( | ||
| lineTile({ enableExemplars: true, exemplarTraceSourceId: traceSourceId }), | ||
| ); | ||
| expect(parsed[0].config).toMatchObject({ | ||
| enableExemplars: true, | ||
| exemplarTraceSourceId: traceSourceId, | ||
| }); | ||
| }); | ||
|
|
||
| it.each([ | ||
| ['a source name rather than an id', 'Traces'], | ||
| ['a truncated id', '507f1f77bcf86cd7994390'], | ||
| ['an over-long id', '507f1f77bcf86cd799439011ff'], | ||
| ['an empty string', ''], | ||
| ['a non-hex id of the right length', 'zzzzzzzzzzzzzzzzzzzzzzzz'], | ||
| ])('rejects %s as the exemplar trace source', (_label, value) => { | ||
| expect(() => | ||
| mcpTilesParam.parse(lineTile({ exemplarTraceSourceId: value })), | ||
| ).toThrow(/Invalid ObjectId/); | ||
| }); | ||
|
|
||
| // Worth recording because it is surprising: Mongo also accepts a 12-character | ||
| // string as 12 raw bytes, so `Types.ObjectId.isValid` — and therefore every | ||
| // objectIdSchema field in this codebase, not just this one — lets one through. | ||
| // Such an id simply resolves to no source, which is the same outcome as any | ||
| // other id that does not exist, so it is not worth diverging from the shared | ||
| // validator here. | ||
| it('lets a 12-character string through, as every other id field does', () => { | ||
| expect(() => | ||
| mcpTilesParam.parse(lineTile({ exemplarTraceSourceId: 'trace-source' })), | ||
| ).not.toThrow(); | ||
| }); | ||
|
|
||
| it('leaves both settings optional', () => { | ||
| const parsed = mcpTilesParam.parse(lineTile({})); | ||
| expect(parsed[0].config).not.toHaveProperty('enableExemplars'); | ||
| expect(parsed[0].config).not.toHaveProperty('exemplarTraceSourceId'); | ||
| }); | ||
|
|
||
| it.each([ | ||
| ['line', lineTile], | ||
| ['stacked_bar', barTile], | ||
| ])('validates the trace source on a %s tile', (_label, build) => { | ||
| expect(() => | ||
| mcpTilesParam.parse(build({ exemplarTraceSourceId: 'Traces' })), | ||
| ).toThrow(/Invalid ObjectId/); | ||
| const id = new Types.ObjectId().toString(); | ||
| expect( | ||
| mcpTilesParam.parse(build({ exemplarTraceSourceId: id }))[0].config, | ||
| ).toMatchObject({ exemplarTraceSourceId: id }); | ||
| }); | ||
| }); |
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.
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.