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
5 changes: 5 additions & 0 deletions .changeset/chart-editor-source-filtering.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hyperdx/app': patch
---

fix: Only offer PromQL sources in the chart editor's PromQL mode
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ import { ChartEditorFormState } from './types';
export default function PromqlChartEditor({
control,
getValues,
allowedSourceKinds,
Comment thread
pulpdrew marked this conversation as resolved.
Resolved
onSubmit,
onOpenDisplaySettings,
}: {
control: Control<ChartEditorFormState>;
getValues: UseFormGetValues<ChartEditorFormState>;
allowedSourceKinds: SourceKind[];
onSubmit: (suppressErrorNotification?: boolean) => void;
onOpenDisplaySettings: () => void;
}) {
Expand Down Expand Up @@ -100,7 +102,8 @@ export default function PromqlChartEditor({
size="xs"
control={control}
name="source"
allowedSourceKinds={[SourceKind.Promql]}
data-testid="source-selector"
allowedSourceKinds={allowedSourceKinds}
Comment thread
pulpdrew marked this conversation as resolved.
Resolved
Comment thread
pulpdrew marked this conversation as resolved.
Resolved
/>
</Group>
{expressions.map((field, index) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
import {
ChartVariable,
RawSqlChartConfig,
SourceKind,
} from '@hyperdx/common-utils/dist/types';
import {
DisplayType,
Expand Down Expand Up @@ -114,6 +115,7 @@ export function resolveConnectionSourceSync({
export default function RawSqlChartEditor({
control,
setValue,
allowedSourceKinds,
onOpenDisplaySettings,
onSubmit,
isDashboardForm,
Expand All @@ -126,6 +128,7 @@ export default function RawSqlChartEditor({
}: {
control: Control<ChartEditorFormState>;
setValue: UseFormSetValue<ChartEditorFormState>;
allowedSourceKinds: SourceKind[];
onOpenDisplaySettings: () => void;
onSubmit: (suppressErrorNotification?: boolean) => void;
isDashboardForm: boolean;
Expand Down Expand Up @@ -281,6 +284,8 @@ export default function RawSqlChartEditor({
<SourceSelectControlled
control={control}
name="source"
data-testid="source-selector"
allowedSourceKinds={allowedSourceKinds}
connectionId={connection}
size="xs"
clearable
Expand Down
67 changes: 67 additions & 0 deletions packages/app/src/components/ChartEditor/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
convertFormStateToChartConfig,
convertFormStateToSavedChartConfig,
convertSavedChartConfigToFormState,
getAllowedSourceKinds,
validateChartForm,
} from '@/components/ChartEditor/utils';

Expand Down Expand Up @@ -2297,3 +2298,69 @@ describe('metric formulas (HDX-5080)', () => {
});
});
});

describe('getAllowedSourceKinds', () => {
it('offers only PromQL sources in PromQL mode', () => {
expect(
getAllowedSourceKinds({
configType: 'promql',
displayType: DisplayType.Line,
}),
).toEqual([SourceKind.Promql]);
});

it.each(['builder', 'sql'] as const)(
'excludes PromQL sources in %s mode',
configType => {
const kinds = getAllowedSourceKinds({
configType,
displayType: DisplayType.Line,
});
expect(kinds).not.toContain(SourceKind.Promql);
expect(kinds).toEqual(
Comment thread
pulpdrew marked this conversation as resolved.
Resolved
expect.arrayContaining([
SourceKind.Log,
SourceKind.Trace,
SourceKind.Session,
SourceKind.Metric,
]),
);
},
);

it.each([DisplayType.Search, DisplayType.EventPatterns])(
'excludes PromQL sources on %s tiles, which PromQL cannot render',
displayType => {
expect(
getAllowedSourceKinds({ configType: 'promql', displayType }),
).not.toContain(SourceKind.Promql);
},
);

it.each([DisplayType.Search, DisplayType.EventPatterns])(
'excludes metric sources on %s tiles, which have no rows to list',
displayType => {
const kinds = getAllowedSourceKinds({
configType: 'builder',
displayType,
});
expect(kinds).not.toContain(SourceKind.Metric);
expect(kinds).toEqual(
expect.arrayContaining([
SourceKind.Log,
SourceKind.Trace,
SourceKind.Session,
]),
);
},
);

it('narrows to traces on heatmap tiles', () => {
expect(
getAllowedSourceKinds({
configType: 'promql',
displayType: DisplayType.Heatmap,
}),
).toEqual([SourceKind.Trace]);
});
});
34 changes: 34 additions & 0 deletions packages/app/src/components/ChartEditor/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
validateRawSqlForAlert,
} from '@hyperdx/common-utils/dist/core/utils';
import {
HEATMAP_ALLOWED_SOURCE_KINDS,
isBuilderSavedChartConfig,
isPromqlSavedChartConfig,
isRawSqlSavedChartConfig,
Expand Down Expand Up @@ -176,6 +177,39 @@ export const isPromqlDisplayType = (
displayType === DisplayType.Bar ||
displayType === DisplayType.Number;

const NON_PROMQL_SOURCE_KINDS = Object.values(SourceKind).filter(
Comment thread
pulpdrew marked this conversation as resolved.
Resolved
kind => kind !== SourceKind.Promql,
);

/**
* Search and event patterns list raw rows out of the source's `from` table. A
* metric source keeps its rows in `metricTables` and leaves `from.tableName`
* empty, so there is nothing for them to read.
*/
const ROW_LISTING_SOURCE_KINDS = NON_PROMQL_SOURCE_KINDS.filter(
Comment thread
pulpdrew marked this conversation as resolved.
Resolved
kind => kind !== SourceKind.Metric,
);

/** Source kinds the Data Source picker offers, given the editor mode and the display type. */
export function getAllowedSourceKinds({
configType,
displayType,
}: {
configType: ChartEditorFormState['configType'];
displayType: DisplayType | undefined;
}): SourceKind[] {
if (configType === 'promql' && isPromqlDisplayType(displayType)) {
return [SourceKind.Promql];
}
if (displayType === DisplayType.Heatmap) {
return [...HEATMAP_ALLOWED_SOURCE_KINDS];
}
if (isStringSelectDisplayType(displayType)) {
return ROW_LISTING_SOURCE_KINDS;
}
Comment thread
pulpdrew marked this conversation as resolved.
Resolved
Comment thread
pulpdrew marked this conversation as resolved.
Resolved
return NON_PROMQL_SOURCE_KINDS;
}

const isCustomOrderByDisplayType = (
displayType: DisplayType | undefined,
): displayType is DisplayType.Table | DisplayType.Bar | DisplayType.Pie =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ import {
useWatch,
} from 'react-hook-form';
import { TableConnection } from '@hyperdx/common-utils/dist/core/metadata';
import {
HEATMAP_ALLOWED_SOURCE_KINDS,
isBuilderChartConfig,
} from '@hyperdx/common-utils/dist/guards';
import { isBuilderChartConfig } from '@hyperdx/common-utils/dist/guards';
import {
ChartConfigWithOptTimestamp,
DisplayType,
Expand Down Expand Up @@ -65,6 +62,7 @@ type ChartEditorControlsProps = {
duplicateSeries: (index: number) => void;
tableSource?: TSource;
tableConnection: TableConnection;
allowedSourceKinds: SourceKind[];
databaseName?: string;
tableName?: string;
dateRange: [Date, Date];
Expand Down Expand Up @@ -100,6 +98,7 @@ export function ChartEditorControls({
duplicateSeries,
tableSource,
tableConnection,
allowedSourceKinds,
databaseName,
tableName,
dateRange,
Expand Down Expand Up @@ -198,11 +197,7 @@ export function ChartEditorControls({
control={control}
name="source"
data-testid="source-selector"
allowedSourceKinds={
displayType === DisplayType.Heatmap
? [...HEATMAP_ALLOWED_SOURCE_KINDS]
: undefined
}
allowedSourceKinds={allowedSourceKinds}
onSchemaPreview={() => setIsSourceSchemaPreviewOpen(true)}
isSchemaPreviewEnabled={isSourceSchemaPreviewEnabled(tableSource)}
/>
Expand Down
Loading
Loading