plugin-elastic-report 0.1.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ai/skills/elastic-report/SKILLS.md +5 -3
- package/dist/client/357.0dd385384cab5dbf.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/851.142c93fc6d666b28.js +10 -0
- package/dist/client-v2/857.a5bf9637d5fd4ef5.js +10 -0
- package/dist/client-v2/877.f4095a3dbcadf98f.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +3 -2
- package/dist/locale/en-US.json +100 -1
- package/dist/locale/vi-VN.json +100 -1
- package/dist/locale/zh-CN.json +100 -1
- package/dist/node_modules/@elastic/elasticsearch/package.json +1 -1
- package/dist/server/acl-guard.js +97 -25
- package/dist/server/collections/es-report-data-views.js +6 -0
- package/dist/server/collections/es-reports.js +6 -0
- package/dist/server/mcp/ElasticReportToolCatalog.js +232 -10
- package/dist/server/plugin.js +153 -19
- package/dist/server/services/ElasticReportService.js +125 -11
- package/dist/server/services/ElasticsearchConnectionService.js +274 -34
- package/dist/server/services/ReportExportService.js +243 -0
- package/dist/server/services/ReportQueryCompiler.js +532 -91
- package/dist/server/workflow/ElasticReportQueryInstruction.js +123 -0
- package/dist/shared/constants.js +17 -2
- package/package.json +3 -2
- package/src/client/index.tsx +16 -1
- package/src/client/workflow-instructions.tsx +44 -0
- package/src/client-v2/__tests__/elastic-report.test.tsx +519 -39
- package/src/client-v2/__tests__/kql-autocomplete.test.ts +178 -0
- package/src/client-v2/api.ts +96 -0
- package/src/client-v2/bus/DashboardFilterBus.ts +212 -0
- package/src/client-v2/components/ElasticBasicCharts.tsx +345 -92
- package/src/client-v2/components/ElasticFilterBar.tsx +372 -0
- package/src/client-v2/components/ElasticKqlInput.tsx +421 -0
- package/src/client-v2/components/ElasticReportBlock.tsx +157 -11
- package/src/client-v2/components/ElasticReportRenderer.tsx +621 -71
- package/src/client-v2/components/ReportSelect.tsx +39 -26
- package/src/client-v2/models/ElasticFilterBarBlockModel.tsx +115 -0
- package/src/client-v2/models/ElasticReportBlockModel.tsx +36 -3
- package/src/client-v2/pages/ElasticReportManager.tsx +432 -26
- package/src/client-v2/plugin.tsx +20 -0
- package/src/client-v2/utils/kqlAutocomplete.ts +861 -0
- package/src/client-v2/workflow/instructions.tsx +149 -0
- package/src/locale/en-US.json +100 -1
- package/src/locale/vi-VN.json +100 -1
- package/src/locale/zh-CN.json +100 -1
- package/src/server/__tests__/query-compiler.test.ts +390 -1
- package/src/server/__tests__/report-mcp-acl.integration.test.ts +271 -3
- package/src/server/acl-guard.ts +119 -28
- package/src/server/collections/es-report-data-views.ts +6 -0
- package/src/server/collections/es-reports.ts +6 -0
- package/src/server/mcp/ElasticReportToolCatalog.ts +255 -9
- package/src/server/plugin.ts +189 -21
- package/src/server/services/ElasticReportService.ts +165 -5
- package/src/server/services/ElasticsearchConnectionService.ts +375 -48
- package/src/server/services/ReportExportService.ts +282 -0
- package/src/server/services/ReportQueryCompiler.ts +629 -94
- package/src/server/workflow/ElasticReportQueryInstruction.ts +124 -0
- package/src/shared/constants.ts +7 -0
- package/src/shared/types.ts +98 -1
- package/dist/client-v2/851.488fdbf5bc5b6a36.js +0 -10
|
@@ -7,8 +7,9 @@
|
|
|
7
7
|
* For more information, please refer to: https://www.nocobase.com/agreement.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { cleanup, render, screen, waitFor } from '@testing-library/react';
|
|
10
|
+
import { act, cleanup, render, screen, waitFor } from '@testing-library/react';
|
|
11
11
|
import userEvent from '@testing-library/user-event';
|
|
12
|
+
import { ConfigProvider } from 'antd';
|
|
12
13
|
import React from 'react';
|
|
13
14
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
14
15
|
import { HIGHLIGHT_POST_TAG, HIGHLIGHT_PRE_TAG } from '../../shared/constants';
|
|
@@ -17,6 +18,7 @@ const mocks = vi.hoisted(() => {
|
|
|
17
18
|
const request = vi.fn();
|
|
18
19
|
const apiClient = { request };
|
|
19
20
|
const registerModelLoaders = vi.fn();
|
|
21
|
+
const registerComponents = vi.fn();
|
|
20
22
|
const addMenuItem = vi.fn();
|
|
21
23
|
const addPageTabItem = vi.fn();
|
|
22
24
|
const setPluginSettingsLink = vi.fn();
|
|
@@ -24,10 +26,12 @@ const mocks = vi.hoisted(() => {
|
|
|
24
26
|
class MockBlockModel {
|
|
25
27
|
props: Record<string, unknown> = {};
|
|
26
28
|
static definedMeta: Record<string, unknown> | undefined;
|
|
29
|
+
static definedMetas: Record<string, unknown>[] = [];
|
|
27
30
|
static registeredFlows: Record<string, unknown>[] = [];
|
|
28
31
|
|
|
29
32
|
static define(meta: Record<string, unknown>) {
|
|
30
33
|
this.definedMeta = meta;
|
|
34
|
+
this.definedMetas.push(meta);
|
|
31
35
|
}
|
|
32
36
|
|
|
33
37
|
static registerFlow(flow: Record<string, unknown>) {
|
|
@@ -41,15 +45,17 @@ const mocks = vi.hoisted(() => {
|
|
|
41
45
|
|
|
42
46
|
class MockPlugin {
|
|
43
47
|
options: Record<string, unknown>;
|
|
44
|
-
|
|
48
|
+
app: Record<string, unknown>;
|
|
49
|
+
flowEngine = { registerModelLoaders, flowSettings: { registerComponents } };
|
|
45
50
|
pluginSettingsManager = {
|
|
46
51
|
addMenuItem,
|
|
47
52
|
addPageTabItem,
|
|
48
53
|
setPluginSettingsLink,
|
|
49
54
|
};
|
|
50
55
|
|
|
51
|
-
constructor(options: Record<string, unknown> = {}) {
|
|
56
|
+
constructor(options: Record<string, unknown> = {}, app: Record<string, unknown> = {}) {
|
|
52
57
|
this.options = options;
|
|
58
|
+
this.app = app;
|
|
53
59
|
}
|
|
54
60
|
|
|
55
61
|
t(key: string) {
|
|
@@ -61,6 +67,7 @@ const mocks = vi.hoisted(() => {
|
|
|
61
67
|
request,
|
|
62
68
|
apiClient,
|
|
63
69
|
registerModelLoaders,
|
|
70
|
+
registerComponents,
|
|
64
71
|
addMenuItem,
|
|
65
72
|
addPageTabItem,
|
|
66
73
|
setPluginSettingsLink,
|
|
@@ -87,12 +94,24 @@ vi.mock('@nocobase/flow-engine', () => ({
|
|
|
87
94
|
}),
|
|
88
95
|
}));
|
|
89
96
|
|
|
97
|
+
vi.mock('@nocobase/plugin-workflow/client-v2', () => ({
|
|
98
|
+
Instruction: class {},
|
|
99
|
+
NodeDefaultView: () => null,
|
|
100
|
+
}));
|
|
101
|
+
|
|
102
|
+
import { clearDashboardScope } from '../bus/DashboardFilterBus';
|
|
90
103
|
import { ElasticBasicChart } from '../components/ElasticBasicCharts';
|
|
104
|
+
import { ElasticFilterBar } from '../components/ElasticFilterBar';
|
|
91
105
|
import { ElasticReportBlock } from '../components/ElasticReportBlock';
|
|
92
106
|
import { HighlightText } from '../components/HighlightText';
|
|
107
|
+
import { ElasticFilterBarBlockModel } from '../models/ElasticFilterBarBlockModel';
|
|
93
108
|
import { ElasticReportBlockModel } from '../models/ElasticReportBlockModel';
|
|
94
109
|
import { PluginElasticReportClient } from '../plugin';
|
|
95
110
|
|
|
111
|
+
function renderWithoutMotion(ui: React.ReactElement) {
|
|
112
|
+
return render(<ConfigProvider theme={{ token: { motion: false }, hashed: false }}>{ui}</ConfigProvider>);
|
|
113
|
+
}
|
|
114
|
+
|
|
96
115
|
describe('plugin-elastic-report client-v2', () => {
|
|
97
116
|
beforeEach(() => {
|
|
98
117
|
mocks.request.mockReset();
|
|
@@ -102,19 +121,35 @@ describe('plugin-elastic-report client-v2', () => {
|
|
|
102
121
|
mocks.setPluginSettingsLink.mockClear();
|
|
103
122
|
});
|
|
104
123
|
|
|
105
|
-
afterEach(() => {
|
|
124
|
+
afterEach(async () => {
|
|
125
|
+
await act(async () => {
|
|
126
|
+
await new Promise((resolve) => setTimeout(resolve, 0));
|
|
127
|
+
});
|
|
106
128
|
cleanup();
|
|
107
129
|
});
|
|
108
130
|
|
|
109
|
-
it('registers
|
|
110
|
-
const
|
|
131
|
+
it('registers Report + FilterBar block loaders, settings page, and workflow instruction on load()', async () => {
|
|
132
|
+
const registerInstructionGroup = vi.fn();
|
|
133
|
+
const registerInstruction = vi.fn();
|
|
134
|
+
const mockApp = {
|
|
135
|
+
pm: {
|
|
136
|
+
get: (name: string) => (name === 'workflow' ? { registerInstructionGroup, registerInstruction } : undefined),
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
const plugin = new PluginElasticReportClient({ name: 'plugin-elastic-report' } as never, mockApp as never);
|
|
111
140
|
await plugin.load();
|
|
112
141
|
|
|
142
|
+
expect(mocks.registerComponents).toHaveBeenCalledWith({
|
|
143
|
+
ElasticReportSelect: expect.any(Function),
|
|
144
|
+
});
|
|
113
145
|
expect(mocks.registerModelLoaders).toHaveBeenCalledWith(
|
|
114
146
|
expect.objectContaining({
|
|
115
147
|
ElasticReportBlockModel: expect.objectContaining({
|
|
116
148
|
extends: 'BlockModel',
|
|
117
149
|
}),
|
|
150
|
+
ElasticFilterBarBlockModel: expect.objectContaining({
|
|
151
|
+
extends: 'BlockModel',
|
|
152
|
+
}),
|
|
118
153
|
}),
|
|
119
154
|
);
|
|
120
155
|
expect(mocks.addMenuItem).toHaveBeenCalledWith(
|
|
@@ -124,15 +159,30 @@ describe('plugin-elastic-report client-v2', () => {
|
|
|
124
159
|
}),
|
|
125
160
|
);
|
|
126
161
|
expect(mocks.addPageTabItem).toHaveBeenCalledTimes(1);
|
|
127
|
-
expect(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
162
|
+
expect(registerInstructionGroup).toHaveBeenCalledWith(
|
|
163
|
+
'elastic-report',
|
|
164
|
+
expect.objectContaining({ key: 'elastic-report' }),
|
|
165
|
+
);
|
|
166
|
+
expect(registerInstruction).toHaveBeenCalledWith('elastic-report-query', expect.any(Function));
|
|
167
|
+
expect(ElasticReportBlockModel).toBeDefined();
|
|
168
|
+
expect(ElasticFilterBarBlockModel).toBeDefined();
|
|
169
|
+
expect(mocks.MockBlockModel.definedMetas).toEqual(
|
|
170
|
+
expect.arrayContaining([
|
|
171
|
+
expect.objectContaining({
|
|
172
|
+
label: 'Elastic Report',
|
|
173
|
+
createModelOptions: { use: 'ElasticReportBlockModel' },
|
|
174
|
+
}),
|
|
175
|
+
expect.objectContaining({
|
|
176
|
+
label: 'Elastic Filter Bar',
|
|
177
|
+
createModelOptions: { use: 'ElasticFilterBarBlockModel' },
|
|
178
|
+
}),
|
|
179
|
+
]),
|
|
180
|
+
);
|
|
131
181
|
});
|
|
132
182
|
|
|
133
183
|
it('renders Elasticsearch highlights safely with <mark> without injecting raw HTML', () => {
|
|
134
184
|
const text = ` Normal <img src=x onerror=alert(1)> ${HIGHLIGHT_PRE_TAG}matched term${HIGHLIGHT_POST_TAG} tail`;
|
|
135
|
-
const { container } =
|
|
185
|
+
const { container } = renderWithoutMotion(<HighlightText text={text} />);
|
|
136
186
|
|
|
137
187
|
const mark = container.querySelector('mark');
|
|
138
188
|
expect(mark?.textContent).toBe('matched term');
|
|
@@ -140,35 +190,59 @@ describe('plugin-elastic-report client-v2', () => {
|
|
|
140
190
|
expect(container.textContent).toContain('<img src=x onerror=alert(1)>');
|
|
141
191
|
});
|
|
142
192
|
|
|
143
|
-
it('renders accessible SVG bar chart
|
|
193
|
+
it('renders accessible SVG bar chart, switches to data table, and indicates >= on truncated KPI counts', async () => {
|
|
144
194
|
const user = userEvent.setup();
|
|
145
|
-
|
|
146
|
-
<
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
{
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
195
|
+
renderWithoutMotion(
|
|
196
|
+
<div>
|
|
197
|
+
<ElasticBasicChart
|
|
198
|
+
title="Requests by Service"
|
|
199
|
+
visualization="bar"
|
|
200
|
+
metricLabel="Requests"
|
|
201
|
+
metricValue={null}
|
|
202
|
+
totalHits={42}
|
|
203
|
+
series={[
|
|
204
|
+
{ key: 'checkout', label: 'checkout', value: 30, count: 30 },
|
|
205
|
+
{ key: 'catalog', label: 'catalog', value: 12, count: 12 },
|
|
206
|
+
]}
|
|
207
|
+
/>
|
|
208
|
+
<ElasticBasicChart
|
|
209
|
+
title="Total Errors KPI"
|
|
210
|
+
visualization="metric"
|
|
211
|
+
metricType="count"
|
|
212
|
+
metricLabel="Error Count"
|
|
213
|
+
metricValue={10000}
|
|
214
|
+
totalHits={10000}
|
|
215
|
+
totalRelation="gte"
|
|
216
|
+
series={[]}
|
|
217
|
+
/>
|
|
218
|
+
</div>,
|
|
157
219
|
);
|
|
158
220
|
|
|
159
221
|
expect(screen.getByRole('img', { name: /Requests by Service/i })).toBeTruthy();
|
|
160
|
-
|
|
161
|
-
expect(screen.getByText(
|
|
222
|
+
expect(screen.getByText('≥')).toBeTruthy();
|
|
223
|
+
expect(screen.getByText(/Hits: 10,000\+/)).toBeTruthy();
|
|
224
|
+
|
|
225
|
+
await act(async () => {
|
|
226
|
+
await user.click(screen.getByRole('button', { name: 'Show data table' }));
|
|
227
|
+
});
|
|
228
|
+
expect(await screen.findByText('checkout')).toBeTruthy();
|
|
162
229
|
expect(screen.getByText('catalog')).toBeTruthy();
|
|
163
230
|
});
|
|
164
231
|
|
|
165
|
-
it('preserves KQL
|
|
232
|
+
it('preserves KQL, custom timeRange bounds on Refresh, lockedFilters, shard warnings, and edited filter pills', async () => {
|
|
166
233
|
const user = userEvent.setup();
|
|
167
234
|
const savedSpec = {
|
|
168
235
|
visualization: 'table' as const,
|
|
169
236
|
query: 'status >= 400',
|
|
237
|
+
lockedFilters: [
|
|
238
|
+
{ id: 'lock-1', field: 'region', operator: 'eq' as const, value: 'ap-southeast-1', enabled: true },
|
|
239
|
+
],
|
|
170
240
|
filters: [{ id: 'f1', field: 'service', operator: 'eq' as const, value: 'checkout-api', enabled: true }],
|
|
171
|
-
timeRange: {
|
|
241
|
+
timeRange: {
|
|
242
|
+
preset: 'custom' as const,
|
|
243
|
+
from: '2026-11-29T00:00:00Z',
|
|
244
|
+
to: '2026-11-30T00:00:00Z',
|
|
245
|
+
},
|
|
172
246
|
columns: ['@timestamp', 'service', 'status'],
|
|
173
247
|
pageSize: 20,
|
|
174
248
|
allowInteractiveControls: true,
|
|
@@ -198,6 +272,7 @@ describe('plugin-elastic-report client-v2', () => {
|
|
|
198
272
|
{ name: '@timestamp', type: 'date', searchable: true, aggregatable: true },
|
|
199
273
|
{ name: 'service', type: 'keyword', searchable: true, aggregatable: true },
|
|
200
274
|
{ name: 'status', type: 'integer', searchable: true, aggregatable: true },
|
|
275
|
+
{ name: 'region', type: 'keyword', searchable: true, aggregatable: true },
|
|
201
276
|
],
|
|
202
277
|
},
|
|
203
278
|
},
|
|
@@ -214,10 +289,10 @@ describe('plugin-elastic-report client-v2', () => {
|
|
|
214
289
|
dataViewId: 1,
|
|
215
290
|
visualization: 'table',
|
|
216
291
|
published: true,
|
|
217
|
-
// Real server always returns the persisted spec (with a fresh object reference), NOT overrides
|
|
218
292
|
spec: {
|
|
219
293
|
...savedSpec,
|
|
220
294
|
filters: savedSpec.filters.map((f) => ({ ...f })),
|
|
295
|
+
lockedFilters: savedSpec.lockedFilters.map((f) => ({ ...f })),
|
|
221
296
|
},
|
|
222
297
|
},
|
|
223
298
|
dataView: {
|
|
@@ -231,6 +306,8 @@ describe('plugin-elastic-report client-v2', () => {
|
|
|
231
306
|
total: 1,
|
|
232
307
|
totalRelation: 'eq',
|
|
233
308
|
tookMs: 4,
|
|
309
|
+
timedOut: true,
|
|
310
|
+
shards: { total: 5, successful: 4, skipped: 0, failed: 1 },
|
|
234
311
|
visualization: 'table',
|
|
235
312
|
columns: ['@timestamp', 'service', 'status'],
|
|
236
313
|
rows: [
|
|
@@ -257,18 +334,49 @@ describe('plugin-elastic-report client-v2', () => {
|
|
|
257
334
|
return { data: { data: [] } };
|
|
258
335
|
});
|
|
259
336
|
|
|
260
|
-
|
|
337
|
+
await act(async () => {
|
|
338
|
+
renderWithoutMotion(<ElasticReportBlock reportId={10} showToolbar={true} />);
|
|
339
|
+
});
|
|
261
340
|
|
|
262
341
|
await waitFor(() => {
|
|
263
342
|
expect(screen.getByText('gateway')).toBeTruthy();
|
|
264
343
|
});
|
|
265
344
|
|
|
266
|
-
|
|
345
|
+
// Locked filter badge and partial shard/timeout warning alert are both rendered
|
|
346
|
+
expect(screen.getByText(/region eq ap-southeast-1/)).toBeTruthy();
|
|
347
|
+
expect(screen.getByText('Partial results warning')).toBeTruthy();
|
|
348
|
+
expect(screen.getByText(/Failed shards: 1 \/ 5/)).toBeTruthy();
|
|
349
|
+
|
|
350
|
+
// Clicking Refresh preserves custom timeRange { preset: 'custom', from, to }
|
|
351
|
+
await act(async () => {
|
|
352
|
+
await user.click(screen.getByRole('button', { name: 'Refresh' }));
|
|
353
|
+
});
|
|
354
|
+
await waitFor(() => {
|
|
355
|
+
expect(mocks.request).toHaveBeenCalledWith(
|
|
356
|
+
expect.objectContaining({
|
|
357
|
+
url: 'esReportService:runReport',
|
|
358
|
+
data: expect.objectContaining({
|
|
359
|
+
reportId: 10,
|
|
360
|
+
overrides: expect.objectContaining({
|
|
361
|
+
timeRange: {
|
|
362
|
+
preset: 'custom',
|
|
363
|
+
from: '2026-11-29T00:00:00Z',
|
|
364
|
+
to: '2026-11-30T00:00:00Z',
|
|
365
|
+
},
|
|
366
|
+
}),
|
|
367
|
+
}),
|
|
368
|
+
}),
|
|
369
|
+
);
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
const searchInput = screen.getByRole('combobox', { name: 'KQL / Search Query' }) as HTMLInputElement;
|
|
267
373
|
expect(searchInput.value).toBe('status >= 400');
|
|
268
374
|
|
|
269
|
-
await
|
|
270
|
-
|
|
271
|
-
|
|
375
|
+
await act(async () => {
|
|
376
|
+
await user.clear(searchInput);
|
|
377
|
+
await user.type(searchInput, 'status >= 500');
|
|
378
|
+
await user.click(screen.getByRole('button', { name: /Search/i }));
|
|
379
|
+
});
|
|
272
380
|
|
|
273
381
|
await waitFor(() => {
|
|
274
382
|
expect(mocks.request).toHaveBeenCalledWith(
|
|
@@ -286,11 +394,15 @@ describe('plugin-elastic-report client-v2', () => {
|
|
|
286
394
|
expect(searchInput.value).toBe('status >= 500');
|
|
287
395
|
|
|
288
396
|
// Click existing filter pill to edit its value in place
|
|
289
|
-
await
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
await
|
|
293
|
-
await
|
|
397
|
+
await act(async () => {
|
|
398
|
+
await user.click(screen.getByRole('button', { name: 'Edit Filter: service' }));
|
|
399
|
+
});
|
|
400
|
+
const valueInput = await screen.findByDisplayValue('checkout-api');
|
|
401
|
+
await act(async () => {
|
|
402
|
+
await user.clear(valueInput);
|
|
403
|
+
await user.type(valueInput, 'auth-service');
|
|
404
|
+
await user.click(screen.getByRole('button', { name: 'Apply' }));
|
|
405
|
+
});
|
|
294
406
|
|
|
295
407
|
await waitFor(() => {
|
|
296
408
|
expect(mocks.request).toHaveBeenCalledWith(
|
|
@@ -308,4 +420,372 @@ describe('plugin-elastic-report client-v2', () => {
|
|
|
308
420
|
});
|
|
309
421
|
expect(screen.getByText(/service eq auth-service/)).toBeTruthy();
|
|
310
422
|
});
|
|
423
|
+
|
|
424
|
+
it('supports stacked multi-series charts, KPI delta badges, DashboardFilterBus cross-filtering, cell + filter, and fieldFormats', async () => {
|
|
425
|
+
const user = userEvent.setup();
|
|
426
|
+
const scopeKey = 'page-root-test:ops';
|
|
427
|
+
clearDashboardScope(scopeKey);
|
|
428
|
+
|
|
429
|
+
mocks.request.mockImplementation(async (cfg: { url: string; data?: Record<string, unknown> }) => {
|
|
430
|
+
if (cfg.url === 'esReportService:getReportMeta') {
|
|
431
|
+
return {
|
|
432
|
+
data: {
|
|
433
|
+
data: {
|
|
434
|
+
report: {
|
|
435
|
+
id: 21,
|
|
436
|
+
title: 'Service Latency Table',
|
|
437
|
+
dataViewId: 1,
|
|
438
|
+
visualization: 'table',
|
|
439
|
+
published: true,
|
|
440
|
+
spec: {
|
|
441
|
+
visualization: 'table',
|
|
442
|
+
columns: ['@timestamp', 'service', 'status', 'latency_ms'],
|
|
443
|
+
fieldFormats: {
|
|
444
|
+
status: 'status_badge',
|
|
445
|
+
latency_ms: 'duration_ms',
|
|
446
|
+
},
|
|
447
|
+
contextBindings: [{ esField: 'customer_id', recordFieldPath: 'account.code' }],
|
|
448
|
+
allowInteractiveControls: true,
|
|
449
|
+
allowExport: true,
|
|
450
|
+
},
|
|
451
|
+
},
|
|
452
|
+
dataView: {
|
|
453
|
+
id: 1,
|
|
454
|
+
title: 'Logs',
|
|
455
|
+
dataSourceKey: 'es_main',
|
|
456
|
+
indexPattern: 'logs-*',
|
|
457
|
+
timeField: '@timestamp',
|
|
458
|
+
},
|
|
459
|
+
fields: [
|
|
460
|
+
{ name: '@timestamp', type: 'date', searchable: true, aggregatable: true },
|
|
461
|
+
{ name: 'service', type: 'keyword', searchable: true, aggregatable: true },
|
|
462
|
+
{ name: 'status', type: 'integer', searchable: true, aggregatable: true },
|
|
463
|
+
{ name: 'latency_ms', type: 'double', searchable: true, aggregatable: true },
|
|
464
|
+
],
|
|
465
|
+
},
|
|
466
|
+
},
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
if (cfg.url === 'esReportService:runReport') {
|
|
471
|
+
return {
|
|
472
|
+
data: {
|
|
473
|
+
data: {
|
|
474
|
+
report: {
|
|
475
|
+
id: 21,
|
|
476
|
+
title: 'Service Latency Table',
|
|
477
|
+
dataViewId: 1,
|
|
478
|
+
visualization: 'table',
|
|
479
|
+
published: true,
|
|
480
|
+
spec: {
|
|
481
|
+
visualization: 'table',
|
|
482
|
+
columns: ['@timestamp', 'service', 'status', 'latency_ms'],
|
|
483
|
+
fieldFormats: {
|
|
484
|
+
status: 'status_badge',
|
|
485
|
+
latency_ms: 'duration_ms',
|
|
486
|
+
},
|
|
487
|
+
contextBindings: [{ esField: 'customer_id', recordFieldPath: 'account.code' }],
|
|
488
|
+
allowInteractiveControls: true,
|
|
489
|
+
allowExport: true,
|
|
490
|
+
},
|
|
491
|
+
},
|
|
492
|
+
dataView: {
|
|
493
|
+
id: 1,
|
|
494
|
+
title: 'Logs',
|
|
495
|
+
dataSourceKey: 'es_main',
|
|
496
|
+
indexPattern: 'logs-*',
|
|
497
|
+
timeField: '@timestamp',
|
|
498
|
+
},
|
|
499
|
+
result: {
|
|
500
|
+
total: 1,
|
|
501
|
+
totalRelation: 'eq',
|
|
502
|
+
tookMs: 3,
|
|
503
|
+
visualization: 'table',
|
|
504
|
+
columns: ['@timestamp', 'service', 'status', 'latency_ms'],
|
|
505
|
+
rows: [
|
|
506
|
+
{
|
|
507
|
+
_id: 'doc-21',
|
|
508
|
+
_index: 'logs-2026',
|
|
509
|
+
source: {
|
|
510
|
+
'@timestamp': '2026-11-30T02:00:00Z',
|
|
511
|
+
service: 'payments',
|
|
512
|
+
status: 502,
|
|
513
|
+
latency_ms: 1500,
|
|
514
|
+
},
|
|
515
|
+
},
|
|
516
|
+
],
|
|
517
|
+
series: [],
|
|
518
|
+
histogram: [],
|
|
519
|
+
metricValue: null,
|
|
520
|
+
metricLabel: 'Count',
|
|
521
|
+
compiledDsl: { query: { match_all: {} } },
|
|
522
|
+
},
|
|
523
|
+
},
|
|
524
|
+
},
|
|
525
|
+
};
|
|
526
|
+
}
|
|
527
|
+
return { data: { data: { buckets: [] } } };
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
await act(async () => {
|
|
531
|
+
renderWithoutMotion(
|
|
532
|
+
<div>
|
|
533
|
+
<ElasticBasicChart
|
|
534
|
+
title="Stacked Latency by Service"
|
|
535
|
+
visualization="bar"
|
|
536
|
+
stackMode="stacked"
|
|
537
|
+
seriesKeys={['checkout', 'payments']}
|
|
538
|
+
metricLabel="P95 Latency"
|
|
539
|
+
metricValue={null}
|
|
540
|
+
totalHits={25}
|
|
541
|
+
series={[
|
|
542
|
+
{
|
|
543
|
+
key: '10:00',
|
|
544
|
+
label: '10:00',
|
|
545
|
+
value: 600,
|
|
546
|
+
count: 25,
|
|
547
|
+
breakdown: [
|
|
548
|
+
{ seriesKey: 'checkout', value: 250, count: 15 },
|
|
549
|
+
{ seriesKey: 'payments', value: 350, count: 10 },
|
|
550
|
+
],
|
|
551
|
+
},
|
|
552
|
+
]}
|
|
553
|
+
/>
|
|
554
|
+
<ElasticBasicChart
|
|
555
|
+
title="P95 Latency KPI"
|
|
556
|
+
visualization="metric"
|
|
557
|
+
metricType="p95"
|
|
558
|
+
metricLabel="P95 Latency"
|
|
559
|
+
metricValue={250}
|
|
560
|
+
previousMetricValue={200}
|
|
561
|
+
deltaPercent={25}
|
|
562
|
+
totalHits={100}
|
|
563
|
+
series={[]}
|
|
564
|
+
/>
|
|
565
|
+
<ElasticFilterBar scopeKey={scopeKey} showGlobalKql={true} showGlobalTimeRange={true} />
|
|
566
|
+
<ElasticReportBlock
|
|
567
|
+
reportId={21}
|
|
568
|
+
scopeKey={scopeKey}
|
|
569
|
+
subscribeDashboardFilters={true}
|
|
570
|
+
contextRecord={{ account: { code: 'ACME-01' } }}
|
|
571
|
+
/>
|
|
572
|
+
</div>,
|
|
573
|
+
);
|
|
574
|
+
});
|
|
575
|
+
|
|
576
|
+
// Formatted duration_ms (1500 -> "1.50 s") and KPI previous-period delta (+25%) are rendered
|
|
577
|
+
await waitFor(() => {
|
|
578
|
+
expect(screen.getByText('1.50 s')).toBeTruthy();
|
|
579
|
+
});
|
|
580
|
+
expect(screen.getByText(/\+25%/)).toBeTruthy();
|
|
581
|
+
|
|
582
|
+
// Context binding filter (customer_id = ACME-01) is sent automatically
|
|
583
|
+
await waitFor(() => {
|
|
584
|
+
expect(mocks.request).toHaveBeenCalledWith(
|
|
585
|
+
expect.objectContaining({
|
|
586
|
+
url: 'esReportService:runReport',
|
|
587
|
+
data: expect.objectContaining({
|
|
588
|
+
reportId: 21,
|
|
589
|
+
overrides: expect.objectContaining({
|
|
590
|
+
contextFilters: [expect.objectContaining({ field: 'customer_id', operator: 'eq', value: 'ACME-01' })],
|
|
591
|
+
}),
|
|
592
|
+
}),
|
|
593
|
+
}),
|
|
594
|
+
);
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
// Global KQL from ElasticFilterBar propagates via DashboardFilterBus to ElasticReportBlock
|
|
598
|
+
const kqlInputs = screen.getAllByRole('combobox', { name: 'KQL / Search Query' });
|
|
599
|
+
await act(async () => {
|
|
600
|
+
await user.type(kqlInputs[0], 'status >= 500');
|
|
601
|
+
await user.click(screen.getByRole('button', { name: 'Apply' }));
|
|
602
|
+
});
|
|
603
|
+
|
|
604
|
+
await waitFor(() => {
|
|
605
|
+
expect(mocks.request).toHaveBeenCalledWith(
|
|
606
|
+
expect.objectContaining({
|
|
607
|
+
url: 'esReportService:runReport',
|
|
608
|
+
data: expect.objectContaining({
|
|
609
|
+
reportId: 21,
|
|
610
|
+
overrides: expect.objectContaining({
|
|
611
|
+
query: 'status >= 500',
|
|
612
|
+
}),
|
|
613
|
+
}),
|
|
614
|
+
}),
|
|
615
|
+
);
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
// Clicking Discover cell "+" button pushes shared cross-filter pill to ElasticFilterBar and re-queries
|
|
619
|
+
await act(async () => {
|
|
620
|
+
await user.click(screen.getByRole('button', { name: 'Filter for value: service=payments' }));
|
|
621
|
+
});
|
|
622
|
+
|
|
623
|
+
await waitFor(() => {
|
|
624
|
+
expect(mocks.request).toHaveBeenCalledWith(
|
|
625
|
+
expect.objectContaining({
|
|
626
|
+
url: 'esReportService:runReport',
|
|
627
|
+
data: expect.objectContaining({
|
|
628
|
+
reportId: 21,
|
|
629
|
+
overrides: expect.objectContaining({
|
|
630
|
+
sharedFilters: [expect.objectContaining({ field: 'service', operator: 'eq', value: 'payments' })],
|
|
631
|
+
}),
|
|
632
|
+
}),
|
|
633
|
+
}),
|
|
634
|
+
);
|
|
635
|
+
});
|
|
636
|
+
expect(screen.getByText(/service eq payments/)).toBeTruthy();
|
|
637
|
+
});
|
|
638
|
+
|
|
639
|
+
it('provides guided KQL autocomplete for fields, operators, live Elasticsearch top values, and Enter-to-submit', async () => {
|
|
640
|
+
const user = userEvent.setup();
|
|
641
|
+
|
|
642
|
+
mocks.request.mockImplementation(async (cfg: { url: string; data?: Record<string, unknown> }) => {
|
|
643
|
+
if (cfg.url === 'esReportService:getReportMeta') {
|
|
644
|
+
return {
|
|
645
|
+
data: {
|
|
646
|
+
data: {
|
|
647
|
+
report: {
|
|
648
|
+
id: 30,
|
|
649
|
+
title: 'Guided Search Report',
|
|
650
|
+
dataViewId: 1,
|
|
651
|
+
visualization: 'table',
|
|
652
|
+
published: true,
|
|
653
|
+
spec: {
|
|
654
|
+
visualization: 'table',
|
|
655
|
+
columns: ['@timestamp', 'service', 'status'],
|
|
656
|
+
allowInteractiveControls: true,
|
|
657
|
+
},
|
|
658
|
+
},
|
|
659
|
+
dataView: {
|
|
660
|
+
id: 1,
|
|
661
|
+
title: 'Logs',
|
|
662
|
+
dataSourceKey: 'es_main',
|
|
663
|
+
indexPattern: 'logs-*',
|
|
664
|
+
timeField: '@timestamp',
|
|
665
|
+
},
|
|
666
|
+
fields: [
|
|
667
|
+
{ name: '@timestamp', type: 'date', searchable: true, aggregatable: true },
|
|
668
|
+
{ name: 'service', type: 'keyword', searchable: true, aggregatable: true },
|
|
669
|
+
{ name: 'status', type: 'integer', searchable: true, aggregatable: true },
|
|
670
|
+
],
|
|
671
|
+
},
|
|
672
|
+
},
|
|
673
|
+
};
|
|
674
|
+
}
|
|
675
|
+
if (cfg.url === 'esReportService:inspectTopValues') {
|
|
676
|
+
return {
|
|
677
|
+
data: {
|
|
678
|
+
data: {
|
|
679
|
+
field: cfg.data?.field,
|
|
680
|
+
resolvedField: cfg.data?.field,
|
|
681
|
+
totalDocs: 50,
|
|
682
|
+
buckets:
|
|
683
|
+
cfg.data?.field === 'service'
|
|
684
|
+
? [
|
|
685
|
+
{ value: 'gateway', count: 32, percentage: 64 },
|
|
686
|
+
{ value: 'billing-api', count: 18, percentage: 36 },
|
|
687
|
+
]
|
|
688
|
+
: [{ value: '500', count: 20, percentage: 40 }],
|
|
689
|
+
},
|
|
690
|
+
},
|
|
691
|
+
};
|
|
692
|
+
}
|
|
693
|
+
if (cfg.url === 'esReportService:runReport') {
|
|
694
|
+
return {
|
|
695
|
+
data: {
|
|
696
|
+
data: {
|
|
697
|
+
report: {
|
|
698
|
+
id: 30,
|
|
699
|
+
title: 'Guided Search Report',
|
|
700
|
+
dataViewId: 1,
|
|
701
|
+
visualization: 'table',
|
|
702
|
+
published: true,
|
|
703
|
+
spec: {
|
|
704
|
+
visualization: 'table',
|
|
705
|
+
columns: ['@timestamp', 'service', 'status'],
|
|
706
|
+
allowInteractiveControls: true,
|
|
707
|
+
},
|
|
708
|
+
},
|
|
709
|
+
dataView: {
|
|
710
|
+
id: 1,
|
|
711
|
+
title: 'Logs',
|
|
712
|
+
dataSourceKey: 'es_main',
|
|
713
|
+
indexPattern: 'logs-*',
|
|
714
|
+
timeField: '@timestamp',
|
|
715
|
+
},
|
|
716
|
+
result: {
|
|
717
|
+
total: 1,
|
|
718
|
+
totalRelation: 'eq',
|
|
719
|
+
tookMs: 2,
|
|
720
|
+
visualization: 'table',
|
|
721
|
+
columns: ['@timestamp', 'service', 'status'],
|
|
722
|
+
rows: [],
|
|
723
|
+
series: [],
|
|
724
|
+
histogram: [],
|
|
725
|
+
metricValue: null,
|
|
726
|
+
metricLabel: 'Count',
|
|
727
|
+
compiledDsl: { query: { match_all: {} } },
|
|
728
|
+
},
|
|
729
|
+
},
|
|
730
|
+
},
|
|
731
|
+
};
|
|
732
|
+
}
|
|
733
|
+
return { data: { data: [] } };
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
await act(async () => {
|
|
737
|
+
renderWithoutMotion(<ElasticReportBlock reportId={30} showToolbar={true} />);
|
|
738
|
+
});
|
|
739
|
+
|
|
740
|
+
const kqlCombo = await screen.findByRole('combobox', { name: 'KQL / Search Query' });
|
|
741
|
+
|
|
742
|
+
// 1. Focus empty search input -> field suggestions appear
|
|
743
|
+
await act(async () => {
|
|
744
|
+
await user.click(kqlCombo);
|
|
745
|
+
});
|
|
746
|
+
const serviceFieldOpt = await screen.findByRole('option', { name: /service/i });
|
|
747
|
+
|
|
748
|
+
// 2. Click `service` -> inserts `service: ` and automatically loads live top values from Elasticsearch
|
|
749
|
+
await act(async () => {
|
|
750
|
+
await user.click(serviceFieldOpt);
|
|
751
|
+
});
|
|
752
|
+
expect((kqlCombo as HTMLInputElement).value).toBe('service: ');
|
|
753
|
+
|
|
754
|
+
const gatewayValOpt = await screen.findByRole('option', { name: /"gateway"/i });
|
|
755
|
+
expect(mocks.request).toHaveBeenCalledWith(
|
|
756
|
+
expect.objectContaining({
|
|
757
|
+
url: 'esReportService:inspectTopValues',
|
|
758
|
+
data: expect.objectContaining({
|
|
759
|
+
reportId: 30,
|
|
760
|
+
field: 'service',
|
|
761
|
+
overrides: expect.objectContaining({
|
|
762
|
+
query: '',
|
|
763
|
+
}),
|
|
764
|
+
}),
|
|
765
|
+
}),
|
|
766
|
+
);
|
|
767
|
+
await act(async () => {
|
|
768
|
+
await user.click(gatewayValOpt);
|
|
769
|
+
});
|
|
770
|
+
expect((kqlCombo as HTMLInputElement).value).toBe('service: "gateway" ');
|
|
771
|
+
|
|
772
|
+
// 3. Press Enter directly without highlighting another option -> executes the search immediately
|
|
773
|
+
await act(async () => {
|
|
774
|
+
await user.keyboard('{Enter}');
|
|
775
|
+
});
|
|
776
|
+
|
|
777
|
+
await waitFor(() => {
|
|
778
|
+
expect(mocks.request).toHaveBeenCalledWith(
|
|
779
|
+
expect.objectContaining({
|
|
780
|
+
url: 'esReportService:runReport',
|
|
781
|
+
data: expect.objectContaining({
|
|
782
|
+
reportId: 30,
|
|
783
|
+
overrides: expect.objectContaining({
|
|
784
|
+
query: 'service: "gateway"',
|
|
785
|
+
}),
|
|
786
|
+
}),
|
|
787
|
+
}),
|
|
788
|
+
);
|
|
789
|
+
});
|
|
790
|
+
});
|
|
311
791
|
});
|