Skip to content

feat: introduce session table model form #606

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

Merged
merged 3 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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/dull-radios-wink.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@hyperdx/app": patch
---

feat: introduce session table model form
3 changes: 2 additions & 1 deletion packages/app/src/TeamPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import { useConnections } from './connection';
import { withAppNav } from './layout';
import { useSources } from './source';
import { useConfirm } from './useConfirm';
import { capitalizeFirstLetter } from './utils';

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

Expand Down Expand Up @@ -193,7 +194,7 @@ function SourcesSection() {
<div>
<Text>{s.name}</Text>
<Text size="xxs" c="dimmed">
{s.kind === 'log' ? 'Logs' : 'Metrics'}
{capitalizeFirstLetter(s.kind)}
{s.from && (
<>
{' '}
Expand Down
109 changes: 106 additions & 3 deletions packages/app/src/components/SourceForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import { useDebouncedCallback } from '@mantine/hooks';
import { notifications } from '@mantine/notifications';

import { SourceSelectControlled } from '@/components/SourceSelect';
import { IS_SESSIONS_ENABLED } from '@/config';
import { IS_METRICS_ENABLED, IS_SESSIONS_ENABLED } from '@/config';
import { useConnections } from '@/connection';
import {
inferTableSourceConfig,
Expand Down Expand Up @@ -537,6 +537,100 @@ export function TraceTableModelForm({
);
}

export function SessionTableModelForm({
control,
watch,
setValue,
}: {
control: Control<TSource>;
watch: UseFormWatch<TSource>;
setValue: UseFormSetValue<TSource>;
}) {
const databaseName = watch(`from.databaseName`, DEFAULT_DATABASE);
const tableName = watch(`from.tableName`);
const connectionId = watch(`connection`);

const [showOptionalFields, setShowOptionalFields] = useState(false);

return (
<>
<Stack gap="sm">
<FormRow label={'Server Connection'}>
<ConnectionSelectControlled control={control} name={`connection`} />
</FormRow>
<FormRow label={'Database'}>
<DatabaseSelectControlled
control={control}
name={`from.databaseName`}
connectionId={connectionId}
/>
</FormRow>
<FormRow label={'Table'}>
<DBTableSelectControlled
database={databaseName}
control={control}
name={`from.tableName`}
connectionId={connectionId}
rules={{ required: 'Table is required' }}
/>
</FormRow>
<FormRow
label={'Timestamp Column'}
helpText="DateTime column or expression that is part of your table's primary key."
>
<SQLInlineEditorControlled
database={databaseName}
table={tableName}
control={control}
name="timestampValueExpression"
disableKeywordAutocomplete
connectionId={connectionId}
/>
</FormRow>
<FormRow label={'Log Attributes Expression'}>
<SQLInlineEditorControlled
database={databaseName}
table={tableName}
control={control}
name="eventAttributesExpression"
placeholder="LogAttributes"
connectionId={connectionId}
/>
</FormRow>
<FormRow label={'Resource Attributes Expression'}>
<SQLInlineEditorControlled
database={databaseName}
table={tableName}
control={control}
name="resourceAttributesExpression"
placeholder="ResourceAttributes"
connectionId={connectionId}
/>
</FormRow>
<FormRow
label={'Correlated Trace Source'}
helpText="HyperDX Source for traces associated with sessions. Required"
>
<SourceSelectControlled control={control} name="traceSourceId" />
</FormRow>
<FormRow
label={'Implicit Column Expression'}
helpText="Column used for full text search if no property is specified in a Lucene-based search. Typically the message body of a log."
>
<SQLInlineEditorControlled
database={databaseName}
table={tableName}
control={control}
name="implicitColumnExpression"
placeholder="Body"
connectionId={connectionId}
/>
</FormRow>
</Stack>
</>
);
}

export function MetricTableModelForm({
control,
watch,
Expand Down Expand Up @@ -746,7 +840,6 @@ function TableModelForm({
}) {
switch (kind) {
case SourceKind.Log:
case SourceKind.Session:
return (
<LogTableModelForm
control={control}
Expand All @@ -762,6 +855,14 @@ function TableModelForm({
setValue={setValue}
/>
);
case SourceKind.Session:
return (
<SessionTableModelForm
control={control}
watch={watch}
setValue={setValue}
/>
);
case SourceKind.Metric:
return (
<MetricTableModelForm
Expand Down Expand Up @@ -974,7 +1075,9 @@ export function TableSourceForm({
<Group>
<Radio value={SourceKind.Log} label="Log" />
<Radio value={SourceKind.Trace} label="Trace" />
<Radio value={SourceKind.Metric} label="Metric" />
{IS_METRICS_ENABLED && (
Copy link
Member Author

Choose a reason for hiding this comment

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

show metrics only in dev

<Radio value={SourceKind.Metric} label="Metric" />
)}
{IS_SESSIONS_ENABLED && (
<Radio value={SourceKind.Session} label="Session" />
)}
Expand Down
2 changes: 1 addition & 1 deletion packages/app/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,6 @@ export const IS_LOCAL_MODE = //true;
(process.env.NEXT_PUBLIC_IS_LOCAL_MODE ?? 'false') === 'true';

// Features in development
export const IS_METRICS_ENABLED = false || IS_DEV;
export const IS_MTVIEWS_ENABLED = false;

export const IS_SESSIONS_ENABLED = false || IS_DEV;
Loading