Skip to content
Open
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
1 change: 1 addition & 0 deletions packages/app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
"@testing-library/jest-dom": "^6.4.2",
"@testing-library/react": "^16.3.0",
"@testing-library/user-event": "^14.5.2",
"@total-typescript/shoehorn": "^0.1.2",
"@types/crypto-js": "^4",
"@types/flat": "^5.0.5",
"@types/identity-obj-proxy": "^3",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import { TSource } from '@hyperdx/common-utils/dist/types';
import { SourceKind, TSource } from '@hyperdx/common-utils/dist/types';
import { MantineProvider } from '@mantine/core';
import { fireEvent, render, screen } from '@testing-library/react';
import { fromPartial } from '@total-typescript/shoehorn';

// Controlled, in-memory replacement for nuqs' useQueryState so each side-panel
// URL param can be seeded and its setter inspected independently. Values are
Expand Down Expand Up @@ -157,14 +158,13 @@ import { DBRowSidePanelInner } from '@/components/DBRowSidePanel';
import useSidePanelStack from '@/hooks/useSidePanelStack';
import { getRowLookupWindow } from '@/utils/rowTimestamps';

// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const ROOT_SOURCE = {
const ROOT_SOURCE = fromPartial<TSource>({
id: 'log-src',
kind: 'log',
kind: SourceKind.Log,
traceSourceId: 'trace-src',
timestampValueExpression: 'Timestamp',
resourceAttributesExpression: 'ResourceAttributes',
} as TSource;
});

