Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/filter-keys-limit-per-map.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ export default function TeamQueryConfigSection() {
<ClickhouseSettingForm
settingKey="filterKeysFetchLimit"
label="Filter Keys Fetch Limit"
tooltip="The number of filter keys to fetch when clicking 'More filters' on the search page"
tooltip="The number of filter keys to fetch per map column (e.g. LogAttributes, ResourceAttributes) on the search page"
type="number"
defaultValue={DEFAULT_FILTER_KEYS_FETCH_LIMIT}
placeholder={`default = ${DEFAULT_FILTER_KEYS_FETCH_LIMIT}`}
Expand Down
59 changes: 59 additions & 0 deletions packages/app/src/hooks/__tests__/useMetadata.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Metadata,
MetadataCache,
} from '@hyperdx/common-utils/dist/core/metadata';
import { FilterState } from '@hyperdx/common-utils/dist/filters';
import { BuilderChartConfigWithDateRange } from '@hyperdx/common-utils/dist/types';
import { QueryClient, QueryClientProvider } from '@tanstack/react-query';
import { renderHook, waitFor } from '@testing-library/react';
Expand Down Expand Up @@ -508,6 +509,64 @@ describe('useGetKeyValues', () => {
},
);

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),
Comment thread
knudtty marked this conversation as resolved.
Resolved
}),
{ 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("retries a failed 'exact' mode lookup per the client's defaults", async () => {
queryClient.setDefaultOptions({ queries: { retry: 1, retryDelay: 0 } });
mockLookups.exact(new Error('transient'), [
Expand Down
31 changes: 28 additions & 3 deletions packages/app/src/hooks/useMetadata.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
import {
Field,
MetricNames,
parseKeyPath,
TableConnection,
TableMetadata,
} from '@hyperdx/common-utils/dist/core/metadata';
Expand Down Expand Up @@ -521,6 +522,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<string, number>;
limitedKeys: string[];
limitedKeyConditions?: (FilterState | undefined)[];
}>(
(acc, key, i) => {
const path = parseKeyPath(key);
const column = path.length > 1 ? path[0] : '';
Comment thread
knudtty marked this conversation as resolved.
Resolved
Comment thread
knudtty marked this conversation as resolved.
Resolved
const count = acc.countByColumn.get(column) ?? 0;
acc.countByColumn.set(column, count + 1);
if (count < maxKeys) {
Comment thread
knudtty marked this conversation as resolved.
Resolved
Comment thread
knudtty marked this conversation as resolved.
Resolved
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
Expand All @@ -539,8 +564,8 @@ export function useMultipleGetKeyValues(
lookups.map(({ chartConfig, source }) =>
metadata.getKeyValuesWithMVs({
chartConfig,
keys: keys.slice(0, maxKeys),
keyConditions: keyConditions?.slice(0, maxKeys),
keys: limitedKeys,
keyConditions: limitedKeyConditions,
limit,
disableRowLimit,
source,
Expand All @@ -559,7 +584,7 @@ export function useMultipleGetKeyValues(
metadata.streamAllKeyValues({
databaseName: chartConfig.from.databaseName,
tableName: chartConfig.from.tableName,
keyExpressions: keys.slice(0, maxKeys),
keyExpressions: limitedKeys,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Later maps lack loading rows

The hook now fetches keys beyond the first global maxKeys, but the sidebar still passes escapedKeysToFetch.slice(0, maxKeys) to listRequestedFacets. With 100 LogAttributes keys followed by ResourceAttributes, the resource filters get no loading rows. They appear only when their values arrive, and later maps follow completion order rather than request order.

Use the same per-map selection for the sidebar's requested-key list so these filters stay visible and keep their order while loading.

Fix in Claude Code Fix in Conductor Fix in Cursor Fix in Codex

maxValuesPerKey: limit,
connectionId: chartConfig.connection,
metadataMVs,
Expand Down
Loading