Repository navigation
[FEATURE] ExemplarMetadataTooltip: display the links of the exemplar (perses#3445) - #442
austinlparker wants to merge 7 commits into
Conversation
Signed-off-by: Augustin Husson <augustin.husson@amadeus.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Augustin Husson <augustin.husson@amadeus.com>
…(perses#3445) Exemplars can carry links since perses/spec#118, e.g. to open their trace in a tracing UI. List them in the exemplar tooltip, above the labels so they stay in view with long label sets. The links open in a new tab. Their URLs are built by query plugins from exemplar labels, so links with an unsafe scheme are not rendered. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Signed-off-by: Austin Parker <austin@ap2.io>
Tag links have no URL. The links display shows URL links only, and the dashboard links editor keeps tag links without editing them. Signed-off-by: Juliano Costa <julianocosta89@outlook.com>
…lar-trace-links Signed-off-by: Juliano Costa <julianocosta89@outlook.com> # Conflicts: # package-lock.json
|
@Nexucis would you be able to approve and run the CI? |
A link has either a URL or tags. The panel links editor showed an empty URL field for tag links, and typing in it made a link with both, which the spec schema rejects. Tag links now show their name and tags, and can still be removed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Austin Parker <austin@ap2.io>
| export const panelEditorSchema: z.ZodType<PanelEditorValues, PanelEditorValues> = z.object({ | ||
| groupId: z.number(), | ||
| panelDefinition: panelDefinitionSchema, | ||
| panelDefinition: panelDefinitionSchema as PanelDefinitionEditorSchema, |
There was a problem hiding this comment.
Panel links with an empty URL now save without an error. spec 0.3.0 had url: z.string().min(1); the 0.4.0-beta.0 linkSchema accepts url: ''. Clicking "+" in the panel Links editor and saving with the URL blank stores links: [{url: ''}]. LinksDisplay then renders a link with an empty href (it reloads the current page), and two such links share key={link.url} = ''. DashboardLinksEditor still rejects empty URLs, so the two editors now disagree. This also applies to buildPanelEditorSchema (line 47).
Suggested fix: refine both editor schemas and attach the error to the link path, so the existing fieldState.error in LinkControl shows it:
const requireLinkUrls = (values: PanelEditorValues, ctx: z.RefinementCtx): void => {
values.panelDefinition.spec.links?.forEach((link, i) => {
if (!link.tags?.length && !link.url?.trim()) {
ctx.addIssue({ code: 'custom', message: 'URL is required', path: ['panelDefinition', 'spec', 'links', i] });
}
});
};
// z.object({...}).superRefine(requireLinkUrls) in panelEditorSchema and buildPanelEditorSchemaPlease also add a test that runs the form through zodResolver(panelEditorSchema). LinksEditor.test.tsx has no resolver, so it doesn't exercise the link schema.
There was a problem hiding this comment.
Fixed in 93ac8a2. panelEditorSchema and buildPanelEditorSchema now share a requireLinkUrls refinement that puts "URL is required" on panelDefinition.spec.links.<i> for a URL link with a blank URL, so LinkControl shows it. LinksEditor.test.tsx now has cases that go through zodResolver(panelEditorSchema): a valid link saves, an empty URL link added with "+" is blocked with the message, and an invalid tag link shows its spec error. (The test form uses noValidate, because the URL field is required and jsdom's own validation otherwise blocks the submit before the resolver runs.)
| ); | ||
| } | ||
|
|
||
| function isURLLink(link: Link): link is URLLink { |
There was a problem hiding this comment.
This tag-link vs URL-link check doesn't match the panel editor or the spec. This isURLLink (and the copy in LinksDisplay.tsx:197) checks link.url !== undefined, while LinksEditor.tsx:72 checks link.tags?.length. The spec schema treats {url: '', tags: [...]} as a tag link, but here it's treated as a URL link with an empty URL: the editor shows "URL is required" and blocks saving, and LinksDisplay renders it with an empty href instead of hiding it.
Suggested fix: one exported helper that follows the spec (non-empty tags means a tag link), in the lowest layer that owns links (plugin-system or components), used in all three places instead of the two private copies:
export function isTagLink(link: Link): link is TagLink {
return (link.tags?.length ?? 0) > 0;
}
export function isURLLink(link: Link): link is URLLink {
return !isTagLink(link);
}There was a problem hiding this comment.
Fixed in 93ac8a2. @perses-dev/components now exports isTagLink / isURLLink (components/src/utils/link.ts): a link with at least one tag is a tag link, like the spec schema, and anything else is a URL link. DashboardLinksEditor, LinksDisplay, LinksEditor and the panel editor schema use them, and the private copies are gone. components is the lowest layer here that already depends on the spec types. Unit tests cover {url: '', tags: [...]}, an empty tag list, and a link with neither field.
| description: string; | ||
| } | ||
|
|
||
| function isURLLink(link: Link): link is URLLink { |
There was a problem hiding this comment.
Same as the comment on DashboardLinksEditor.tsx:351: link.url !== undefined disagrees with the spec and with LinksEditor (tags?.length). Suggested fix: use the shared isURLLink/isTagLink helper instead of this private copy.
There was a problem hiding this comment.
Fixed in 93ac8a2: this uses the shared isURLLink from @perses-dev/components now. LinksDisplay also skips URL links whose URL is blank, so they no longer render with an empty href.
| name={`panelDefinition.spec.links.${index}`} | ||
| render={({ field, field: { value: link }, fieldState }) => { | ||
| // A link has either a URL or tags. Tag links are not edited here, as setting a URL on one makes it invalid. | ||
| if (link?.tags?.length) { |
There was a problem hiding this comment.
An invalid tag link blocks saving with no visible message. This branch ignores fieldState.error. The spec's superRefine errors ("a tag link must set a name", "link must set either a url or tags, not both") have an empty path, so they land on this link's Controller. Save does nothing, nothing is shown, and there is no field to correct.
Suggested fix: render the error inside the tag-link Stack:
{fieldState.error && (
<Typography variant="body2" color="error">
{fieldState.error.message}
</Typography>
)}There was a problem hiding this comment.
Fixed in 93ac8a2. The tag-link branch now shows fieldState.error.message under the tags. Covered by the "shows the error of an invalid tag link" test (a tag link must set a name).
| // Links come first: they are the main action of the tooltip and must not be pushed out of | ||
| // view by long label sets. The URLs are built from exemplar labels, i.e. from data that is | ||
| // not controlled by Perses, so an unsafe one (e.g. javascript:) is never rendered as a link. | ||
| const safeLinks = (exemplar.links ?? []).filter((link) => sanitizeUrl(link.url) !== undefined); |
There was a problem hiding this comment.
An exemplar link with an empty URL is still rendered. sanitizeUrl('') returns '', not undefined, so this filter keeps it. The tooltip shows a "Links" section with a blank link that opens the current page in a new tab (e.g. when a plugin builds {url: ''} because the trace-id label is missing).
Suggested fix (plus a test case for { url: '' }):
| const safeLinks = (exemplar.links ?? []).filter((link) => sanitizeUrl(link.url) !== undefined); | |
| const safeLinks = (exemplar.links ?? []).filter( | |
| (link) => link.url.trim() !== '' && sanitizeUrl(link.url) !== undefined | |
| ); |
There was a problem hiding this comment.
Applied in 93ac8a2: links with a blank URL (after trimming) are filtered out, and a test covers '' and ' '.
| * Follows the mouse while hovering an exemplar marker and can be pinned in place, the same way | ||
| * the annotation tooltip works. | ||
| * the annotation tooltip works. The links of the exemplar (e.g. to its trace in a tracing UI) open | ||
| * in a new tab; they can only be reached once the tooltip is pinned. |
There was a problem hiding this comment.
The links may never be clickable in the app. As this docstring says, the links can only be reached once the tooltip is pinned; until then it follows the cursor. DashboardApp.tsx:187 and ViewExploreApp.tsx:46 set ChartsProvider enablePinning={false}.
Suggested fix: check how the consuming plugin sets pinnedPos for exemplars when pinning is disabled. If it never pins, pin the exemplar tooltip on click regardless of enablePinning, or document that pinning is required.
There was a problem hiding this comment.
I checked the consumers. In the Perses app the root ChartsProvider (ui/app/src/context/DarkMode.tsx) sets enablePinning={true}. DashboardApp.tsx:187 only wraps the PanelDrawer (the panel editor preview) with enablePinning={false}, so panels on a dashboard can pin. Explore (ViewExploreApp.tsx:46) does disable pinning. There, TimeSeriesChart still pins an exemplar on click, because its click handler doesn't check enablePinning, but HeatMapChart returns early, so HeatMap exemplar links can't be clicked in Explore. That's a fix for perses/plugins. Here, I updated the docstring in 93ac8a2 to say that pinning is driven by pinnedPos, that a consumer rendering links has to set it on click whether or not enablePinning is set, and that enablePinning only controls the pin button.
| "@perses-dev/client": "0.56.0-beta.1", | ||
| "@perses-dev/components": "0.56.0-beta.1", | ||
| "@perses-dev/spec": "0.3.0", | ||
| "@perses-dev/spec": "0.4.0-beta.0", |
There was a problem hiding this comment.
@perses-dev/spec dependency range bumped 0.3.0 → 0.4.0-beta.0 here and in client/package.json:20, components/package.json:69 and dashboards/package.json:37. AGENTS.md says not to change dependency ranges unless explicitly requested.
Suggested fix: confirm the bump is intended, and note the plugin compatibility impact in the PR description (see the comment on PluginRuntime.tsx:148).
There was a problem hiding this comment.
The bump is intended: Exemplar.links only exists from @perses-dev/spec 0.4.0-beta.0 (perses/spec#118), so this feature can't ship on 0.3.0. The bump itself comes from #429, which this PR depends on. The plugin compatibility impact is written up in #442 (comment) for the PR description.
| shareConfig: { | ||
| singleton: true, | ||
| requiredVersion: '^0.3.0', | ||
| requiredVersion: '^0.4.0-beta.0', |
There was a problem hiding this comment.
The shared singleton requiredVersion is now ^0.4.0-beta.0. Under semver, ^0.3.0 and ^0.4.0-beta.0 don't overlap, so plugins built against spec ^0.3.0 will hit a shared-version mismatch when they load.
Suggested fix: confirm this is intended and coordinate it with a plugins release, or call it out as a breaking change for plugin authors.
There was a problem hiding this comment.
Intended, and it is a breaking change for plugin authors: a plugin built against spec ^0.3.0 won't satisfy the shared singleton ^0.4.0-beta.0. It has to be released together with a perses/plugins release that moves to @perses-dev/spec ^0.4.0-beta.0. It's called out in #442 (comment), which is meant to go into the PR description.
|
|
||
| if (links.length === 0) { | ||
| // Tag links open a menu of dashboards, which needs the application to list them. Only URL links are displayed here. | ||
| const urlLinks = links.filter(isURLLink); |
There was a problem hiding this comment.
The new tag-link behaviour has no tests. LinksDisplay now hides tag links, and DashboardLinksEditor keeps tag links, shows Tags: … and disables editing them. LinksDisplay.test.tsx has no tag cases, and DashboardLinksEditor has no test file.
Suggested fix: add cases to LinksDisplay.test.tsx (tag links only render nothing; mixed links render only the URL links), and add DashboardLinksEditor.test.tsx (a tag link is listed read-only and survives a save unchanged).
There was a problem hiding this comment.
Added in 93ac8a2. LinksDisplay.test.tsx covers: only tag links renders nothing, mixed links render only the URL links (dashboard chips, and a single panel URL link rendered as a button), and blank-URL links aren't rendered. The new DashboardLinksEditor.test.tsx covers a tag link listed read-only ("Edit link" disabled) and passed through unchanged on Apply, an empty URL blocking Apply, and a link with neither field.
| const hasError = link.url.trim().length === 0; | ||
| const urlLink = isURLLink(link) ? link : undefined; | ||
| const hasError = urlLink !== undefined && urlLink.url.trim().length === 0; | ||
| const target = isURLLink(link) ? link.url || '(no URL)' : `Tags: ${link.tags.join(', ')}`; |
There was a problem hiding this comment.
Crash on a link with neither url nor tags (this one predates the PR). For links: [{name: 'x'}], isURLLink returns false and link.tags.join throws TypeError: Cannot read properties of undefined (reading 'join'). Before this change the same data crashed one line earlier, at link.url.trim().
Suggested fix: the shared isURLLink from the comment on line 351 treats a link without tags as a URL link, and the URL should be defaulted:
const hasError = urlLink !== undefined && (urlLink.url ?? '').trim().length === 0;
const target = urlLink ? urlLink.url || '(no URL)' : `Tags: ${link.tags?.join(', ') ?? ''}`;There was a problem hiding this comment.
Fixed in 93ac8a2, following your suggestion: the shared isURLLink treats a link without tags as a URL link, the URL defaults to '' (hasError, isValid, target and the form value), and link.tags?.join is guarded. {name: 'x'} now shows "(no URL)" and blocks Apply. A test covers it.
- Add isTagLink/isURLLink to @perses-dev/components, following the spec (a link with tags is a tag link), and use them in LinksEditor, LinksDisplay and DashboardLinksEditor instead of private copies. - Require a URL on URL links in the panel editor schemas. - Show the errors of a tag link in the panel links editor. - Do not render links with an empty URL in LinksDisplay and ExemplarMetadataTooltip. - Do not crash on a dashboard link with neither a URL nor tags. - Document that exemplar links need the consumer to pin the tooltip. - Add tests for tag links, empty URLs and schema validation. Signed-off-by: Juliano Costa <julianocosta89@outlook.com>
|
I couldn't edit the PR description, so here is the compatibility note for it. @austinlparker, could you add it to the description? CompatibilityThis bumps Plugin authors: the module federation runtime shares The spec 0.4 |
|
@jgbernalp all reviews were addressed ✅ Thank you for all comments! |
Description
Part of perses/perses#3445, step 2 ("Embed links") of the exemplars roadmap.
Exemplars can carry links since perses/spec#118, for example to open their trace in a tracing UI. This lists them in a "Links" section of
ExemplarMetadataTooltip:nameshows its URL.javascript:) is not rendered, using the existingsanitizeUrl.Since the tooltip follows the mouse until it is pinned, the links can only be clicked once the tooltip is pinned.
Depends on #429. If merged first, this PR supersedes #429. The
linksfield only exists from@perses-dev/spec0.4.0-beta.0, so this branch carries the two commits of #429. It also adapts the links editors and display to theLinkunion of spec 0.4 (URL links and tag links), fixing thetype-checkfailure inplugin-system/src/components/LinksEditor/LinksEditor.tsxcaused by the bump and also present on #429. Tag links are kept and can be removed, but they are not edited or displayed as links: the panel links editor shows them as read-only.The links are produced by the Prometheus plugin in perses/plugins#927.
Tested with unit tests (links rendered with their attributes, URL fallback, unsafe URL dropped, no section without links) and in a Perses build from
mainusing this branch, with TimeSeriesChart and HeatMapChart panels on a Prometheus fed by the OpenTelemetry Collector spanmetrics connector: the link of a pinned exemplar opens its trace in Jaeger.Screenshots
Tooltip with a named link and a link without a name (the URL is shown):
In a dashboard, with the links produced by perses/plugins#927:
Checklist
[<catalog_entry>] <commit message>naming convention using one of thefollowing
catalog_entryvalues:FEATURE,ENHANCEMENT,BUGFIX,BREAKINGCHANGE,DOC,IGNORE.UI Changes
🤖 Generated with Claude Code