const TRACE_ID = '7316d5a2ab0dc2efa72258f64a98a405';
const SPAN_ID = 'e3748131832d6176';
Expand Down Expand Up @@ -278,7 +278,7 @@ describe('DBRowSidePanelInner, "View Trace" row lookup time filter', () => {
const compositeSource = {
...ROOT_SOURCE,
timestampValueExpression: 'EventDate, EventTime',
} as TSource;
};

mockUseRowData.mockReturnValue(
rowResult({
Expand Down
102 changes: 58 additions & 44 deletions packages/app/src/components/__tests__/DBTimeChart.test.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React from 'react';
import { DisplayType } from '@hyperdx/common-utils/dist/types';
import { MantineProvider } from '@mantine/core';
import { Notifications } from '@mantine/notifications';
import { screen, waitFor } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { fromPartial } from '@total-typescript/shoehorn';

import api from '@/api';
import { ChartKeyJoiner } from '@/ChartUtils';
Expand Down Expand Up @@ -155,9 +157,11 @@ describe('DBTimeChart', () => {

it('passes the same config to useMVOptimizationExplanation, useQueriedChartConfig, and MVOptimizationIndicator', () => {
// Mock useSource to return a source so MVOptimizationIndicator is rendered
jest.mocked(useSource).mockReturnValue({
data: { id: 'test-source', name: 'Test Source' },
} as any);
jest.mocked(useSource).mockReturnValue(
fromPartial<ReturnType<typeof useSource>>({
data: { id: 'test-source', name: 'Test Source' },
}),
);

renderWithMantine(<DBTimeChart config={baseTestConfig} />);

Expand All @@ -183,9 +187,11 @@ describe('DBTimeChart', () => {
});

it('disables the MV-optimization query when both MV and date-range indicators are hidden', () => {
jest.mocked(useSource).mockReturnValue({
data: { id: 'test-source', name: 'Test Source' },
} as any);
jest.mocked(useSource).mockReturnValue(
fromPartial<ReturnType<typeof useSource>>({
data: { id: 'test-source', name: 'Test Source' },
}),
);

renderWithMantine(
<DBTimeChart
Expand All @@ -201,9 +207,11 @@ describe('DBTimeChart', () => {
});

it('keeps the MV-optimization query enabled when only the date-range indicator is shown', () => {
jest.mocked(useSource).mockReturnValue({
data: { id: 'test-source', name: 'Test Source' },
} as any);
jest.mocked(useSource).mockReturnValue(
fromPartial<ReturnType<typeof useSource>>({
data: { id: 'test-source', name: 'Test Source' },
}),
);

renderWithMantine(
<DBTimeChart
Expand Down Expand Up @@ -424,25 +432,27 @@ describe('DBTimeChart', () => {
};

// Mock useMVOptimizationExplanation to return an optimized config with aligned date range
jest.mocked(useMVOptimizationExplanation).mockReturnValue({
data: {
optimizedConfig: {
...config,
dateRange: [alignedStartDate, alignedEndDate] as [Date, Date],
},
explanations: [
{
success: true,
mvConfig: {
minGranularity: '1 minute',
tableName: 'metrics_rollup_1m',
},
jest.mocked(useMVOptimizationExplanation).mockReturnValue(
fromPartial<ReturnType<typeof useMVOptimizationExplanation>>({
data: {
optimizedConfig: {
...config,
dateRange: [alignedStartDate, alignedEndDate] as [Date, Date],
},
],
},
isLoading: false,
isPlaceholderData: false,
} as any);
explanations: [
{
success: true,
mvConfig: {
minGranularity: '1 minute',
tableName: 'metrics_rollup_1m',
},
},
],
},
isLoading: false,
isPlaceholderData: false,
}),
);

renderWithMantine(<DBTimeChart config={config} />);

Expand Down Expand Up @@ -477,14 +487,16 @@ describe('DBTimeChart', () => {
};

// Mock useMVOptimizationExplanation to return no optimized config
jest.mocked(useMVOptimizationExplanation).mockReturnValue({
data: {
optimizedConfig: undefined,
explanations: [],
},
isLoading: false,
isPlaceholderData: false,
} as any);
jest.mocked(useMVOptimizationExplanation).mockReturnValue(
fromPartial<ReturnType<typeof useMVOptimizationExplanation>>({
data: {
optimizedConfig: undefined,
explanations: [],
},
isLoading: false,
isPlaceholderData: false,
}),
);

renderWithMantine(<DBTimeChart config={config} />);

Expand All @@ -511,7 +523,7 @@ describe('DBTimeChart', () => {
sqlTemplate:
'SELECT toStartOfInterval(ts, INTERVAL {intervalSeconds:Int64} SECOND) AS ts, count() AS count FROM logs GROUP BY ts ORDER BY ts ASC',
connection: 'test-connection',
displayType: 'line' as any,
displayType: DisplayType.Line,
dateRange: [new Date('2024-01-01'), new Date('2024-01-02')] as [
Date,
Date,
Expand Down Expand Up @@ -669,14 +681,16 @@ describe('DBTimeChart', () => {

it('does not render DateRangeIndicator when MV optimization has no optimized date range and showDateRangeIndicator is false', () => {
// Mock useMVOptimizationExplanation to return data without an optimized config
jest.mocked(useMVOptimizationExplanation).mockReturnValue({
data: {
optimizedConfig: undefined,
explanations: [],
},
isLoading: false,
isPlaceholderData: false,
} as any);
jest.mocked(useMVOptimizationExplanation).mockReturnValue(
fromPartial<ReturnType<typeof useMVOptimizationExplanation>>({
data: {
optimizedConfig: undefined,
explanations: [],
},
isLoading: false,
isPlaceholderData: false,
}),
);

renderWithMantine(
<DBTimeChart config={baseTestConfig} showDateRangeIndicator={false} />,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import React, { useEffect } from 'react';
import { useForm } from 'react-hook-form';
import { SourceKind, TSource } from '@hyperdx/common-utils/dist/types';
import {
SourceKind,
TMetricSource,
TSource,
} from '@hyperdx/common-utils/dist/types';
import { MantineProvider } from '@mantine/core';
import { render, waitFor } from '@testing-library/react';
import { fromPartial } from '@total-typescript/shoehorn';

import { MetricTableModelForm } from '@/components/Sources/SourceForm/MetricTableModelForm';

Expand Down Expand Up @@ -122,8 +127,7 @@ function autofilledTables() {
.map(([path, value]) => [path, value]);
}

// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const SAVED_SOURCE: TSource = {
const SAVED_SOURCE = fromPartial<TMetricSource>({
id: 'metric-source-1',
kind: SourceKind.Metric,
name: 'Metrics',
Expand All @@ -134,7 +138,7 @@ const SAVED_SOURCE: TSource = {
gauge: 'otel_metrics_gauge',
sum: 'otel_metrics_sum',
},
} as any;
});

describe('MetricTableModelForm metric table autofill', () => {
beforeEach(() => {
Expand Down Expand Up @@ -237,12 +241,12 @@ describe('MetricTableModelForm metric table autofill', () => {
// A saved source of another kind switched over to OTEL Metrics has no metric
// tables to preserve, so it autofills like a new source.
it('autofills for an existing source switched to the metrics kind', async () => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
savedSource = {
...SAVED_SOURCE,
const { metricTables: _metricTables, ...savedSourceWithoutMetricTables } =
SAVED_SOURCE;
savedSource = fromPartial<TSource>({
...savedSourceWithoutMetricTables,
kind: SourceKind.Log,
metricTables: undefined,
} as any;
});

renderHarness(
<Harness databaseName="otel_v2" sourceId="metric-source-1" />,
Expand Down
6 changes: 3 additions & 3 deletions scripts/ci/ratchet-baseline.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
"eslint-disable": 31
},
"app": {
"as-any": 215,
"as-any": 206,
"ts-ignore": 0,
"eslint-disable": 144
"eslint-disable": 141
},
"cli": {
"as-any": 0,
Expand All @@ -29,4 +29,4 @@
"ts-ignore": 0,
"eslint-disable": 0
}
}
}
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4734,6 +4734,7 @@ __metadata:
"@testing-library/jest-dom": "npm:^6.4.2"
"@testing-library/react": "npm:^16.3.0"
"@testing-library/user-event": "npm:^14.5.2"
"@total-typescript/shoehorn": "npm:^0.1.2"
"@types/crypto-js": "npm:^4"
"@types/flat": "npm:^5.0.5"
"@types/identity-obj-proxy": "npm:^3"
Expand Down Expand Up @@ -9982,6 +9983,13 @@ __metadata:
languageName: node
linkType: hard

"@total-typescript/shoehorn@npm:^0.1.2":
version: 0.1.2
resolution: "@total-typescript/shoehorn@npm:0.1.2"
checksum: 10c0/e1bb904a3c46bd00a3a31a4f24a07a5de8f6c4aebb811f4ac108dfad066d2797c682b49bbcd09e98e2bd12e8b67db9bcb793e02e2ed8a996e1fe0d232a7efcf1
languageName: node
linkType: hard

"@tsconfig/node10@npm:^1.0.7":
version: 1.0.9
resolution: "@tsconfig/node10@npm:1.0.9"
Expand Down
Loading