SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.
TypeScript apmapplication-monitoringdistributed-tracinggogood-first-issuejaegerloglogsmetricsmonitoringnextjsobservabilityopen-sourceopentelemetryprometheusreactreactjsself-hostedtracingtypescript
feat: 3729 Add to alert flow from Logs Explorer doesn't work (#10241)
Ishanc9da09256e3c
diff --git a/frontend/src/container/ExplorerOptions/ExplorerOptions.tsx b/frontend/src/container/ExplorerOptions/ExplorerOptions.tsxindex 5c5c67cf22..1b6b5d7a9d 100644--- a/frontend/src/container/ExplorerOptions/ExplorerOptions.tsx+++ b/frontend/src/container/ExplorerOptions/ExplorerOptions.tsx@@ -172,23 +172,51 @@ function ExplorerOptions({const { user } = useAppContext();const handleConditionalQueryModification = useCallback(+ // eslint-disable-next-line sonarjs/cognitive-complexity(defaultQuery: Query | null): string => {const queryToUse = defaultQuery || query;+ if (!queryToUse) {+ throw new Error('No query provided');+ }if (queryToUse?.builder?.queryData?.[0]?.aggregateOperator !==- StringOperators.NOOP+ StringOperators.NOOP &&+ sourcepage !== DataSource.LOGS) {return JSON.stringify(queryToUse);}- // Modify aggregateOperator to count, as noop is not supported in alerts+ // Convert NOOP to COUNT for alerts and strip orderBy for logsconst modifiedQuery = cloneDeep(queryToUse);+ if (modifiedQuery && modifiedQuery.builder?.queryData) {+ modifiedQuery.builder.queryData = modifiedQuery.builder.queryData.map(+ (item) => {+ const updatedItem = { ...item };- modifiedQuery.builder.queryData[0].aggregateOperator = StringOperators.COUNT;+ if (updatedItem.aggregateOperator === StringOperators.NOOP) {+ updatedItem.aggregateOperator = StringOperators.COUNT;+ }- return JSON.stringify(modifiedQuery);+ // Alerts do not support order by on logs explorer queries+ if (sourcepage === DataSource.LOGS && panelType === PANEL_TYPES.LIST) {+ updatedItem.orderBy = [];+ }++ return updatedItem;+ },+ );+ }++ try {+ return JSON.stringify(modifiedQuery);+ } catch (err) {+ throw new Error(+ 'Failed to stringify modified query: ' ++ (err instanceof Error ? err.message : String(err)),+ );+ }},- [query],+ [panelType, query, sourcepage],);const onCreateAlertsHandler = useCallback(@@ -757,9 +785,9 @@ function ExplorerOptions({);}, [disabled,+ query,isOneChartPerQuery,onCreateAlertsHandler,- query,splitedQueries,]);diff --git a/frontend/src/container/ExplorerOptions/__tests__/ExplorerOptionWrapper.test.tsx b/frontend/src/container/ExplorerOptions/__tests__/ExplorerOptionWrapper.test.tsxindex ae25d01d61..6515d779b7 100644--- a/frontend/src/container/ExplorerOptions/__tests__/ExplorerOptionWrapper.test.tsx+++ b/frontend/src/container/ExplorerOptions/__tests__/ExplorerOptionWrapper.test.tsx@@ -1,3 +1,4 @@+import { useHistory } from 'react-router-dom';import { PANEL_TYPES } from 'constants/queryBuilder';import { MOCK_QUERY } from 'container/QueryTable/Drilldown/__tests__/mockTableData';import { useUpdateDashboard } from 'hooks/dashboard/useUpdateDashboard';@@ -15,6 +16,11 @@ import { getExplorerToolBarVisibility } from '../utils';// Mock dependenciesjest.mock('hooks/dashboard/useUpdateDashboard');+jest.mock('react-router-dom', () => ({+ ...jest.requireActual('react-router-dom'),+ useHistory: jest.fn(),+}));+jest.mock('../utils', () => ({getExplorerToolBarVisibility: jest.fn(),generateRGBAFromHex: jest.fn(() => 'rgba(0, 0, 0, 0.08)'),@@ -29,6 +35,7 @@ const mockGetExplorerToolBarVisibility = jest.mocked();const mockUseUpdateDashboard = jest.mocked(useUpdateDashboard);+const mockUseHistory = jest.mocked(useHistory);// Mock dataconst TEST_QUERY_ID = 'test-query-id';@@ -103,7 +110,6 @@ describe('ExplorerOptionWrapper', () => {beforeEach(() => {jest.clearAllMocks();mockGetExplorerToolBarVisibility.mockReturnValue(true);-// Mock useUpdateDashboard to return a mutation objectmockUseUpdateDashboard.mockReturnValue(({mutate: jest.fn(),@@ -117,6 +123,28 @@ describe('ExplorerOptionWrapper', () => {} as unknown) as ReturnType<typeof useUpdateDashboard>);});+ it('should navigate to alert creation page when "Create an Alert" is clicked in logs-explorer', async () => {+ const user = userEvent.setup({ pointerEventsCheck: 0 });+ const mockPush = jest.fn();+ mockUseHistory.mockReturnValue(({+ push: mockPush,+ } as unknown) as ReturnType<typeof useHistory>);++ renderExplorerOptionWrapper({ sourcepage: DataSource.LOGS });++ const createAlertButton = screen.getByRole('button', {+ name: 'Create an Alert',+ });+ await user.click(createAlertButton);++ expect(mockPush).toHaveBeenCalledTimes(1);+ const calledWith = mockPush.mock.calls[0][0] as string;+ const [path, search = ''] = calledWith.split('?');+ expect(path).toBe('/alerts/new');+ const params = new URLSearchParams(search);+ expect(params.has('compositeQuery')).toBe(true);+ });+describe('onExport functionality', () => {it('should call onExport when New Dashboard button is clicked in export modal', async () => {const user = userEvent.setup({ pointerEventsCheck: 0 });