Skip to content

Commit eb16df4

Browse files
feat: Add ability to disable data sources (fixes #1545) (#2186)
Co-authored-by: Alok Kumar Singh <mail.alok87@gmail.com>
1 parent 2671166 commit eb16df4

17 files changed

Lines changed: 133 additions & 23 deletions

File tree

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
"@hyperdx/common-utils": minor
3+
"@hyperdx/api": minor
4+
"@hyperdx/app": minor
5+
---
6+
7+
Add ability to disable data sources with improved UX
8+

‎packages/api/src/models/source.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ const sourceBaseSchema = new Schema<MongooseSourceBase>(
8585
ref: 'Connection',
8686
},
8787
name: String,
88+
disabled: {
89+
type: Boolean,
90+
default: false,
91+
},
8892
from: {
8993
databaseName: String,
9094
tableName: String,

‎packages/api/src/routers/external-api/__tests__/sources.test.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ describe('External API v2 Sources', () => {
101101
name: 'Test Log Source',
102102
kind: SourceKind.Log,
103103
connection: connection._id.toString(),
104+
disabled: false,
104105
from: {
105106
databaseName: DEFAULT_DATABASE,
106107
tableName: DEFAULT_LOGS_TABLE,
@@ -189,6 +190,7 @@ describe('External API v2 Sources', () => {
189190
expect(response.body.data[0]).toEqual({
190191
id: traceSource._id.toString(),
191192
name: 'Test Trace Source',
193+
disabled: false,
192194
from: {
193195
databaseName: DEFAULT_DATABASE,
194196
tableName: 'otel_traces',
@@ -282,6 +284,7 @@ describe('External API v2 Sources', () => {
282284
name: 'Test Metric Source',
283285
kind: SourceKind.Metric,
284286
connection: connection._id.toString(),
287+
disabled: false,
285288
from: {
286289
databaseName: DEFAULT_DATABASE,
287290
tableName: '',
@@ -343,6 +346,7 @@ describe('External API v2 Sources', () => {
343346
name: 'Test Session Source',
344347
kind: SourceKind.Session,
345348
connection: connection._id.toString(),
349+
disabled: false,
346350
from: {
347351
databaseName: DEFAULT_DATABASE,
348352
tableName: 'rrweb_events',

‎packages/app/src/DBSearchPage.tsx‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -185,17 +185,22 @@ const QUERY_KEY_PREFIX = 'search';
185185

186186
// Helper function to get the default source id
187187
export function getDefaultSourceId(
188-
sources: { id: string }[] | undefined,
188+
sources: { id: string; disabled?: boolean }[] | undefined,
189189
lastSelectedSourceId: string | undefined,
190190
): string {
191191
if (!sources || sources.length === 0) return '';
192+
193+
// Filter out disabled sources
194+
const enabledSources = sources.filter(s => !s.disabled);
195+
if (enabledSources.length === 0) return '';
196+
192197
if (
193198
lastSelectedSourceId &&
194-
sources.some(s => s.id === lastSelectedSourceId)
199+
enabledSources.some(s => s.id === lastSelectedSourceId)
195200
) {
196201
return lastSelectedSourceId;
197202
}
198-
return sources[0].id;
203+
return enabledSources[0].id;
199204
}
200205

201206
function SourceEditModal({

‎packages/app/src/KubernetesDashboardPage.tsx‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,8 @@ const findSource = (
954954
s =>
955955
(kind === undefined || s.kind === kind) &&
956956
(id === undefined || s.id === id) &&
957-
(connection === undefined || s.connection === connection),
957+
(connection === undefined || s.connection === connection) &&
958+
!s.disabled,
958959
);
959960
};
960961

@@ -1007,7 +1008,8 @@ export const resolveSourceIds = (
10071008
(s): s is TLogSource =>
10081009
s.kind === SourceKind.Log &&
10091010
!!s.metricSourceId &&
1010-
!!findSource(sources, { id: s.metricSourceId }),
1011+
!!findSource(sources, { id: s.metricSourceId }) &&
1012+
!s.disabled,
10111013
);
10121014

10131015
if (logSourceWithMetricSource) {

‎packages/app/src/ServicesDashboardPage.tsx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1433,7 +1433,9 @@ function ServicesDashboardPage() {
14331433
const appliedConfigWithoutFilters = useMemo(() => {
14341434
if (!sources?.length) return appliedConfigParams;
14351435

1436-
const traceSources = sources?.filter(s => s.kind === SourceKind.Trace);
1436+
const traceSources = sources?.filter(
1437+
s => s.kind === SourceKind.Trace && !s.disabled,
1438+
);
14371439
const paramsSourceIdIsTraceSource = traceSources?.find(
14381440
s => s.id === appliedConfigParams.source,
14391441
);

‎packages/app/src/SessionsPage.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,9 @@ export default function SessionsPage() {
252252
// Auto-select the first session source when the page loads
253253
useEffect(() => {
254254
if (sources && sources.length > 0 && !appliedConfig.sessionSource) {
255-
// Find the first session source
255+
// Find the first enabled session source
256256
const sessionSource = sources.find(
257-
source => source.kind === SourceKind.Session,
257+
source => source.kind === SourceKind.Session && !source.disabled,
258258
);
259259
if (sessionSource) {
260260
setValue('source', sessionSource.id);

‎packages/app/src/__tests__/DBSearchPage.test.tsx‎

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { renderHook } from '@testing-library/react';
33

44
import * as sourceModule from '@/source';
55

6-
import { useDefaultOrderBy } from '../DBSearchPage';
6+
import { getDefaultSourceId, useDefaultOrderBy } from '../DBSearchPage';
77
import * as metadataModule from '../hooks/useMetadata';
88

99
// Mock the dependencies
@@ -390,3 +390,57 @@ describe('useDefaultOrderBy', () => {
390390
});
391391
});
392392
});
393+
394+
describe('getDefaultSourceId', () => {
395+
it('returns "" when sources is undefined', () => {
396+
expect(getDefaultSourceId(undefined, undefined)).toBe('');
397+
});
398+
399+
it('returns "" when sources is empty', () => {
400+
expect(getDefaultSourceId([], undefined)).toBe('');
401+
});
402+
403+
it('returns "" when every source is disabled', () => {
404+
const sources = [
405+
{ id: 'a', disabled: true },
406+
{ id: 'b', disabled: true },
407+
];
408+
expect(getDefaultSourceId(sources, 'a')).toBe('');
409+
});
410+
411+
it('returns the last-selected source when it is enabled', () => {
412+
const sources = [
413+
{ id: 'a', disabled: false },
414+
{ id: 'b', disabled: false },
415+
{ id: 'c' }, // disabled is undefined => treated as enabled
416+
];
417+
expect(getDefaultSourceId(sources, 'b')).toBe('b');
418+
expect(getDefaultSourceId(sources, 'c')).toBe('c');
419+
});
420+
421+
it('falls back to the first enabled source when last-selected is disabled', () => {
422+
const sources = [
423+
{ id: 'a', disabled: true },
424+
{ id: 'b', disabled: false },
425+
{ id: 'c', disabled: false },
426+
];
427+
expect(getDefaultSourceId(sources, 'a')).toBe('b');
428+
});
429+
430+
it('falls back to the first enabled source when last-selected is unknown', () => {
431+
const sources = [
432+
{ id: 'a', disabled: true },
433+
{ id: 'b', disabled: false },
434+
];
435+
expect(getDefaultSourceId(sources, 'unknown-id')).toBe('b');
436+
});
437+
438+
it('returns the first enabled source when last-selected is undefined and the list is mixed', () => {
439+
const sources = [
440+
{ id: 'a', disabled: true },
441+
{ id: 'b', disabled: false },
442+
{ id: 'c', disabled: false },
443+
];
444+
expect(getDefaultSourceId(sources, undefined)).toBe('b');
445+
});
446+
});

‎packages/app/src/components/SourceSelect.tsx‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ function SourceSelectControlledComponent({
132132
?.filter(
133133
source =>
134134
(!allowedSourceKinds || allowedSourceKinds.includes(source.kind)) &&
135-
(!connectionId || source.connection === connectionId),
135+
(!connectionId || source.connection === connectionId) &&
136+
!source.disabled,
136137
)
137138
.map(d => ({
138139
value: d.id,

‎packages/app/src/components/Sources/SourceForm.tsx‎

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import {
3636
Select,
3737
Slider,
3838
Stack,
39+
Switch,
3940
Text,
4041
Tooltip,
4142
} from '@mantine/core';
@@ -2202,7 +2203,23 @@ export function TableSourceForm({
22022203
}
22032204
>
22042205
<Stack gap="md" mb="md">
2205-
<Text mb="lg">Source Settings</Text>
2206+
<Flex justify="space-between" align="center" mb="lg">
2207+
<Text>Source Settings</Text>
2208+
{!isNew && (
2209+
<Controller
2210+
control={control}
2211+
name="disabled"
2212+
render={({ field: { value, onChange } }) => (
2213+
<Switch
2214+
size="sm"
2215+
checked={!value}
2216+
onChange={event => onChange(!event.currentTarget.checked)}
2217+
label={value ? 'Disabled' : 'Enabled'}
2218+
/>
2219+
)}
2220+
/>
2221+
)}
2222+
</Flex>
22062223
<FormRow label={'Name'}>
22072224
<InputControlled
22082225
control={control}

0 commit comments

Comments
 (0)