From 86aa44990f510f0f5bd553ec80e31bf42999df6e Mon Sep 17 00:00:00 2001 From: Aaron Knudtson <87577305+knudtty@users.noreply.github.com> Date: Fri, 16 Oct 2026 13:07:19 -0400 Subject: [PATCH] feat: fetch key limit now applies per map --- .changeset/filter-keys-limit-per-map.md | 7 +++ .../TeamSettings/TeamQueryConfigSection.tsx | 2 +- .../src/hooks/__tests__/useMetadata.test.tsx | 59 +++++++++++++++++++ packages/app/src/hooks/useMetadata.tsx | 31 +++++++++- 4 files changed, 95 insertions(+), 4 deletions(-) create mode 100644 .changeset/filter-keys-limit-per-map.md diff --git a/.changeset/filter-keys-limit-per-map.md b/.changeset/filter-keys-limit-per-map.md new file mode 100644 index 0000000000..2939bbc6ea --- /dev/null +++ b/.changeset/filter-keys-limit-per-map.md @@ -0,0 +1,7 @@ +--- +'@hyperdx/app': patch +--- + +fix: the search page filter key limit (Filter Keys Fetch Limit, default 100) +now applies to each Map column, so keys from `LogAttributes` no longer crowd out +`ResourceAttributes` and other Map columns diff --git a/packages/app/src/components/TeamSettings/TeamQueryConfigSection.tsx b/packages/app/src/components/TeamSettings/TeamQueryConfigSection.tsx index e685112003..bebf127d3d 100644 --- a/packages/app/src/components/TeamSettings/TeamQueryConfigSection.tsx +++ b/packages/app/src/components/TeamSettings/TeamQueryConfigSection.tsx @@ -319,7 +319,7 @@ export default function TeamQueryConfigSection() { { }, ); + it('applies the filter key limit to each Map column separately', async () => { + queryClient.setQueryData(['me'], { team: { filterKeysFetchLimit: 2 } }); + const getKeyValuesWithMVs = jest + .spyOn(mockMetadata, 'getKeyValuesWithMVs') + .mockResolvedValue([]); + const conditionFor = (key: string): FilterState => ({ + [key]: { included: new Set(['v']), excluded: new Set() }, + }); + const allKeys = [ + "LogAttributes['a']", + "LogAttributes['b']", + "LogAttributes['c']", + "`Resource-Attributes`['x']", + 'ServiceName', + 'SeverityText', + 'SpanName', + ]; + const keptKeys = [ + "LogAttributes['a']", + "LogAttributes['b']", + "`Resource-Attributes`['x']", + 'ServiceName', + 'SeverityText', + ]; + + const { result } = renderHook( + () => + useGetKeyValues({ + chartConfig: createMockChartConfig(), + keys: allKeys, + keyConditions: allKeys.map(conditionFor), + }), + { wrapper }, + ); + + await waitFor(() => expect(result.current.isSuccess).toBe(true)); + expect(getKeyValuesWithMVs).toHaveBeenCalledWith( + expect.objectContaining({ + keys: keptKeys, + keyConditions: keptKeys.map(conditionFor), + }), + ); + }); + + it('passes no keyConditions when none are given', async () => { + const getKeyValuesWithMVs = jest + .spyOn(mockMetadata, 'getKeyValuesWithMVs') + .mockResolvedValue([]); + + const { result } = renderHook( + () => useGetKeyValues({ chartConfig: createMockChartConfig(), keys }), + { wrapper }, + ); + + await waitFor(() => expect(result.current.isSuccess).toBe(true)); + expect(getKeyValuesWithMVs.mock.calls[0][0].keyConditions).toBeUndefined(); + }); + it('should be in a loading state while fetching sources', async () => { jest.mocked(useSources).mockReturnValue({ data: undefined, diff --git a/packages/app/src/hooks/useMetadata.tsx b/packages/app/src/hooks/useMetadata.tsx index c55ac4cc8c..311b81f37e 100644 --- a/packages/app/src/hooks/useMetadata.tsx +++ b/packages/app/src/hooks/useMetadata.tsx @@ -9,6 +9,7 @@ import { import { Field, MetricNames, + parseKeyPath, TableConnection, TableMetadata, } from '@hyperdx/common-utils/dist/core/metadata'; @@ -501,6 +502,30 @@ export function useMultipleGetKeyValues( if (keys.length === 0) return []; const usableMVsOverride = chartConfigsArr.length === 1 ? metadataMVsOverride : undefined; + // The limit applies per Map column, so one wide Map (e.g. LogAttributes) + // can't crowd out the others. Top-level columns share a single limit. + const { limitedKeys, limitedKeyConditions } = keys.reduce<{ + countByColumn: Map; + limitedKeys: string[]; + limitedKeyConditions?: (FilterState | undefined)[]; + }>( + (acc, key, i) => { + const path = parseKeyPath(key); + const column = path.length > 1 ? path[0] : ''; + const count = acc.countByColumn.get(column) ?? 0; + acc.countByColumn.set(column, count + 1); + if (count < maxKeys) { + acc.limitedKeys.push(key); + acc.limitedKeyConditions?.push(keyConditions?.[i]); + } + return acc; + }, + { + countByColumn: new Map(), + limitedKeys: [], + limitedKeyConditions: keyConditions ? [] : undefined, + }, + ); const lookups = chartConfigsArr.map(chartConfig => { const source = chartConfig.source @@ -520,7 +545,7 @@ export function useMultipleGetKeyValues( ? metadata.getAllKeyValues({ databaseName: chartConfig.from.databaseName, tableName: chartConfig.from.tableName, - keyExpressions: keys.slice(0, maxKeys), + keyExpressions: limitedKeys, maxValuesPerKey: limit, connectionId: chartConfig.connection, metadataMVs, @@ -530,8 +555,8 @@ export function useMultipleGetKeyValues( }) : metadata.getKeyValuesWithMVs({ chartConfig, - keys: keys.slice(0, maxKeys), - keyConditions: keyConditions?.slice(0, maxKeys), + keys: limitedKeys, + keyConditions: limitedKeyConditions, limit, disableRowLimit, source,