-
Notifications
You must be signed in to change notification settings - Fork 421
fix: support service name expression and quick attribute filters in surrounding context #2558
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
MikeShi42
wants to merge
10
commits into
main
Choose a base branch
from
cursor/fix-surrounding-context-filters-8b00
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,149
−130
Open
Changes from 5 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
34ce8a6
fix: support service name expression and quick attribute filters in s…
cursoragent 4314df7
chore: add changeset for surrounding context filters fix
cursoragent 1250d47
refactor: unify surrounding context filters into single pill-based UI
cursoragent 95466e9
refactor: extract filter pills into ContextFilterPills.tsx
cursoragent 9ce367d
fix: reset filter state on row change and remove unused export
cursoragent 16915c3
refactor: redesign surrounding context with preset-based filter UI
cursoragent 3f4083d
fix: polish surrounding context filter UX
cursoragent 6d4e195
fix: show custom search input when pill toggled to Custom mode
cursoragent ac8b034
refactor: derive showCustomSearch from preset, DRY formatColumnEquals…
cursoragent c97c9ca
fix: address surrounding context review feedback
cursoragent 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
Some comments aren't visible on the classic Files Changed page.
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,5 @@ | ||
| --- | ||
| "@hyperdx/app": patch | ||
| --- | ||
|
|
||
| Fix Surrounding Context filters for non-OTEL schemas by using the source's serviceNameExpression for the "Service" filter instead of hardcoded ResourceAttributes lookup. Also adds quick event attribute filters that let users toggle attributes from the current event to narrow surrounding context results. |
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,223 @@ | ||
| import { | ||
| isLogSource, | ||
| isTraceSource, | ||
| TSource, | ||
| } from '@hyperdx/common-utils/dist/types'; | ||
| import { Text, Tooltip } from '@mantine/core'; | ||
| import { IconX } from '@tabler/icons-react'; | ||
|
|
||
| import { formatAttributeClause } from '@/utils'; | ||
|
|
||
| import { ROW_DATA_ALIASES } from './DBRowDataPanel'; | ||
|
|
||
| export interface QuickFilterItem { | ||
| id: string; | ||
| label: string; | ||
| value: string; | ||
| generateWhere: (isSql: boolean) => string; | ||
| } | ||
|
|
||
| function formatColumnEquals( | ||
| column: string, | ||
| value: string, | ||
| isSql: boolean, | ||
| ): string { | ||
| if (isSql) { | ||
| return `${column} = '${value.replace(/'/g, "''")}'`; | ||
| } | ||
| return `${column}:"${value.replace(/"/g, '\\"')}"`; | ||
| } | ||
|
|
||
| const PROMOTED_RESOURCE_ATTR_KEYS = [ | ||
| 'host.name', | ||
| 'k8s.pod.name', | ||
| 'k8s.node.name', | ||
| ]; | ||
|
|
||
| export function extractQuickFilters( | ||
| rowData: Record<string, any>, | ||
| source: TSource, | ||
| ): QuickFilterItem[] { | ||
| const filters: QuickFilterItem[] = []; | ||
| const skipAliases = new Set<string>(Object.values(ROW_DATA_ALIASES)); | ||
|
|
||
| const serviceNameExpr = | ||
| isLogSource(source) || isTraceSource(source) | ||
| ? source.serviceNameExpression | ||
| : undefined; | ||
| const resourceAttrExpr = | ||
| 'resourceAttributesExpression' in source | ||
| ? source.resourceAttributesExpression | ||
| : undefined; | ||
| const eventAttrExpr = | ||
| isLogSource(source) || isTraceSource(source) | ||
| ? source.eventAttributesExpression | ||
| : undefined; | ||
|
|
||
| const resourceAttrs = rowData[ROW_DATA_ALIASES.RESOURCE_ATTRIBUTES] as | ||
| | Record<string, unknown> | ||
| | undefined; | ||
|
|
||
| // Service name pill (promoted, always first) | ||
| const serviceNameValue = rowData[ROW_DATA_ALIASES.SERVICE_NAME]; | ||
| if (serviceNameExpr && serviceNameValue) { | ||
| filters.push({ | ||
| id: 'svc', | ||
| label: serviceNameExpr, | ||
| value: String(serviceNameValue), | ||
| generateWhere: isSql => | ||
| formatColumnEquals(serviceNameExpr, String(serviceNameValue), isSql), | ||
| }); | ||
| } else if ( | ||
| resourceAttrs?.['service.name'] && | ||
| typeof resourceAttrs['service.name'] === 'string' && | ||
| resourceAttrExpr | ||
| ) { | ||
| filters.push({ | ||
| id: 'ra:service.name', | ||
| label: 'service.name', | ||
| value: String(resourceAttrs['service.name']), | ||
| generateWhere: isSql => | ||
| formatAttributeClause( | ||
| resourceAttrExpr, | ||
| 'service.name', | ||
| String(resourceAttrs['service.name']), | ||
| isSql, | ||
| ), | ||
| }); | ||
| } | ||
|
|
||
| // Promoted resource attribute pills (host, k8s) | ||
| if (resourceAttrs && resourceAttrExpr) { | ||
| for (const key of PROMOTED_RESOURCE_ATTR_KEYS) { | ||
| const val = resourceAttrs[key]; | ||
| if (typeof val !== 'string' || !val) continue; | ||
| filters.push({ | ||
| id: `ra:${key}`, | ||
| label: key, | ||
| value: val, | ||
| generateWhere: isSql => | ||
| formatAttributeClause(resourceAttrExpr, key, val, isSql), | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| // Remaining resource attributes | ||
| const addedIds = new Set(filters.map(f => f.id)); | ||
| if (resourceAttrs && resourceAttrExpr) { | ||
| for (const [key, val] of Object.entries(resourceAttrs)) { | ||
| if (addedIds.has(`ra:${key}`)) continue; | ||
| if (typeof val !== 'string' || !val || val.length > 200) continue; | ||
| filters.push({ | ||
| id: `ra:${key}`, | ||
| label: key, | ||
| value: val, | ||
| generateWhere: isSql => | ||
| formatAttributeClause(resourceAttrExpr, key, val, isSql), | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| // Event attributes | ||
| const eventAttrs = rowData[ROW_DATA_ALIASES.EVENT_ATTRIBUTES]; | ||
| if (eventAttrs && typeof eventAttrs === 'object' && eventAttrExpr) { | ||
| for (const [key, val] of Object.entries( | ||
| eventAttrs as Record<string, unknown>, | ||
| )) { | ||
| if (typeof val !== 'string' || !val || val.length > 200) continue; | ||
| filters.push({ | ||
| id: `ea:${key}`, | ||
| label: key, | ||
| value: val, | ||
| generateWhere: isSql => | ||
| formatAttributeClause(eventAttrExpr, key, val, isSql), | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| // Top-level columns | ||
| for (const [key, val] of Object.entries(rowData)) { | ||
| if (skipAliases.has(key) || key.startsWith('__hdx_')) continue; | ||
| if (typeof val !== 'string' || !val || val.length > 200) continue; | ||
| if (/timestamp|ttl/i.test(key)) continue; | ||
| if (serviceNameExpr && key === serviceNameExpr) continue; | ||
|
|
||
| filters.push({ | ||
| id: `col:${key}`, | ||
| label: key, | ||
| value: String(val), | ||
| generateWhere: isSql => formatColumnEquals(key, String(val), isSql), | ||
| }); | ||
| } | ||
|
|
||
| return filters; | ||
| } | ||
|
|
||
| const filterPillStyle = { | ||
| display: 'inline-flex', | ||
| alignItems: 'center' as const, | ||
| gap: 4, | ||
| padding: '2px 8px', | ||
| borderRadius: 4, | ||
| fontSize: 12, | ||
| lineHeight: '20px', | ||
| cursor: 'pointer', | ||
| whiteSpace: 'nowrap' as const, | ||
| maxWidth: 400, | ||
| overflow: 'hidden', | ||
| }; | ||
|
|
||
| export function FilterPill({ | ||
| filter, | ||
| isSelected, | ||
| onToggle, | ||
| }: { | ||
| filter: QuickFilterItem; | ||
| isSelected: boolean; | ||
| onToggle: () => void; | ||
| }) { | ||
| return ( | ||
| <Tooltip | ||
| label={`${filter.label} = ${filter.value}`} | ||
| openDelay={400} | ||
| maw={400} | ||
| multiline | ||
| > | ||
| <span | ||
| data-testid={`context-filter-${filter.id}`} | ||
| onClick={onToggle} | ||
| style={{ | ||
| ...filterPillStyle, | ||
| backgroundColor: isSelected ? 'var(--color-bg-hover)' : 'transparent', | ||
| border: isSelected | ||
| ? '1px solid var(--color-border-emphasis)' | ||
| : '1px solid var(--color-border)', | ||
| opacity: isSelected ? 1 : 0.7, | ||
| }} | ||
| > | ||
| <Text span size="xs" c="dimmed" fw={500} style={{ flexShrink: 0 }}> | ||
| {filter.label} | ||
| </Text> | ||
| <Text span size="xs" c="dimmed"> | ||
| = | ||
| </Text> | ||
| <Text | ||
| span | ||
| size="xs" | ||
| fw={500} | ||
| truncate | ||
| style={{ maxWidth: 180, display: 'inline-block' }} | ||
| > | ||
| {filter.value} | ||
| </Text> | ||
| {isSelected && ( | ||
| <IconX | ||
| size={12} | ||
| style={{ flexShrink: 0, marginLeft: 2 }} | ||
| aria-label="Remove filter" | ||
| /> | ||
| )} | ||
| </span> | ||
| </Tooltip> | ||
| ); | ||
| } | ||
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.