Skip to content

Commit 459267a

Browse files
authored
feat: introduce session table model form (#606)
<img width="699" alt="Screenshot 2025-02-11 at 10 24 35 AM" src="https://github.com/user-attachments/assets/8df05bf1-f542-4f50-ba56-f57b2e82e819" />
1 parent 3fb3169 commit 459267a

File tree

4 files changed

+114
-5
lines changed

4 files changed

+114
-5
lines changed

.changeset/dull-radios-wink.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hyperdx/app": patch
3+
---
4+
5+
feat: introduce session table model form

packages/app/src/TeamPage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import { useConnections } from './connection';
3232
import { withAppNav } from './layout';
3333
import { useSources } from './source';
3434
import { useConfirm } from './useConfirm';
35+
import { capitalizeFirstLetter } from './utils';
3536

3637
import styles from '../styles/TeamPage.module.scss';
3738

@@ -193,7 +194,7 @@ function SourcesSection() {
193194
<div>
194195
<Text>{s.name}</Text>
195196
<Text size="xxs" c="dimmed">
196-
{s.kind === 'log' ? 'Logs' : 'Metrics'}
197+
{capitalizeFirstLetter(s.kind)}
197198
{s.from && (
198199
<>
199200
{' '}

packages/app/src/components/SourceForm.tsx

Lines changed: 106 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import { useDebouncedCallback } from '@mantine/hooks';
2828
import { notifications } from '@mantine/notifications';
2929

3030
import { SourceSelectControlled } from '@/components/SourceSelect';
31-
import { IS_SESSIONS_ENABLED } from '@/config';
31+
import { IS_METRICS_ENABLED, IS_SESSIONS_ENABLED } from '@/config';
3232
import { useConnections } from '@/connection';
3333
import {
3434
inferTableSourceConfig,
@@ -537,6 +537,100 @@ export function TraceTableModelForm({
537537
);
538538
}
539539

540+
export function SessionTableModelForm({
541+
control,
542+
watch,
543+
setValue,
544+
}: {
545+
control: Control<TSource>;
546+
watch: UseFormWatch<TSource>;
547+
setValue: UseFormSetValue<TSource>;
548+
}) {
549+
const databaseName = watch(`from.databaseName`, DEFAULT_DATABASE);
550+
const tableName = watch(`from.tableName`);
551+
const connectionId = watch(`connection`);
552+
553+
const [showOptionalFields, setShowOptionalFields] = useState(false);
554+
555+
return (
556+
<>
557+
<Stack gap="sm">
558+
<FormRow label={'Server Connection'}>
559+
<ConnectionSelectControlled control={control} name={`connection`} />
560+
</FormRow>
561+
<FormRow label={'Database'}>
562+
<DatabaseSelectControlled
563+
control={control}
564+
name={`from.databaseName`}
565+
connectionId={connectionId}
566+
/>
567+
</FormRow>
568+
<FormRow label={'Table'}>
569+
<DBTableSelectControlled
570+
database={databaseName}
571+
control={control}
572+
name={`from.tableName`}
573+
connectionId={connectionId}
574+
rules={{ required: 'Table is required' }}
575+
/>
576+
</FormRow>
577+
<FormRow
578+
label={'Timestamp Column'}
579+
helpText="DateTime column or expression that is part of your table's primary key."
580+
>
581+
<SQLInlineEditorControlled
582+
database={databaseName}
583+
table={tableName}
584+
control={control}
585+
name="timestampValueExpression"
586+
disableKeywordAutocomplete
587+
connectionId={connectionId}
588+
/>
589+
</FormRow>
590+
<FormRow label={'Log Attributes Expression'}>
591+
<SQLInlineEditorControlled
592+
database={databaseName}
593+
table={tableName}
594+
control={control}
595+
name="eventAttributesExpression"
596+
placeholder="LogAttributes"
597+
connectionId={connectionId}
598+
/>
599+
</FormRow>
600+
<FormRow label={'Resource Attributes Expression'}>
601+
<SQLInlineEditorControlled
602+
database={databaseName}
603+
table={tableName}
604+
control={control}
605+
name="resourceAttributesExpression"
606+
placeholder="ResourceAttributes"
607+
connectionId={connectionId}
608+
/>
609+
</FormRow>
610+
<FormRow
611+
label={'Correlated Trace Source'}
612+
helpText="HyperDX Source for traces associated with sessions. Required"
613+
>
614+
<SourceSelectControlled control={control} name="traceSourceId" />
615+
</FormRow>
616+
<FormRow
617+
label={'Implicit Column Expression'}
618+
helpText="Column used for full text search if no property is specified in a Lucene-based search. Typically the message body of a log."
619+
>
620+
<SQLInlineEditorControlled
621+
database={databaseName}
622+
table={tableName}
623+
control={control}
624+
name="implicitColumnExpression"
625+
placeholder="Body"
626+
connectionId={connectionId}
627+
/>
628+
</FormRow>
629+
</Stack>
630+
</>
631+
);
632+
}
633+
540634
export function MetricTableModelForm({
541635
control,
542636
watch,
@@ -746,7 +840,6 @@ function TableModelForm({
746840
}) {
747841
switch (kind) {
748842
case SourceKind.Log:
749-
case SourceKind.Session:
750843
return (
751844
<LogTableModelForm
752845
control={control}
@@ -762,6 +855,14 @@ function TableModelForm({
762855
setValue={setValue}
763856
/>
764857
);
858+
case SourceKind.Session:
859+
return (
860+
<SessionTableModelForm
861+
control={control}
862+
watch={watch}
863+
setValue={setValue}
864+
/>
865+
);
765866
case SourceKind.Metric:
766867
return (
767868
<MetricTableModelForm
@@ -974,7 +1075,9 @@ export function TableSourceForm({
9741075
<Group>
9751076
<Radio value={SourceKind.Log} label="Log" />
9761077
<Radio value={SourceKind.Trace} label="Trace" />
977-
<Radio value={SourceKind.Metric} label="Metric" />
1078+
{IS_METRICS_ENABLED && (
1079+
<Radio value={SourceKind.Metric} label="Metric" />
1080+
)}
9781081
{IS_SESSIONS_ENABLED && (
9791082
<Radio value={SourceKind.Session} label="Session" />
9801083
)}

packages/app/src/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ export const IS_LOCAL_MODE = //true;
2626
(process.env.NEXT_PUBLIC_IS_LOCAL_MODE ?? 'false') === 'true';
2727

2828
// Features in development
29+
export const IS_METRICS_ENABLED = false || IS_DEV;
2930
export const IS_MTVIEWS_ENABLED = false;
30-
3131
export const IS_SESSIONS_ENABLED = false || IS_DEV;

0 commit comments

Comments
 (0)