mirror of
https://github.com/SigNoz/signoz.git
synced 2026-11-27 18:50:47 +00:00
Compare commits
1 Commits
perf/front
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a6be4d894c |
@@ -10,23 +10,23 @@ import { useGetExportToDashboardLink } from 'hooks/dashboard/useGetExportToDashb
|
||||
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
|
||||
import { useSafeNavigate } from 'hooks/useSafeNavigate';
|
||||
import { Query } from 'types/api/queryBuilder/queryBuilderData';
|
||||
import { DataSource } from 'types/common/queryBuilder';
|
||||
import { v4 } from 'uuid';
|
||||
|
||||
import {
|
||||
EXPLORER_ACTION_EVENTS,
|
||||
ExplorerActionsSource,
|
||||
getExplorerActionEventPayload,
|
||||
getExportPanelType,
|
||||
} from './utils';
|
||||
|
||||
function AddToDashboardButton({
|
||||
query,
|
||||
sourcepage,
|
||||
sourcePage,
|
||||
panelType,
|
||||
isOneChartPerQuery = false,
|
||||
}: {
|
||||
query: Query | null;
|
||||
sourcepage: DataSource;
|
||||
sourcePage: ExplorerActionsSource;
|
||||
panelType?: PANEL_TYPES;
|
||||
isOneChartPerQuery?: boolean;
|
||||
}): JSX.Element {
|
||||
@@ -40,9 +40,9 @@ function AddToDashboardButton({
|
||||
return;
|
||||
}
|
||||
void logEvent(
|
||||
EXPLORER_ACTION_EVENTS[sourcepage].addToDashboard,
|
||||
EXPLORER_ACTION_EVENTS[sourcePage].addToDashboard,
|
||||
getExplorerActionEventPayload({
|
||||
sourcepage,
|
||||
sourcePage,
|
||||
panelType: contextPanelType,
|
||||
isOneChartPerQuery,
|
||||
}),
|
||||
@@ -59,9 +59,9 @@ function AddToDashboardButton({
|
||||
}
|
||||
const exportPanelType = panelType ?? getExportPanelType(contextPanelType);
|
||||
|
||||
void logEvent(EXPLORER_ACTION_EVENTS[sourcepage].exported, {
|
||||
void logEvent(EXPLORER_ACTION_EVENTS[sourcePage].exported, {
|
||||
...getExplorerActionEventPayload({
|
||||
sourcepage,
|
||||
sourcePage,
|
||||
panelType: contextPanelType,
|
||||
isOneChartPerQuery,
|
||||
}),
|
||||
|
||||
@@ -5,21 +5,21 @@ import logEvent from 'api/common/logEvent';
|
||||
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
|
||||
import { useAppNavigate } from 'lib/router/useAppNavigate';
|
||||
import { Query } from 'types/api/queryBuilder/queryBuilderData';
|
||||
import { DataSource } from 'types/common/queryBuilder';
|
||||
|
||||
import {
|
||||
EXPLORER_ACTION_EVENTS,
|
||||
ExplorerActionsSource,
|
||||
getCreateAlertLink,
|
||||
getExplorerActionEventPayload,
|
||||
} from './utils';
|
||||
|
||||
function CreateAlertButton({
|
||||
query,
|
||||
sourcepage,
|
||||
sourcePage,
|
||||
isOneChartPerQuery = false,
|
||||
}: {
|
||||
query: Query | null;
|
||||
sourcepage: DataSource;
|
||||
sourcePage: ExplorerActionsSource;
|
||||
isOneChartPerQuery?: boolean;
|
||||
}): JSX.Element {
|
||||
const navigate = useAppNavigate();
|
||||
@@ -30,8 +30,8 @@ function CreateAlertButton({
|
||||
return;
|
||||
}
|
||||
void logEvent(
|
||||
EXPLORER_ACTION_EVENTS[sourcepage].createAlert,
|
||||
getExplorerActionEventPayload({ sourcepage, panelType, isOneChartPerQuery }),
|
||||
EXPLORER_ACTION_EVENTS[sourcePage].createAlert,
|
||||
getExplorerActionEventPayload({ sourcePage, panelType, isOneChartPerQuery }),
|
||||
);
|
||||
navigate(getCreateAlertLink({ query, panelType }));
|
||||
};
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
import { PANEL_TYPES } from 'constants/queryBuilder';
|
||||
import { Query } from 'types/api/queryBuilder/queryBuilderData';
|
||||
import { DataSource } from 'types/common/queryBuilder';
|
||||
|
||||
import AddToDashboardButton from './AddToDashboardButton';
|
||||
import CreateAlertButton from './CreateAlertButton';
|
||||
import { ExplorerActionsSource } from './utils';
|
||||
|
||||
function ExplorerActions({
|
||||
query,
|
||||
dashboardQuery = query,
|
||||
sourcepage,
|
||||
sourcePage,
|
||||
panelType,
|
||||
isOneChartPerQuery,
|
||||
}: {
|
||||
query: Query | null;
|
||||
// When the dashboard export differs from the alert one (traces list injects columns).
|
||||
dashboardQuery?: Query | null;
|
||||
sourcepage: DataSource;
|
||||
sourcePage: ExplorerActionsSource;
|
||||
panelType?: PANEL_TYPES;
|
||||
isOneChartPerQuery?: boolean;
|
||||
}): JSX.Element {
|
||||
@@ -23,12 +23,12 @@ function ExplorerActions({
|
||||
<>
|
||||
<CreateAlertButton
|
||||
query={query}
|
||||
sourcepage={sourcepage}
|
||||
sourcePage={sourcePage}
|
||||
isOneChartPerQuery={isOneChartPerQuery}
|
||||
/>
|
||||
<AddToDashboardButton
|
||||
query={dashboardQuery}
|
||||
sourcepage={sourcepage}
|
||||
sourcePage={sourcePage}
|
||||
panelType={panelType}
|
||||
isOneChartPerQuery={isOneChartPerQuery}
|
||||
/>
|
||||
|
||||
@@ -17,7 +17,7 @@ import { Query } from 'types/api/queryBuilder/queryBuilderData';
|
||||
import { DataSource, StringOperators } from 'types/common/queryBuilder';
|
||||
|
||||
import AddToDashboardButton from '../AddToDashboardButton';
|
||||
import { getExportPanelType } from '../utils';
|
||||
import { ExplorerActionsSource, getExportPanelType } from '../utils';
|
||||
|
||||
const DASHBOARD = { id: 'dash-1', title: 'Dash 1' };
|
||||
|
||||
@@ -94,7 +94,7 @@ function setPanelType(panelType: PANEL_TYPES): void {
|
||||
|
||||
async function exportTo(
|
||||
query: Query | null,
|
||||
sourcepage: DataSource,
|
||||
sourcePage: ExplorerActionsSource,
|
||||
panelType: PANEL_TYPES,
|
||||
panelTypeProp?: PANEL_TYPES,
|
||||
): Promise<void> {
|
||||
@@ -102,7 +102,7 @@ async function exportTo(
|
||||
render(
|
||||
<AddToDashboardButton
|
||||
query={query}
|
||||
sourcepage={sourcepage}
|
||||
sourcePage={sourcePage}
|
||||
panelType={panelTypeProp}
|
||||
/>,
|
||||
);
|
||||
@@ -128,7 +128,12 @@ describe('AddToDashboardButton', () => {
|
||||
|
||||
it('is disabled without a query and the picker stays closed', () => {
|
||||
setPanelType(PANEL_TYPES.LIST);
|
||||
render(<AddToDashboardButton query={null} sourcepage={DataSource.LOGS} />);
|
||||
render(
|
||||
<AddToDashboardButton
|
||||
query={null}
|
||||
sourcePage={ExplorerActionsSource.LOGS_EXPLORER}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(screen.getByTestId('explorer-add-to-dashboard')).toHaveAttribute(
|
||||
'aria-disabled',
|
||||
@@ -140,7 +145,12 @@ describe('AddToDashboardButton', () => {
|
||||
it('hands the picker the same query it will export', async () => {
|
||||
const query = stagedQuery(DataSource.LOGS);
|
||||
setPanelType(PANEL_TYPES.TIME_SERIES);
|
||||
render(<AddToDashboardButton query={query} sourcepage={DataSource.LOGS} />);
|
||||
render(
|
||||
<AddToDashboardButton
|
||||
query={query}
|
||||
sourcePage={ExplorerActionsSource.LOGS_EXPLORER}
|
||||
/>,
|
||||
);
|
||||
|
||||
await userEvent
|
||||
.setup()
|
||||
@@ -155,19 +165,23 @@ describe('AddToDashboardButton', () => {
|
||||
it("logs the explorer's own open and success events", async () => {
|
||||
const query = stagedQuery(DataSource.TRACES);
|
||||
|
||||
await exportTo(query, DataSource.TRACES, PANEL_TYPES.TABLE);
|
||||
await exportTo(
|
||||
query,
|
||||
ExplorerActionsSource.TRACES_EXPLORER,
|
||||
PANEL_TYPES.TABLE,
|
||||
);
|
||||
|
||||
expect(mockedLogEvent).toHaveBeenCalledWith(
|
||||
'Traces Explorer: Add to dashboard clicked',
|
||||
{
|
||||
sourcepage: DataSource.TRACES,
|
||||
sourcepage: ExplorerActionsSource.TRACES_EXPLORER,
|
||||
panelType: PANEL_TYPES.TABLE,
|
||||
},
|
||||
);
|
||||
expect(mockedLogEvent).toHaveBeenCalledWith(
|
||||
'Traces Explorer: Add to dashboard successful',
|
||||
{
|
||||
sourcepage: DataSource.TRACES,
|
||||
sourcepage: ExplorerActionsSource.TRACES_EXPLORER,
|
||||
panelType: PANEL_TYPES.TABLE,
|
||||
isNewDashboard: undefined,
|
||||
dashboardName: DASHBOARD.title,
|
||||
@@ -181,7 +195,7 @@ describe('AddToDashboardButton', () => {
|
||||
// context says list, the page says time series
|
||||
await exportTo(
|
||||
query,
|
||||
DataSource.METRICS,
|
||||
ExplorerActionsSource.METRICS_EXPLORER,
|
||||
PANEL_TYPES.LIST,
|
||||
PANEL_TYPES.TIME_SERIES,
|
||||
);
|
||||
@@ -206,7 +220,11 @@ describe('AddToDashboardButton', () => {
|
||||
PANEL_TYPES.LIST,
|
||||
) as Query;
|
||||
|
||||
await exportTo(exportQuery, DataSource.LOGS, PANEL_TYPES.LIST);
|
||||
await exportTo(
|
||||
exportQuery,
|
||||
ExplorerActionsSource.LOGS_EXPLORER,
|
||||
PANEL_TYPES.LIST,
|
||||
);
|
||||
|
||||
expect(exportQuery.builder.queryData[0].orderBy).toStrictEqual([
|
||||
{ columnName: 'timestamp', order: 'desc' },
|
||||
@@ -221,7 +239,7 @@ describe('AddToDashboardButton', () => {
|
||||
async (panelType) => {
|
||||
const exportQuery = getLogsExportQuery(staged, panelType) as Query;
|
||||
|
||||
await exportTo(exportQuery, DataSource.LOGS, panelType);
|
||||
await exportTo(exportQuery, ExplorerActionsSource.LOGS_EXPLORER, panelType);
|
||||
|
||||
expect(exportQuery).toBe(staged);
|
||||
expect(mockSafeNavigate).toHaveBeenCalledWith(
|
||||
@@ -241,7 +259,11 @@ describe('AddToDashboardButton', () => {
|
||||
options,
|
||||
);
|
||||
|
||||
await exportTo(exportQuery, DataSource.TRACES, PANEL_TYPES.LIST);
|
||||
await exportTo(
|
||||
exportQuery,
|
||||
ExplorerActionsSource.TRACES_EXPLORER,
|
||||
PANEL_TYPES.LIST,
|
||||
);
|
||||
|
||||
const [queryData] = exportQuery.builder.queryData;
|
||||
expect(queryData.selectColumns).toStrictEqual(COLUMNS);
|
||||
@@ -258,7 +280,11 @@ describe('AddToDashboardButton', () => {
|
||||
options,
|
||||
);
|
||||
|
||||
await exportTo(exportQuery, DataSource.TRACES, PANEL_TYPES.TRACE);
|
||||
await exportTo(
|
||||
exportQuery,
|
||||
ExplorerActionsSource.TRACES_EXPLORER,
|
||||
PANEL_TYPES.TRACE,
|
||||
);
|
||||
|
||||
expect(exportQuery.builder.queryData[0].selectColumns).toBeUndefined();
|
||||
expect(mockSafeNavigate).toHaveBeenCalledWith(
|
||||
@@ -278,7 +304,11 @@ describe('AddToDashboardButton', () => {
|
||||
options,
|
||||
);
|
||||
|
||||
await exportTo(exportQuery, DataSource.TRACES, panelType);
|
||||
await exportTo(
|
||||
exportQuery,
|
||||
ExplorerActionsSource.TRACES_EXPLORER,
|
||||
panelType,
|
||||
);
|
||||
|
||||
expect(exportQuery.builder.queryData[0].orderBy).toStrictEqual([]);
|
||||
expect(mockSafeNavigate).toHaveBeenCalledWith(
|
||||
@@ -296,7 +326,11 @@ describe('AddToDashboardButton', () => {
|
||||
options,
|
||||
);
|
||||
|
||||
await exportTo(exportQuery, DataSource.TRACES, panelType);
|
||||
await exportTo(
|
||||
exportQuery,
|
||||
ExplorerActionsSource.TRACES_EXPLORER,
|
||||
panelType,
|
||||
);
|
||||
|
||||
expect(exportQuery).toBe(staged);
|
||||
expect(mockSafeNavigate).toHaveBeenCalledWith(
|
||||
@@ -311,7 +345,7 @@ describe('AddToDashboardButton', () => {
|
||||
|
||||
await exportTo(
|
||||
query,
|
||||
DataSource.METRICS,
|
||||
ExplorerActionsSource.METRICS_EXPLORER,
|
||||
PANEL_TYPES.TIME_SERIES,
|
||||
PANEL_TYPES.TIME_SERIES,
|
||||
);
|
||||
|
||||
@@ -14,6 +14,7 @@ import { Query } from 'types/api/queryBuilder/queryBuilderData';
|
||||
import { DataSource, StringOperators } from 'types/common/queryBuilder';
|
||||
|
||||
import CreateAlertButton from '../CreateAlertButton';
|
||||
import { ExplorerActionsSource } from '../utils';
|
||||
|
||||
jest.mock('hooks/queryBuilder/useQueryBuilder', () => ({
|
||||
useQueryBuilder: jest.fn(),
|
||||
@@ -60,7 +61,7 @@ function pushedQuery(): Query {
|
||||
const [path, search] = (mockedNavigate.mock.calls[0][0] as string).split('?');
|
||||
expect(path).toBe(ROUTES.ALERTS_NEW);
|
||||
const raw = new URLSearchParams(search).get(QueryParams.compositeQuery);
|
||||
return JSON.parse(raw as string);
|
||||
return JSON.parse(decodeURIComponent(raw as string));
|
||||
}
|
||||
|
||||
function setPanelType(panelType: PANEL_TYPES): void {
|
||||
@@ -71,11 +72,11 @@ function setPanelType(panelType: PANEL_TYPES): void {
|
||||
|
||||
async function clickCreateAlert(
|
||||
query: Query | null,
|
||||
sourcepage: DataSource,
|
||||
sourcePage: ExplorerActionsSource,
|
||||
panelType: PANEL_TYPES,
|
||||
): Promise<void> {
|
||||
setPanelType(panelType);
|
||||
render(<CreateAlertButton query={query} sourcepage={sourcepage} />);
|
||||
render(<CreateAlertButton query={query} sourcePage={sourcePage} />);
|
||||
await userEvent.setup().click(screen.getByTestId('explorer-create-alert'));
|
||||
}
|
||||
|
||||
@@ -86,7 +87,11 @@ describe('CreateAlertButton', () => {
|
||||
});
|
||||
|
||||
it('is disabled and does nothing without a query', async () => {
|
||||
await clickCreateAlert(null, DataSource.LOGS, PANEL_TYPES.LIST);
|
||||
await clickCreateAlert(
|
||||
null,
|
||||
ExplorerActionsSource.LOGS_EXPLORER,
|
||||
PANEL_TYPES.LIST,
|
||||
);
|
||||
|
||||
expect(screen.getByTestId('explorer-create-alert')).toHaveAttribute(
|
||||
'aria-disabled',
|
||||
@@ -98,10 +103,14 @@ describe('CreateAlertButton', () => {
|
||||
it("logs the explorer's own create alert event", async () => {
|
||||
const query = stagedQuery(DataSource.TRACES, StringOperators.COUNT);
|
||||
|
||||
await clickCreateAlert(query, DataSource.TRACES, PANEL_TYPES.TIME_SERIES);
|
||||
await clickCreateAlert(
|
||||
query,
|
||||
ExplorerActionsSource.TRACES_EXPLORER,
|
||||
PANEL_TYPES.TIME_SERIES,
|
||||
);
|
||||
|
||||
expect(mockedLogEvent).toHaveBeenCalledWith('Traces Explorer: Create alert', {
|
||||
sourcepage: DataSource.TRACES,
|
||||
sourcepage: ExplorerActionsSource.TRACES_EXPLORER,
|
||||
panelType: PANEL_TYPES.TIME_SERIES,
|
||||
});
|
||||
});
|
||||
@@ -111,7 +120,7 @@ describe('CreateAlertButton', () => {
|
||||
render(
|
||||
<CreateAlertButton
|
||||
query={stagedQuery(DataSource.METRICS, StringOperators.COUNT)}
|
||||
sourcepage={DataSource.METRICS}
|
||||
sourcePage={ExplorerActionsSource.METRICS_EXPLORER}
|
||||
isOneChartPerQuery
|
||||
/>,
|
||||
);
|
||||
@@ -123,7 +132,7 @@ describe('CreateAlertButton', () => {
|
||||
expect(mockedLogEvent).toHaveBeenCalledWith(
|
||||
'Metrics Explorer: Add to alert clicked',
|
||||
{
|
||||
sourcepage: DataSource.METRICS,
|
||||
sourcepage: ExplorerActionsSource.METRICS_EXPLORER,
|
||||
panelType: PANEL_TYPES.TIME_SERIES,
|
||||
tab: 'explorer',
|
||||
oneChartPerQueryEnabled: true,
|
||||
@@ -146,7 +155,11 @@ describe('CreateAlertButton', () => {
|
||||
PANEL_TYPES.LIST,
|
||||
) as Query;
|
||||
|
||||
await clickCreateAlert(exportQuery, DataSource.LOGS, PANEL_TYPES.LIST);
|
||||
await clickCreateAlert(
|
||||
exportQuery,
|
||||
ExplorerActionsSource.LOGS_EXPLORER,
|
||||
PANEL_TYPES.LIST,
|
||||
);
|
||||
|
||||
const [queryData] = pushedQuery().builder.queryData;
|
||||
expect(queryData.aggregateOperator).toBe(StringOperators.COUNT);
|
||||
@@ -165,7 +178,7 @@ describe('CreateAlertButton', () => {
|
||||
|
||||
await clickCreateAlert(
|
||||
exportQuery,
|
||||
DataSource.LOGS,
|
||||
ExplorerActionsSource.LOGS_EXPLORER,
|
||||
PANEL_TYPES.TIME_SERIES,
|
||||
);
|
||||
|
||||
@@ -180,7 +193,11 @@ describe('CreateAlertButton', () => {
|
||||
PANEL_TYPES.TABLE,
|
||||
) as Query;
|
||||
|
||||
await clickCreateAlert(exportQuery, DataSource.LOGS, PANEL_TYPES.TABLE);
|
||||
await clickCreateAlert(
|
||||
exportQuery,
|
||||
ExplorerActionsSource.LOGS_EXPLORER,
|
||||
PANEL_TYPES.TABLE,
|
||||
);
|
||||
|
||||
expect(pushedQuery().builder).toStrictEqual(tableStaged.builder);
|
||||
});
|
||||
@@ -194,7 +211,11 @@ describe('CreateAlertButton', () => {
|
||||
async (panelType) => {
|
||||
const exportQuery = getTracesQueryByPanelType(staged, panelType);
|
||||
|
||||
await clickCreateAlert(exportQuery, DataSource.TRACES, panelType);
|
||||
await clickCreateAlert(
|
||||
exportQuery,
|
||||
ExplorerActionsSource.TRACES_EXPLORER,
|
||||
panelType,
|
||||
);
|
||||
|
||||
const [queryData] = pushedQuery().builder.queryData;
|
||||
expect(queryData.aggregateOperator).toBe(StringOperators.COUNT);
|
||||
@@ -211,7 +232,11 @@ describe('CreateAlertButton', () => {
|
||||
expect(staged.builder.queryData[0].orderBy).toStrictEqual(ORDER_BY);
|
||||
const exportQuery = getTracesQueryByPanelType(staged, panelType);
|
||||
|
||||
await clickCreateAlert(exportQuery, DataSource.TRACES, panelType);
|
||||
await clickCreateAlert(
|
||||
exportQuery,
|
||||
ExplorerActionsSource.TRACES_EXPLORER,
|
||||
panelType,
|
||||
);
|
||||
|
||||
expect(pushedQuery().builder.queryData[0].orderBy).toStrictEqual([]);
|
||||
},
|
||||
@@ -223,7 +248,11 @@ describe('CreateAlertButton', () => {
|
||||
const aggStaged = stagedQuery(DataSource.TRACES, StringOperators.COUNT);
|
||||
const exportQuery = getTracesQueryByPanelType(aggStaged, panelType);
|
||||
|
||||
await clickCreateAlert(exportQuery, DataSource.TRACES, panelType);
|
||||
await clickCreateAlert(
|
||||
exportQuery,
|
||||
ExplorerActionsSource.TRACES_EXPLORER,
|
||||
panelType,
|
||||
);
|
||||
|
||||
expect(pushedQuery().builder).toStrictEqual(aggStaged.builder);
|
||||
},
|
||||
@@ -233,7 +262,11 @@ describe('CreateAlertButton', () => {
|
||||
it('metrics: the chart query as is', async () => {
|
||||
const query = stagedQuery(DataSource.METRICS, StringOperators.COUNT);
|
||||
|
||||
await clickCreateAlert(query, DataSource.METRICS, PANEL_TYPES.TIME_SERIES);
|
||||
await clickCreateAlert(
|
||||
query,
|
||||
ExplorerActionsSource.METRICS_EXPLORER,
|
||||
PANEL_TYPES.TIME_SERIES,
|
||||
);
|
||||
|
||||
expect(pushedQuery().builder).toStrictEqual(query.builder);
|
||||
});
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { QueryParams } from 'constants/query';
|
||||
import { initialQueriesMap, PANEL_TYPES } from 'constants/queryBuilder';
|
||||
import ROUTES from 'constants/routes';
|
||||
import { useGetCompositeQueryParam } from 'hooks/queryBuilder/useGetCompositeQueryParam';
|
||||
import { AllTheProviders, renderHook } from 'tests/test-utils';
|
||||
import { Query } from 'types/api/queryBuilder/queryBuilderData';
|
||||
import { StringOperators } from 'types/common/queryBuilder';
|
||||
|
||||
@@ -22,7 +24,7 @@ function withFirstQuery(
|
||||
function decodeQuery(link: string): Query {
|
||||
const search = link.split('?')[1];
|
||||
const raw = new URLSearchParams(search).get(QueryParams.compositeQuery);
|
||||
return JSON.parse(raw as string);
|
||||
return JSON.parse(decodeURIComponent(raw as string));
|
||||
}
|
||||
|
||||
describe('getExportPanelType', () => {
|
||||
@@ -55,6 +57,26 @@ describe('getCreateAlertLink', () => {
|
||||
expect(decodeQuery(link)).toStrictEqual(query);
|
||||
});
|
||||
|
||||
it.each(["service.name ILIKE 'api%'", "http.route = '/a+b'"])(
|
||||
'the alert page reads back the filter %s unchanged',
|
||||
(expression) => {
|
||||
const link = getCreateAlertLink({
|
||||
query: withFirstQuery(initialQueriesMap.logs, { filter: { expression } }),
|
||||
panelType: PANEL_TYPES.TIME_SERIES,
|
||||
});
|
||||
|
||||
const { result } = renderHook(() => useGetCompositeQueryParam(), {
|
||||
wrapper: ({ children }): JSX.Element => (
|
||||
<AllTheProviders initialRoute={link}>{children}</AllTheProviders>
|
||||
),
|
||||
});
|
||||
|
||||
expect(result.current?.builder.queryData[0].filter?.expression).toBe(
|
||||
expression,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it('logs list: noop becomes count and order by is dropped', () => {
|
||||
const query = withFirstQuery(initialQueriesMap.logs, {
|
||||
aggregateOperator: StringOperators.NOOP,
|
||||
@@ -10,41 +10,57 @@ import { cloneDeep } from 'lodash-es';
|
||||
import { Query } from 'types/api/queryBuilder/queryBuilderData';
|
||||
import { DataSource, StringOperators } from 'types/common/queryBuilder';
|
||||
|
||||
// The explorer page, not its DataSource: the AI explorer queries traces but logs its own events.
|
||||
export const ExplorerActionsSource = {
|
||||
LOGS_EXPLORER: DataSource.LOGS,
|
||||
TRACES_EXPLORER: DataSource.TRACES,
|
||||
METRICS_EXPLORER: DataSource.METRICS,
|
||||
AI_OBSERVABILITY_EXPLORER: 'ai_observability',
|
||||
} as const;
|
||||
|
||||
export type ExplorerActionsSource =
|
||||
(typeof ExplorerActionsSource)[keyof typeof ExplorerActionsSource];
|
||||
|
||||
export const EXPLORER_ACTION_EVENTS: Record<
|
||||
DataSource,
|
||||
ExplorerActionsSource,
|
||||
{ createAlert: string; addToDashboard: string; exported: string }
|
||||
> = {
|
||||
[DataSource.LOGS]: {
|
||||
[ExplorerActionsSource.LOGS_EXPLORER]: {
|
||||
createAlert: 'Logs Explorer: Create alert',
|
||||
addToDashboard: 'Logs Explorer: Add to dashboard clicked',
|
||||
exported: 'Logs Explorer: Add to dashboard successful',
|
||||
},
|
||||
[DataSource.TRACES]: {
|
||||
[ExplorerActionsSource.TRACES_EXPLORER]: {
|
||||
createAlert: 'Traces Explorer: Create alert',
|
||||
addToDashboard: 'Traces Explorer: Add to dashboard clicked',
|
||||
exported: 'Traces Explorer: Add to dashboard successful',
|
||||
},
|
||||
[DataSource.METRICS]: {
|
||||
[ExplorerActionsSource.METRICS_EXPLORER]: {
|
||||
createAlert: MetricsExplorerEvents.AddToAlertClicked,
|
||||
addToDashboard: MetricsExplorerEvents.AddToDashboardClicked,
|
||||
exported: MetricsExplorerEvents.AddToDashboardSuccessful,
|
||||
},
|
||||
[ExplorerActionsSource.AI_OBSERVABILITY_EXPLORER]: {
|
||||
createAlert: 'AI Observability Explorer: Create alert',
|
||||
addToDashboard: 'AI Observability Explorer: Add to dashboard clicked',
|
||||
exported: 'AI Observability Explorer: Add to dashboard successful',
|
||||
},
|
||||
};
|
||||
|
||||
export function getExplorerActionEventPayload({
|
||||
sourcepage,
|
||||
sourcePage,
|
||||
panelType,
|
||||
isOneChartPerQuery,
|
||||
}: {
|
||||
sourcepage: DataSource;
|
||||
sourcePage: ExplorerActionsSource;
|
||||
panelType: PANEL_TYPES | null;
|
||||
isOneChartPerQuery: boolean;
|
||||
}): Record<string, unknown> {
|
||||
if (sourcepage !== DataSource.METRICS) {
|
||||
return { sourcepage, panelType };
|
||||
if (sourcePage !== ExplorerActionsSource.METRICS_EXPLORER) {
|
||||
return { sourcepage: sourcePage, panelType };
|
||||
}
|
||||
return {
|
||||
sourcepage,
|
||||
sourcepage: sourcePage,
|
||||
panelType,
|
||||
[MetricsExplorerEventKeys.Tab]: 'explorer',
|
||||
[MetricsExplorerEventKeys.OneChartPerQueryEnabled]: isOneChartPerQuery,
|
||||
@@ -79,7 +95,8 @@ export function getCreateAlertLink({
|
||||
orderBy: isListStyle ? [] : item.orderBy,
|
||||
}));
|
||||
|
||||
// Encoded twice: the alert page decodes it again after the URL does.
|
||||
return `${ROUTES.ALERTS_NEW}?${QueryParams.compositeQuery}=${encodeURIComponent(
|
||||
JSON.stringify(alertQuery),
|
||||
encodeURIComponent(JSON.stringify(alertQuery)),
|
||||
)}`;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import { useMemo } from 'react';
|
||||
import { TelemetryFieldKey } from 'api/v5/v5';
|
||||
import { PANEL_TYPES } from 'constants/queryBuilder';
|
||||
import ExplorerActions from 'container/ExplorerActions/ExplorerActions';
|
||||
import { ExplorerActionsSource } from 'container/ExplorerActions/utils';
|
||||
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
|
||||
|
||||
import { getAlertQuery, getExportQuery } from '../explorerUtils';
|
||||
|
||||
interface AIExplorerActionsProps {
|
||||
panelType: PANEL_TYPES;
|
||||
selectColumns?: TelemetryFieldKey[];
|
||||
}
|
||||
|
||||
function AIExplorerActions({
|
||||
panelType,
|
||||
selectColumns,
|
||||
}: AIExplorerActionsProps): JSX.Element {
|
||||
const { stagedQuery } = useQueryBuilder();
|
||||
|
||||
const alertQuery = useMemo(
|
||||
() => (stagedQuery ? getAlertQuery(stagedQuery, panelType) : null),
|
||||
[stagedQuery, panelType],
|
||||
);
|
||||
|
||||
const dashboardQuery = useMemo(
|
||||
() =>
|
||||
stagedQuery ? getExportQuery(stagedQuery, panelType, selectColumns) : null,
|
||||
[stagedQuery, panelType, selectColumns],
|
||||
);
|
||||
|
||||
return (
|
||||
<ExplorerActions
|
||||
query={alertQuery}
|
||||
dashboardQuery={dashboardQuery}
|
||||
sourcePage={ExplorerActionsSource.AI_OBSERVABILITY_EXPLORER}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
export default AIExplorerActions;
|
||||
@@ -0,0 +1,301 @@
|
||||
import { logEventMock } from '__tests__/logEventMock';
|
||||
import { safeNavigateMock } from '__tests__/safeNavigateMock';
|
||||
import { TelemetryFieldKey } from 'api/v5/v5';
|
||||
import { QueryParams } from 'constants/query';
|
||||
import {
|
||||
initialFormulaBuilderFormValues,
|
||||
initialQueryAIWithType,
|
||||
PANEL_TYPES,
|
||||
} from 'constants/queryBuilder';
|
||||
import ROUTES from 'constants/routes';
|
||||
import { ExplorerActionsSource } from 'container/ExplorerActions/utils';
|
||||
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
|
||||
import { getActiveBuilder } from 'lib/query/builderSlot';
|
||||
import { rest, server } from 'mocks-server/server';
|
||||
import { mockAppNavigate } from 'tests/router-mocks';
|
||||
import { render, screen, userEvent, waitFor } from 'tests/test-utils';
|
||||
import { DataTypes } from 'types/api/queryBuilder/queryAutocompleteResponse';
|
||||
import { IBuilderQuery, Query } from 'types/api/queryBuilder/queryBuilderData';
|
||||
import { EQueryType } from 'types/common/dashboard';
|
||||
|
||||
import AIExplorerActions from '../AIExplorerActions';
|
||||
|
||||
jest.mock('hooks/queryBuilder/useQueryBuilder', () => ({
|
||||
useQueryBuilder: jest.fn(),
|
||||
}));
|
||||
|
||||
const mockedUseQueryBuilder = jest.mocked(useQueryBuilder);
|
||||
|
||||
const FILTER = "gen_ai.request.model = 'gpt-4o'";
|
||||
|
||||
const USER_COLUMNS: TelemetryFieldKey[] = [
|
||||
{ name: 'gen_ai.request.model', fieldContext: 'attribute' },
|
||||
{ name: 'duration_nano' },
|
||||
];
|
||||
|
||||
function aiStagedQuery(aggregations?: IBuilderQuery['aggregations']): Query {
|
||||
const aiBuilder = getActiveBuilder(initialQueryAIWithType);
|
||||
return {
|
||||
...initialQueryAIWithType,
|
||||
builder_ai_query: {
|
||||
...aiBuilder,
|
||||
queryData: [
|
||||
{
|
||||
...aiBuilder.queryData[0],
|
||||
...(aggregations && { aggregations }),
|
||||
filter: { expression: FILTER },
|
||||
groupBy: [
|
||||
{ key: 'service.name', dataType: DataTypes.String, type: 'resource' },
|
||||
],
|
||||
having: { expression: 'count() > 5' },
|
||||
orderBy: [{ columnName: 'timestamp', order: 'asc' }],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
async function exportFrom(
|
||||
panelType: PANEL_TYPES,
|
||||
stagedQuery: Query = aiStagedQuery(),
|
||||
selectColumns?: TelemetryFieldKey[],
|
||||
): Promise<void> {
|
||||
mockedUseQueryBuilder.mockReturnValue({
|
||||
stagedQuery,
|
||||
panelType,
|
||||
} as ReturnType<typeof useQueryBuilder>);
|
||||
server.use(
|
||||
rest.get('*/api/v2/users/me/dashboards', (_req, res, ctx) =>
|
||||
res(
|
||||
ctx.status(200),
|
||||
ctx.json({ status: 'success', data: { dashboards: [] } }),
|
||||
),
|
||||
),
|
||||
rest.post('*/api/v2/dashboards', (_req, res, ctx) =>
|
||||
res(
|
||||
ctx.status(200),
|
||||
ctx.json({ status: 'success', data: { id: 'dash-1' } }),
|
||||
),
|
||||
),
|
||||
);
|
||||
const user = userEvent.setup();
|
||||
|
||||
render(
|
||||
<AIExplorerActions panelType={panelType} selectColumns={selectColumns} />,
|
||||
);
|
||||
await user.click(screen.getByTestId('explorer-add-to-dashboard'));
|
||||
await user.click(await screen.findByTestId('export-panel-new-dashboard'));
|
||||
|
||||
await waitFor(() => expect(safeNavigateMock).toHaveBeenCalledTimes(1));
|
||||
}
|
||||
|
||||
async function createAlertFrom(
|
||||
panelType: PANEL_TYPES,
|
||||
stagedQuery: Query = aiStagedQuery(),
|
||||
): Promise<Query> {
|
||||
const navigate = mockAppNavigate();
|
||||
mockedUseQueryBuilder.mockReturnValue({
|
||||
stagedQuery,
|
||||
panelType,
|
||||
} as ReturnType<typeof useQueryBuilder>);
|
||||
|
||||
render(<AIExplorerActions panelType={panelType} />);
|
||||
await userEvent.setup().click(screen.getByTestId('explorer-create-alert'));
|
||||
|
||||
expect(navigate).toHaveBeenCalledTimes(1);
|
||||
const [path, search] = (navigate.mock.calls[0][0] as string).split('?');
|
||||
expect(path).toBe(ROUTES.ALERTS_NEW);
|
||||
return JSON.parse(
|
||||
decodeURIComponent(
|
||||
new URLSearchParams(search).get(QueryParams.compositeQuery) ?? '',
|
||||
),
|
||||
) as Query;
|
||||
}
|
||||
|
||||
function exportedPanel(): { panelKind: string | null; query: Query } {
|
||||
const link = safeNavigateMock.mock.calls[0][0] as string;
|
||||
const params = new URLSearchParams(link.split('?')[1]);
|
||||
return {
|
||||
panelKind: params.get('panelKind'),
|
||||
query: JSON.parse(
|
||||
decodeURIComponent(params.get(QueryParams.compositeQuery) ?? ''),
|
||||
) as Query,
|
||||
};
|
||||
}
|
||||
|
||||
describe('AIExplorerActions', () => {
|
||||
it('logs the AI explorer events, not the traces ones', async () => {
|
||||
await exportFrom(PANEL_TYPES.TABLE);
|
||||
|
||||
expect(logEventMock).toHaveBeenCalledWith(
|
||||
'AI Observability Explorer: Add to dashboard clicked',
|
||||
{
|
||||
sourcepage: ExplorerActionsSource.AI_OBSERVABILITY_EXPLORER,
|
||||
panelType: PANEL_TYPES.TABLE,
|
||||
},
|
||||
);
|
||||
expect(logEventMock).toHaveBeenCalledWith(
|
||||
'AI Observability Explorer: Add to dashboard successful',
|
||||
{
|
||||
sourcepage: ExplorerActionsSource.AI_OBSERVABILITY_EXPLORER,
|
||||
panelType: PANEL_TYPES.TABLE,
|
||||
isNewDashboard: true,
|
||||
dashboardName: expect.any(String),
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('list: exports an AI List panel with the user picked columns and no group by, having or order by', async () => {
|
||||
await exportFrom(PANEL_TYPES.LIST, aiStagedQuery(), USER_COLUMNS);
|
||||
|
||||
const { panelKind, query } = exportedPanel();
|
||||
expect(panelKind).toBe('signoz/ListPanel');
|
||||
expect(query.queryType).toBe(EQueryType.AI_QUERY_BUILDER);
|
||||
expect(getActiveBuilder(query).queryData[0]).toMatchObject({
|
||||
filter: { expression: FILTER },
|
||||
groupBy: [],
|
||||
having: { expression: '' },
|
||||
orderBy: [],
|
||||
selectColumns: USER_COLUMNS,
|
||||
});
|
||||
});
|
||||
|
||||
it('trace: exports an AI Time Series panel with no group by, having or order by', async () => {
|
||||
await exportFrom(PANEL_TYPES.TRACE);
|
||||
|
||||
const { panelKind, query } = exportedPanel();
|
||||
expect(panelKind).toBe('signoz/TimeSeriesPanel');
|
||||
expect(query.queryType).toBe(EQueryType.AI_QUERY_BUILDER);
|
||||
const [queryData] = getActiveBuilder(query).queryData;
|
||||
expect(queryData).toMatchObject({
|
||||
filter: { expression: FILTER },
|
||||
groupBy: [],
|
||||
having: { expression: '' },
|
||||
orderBy: [],
|
||||
});
|
||||
expect(queryData.selectColumns).toBeUndefined();
|
||||
});
|
||||
|
||||
it('trace: exports without the formulas, step, limit and legend Timeseries set', async () => {
|
||||
const stagedQuery = aiStagedQuery();
|
||||
const aiBuilder = getActiveBuilder(stagedQuery);
|
||||
await exportFrom(PANEL_TYPES.TRACE, {
|
||||
...stagedQuery,
|
||||
builder_ai_query: {
|
||||
...aiBuilder,
|
||||
queryData: [
|
||||
{
|
||||
...aiBuilder.queryData[0],
|
||||
stepInterval: 300,
|
||||
limit: 10,
|
||||
legend: '{{service.name}}',
|
||||
},
|
||||
],
|
||||
queryFormulas: [
|
||||
{ ...initialFormulaBuilderFormValues, expression: 'A*100' },
|
||||
],
|
||||
},
|
||||
});
|
||||
|
||||
const exported = getActiveBuilder(exportedPanel().query);
|
||||
expect(exported.queryFormulas).toStrictEqual([]);
|
||||
expect(exported.queryData[0]).toMatchObject({
|
||||
stepInterval: null,
|
||||
limit: null,
|
||||
legend: '',
|
||||
});
|
||||
});
|
||||
|
||||
it('create alert: logs the AI explorer event, not the traces one', async () => {
|
||||
await createAlertFrom(PANEL_TYPES.TIME_SERIES);
|
||||
|
||||
expect(logEventMock).toHaveBeenCalledWith(
|
||||
'AI Observability Explorer: Create alert',
|
||||
{
|
||||
sourcepage: ExplorerActionsSource.AI_OBSERVABILITY_EXPLORER,
|
||||
panelType: PANEL_TYPES.TIME_SERIES,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('without a staged query: both actions are disabled and create alert goes nowhere', async () => {
|
||||
const navigate = mockAppNavigate();
|
||||
mockedUseQueryBuilder.mockReturnValue({
|
||||
stagedQuery: null,
|
||||
panelType: PANEL_TYPES.LIST,
|
||||
} as ReturnType<typeof useQueryBuilder>);
|
||||
|
||||
render(<AIExplorerActions panelType={PANEL_TYPES.LIST} />);
|
||||
const createAlert = screen.getByTestId('explorer-create-alert');
|
||||
await userEvent.setup().click(createAlert);
|
||||
|
||||
expect(createAlert).toHaveAttribute('aria-disabled', 'true');
|
||||
expect(screen.getByTestId('explorer-add-to-dashboard')).toHaveAttribute(
|
||||
'aria-disabled',
|
||||
'true',
|
||||
);
|
||||
expect(navigate).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it.each([PANEL_TYPES.TIME_SERIES, PANEL_TYPES.TABLE])(
|
||||
'create alert from %s: keeps the aggregation, group by, having and order by',
|
||||
async (panelType) => {
|
||||
const query = await createAlertFrom(
|
||||
panelType,
|
||||
aiStagedQuery([{ expression: 'avg(duration_nano)' }]),
|
||||
);
|
||||
|
||||
expect(query.queryType).toBe(EQueryType.AI_QUERY_BUILDER);
|
||||
expect(getActiveBuilder(query).queryData[0]).toMatchObject({
|
||||
aggregations: [{ expression: 'avg(duration_nano)' }],
|
||||
filter: { expression: FILTER },
|
||||
groupBy: [
|
||||
{ key: 'service.name', dataType: DataTypes.String, type: 'resource' },
|
||||
],
|
||||
having: { expression: 'count() > 5' },
|
||||
orderBy: [{ columnName: 'timestamp', order: 'asc' }],
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
it.each([PANEL_TYPES.LIST, PANEL_TYPES.TRACE])(
|
||||
'create alert from %s: a count with no group by, having or order by',
|
||||
async (panelType) => {
|
||||
const query = await createAlertFrom(
|
||||
panelType,
|
||||
aiStagedQuery([{ expression: 'avg(duration_nano)' }]),
|
||||
);
|
||||
|
||||
expect(query.queryType).toBe(EQueryType.AI_QUERY_BUILDER);
|
||||
const [queryData] = getActiveBuilder(query).queryData;
|
||||
expect(queryData).toMatchObject({
|
||||
aggregations: [{ expression: 'count()' }],
|
||||
filter: { expression: FILTER },
|
||||
groupBy: [],
|
||||
having: { expression: '' },
|
||||
orderBy: [],
|
||||
});
|
||||
expect(queryData.selectColumns).toBeUndefined();
|
||||
},
|
||||
);
|
||||
|
||||
it.each([PANEL_TYPES.LIST, PANEL_TYPES.TRACE])(
|
||||
'create alert from %s: only the first query, the one the view shows',
|
||||
async (panelType) => {
|
||||
const stagedQuery = aiStagedQuery();
|
||||
const aiBuilder = getActiveBuilder(stagedQuery);
|
||||
const [first] = aiBuilder.queryData;
|
||||
const query = await createAlertFrom(panelType, {
|
||||
...stagedQuery,
|
||||
builder_ai_query: {
|
||||
...aiBuilder,
|
||||
queryData: [first, { ...first, queryName: 'B', expression: 'B' }],
|
||||
},
|
||||
});
|
||||
|
||||
expect(
|
||||
getActiveBuilder(query).queryData.map(({ queryName }) => queryName),
|
||||
).toStrictEqual([first.queryName]);
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -38,6 +38,7 @@ import { GlobalReducer } from 'types/reducer/globalTime';
|
||||
|
||||
import { getListOrderBy, setListOrderBy } from 'utils/explorerUtils';
|
||||
|
||||
import AIExplorerActions from '../AIExplorerActions/AIExplorerActions';
|
||||
import TraceExplorerControls from '../Controls';
|
||||
import { getListViewQuery } from '../explorerUtils';
|
||||
import { PER_PAGE_OPTIONS, TIMESTAMP_FIELD } from './configs';
|
||||
@@ -213,6 +214,10 @@ function ListView({
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<div className="trace-explorer-controls">
|
||||
<AIExplorerActions
|
||||
panelType={PANEL_TYPES.LIST}
|
||||
selectColumns={selectColumns}
|
||||
/>
|
||||
<div className="order-by-container">
|
||||
<div className="order-by-label">
|
||||
Order by <Minus size={14} /> <ArrowUp10 size={14} />
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
display: flex;
|
||||
justify-content: flex-end;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 12px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import {
|
||||
useEffect,
|
||||
useMemo,
|
||||
} from 'react';
|
||||
import { QueryKey } from 'react-query';
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { useSelector } from 'react-redux';
|
||||
import Space from 'periscope/components/Space/Space';
|
||||
@@ -24,6 +25,8 @@ import { QueryDataV3 } from 'types/api/widgets/getQuery';
|
||||
import { DataSource } from 'types/common/queryBuilder';
|
||||
import { GlobalReducer } from 'types/reducer/globalTime';
|
||||
|
||||
import AIExplorerActions from '../AIExplorerActions/AIExplorerActions';
|
||||
|
||||
import './TableView.styles.scss';
|
||||
|
||||
function TableView({
|
||||
@@ -33,7 +36,7 @@ function TableView({
|
||||
}: {
|
||||
setWarning: Dispatch<SetStateAction<Warning | undefined>>;
|
||||
setIsLoadingQueries: Dispatch<SetStateAction<boolean>>;
|
||||
queryKeyRef?: MutableRefObject<any>;
|
||||
queryKeyRef?: MutableRefObject<QueryKey | undefined>;
|
||||
}): JSX.Element {
|
||||
const { stagedQuery, panelType } = useQueryBuilder();
|
||||
|
||||
@@ -101,14 +104,17 @@ function TableView({
|
||||
return (
|
||||
<Space.Compact block direction="vertical">
|
||||
{isError && error && <ErrorInPlace error={error as APIError} />}
|
||||
{!isError && data && (
|
||||
{!isError && (
|
||||
<div className="traces-table-view-header">
|
||||
<ExportMenu
|
||||
dataSource={DataSource.TRACES}
|
||||
data={data}
|
||||
query={stagedQuery || initialQueriesMap.traces}
|
||||
fileName="ai-traces-table"
|
||||
/>
|
||||
<AIExplorerActions panelType={PANEL_TYPES.TABLE} />
|
||||
{data && (
|
||||
<ExportMenu
|
||||
dataSource={DataSource.TRACES}
|
||||
data={data}
|
||||
query={stagedQuery || initialQueriesMap.traces}
|
||||
fileName="ai-traces-table"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
)}
|
||||
{!isError && (
|
||||
|
||||
@@ -5,6 +5,7 @@ import {
|
||||
useEffect,
|
||||
useMemo,
|
||||
} from 'react';
|
||||
import { QueryKey } from 'react-query';
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { useSelector } from 'react-redux';
|
||||
import { ENTITY_VERSION_V5 } from 'constants/app';
|
||||
@@ -22,6 +23,8 @@ import APIError from 'types/api/error';
|
||||
import { DataSource } from 'types/common/queryBuilder';
|
||||
import { GlobalReducer } from 'types/reducer/globalTime';
|
||||
|
||||
import AIExplorerActions from '../AIExplorerActions/AIExplorerActions';
|
||||
|
||||
import './TimeSeriesView.styles.scss';
|
||||
|
||||
function TimeSeriesViewContainer({
|
||||
@@ -128,6 +131,7 @@ function TimeSeriesViewContainer({
|
||||
setWarning={setWarning}
|
||||
allowExport
|
||||
exportFileName="ai-traces-timeseries"
|
||||
headerActions={<AIExplorerActions panelType={PANEL_TYPES.TIME_SERIES} />}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
@@ -138,7 +142,7 @@ interface TimeSeriesViewProps {
|
||||
isFilterApplied: boolean;
|
||||
setWarning: Dispatch<SetStateAction<Warning | undefined>>;
|
||||
setIsLoadingQueries: Dispatch<SetStateAction<boolean>>;
|
||||
queryKeyRef?: MutableRefObject<any>;
|
||||
queryKeyRef?: MutableRefObject<QueryKey | undefined>;
|
||||
}
|
||||
|
||||
TimeSeriesViewContainer.defaultProps = {
|
||||
|
||||
@@ -34,6 +34,7 @@ import { Warning } from 'types/api';
|
||||
import { DataSource } from 'types/common/queryBuilder';
|
||||
import { GlobalReducer } from 'types/reducer/globalTime';
|
||||
|
||||
import AIExplorerActions from '../AIExplorerActions/AIExplorerActions';
|
||||
import TraceExplorerControls from '../Controls';
|
||||
import {
|
||||
TRACE_VIEW_BUILDER_QUERY_TYPE,
|
||||
@@ -191,6 +192,7 @@ function TracesView({
|
||||
<div className={styles.container}>
|
||||
<div className={styles.actionsContainer}>
|
||||
<div className="trace-explorer-controls">
|
||||
<AIExplorerActions panelType={PANEL_TYPES.TRACE} />
|
||||
<div className={styles.orderByContainer}>
|
||||
<div className={styles.orderByLabel}>
|
||||
Order by <Minus size={14} /> <ArrowUp10 size={14} />
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
import { ENVIRONMENT } from 'constants/env';
|
||||
import { initialQueryAIWithType, PANEL_TYPES } from 'constants/queryBuilder';
|
||||
import { rest, server } from 'mocks-server/server';
|
||||
import { render, screen } from 'tests/test-utils';
|
||||
import { DataSource } from 'types/common/queryBuilder';
|
||||
|
||||
import ListView from '../ListView/ListView';
|
||||
import TableView from '../TableView/TableView';
|
||||
import TimeSeriesView from '../TimeSeriesView/TimeSeriesView';
|
||||
import TracesView from '../TracesView/TracesView';
|
||||
|
||||
const QUERY_RANGE_URL = `${ENVIRONMENT.baseURL}/api/v5/query_range`;
|
||||
|
||||
const VIEWS: [PANEL_TYPES, () => JSX.Element][] = [
|
||||
[
|
||||
PANEL_TYPES.LIST,
|
||||
(): JSX.Element => (
|
||||
<ListView
|
||||
isFilterApplied={false}
|
||||
setWarning={jest.fn()}
|
||||
setIsLoadingQueries={jest.fn()}
|
||||
/>
|
||||
),
|
||||
],
|
||||
[
|
||||
PANEL_TYPES.TRACE,
|
||||
(): JSX.Element => (
|
||||
<TracesView
|
||||
isFilterApplied={false}
|
||||
setWarning={jest.fn()}
|
||||
setIsLoadingQueries={jest.fn()}
|
||||
/>
|
||||
),
|
||||
],
|
||||
[
|
||||
PANEL_TYPES.TIME_SERIES,
|
||||
(): JSX.Element => (
|
||||
<TimeSeriesView
|
||||
dataSource={DataSource.TRACES}
|
||||
isFilterApplied={false}
|
||||
setWarning={jest.fn()}
|
||||
setIsLoadingQueries={jest.fn()}
|
||||
/>
|
||||
),
|
||||
],
|
||||
[
|
||||
PANEL_TYPES.TABLE,
|
||||
(): JSX.Element => (
|
||||
<TableView setWarning={jest.fn()} setIsLoadingQueries={jest.fn()} />
|
||||
),
|
||||
],
|
||||
];
|
||||
|
||||
describe('AI explorer views', () => {
|
||||
beforeEach(() => {
|
||||
server.use(
|
||||
rest.post(QUERY_RANGE_URL, (_req, res, ctx) =>
|
||||
res(ctx.status(200), ctx.json({ data: { data: { results: [] } } })),
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
it.each(VIEWS)(
|
||||
'%s: offers Create an alert and Add to dashboard for the staged query, before data arrives',
|
||||
(panelType, renderView) => {
|
||||
render(
|
||||
renderView(),
|
||||
{},
|
||||
{
|
||||
queryBuilderOverrides: {
|
||||
panelType,
|
||||
stagedQuery: initialQueryAIWithType,
|
||||
currentQuery: initialQueryAIWithType,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
expect(screen.getByTestId('explorer-create-alert')).not.toHaveAttribute(
|
||||
'aria-disabled',
|
||||
'true',
|
||||
);
|
||||
expect(screen.getByTestId('explorer-add-to-dashboard')).not.toHaveAttribute(
|
||||
'aria-disabled',
|
||||
'true',
|
||||
);
|
||||
},
|
||||
);
|
||||
});
|
||||
@@ -1,9 +1,16 @@
|
||||
import { initialQueriesMap } from 'constants/queryBuilder';
|
||||
import { getActiveBuilder } from 'lib/query/builderSlot';
|
||||
import { TelemetryFieldKey } from 'api/v5/v5';
|
||||
import { initialQueriesMap, PANEL_TYPES } from 'constants/queryBuilder';
|
||||
import {
|
||||
getActiveBuilder,
|
||||
getBuilderSlotKeyForQueryType,
|
||||
replaceBuilderBySlotKey,
|
||||
} from 'lib/query/builderSlot';
|
||||
import { cloneDeep } from 'lodash-es';
|
||||
import { OrderByPayload, Query } from 'types/api/queryBuilder/queryBuilderData';
|
||||
import { parseListOrderBy } from 'utils/explorerUtils';
|
||||
|
||||
import { defaultSelectedColumns } from './ListView/configs';
|
||||
|
||||
export const getListViewQuery = (
|
||||
stagedQuery: Query,
|
||||
orderBy?: string,
|
||||
@@ -28,3 +35,43 @@ export const getListViewQuery = (
|
||||
|
||||
return query;
|
||||
};
|
||||
|
||||
export const getAlertQuery = (
|
||||
stagedQuery: Query,
|
||||
panelType: PANEL_TYPES,
|
||||
): Query => {
|
||||
if (panelType !== PANEL_TYPES.LIST && panelType !== PANEL_TYPES.TRACE) {
|
||||
return stagedQuery;
|
||||
}
|
||||
const query = getListViewQuery(stagedQuery);
|
||||
const builder = getActiveBuilder(query);
|
||||
// List and Trace show only the first query's filter, so nothing another view set may reach the alert or chart.
|
||||
return replaceBuilderBySlotKey(
|
||||
query,
|
||||
getBuilderSlotKeyForQueryType(query.queryType),
|
||||
{
|
||||
...builder,
|
||||
queryData: builder.queryData.slice(0, 1).map((item) => ({
|
||||
...item,
|
||||
aggregations: [{ expression: 'count()' }],
|
||||
stepInterval: null,
|
||||
limit: null,
|
||||
legend: '',
|
||||
})),
|
||||
queryFormulas: [],
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
export const getExportQuery = (
|
||||
stagedQuery: Query,
|
||||
panelType: PANEL_TYPES,
|
||||
selectColumns: TelemetryFieldKey[] = defaultSelectedColumns,
|
||||
): Query => {
|
||||
const query = getAlertQuery(stagedQuery, panelType);
|
||||
const [queryData] = getActiveBuilder(query).queryData;
|
||||
if (panelType === PANEL_TYPES.LIST && queryData) {
|
||||
queryData.selectColumns = selectColumns;
|
||||
}
|
||||
return query;
|
||||
};
|
||||
|
||||
@@ -36,6 +36,7 @@ import {
|
||||
getQueryByPanelType,
|
||||
} from 'container/LogsExplorerViews/explorerUtils';
|
||||
import ExplorerActions from 'container/ExplorerActions/ExplorerActions';
|
||||
import { ExplorerActionsSource } from 'container/ExplorerActions/utils';
|
||||
import TimeSeriesView from 'container/TimeSeriesView/TimeSeriesView';
|
||||
import { useCopyLogLink } from 'hooks/logs/useCopyLogLink';
|
||||
import { useGetExplorerQueryRange } from 'hooks/queryBuilder/useGetExplorerQueryRange';
|
||||
@@ -136,7 +137,10 @@ function LogsExplorerViewsContainer({
|
||||
|
||||
const explorerActions = useMemo(
|
||||
() => (
|
||||
<ExplorerActions query={exportDefaultQuery} sourcepage={DataSource.LOGS} />
|
||||
<ExplorerActions
|
||||
query={exportDefaultQuery}
|
||||
sourcePage={ExplorerActionsSource.LOGS_EXPLORER}
|
||||
/>
|
||||
),
|
||||
[exportDefaultQuery],
|
||||
);
|
||||
|
||||
@@ -21,6 +21,7 @@ import { initialQueriesMap, PANEL_TYPES } from 'constants/queryBuilder';
|
||||
import { MAX_QUERY_RETRIES } from 'constants/reactQuery';
|
||||
import { REACT_QUERY_KEY } from 'constants/reactQueryKeys';
|
||||
import ExplorerActions from 'container/ExplorerActions/ExplorerActions';
|
||||
import { ExplorerActionsSource } from 'container/ExplorerActions/utils';
|
||||
import TimeSeriesView from 'container/TimeSeriesView/TimeSeriesView';
|
||||
import { convertDataValueToMs } from 'container/TimeSeriesView/utils';
|
||||
import { useQueryBuilder } from 'hooks/queryBuilder/useQueryBuilder';
|
||||
@@ -347,7 +348,7 @@ function TimeSeries({
|
||||
headerActions={
|
||||
<ExplorerActions
|
||||
query={stagedQuery ? exportQuery : null}
|
||||
sourcepage={DataSource.METRICS}
|
||||
sourcePage={ExplorerActionsSource.METRICS_EXPLORER}
|
||||
panelType={PANEL_TYPES.TIME_SERIES}
|
||||
isOneChartPerQuery={changeLayoutForOneChartPerQuery}
|
||||
/>
|
||||
|
||||
@@ -6,6 +6,9 @@
|
||||
import { RuletypesRuleTypeDTO } from 'api/generated/services/sigNoz.schemas';
|
||||
import { QueryParams } from 'constants/query';
|
||||
import ROUTES from 'constants/routes';
|
||||
import { getCreateAlertLink } from 'container/ExplorerActions/utils';
|
||||
import { DEFAULT_PANEL_TYPE } from 'container/LLMObservability/Explorer/constants';
|
||||
import { getAlertQuery } from 'container/LLMObservability/Explorer/explorerUtils';
|
||||
import { rest } from 'msw';
|
||||
import { expect, screen, userEvent, waitFor, within } from 'storybook/test';
|
||||
import { AlertTypes } from 'types/api/alerts/alertTypes';
|
||||
@@ -24,11 +27,12 @@ import {
|
||||
notificationChannelsResponse,
|
||||
CHANNEL_MAX,
|
||||
} from '../../AlertList/stories/__story_mockdata__/alerts';
|
||||
import { aiExplorerQuery } from '../../LLMObservability/Explorer/stories/__story_mockdata__/explorer';
|
||||
|
||||
/**
|
||||
* Which alert the page is building. The page reads this off the URL, so the
|
||||
* control is a route rather than a response: with no type at all it stays on
|
||||
* the picker and everything else opens the form.
|
||||
* control is a route rather than a response: with neither a type nor a query it
|
||||
* stays on the picker and everything else opens the form.
|
||||
*/
|
||||
const ALERT_MODES = [
|
||||
'select-type',
|
||||
@@ -36,6 +40,7 @@ const ALERT_MODES = [
|
||||
'logs',
|
||||
'traces',
|
||||
'ai-traces',
|
||||
'ai-traces-explorer',
|
||||
'exceptions',
|
||||
'anomaly',
|
||||
] as const;
|
||||
@@ -52,6 +57,14 @@ const ALERT_TYPE_BY_MODE: Partial<Record<AlertMode, AlertTypes>> = {
|
||||
};
|
||||
|
||||
const routeFor = (mode: AlertMode): string => {
|
||||
// The AI explorer's Create an alert sends only the query; the page reads the type off it.
|
||||
if (mode === 'ai-traces-explorer') {
|
||||
return getCreateAlertLink({
|
||||
query: getAlertQuery(aiExplorerQuery(), DEFAULT_PANEL_TYPE),
|
||||
panelType: DEFAULT_PANEL_TYPE,
|
||||
});
|
||||
}
|
||||
|
||||
const alertType = ALERT_TYPE_BY_MODE[mode];
|
||||
|
||||
if (!alertType) {
|
||||
|
||||
@@ -59,6 +59,11 @@ export const AITracesAlert: Story = {
|
||||
args: { alertMode: 'ai-traces' },
|
||||
};
|
||||
|
||||
/** Create an alert from the AI explorer: an AI traces alert counting the explorer's query. */
|
||||
export const AITracesAlertFromExplorer: Story = {
|
||||
args: { alertMode: 'ai-traces-explorer' },
|
||||
};
|
||||
|
||||
/**
|
||||
* Anomaly detection: the condition is a number of deviations from the seasonal
|
||||
* forecast instead of a fixed threshold, and only builder metric queries apply.
|
||||
|
||||
@@ -5,7 +5,9 @@
|
||||
|
||||
import { rest } from 'msw';
|
||||
import { Querybuildertypesv5RequestTypeDTO } from 'api/generated/services/sigNoz.schemas';
|
||||
import { AVAILABLE_EXPORT_PANEL_TYPES } from 'constants/panelTypes';
|
||||
import ROUTES from 'constants/routes';
|
||||
import { getExportQuery } from 'container/LLMObservability/Explorer/explorerUtils';
|
||||
import { buildDashboardReadPermission } from 'lib/authz/hooks/useAuthZ/permissions/dashboard.permissions';
|
||||
import { buildRoutePath } from 'lib/router/buildRoutePath';
|
||||
import { expect, screen, userEvent, waitFor, within } from 'storybook/test';
|
||||
@@ -24,10 +26,13 @@ import {
|
||||
} from '@/storybook/msw/__story_mockdata__/metrics';
|
||||
import type { PageStoryArgs } from '@/storybook/runtime/resolveStory';
|
||||
|
||||
import { aiExplorerQuery } from '../../../LLMObservability/Explorer/stories/__story_mockdata__/explorer';
|
||||
import {
|
||||
buildExportPanelLink,
|
||||
NEW_PANEL_ID,
|
||||
newPanelSearch,
|
||||
} from '../../DashboardContainer/PanelEditor/newPanelRoute';
|
||||
import { PANEL_KIND_TO_PANEL_TYPE } from '../../DashboardContainer/Panels/types/panelKind';
|
||||
import {
|
||||
API_RESULTS,
|
||||
settle,
|
||||
@@ -67,15 +72,32 @@ const PANEL_OPTIONS = [...PANEL_IDS, NEW_PANEL_ID] as const;
|
||||
|
||||
type PanelOption = (typeof PANEL_OPTIONS)[number];
|
||||
|
||||
const editorRoute = (panel: PanelOption, kind: NewPanelKind): string => {
|
||||
const editorRoute = (
|
||||
panel: PanelOption,
|
||||
kind: NewPanelKind,
|
||||
aiExplorerExport: boolean,
|
||||
): string => {
|
||||
const path = buildRoutePath(ROUTES.DASHBOARD_PANEL_EDITOR, {
|
||||
dashboardId: STORY_DASHBOARD_ID,
|
||||
panelId: panel,
|
||||
});
|
||||
|
||||
return panel === NEW_PANEL_ID
|
||||
? `${path}${newPanelSearch(newPanelKindOf(kind))}`
|
||||
: path;
|
||||
if (panel !== NEW_PANEL_ID) {
|
||||
return path;
|
||||
}
|
||||
|
||||
const panelKind = newPanelKindOf(kind);
|
||||
const panelType = PANEL_KIND_TO_PANEL_TYPE[panelKind];
|
||||
const exportLink =
|
||||
aiExplorerExport && AVAILABLE_EXPORT_PANEL_TYPES.includes(panelType)
|
||||
? buildExportPanelLink({
|
||||
dashboardId: STORY_DASHBOARD_ID,
|
||||
panelType,
|
||||
query: getExportQuery(aiExplorerQuery(), panelType),
|
||||
})
|
||||
: null;
|
||||
|
||||
return exportLink ?? `${path}${newPanelSearch(panelKind)}`;
|
||||
};
|
||||
|
||||
export const panelEditorMocks = defineStoryMocks({
|
||||
@@ -93,6 +115,12 @@ export const panelEditorMocks = defineStoryMocks({
|
||||
options: NEW_PANEL_KINDS,
|
||||
value: 'time-series',
|
||||
}),
|
||||
aiExplorerExport: toggleControl('Exported from the AI explorer', {
|
||||
group: PANEL,
|
||||
description:
|
||||
"Seeds the create route with the query the AI explorer's Add to dashboard exports, so it opens on the AI Query Builder. Only the kinds it exports take it: time series, table and list.",
|
||||
value: false,
|
||||
}),
|
||||
locked: toggleControl('Dashboard locked', {
|
||||
group: PANEL,
|
||||
description:
|
||||
@@ -212,7 +240,11 @@ export const panelEditorMocks = defineStoryMocks({
|
||||
];
|
||||
},
|
||||
config: (values) => ({
|
||||
route: editorRoute(values.panel, values.newPanelKind),
|
||||
route: editorRoute(
|
||||
values.panel,
|
||||
values.newPanelKind,
|
||||
values.aiExplorerExport,
|
||||
),
|
||||
}),
|
||||
effect: (values) => {
|
||||
seedDashboardDocument({
|
||||
@@ -305,9 +337,9 @@ export const savePanel = async (): Promise<void> => {
|
||||
);
|
||||
|
||||
await waitFor(
|
||||
() => {
|
||||
expect(save).toBeEnabled();
|
||||
expect(save).not.toHaveAttribute('aria-disabled', 'true');
|
||||
async () => {
|
||||
await expect(save).toBeEnabled();
|
||||
await expect(save).not.toHaveAttribute('aria-disabled', 'true');
|
||||
},
|
||||
{ timeout: 10000 },
|
||||
);
|
||||
|
||||
@@ -83,6 +83,11 @@ export const AIQueryBuilder: Story = {
|
||||
play: openAIQueryBuilder,
|
||||
};
|
||||
|
||||
/** A new time series panel from the AI explorer's Add to dashboard, opened on its AI query. */
|
||||
export const AIExplorerExport: Story = {
|
||||
args: { panel: 'new', aiExplorerExport: true },
|
||||
};
|
||||
|
||||
/** A number panel: one value, formatted, with comparison thresholds. */
|
||||
export const NumberPanel: Story = {
|
||||
args: { panel: 'p99-latency' },
|
||||
|
||||
@@ -16,6 +16,7 @@ import {
|
||||
toggleControl,
|
||||
} from '@/storybook/controls/controls';
|
||||
import { defineStoryMocks } from '@/storybook/controls/defineStoryMocks';
|
||||
import type { PageStoryArgs } from '@/storybook/runtime/resolveStory';
|
||||
import { fieldValuesResponse } from '@/storybook/msw/__story_mockdata__/fields';
|
||||
import {
|
||||
queryRangeV5RawResponse,
|
||||
@@ -206,3 +207,5 @@ export const llmExplorerMocks = defineStoryMocks({
|
||||
],
|
||||
config: (values) => ({ route: explorerRoute(values.view) }),
|
||||
});
|
||||
|
||||
export type LLMExplorerArgs = PageStoryArgs<typeof llmExplorerMocks>;
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
import type { Meta, StoryObj } from '@storybook/react-vite';
|
||||
import { ExplorerViews } from 'pages/LogsExplorer/utils';
|
||||
import { expect, screen, userEvent, waitFor, within } from 'storybook/test';
|
||||
|
||||
import { storyMocks } from '@/storybook/controls/defineStoryMocks';
|
||||
import type { PageStoryArgs } from '@/storybook/runtime/resolveStory';
|
||||
|
||||
import LLMObservabilityPage from '../../index';
|
||||
import { llmExplorerMocks } from './Explorer.stories.mocks';
|
||||
|
||||
type LLMExplorerArgs = PageStoryArgs<typeof llmExplorerMocks>;
|
||||
import {
|
||||
dirtyQuickFiltersSettings,
|
||||
openAddToDashboard,
|
||||
openQuickFiltersSettings,
|
||||
selectFirstQuickFilterValue,
|
||||
} from './__story_mockdata__/explorer.play';
|
||||
import {
|
||||
type LLMExplorerArgs,
|
||||
llmExplorerMocks,
|
||||
} from './Explorer.stories.mocks';
|
||||
|
||||
const pageStory = storyMocks(llmExplorerMocks, { layout: 'app' });
|
||||
|
||||
@@ -31,72 +36,6 @@ export default meta;
|
||||
|
||||
type Story = StoryObj<LLMExplorerArgs>;
|
||||
|
||||
/** The page fetches before it renders a filter, which outlasts the 1s default. */
|
||||
const untilLoaded = { timeout: 15_000 };
|
||||
|
||||
/**
|
||||
* The quick-filter panel has no test id of its own, and it only mounts once the
|
||||
* workspace's filters have answered.
|
||||
*/
|
||||
const selectFirstQuickFilterValue = async (
|
||||
canvasElement: HTMLElement,
|
||||
): Promise<void> => {
|
||||
const panel = await waitFor(() => {
|
||||
const found = canvasElement.querySelector<HTMLElement>('.quick-filters');
|
||||
|
||||
if (!found) {
|
||||
throw new Error('Quick filters did not render');
|
||||
}
|
||||
|
||||
return found;
|
||||
}, untilLoaded);
|
||||
|
||||
const [filter] = await within(panel).findAllByTestId(
|
||||
'checkbox-filter-v2',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
|
||||
const [row] = await within(filter).findAllByTestId(
|
||||
/^checkbox-value-row-/,
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
const value = row.dataset.testid?.replace('checkbox-value-row-', '');
|
||||
|
||||
// Every value starts selected, so the checkbox only excludes one; the row
|
||||
// itself is the "Only" action that narrows the query to a single value.
|
||||
await userEvent.click(within(row).getByRole('button'));
|
||||
// The rows remount around the new query and regroup into sections, so they
|
||||
// are looked up again on every attempt rather than held from before the click.
|
||||
await waitFor(() => {
|
||||
const selected = within(filter).getByTestId('section-selected');
|
||||
|
||||
expect(
|
||||
within(selected)
|
||||
.getAllByTestId(/^checkbox-value-row-/)
|
||||
.map((item) => item.dataset.testid),
|
||||
).toEqual([`checkbox-value-row-${value}`]);
|
||||
}, untilLoaded);
|
||||
};
|
||||
|
||||
const openQuickFiltersSettings = async (): Promise<void> => {
|
||||
// The settings control renders disabled while its permission check is in
|
||||
// flight and is swapped for the enabled one once the check answers, so it is
|
||||
// looked up again on every attempt; a click on the disabled one is dropped in
|
||||
// silence.
|
||||
const control = await waitFor(() => {
|
||||
const settings = screen.getByTestId('settings-icon-container');
|
||||
|
||||
expect(settings).not.toHaveAttribute('aria-disabled', 'true');
|
||||
|
||||
return settings;
|
||||
}, untilLoaded);
|
||||
|
||||
await userEvent.click(control);
|
||||
await screen.findByText('Edit quick filters', undefined, untilLoaded);
|
||||
};
|
||||
|
||||
/**
|
||||
* A full window of LLM spans: the org's quick filters down the left, the query
|
||||
* builder and the view switcher above, and the list paging ten spans at a time
|
||||
@@ -146,18 +85,6 @@ export const Failed: Story = {
|
||||
parameters: { allowConsoleErrors: true },
|
||||
};
|
||||
|
||||
const dirtyQuickFiltersSettings = async (): Promise<void> => {
|
||||
await openQuickFiltersSettings();
|
||||
|
||||
// One Remove per added filter; the first row's is the one clicked.
|
||||
const [removeFilter] = await screen.findAllByRole('button', {
|
||||
name: 'Remove',
|
||||
});
|
||||
|
||||
await userEvent.click(removeFilter);
|
||||
await screen.findByRole('button', { name: 'Save changes' });
|
||||
};
|
||||
|
||||
/** The editable quick-filter settings panel. */
|
||||
export const QuickFiltersSettings: Story = {
|
||||
play: openQuickFiltersSettings,
|
||||
@@ -170,7 +97,10 @@ export const QuickFiltersSettingsDirty: Story = {
|
||||
|
||||
/** A quick-filter value selected against the LLM span query. */
|
||||
export const QuickFilterSelected: Story = {
|
||||
play: async ({ canvasElement }): Promise<void> => {
|
||||
await selectFirstQuickFilterValue(canvasElement);
|
||||
},
|
||||
play: selectFirstQuickFilterValue,
|
||||
};
|
||||
|
||||
/** The dashboard picker Add to dashboard opens to export the AI query as a panel. */
|
||||
export const AddToDashboardDialog: Story = {
|
||||
play: openAddToDashboard,
|
||||
};
|
||||
|
||||
123
frontend/src/pages/LLMObservability/Explorer/stories/__story_mockdata__/explorer.play.ts
generated
Normal file
123
frontend/src/pages/LLMObservability/Explorer/stories/__story_mockdata__/explorer.play.ts
generated
Normal file
@@ -0,0 +1,123 @@
|
||||
/**
|
||||
* AI-owned. Generated and maintained by the `signoz-page-story` skill.
|
||||
* Do not hand-edit: regenerate instead.
|
||||
*/
|
||||
|
||||
import { ExplorerViews } from 'pages/LogsExplorer/utils';
|
||||
import { expect, screen, userEvent, waitFor, within } from 'storybook/test';
|
||||
|
||||
import type { LLMExplorerArgs } from '../Explorer.stories.mocks';
|
||||
|
||||
interface PlayContext {
|
||||
canvasElement: HTMLElement;
|
||||
args: LLMExplorerArgs;
|
||||
}
|
||||
|
||||
/** The page fetches before it renders a filter, which outlasts the 1s default. */
|
||||
const untilLoaded = { timeout: 15_000 };
|
||||
|
||||
/** The table drops its header, and the actions in it, when the query fails. */
|
||||
const showsExplorerActions = (args: LLMExplorerArgs): boolean =>
|
||||
!(args.view === ExplorerViews.TABLE && args.dataState === 'error');
|
||||
|
||||
/**
|
||||
* The quick-filter panel has no test id of its own, and it only mounts once the
|
||||
* workspace's filters have answered.
|
||||
*/
|
||||
export const selectFirstQuickFilterValue = async ({
|
||||
canvasElement,
|
||||
}: PlayContext): Promise<void> => {
|
||||
const panel = await waitFor(() => {
|
||||
const found = canvasElement.querySelector<HTMLElement>('.quick-filters');
|
||||
|
||||
if (!found) {
|
||||
throw new Error('Quick filters did not render');
|
||||
}
|
||||
|
||||
return found;
|
||||
}, untilLoaded);
|
||||
|
||||
const [filter] = await within(panel).findAllByTestId(
|
||||
'checkbox-filter-v2',
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
|
||||
const [row] = await within(filter).findAllByTestId(
|
||||
/^checkbox-value-row-/,
|
||||
undefined,
|
||||
untilLoaded,
|
||||
);
|
||||
const value = row.dataset.testid?.replace('checkbox-value-row-', '');
|
||||
|
||||
// Every value starts selected, so the checkbox only excludes one; the row
|
||||
// itself is the "Only" action that narrows the query to a single value.
|
||||
await userEvent.click(within(row).getByRole('button'));
|
||||
// The rows remount around the new query and regroup into sections, so they
|
||||
// are looked up again on every attempt rather than held from before the click.
|
||||
await waitFor(async () => {
|
||||
const selected = within(filter).getByTestId('section-selected');
|
||||
|
||||
await expect(
|
||||
within(selected)
|
||||
.getAllByTestId(/^checkbox-value-row-/)
|
||||
.map((item) => item.dataset.testid),
|
||||
).toEqual([`checkbox-value-row-${value}`]);
|
||||
}, untilLoaded);
|
||||
};
|
||||
|
||||
export const openQuickFiltersSettings = async (): Promise<void> => {
|
||||
// The settings control renders disabled while its permission check is in
|
||||
// flight and is swapped for the enabled one once the check answers, so it is
|
||||
// looked up again on every attempt; a click on the disabled one is dropped in
|
||||
// silence.
|
||||
const control = await waitFor(async () => {
|
||||
const settings = screen.getByTestId('settings-icon-container');
|
||||
|
||||
await expect(settings).not.toHaveAttribute('aria-disabled', 'true');
|
||||
|
||||
return settings;
|
||||
}, untilLoaded);
|
||||
|
||||
await userEvent.click(control);
|
||||
await screen.findByText('Edit quick filters', undefined, untilLoaded);
|
||||
};
|
||||
|
||||
export const dirtyQuickFiltersSettings = async (): Promise<void> => {
|
||||
await openQuickFiltersSettings();
|
||||
|
||||
// One Remove per added filter; the first row's is the one clicked.
|
||||
const [removeFilter] = await screen.findAllByRole('button', {
|
||||
name: 'Remove',
|
||||
});
|
||||
|
||||
await userEvent.click(removeFilter);
|
||||
await screen.findByRole('button', { name: 'Save changes' });
|
||||
};
|
||||
|
||||
export const openAddToDashboard = async ({
|
||||
canvasElement,
|
||||
args,
|
||||
}: PlayContext): Promise<void> => {
|
||||
if (!showsExplorerActions(args)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const canvas = within(canvasElement);
|
||||
// Disabled until the explorer stages a query, and a click before then is dropped.
|
||||
const addToDashboard = await waitFor(async () => {
|
||||
const button = canvas.getByTestId('explorer-add-to-dashboard');
|
||||
|
||||
await expect(button).not.toHaveAttribute('aria-disabled', 'true');
|
||||
|
||||
return button;
|
||||
}, untilLoaded);
|
||||
|
||||
await expect(canvas.getByTestId('explorer-create-alert')).not.toHaveAttribute(
|
||||
'aria-disabled',
|
||||
'true',
|
||||
);
|
||||
|
||||
await userEvent.click(addToDashboard);
|
||||
await screen.findByTestId('export-panel-dialog', undefined, untilLoaded);
|
||||
};
|
||||
31
frontend/src/pages/LLMObservability/Explorer/stories/__story_mockdata__/explorer.ts
generated
Normal file
31
frontend/src/pages/LLMObservability/Explorer/stories/__story_mockdata__/explorer.ts
generated
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* AI-owned. Generated and maintained by the `signoz-page-story` skill.
|
||||
* Do not hand-edit: regenerate instead.
|
||||
*/
|
||||
|
||||
import { initialQueryAIWithType } from 'constants/queryBuilder';
|
||||
import {
|
||||
getActiveBuilder,
|
||||
replaceBuilderBySlotKey,
|
||||
} from 'lib/query/builderSlot';
|
||||
import type { Query } from 'types/api/queryBuilder/queryBuilderData';
|
||||
import { EQueryType } from 'types/common/dashboard';
|
||||
|
||||
const AI_EXPLORER_FILTER = "gen_ai.request.model = 'gpt-4o'";
|
||||
|
||||
/** The AI explorer's staged query, narrowed to one model, as its actions hand it over. */
|
||||
export const aiExplorerQuery = (): Query => {
|
||||
const aiBuilder = getActiveBuilder(initialQueryAIWithType);
|
||||
|
||||
return replaceBuilderBySlotKey(
|
||||
initialQueryAIWithType,
|
||||
EQueryType.AI_QUERY_BUILDER,
|
||||
{
|
||||
...aiBuilder,
|
||||
queryData: aiBuilder.queryData.map((queryData) => ({
|
||||
...queryData,
|
||||
filter: { expression: AI_EXPLORER_FILTER },
|
||||
})),
|
||||
},
|
||||
);
|
||||
};
|
||||
@@ -13,7 +13,10 @@ import { LOCALSTORAGE } from 'constants/localStorage';
|
||||
import { initialQueriesMap, PANEL_TYPES } from 'constants/queryBuilder';
|
||||
import { usePageActions } from 'container/AIAssistant/pageActions/usePageActions';
|
||||
import ExplorerActions from 'container/ExplorerActions/ExplorerActions';
|
||||
import { getExportPanelType } from 'container/ExplorerActions/utils';
|
||||
import {
|
||||
ExplorerActionsSource,
|
||||
getExportPanelType,
|
||||
} from 'container/ExplorerActions/utils';
|
||||
import { useOptionsMenu } from 'container/OptionsMenu';
|
||||
import LeftToolbarActions from 'container/QueryBuilder/components/ToolbarActions/LeftToolbarActions';
|
||||
import RightToolbarActions from 'container/QueryBuilder/components/ToolbarActions/RightToolbarActions';
|
||||
@@ -204,7 +207,7 @@ function TracesExplorer(): JSX.Element {
|
||||
<ExplorerActions
|
||||
query={stagedQuery ? exportDefaultQuery : null}
|
||||
dashboardQuery={stagedQuery ? exportDashboardQuery : null}
|
||||
sourcepage={DataSource.TRACES}
|
||||
sourcePage={ExplorerActionsSource.TRACES_EXPLORER}
|
||||
/>
|
||||
),
|
||||
[stagedQuery, exportDefaultQuery, exportDashboardQuery],
|
||||
|
||||
Reference in New Issue
Block a user