Skip to content

Commit fa73121

Browse files
kibanamachineSoniaSanzVelasticmachine
authored
[8.19] [Search profiler] Unskip searchprofiler stateful tests (#239364) (#239873)
# Backport This will backport the following commits from `main` to `8.19`: - [[Search profiler] Unskip searchprofiler stateful tests (#239364)](#239364) <!--- Backport version: 9.6.6 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Sonia Sanz Vivas","email":"[email protected]"},"sourceCommit":{"committedDate":"2025-10-21T09:16:02Z","message":"[Search profiler] Unskip searchprofiler stateful tests (#239364)\n\nFixes https://github.com/elastic/kibana/issues/186126\n\n## Summary\nThis tests have been skipped for a long time, so the original builds are\nnot available anymore and it's complicated to know what make them flaky,\nbut most of them seem to be ok now. But the `correctly parses triple\nquotes in JSON` test wasn't correct anymore because it was running for\nAce's conditions and not for Monaco's. And with Monaco we are not\nshowing the syntax errors in the Search profiler as we do with Console,\nso in order to tests that I added now the test verifies the presence of\na toast indicating a `Json parse` error.\n\n**Flaky test runner:**\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/9552\n\nCo-authored-by: Elastic Machine <[email protected]>","sha":"53be4cd42d8d9600ac0d9eeec3e7b477f3f5ffa8","branchLabelMapping":{"^v9.3.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Kibana Management","release_note:skip","Feature:Search Profiler","backport:all-open","v9.3.0"],"title":"[Search profiler] Unskip searchprofiler stateful tests","number":239364,"url":"https://github.com/elastic/kibana/pull/239364","mergeCommit":{"message":"[Search profiler] Unskip searchprofiler stateful tests (#239364)\n\nFixes https://github.com/elastic/kibana/issues/186126\n\n## Summary\nThis tests have been skipped for a long time, so the original builds are\nnot available anymore and it's complicated to know what make them flaky,\nbut most of them seem to be ok now. But the `correctly parses triple\nquotes in JSON` test wasn't correct anymore because it was running for\nAce's conditions and not for Monaco's. And with Monaco we are not\nshowing the syntax errors in the Search profiler as we do with Console,\nso in order to tests that I added now the test verifies the presence of\na toast indicating a `Json parse` error.\n\n**Flaky test runner:**\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/9552\n\nCo-authored-by: Elastic Machine <[email protected]>","sha":"53be4cd42d8d9600ac0d9eeec3e7b477f3f5ffa8"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.3.0","branchLabelMappingKey":"^v9.3.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/239364","number":239364,"mergeCommit":{"message":"[Search profiler] Unskip searchprofiler stateful tests (#239364)\n\nFixes https://github.com/elastic/kibana/issues/186126\n\n## Summary\nThis tests have been skipped for a long time, so the original builds are\nnot available anymore and it's complicated to know what make them flaky,\nbut most of them seem to be ok now. But the `correctly parses triple\nquotes in JSON` test wasn't correct anymore because it was running for\nAce's conditions and not for Monaco's. And with Monaco we are not\nshowing the syntax errors in the Search profiler as we do with Console,\nso in order to tests that I added now the test verifies the presence of\na toast indicating a `Json parse` error.\n\n**Flaky test runner:**\nhttps://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/9552\n\nCo-authored-by: Elastic Machine <[email protected]>","sha":"53be4cd42d8d9600ac0d9eeec3e7b477f3f5ffa8"}}]}] BACKPORT--> Co-authored-by: Sonia Sanz Vivas <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
1 parent d467ff3 commit fa73121

File tree

3 files changed

+81
-65
lines changed

3 files changed

+81
-65
lines changed

x-pack/platform/plugins/shared/searchprofiler/public/application/hooks/use_request_profile.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,12 @@ export const useRequestProfile = () => {
5555
}
5656
const { error, parsed } = checkForParseErrors(query);
5757
if (error) {
58-
notifications.addError(error, {
58+
notifications.addDanger({
59+
'data-test-subj': 'jsonParseErrorToast',
5960
title: i18n.translate('xpack.searchProfiler.errorToastTitle', {
6061
defaultMessage: 'JSON parse error',
6162
}),
63+
text: error.body?.message || error.message,
6264
});
6365
return { data: null };
6466
}

x-pack/platform/test/functional/apps/dev_tools/searchprofiler_editor.ts

Lines changed: 72 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -22,59 +22,31 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
2222
const es = getService('es');
2323
const log = getService('log');
2424

25-
// Failing: See https://github.com/elastic/kibana/issues/186126
26-
describe.skip('Search Profiler Editor', () => {
25+
describe('Search Profiler Editor', () => {
2726
before(async () => {
2827
await security.testUser.setRoles(['global_devtools_read']);
2928
await PageObjects.common.navigateToApp('searchProfiler');
29+
await es.indices.create({ index: testIndex });
30+
await es.index({
31+
index: testIndex,
32+
id: '1',
33+
body: {
34+
test: 'sample value',
35+
},
36+
});
37+
3038
expect(await PageObjects.searchProfiler.editorExists()).to.be(true);
3139
});
3240

3341
after(async () => {
3442
await security.testUser.restoreDefaults();
35-
});
36-
37-
it('correctly parses triple quotes in JSON', async () => {
38-
// The below inputs are written to work _with_ ace's autocomplete unlike console's unit test
39-
// counterparts in src/legacy/core_platform/plugins/shared/console/public/tests/src/editor.test.js
40-
41-
const okInputs = [
42-
`{
43-
"query": {
44-
"match_all": {}`,
45-
`{
46-
"query": {
47-
"match_all": {
48-
"test": """{ "more": "json" }"""`,
49-
];
50-
51-
const notOkInputs = [
52-
`{
53-
"query": {
54-
"match_all": {
55-
"test": """{ "more": "json" }""`,
56-
`{
57-
"query": {
58-
"match_all": {
59-
"test": """{ "more": "json" }""'`,
60-
];
61-
62-
const expectHasParseErrorsToBe = (expectation: boolean) => async (inputs: string[]) => {
63-
for (const input of inputs) {
64-
await PageObjects.searchProfiler.setQuery(input);
65-
66-
await retry.waitFor(
67-
`parser errors to match expectation: HAS ${expectation ? 'ERRORS' : 'NO ERRORS'}`,
68-
async () => {
69-
const actual = await PageObjects.searchProfiler.editorHasParseErrors();
70-
return expectation === actual?.length > 0;
71-
}
72-
);
43+
if (await es.indices.exists({ index: testIndex })) {
44+
try {
45+
await es.indices.delete({ index: testIndex });
46+
} catch (error) {
47+
log.error(`Error deleting index ${testIndex}: ${error}`);
7348
}
74-
};
75-
76-
await expectHasParseErrorsToBe(false)(okInputs);
77-
await expectHasParseErrorsToBe(true)(notOkInputs);
49+
}
7850
});
7951

8052
it('supports pre-configured search query', async () => {
@@ -126,6 +98,62 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
12698
});
12799
});
128100

101+
describe('With a test index', () => {
102+
it('profiles a simple query', async () => {
103+
await PageObjects.searchProfiler.setIndexName(testIndex);
104+
await PageObjects.searchProfiler.setQuery(testQuery);
105+
106+
await PageObjects.searchProfiler.clickProfileButton();
107+
108+
const content = await PageObjects.searchProfiler.getProfileContent();
109+
expect(content).to.contain(testIndex);
110+
});
111+
});
112+
113+
describe('triple quotes in JSON parsing', () => {
114+
const testCases = [
115+
{
116+
shouldHaveErrors: false,
117+
input: `{ "query": { "match_all": {} } }`,
118+
description: 'valid JSON without triple quotes',
119+
},
120+
{
121+
shouldHaveErrors: false,
122+
input: `{ "query": { "match": { "test": """{"more": "json"}""" } } }`,
123+
description: 'valid JSON with triple quotes',
124+
},
125+
{
126+
shouldHaveErrors: true,
127+
input: `{"query": {"match": {"test": """{ "more": "json" }"" } } }`,
128+
description: 'invalid JSON with mismatched triple quotes',
129+
},
130+
{
131+
shouldHaveErrors: true,
132+
input: `{"query": {"match": {"test": """{ "more": "json" }""' } } }`,
133+
description: 'invalid JSON with mixed quote types',
134+
},
135+
];
136+
137+
testCases.forEach(({ shouldHaveErrors, input, description }) => {
138+
it(`${
139+
shouldHaveErrors ? 'should show error toast' : 'should not show error toast'
140+
} for ${description}`, async () => {
141+
await PageObjects.searchProfiler.setStringQuery(input);
142+
await PageObjects.searchProfiler.clickProfileButton();
143+
144+
await retry.waitFor(
145+
`parser errors to match expectation: ${
146+
shouldHaveErrors ? 'HAS ERROR TOAST' : 'NO ERROR TOAST'
147+
}`,
148+
async () => {
149+
const actual = await PageObjects.searchProfiler.editorHasJsonParseErrorNotification();
150+
return shouldHaveErrors === actual;
151+
}
152+
);
153+
});
154+
});
155+
});
156+
129157
describe('No indices', () => {
130158
before(async () => {
131159
// Delete any existing indices that were not properly cleaned up
@@ -157,25 +185,5 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
157185
});
158186
});
159187
});
160-
161-
describe('With a test index', () => {
162-
before(async () => {
163-
await es.indices.create({ index: testIndex });
164-
});
165-
166-
after(async () => {
167-
await es.indices.delete({ index: testIndex });
168-
});
169-
170-
it('profiles a simple query', async () => {
171-
await PageObjects.searchProfiler.setIndexName(testIndex);
172-
await PageObjects.searchProfiler.setQuery(testQuery);
173-
174-
await PageObjects.searchProfiler.clickProfileButton();
175-
176-
const content = await PageObjects.searchProfiler.getProfileContent();
177-
expect(content).to.contain(testIndex);
178-
});
179-
});
180188
});
181189
}

x-pack/platform/test/functional/page_objects/search_profiler_page.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ export function SearchProfilerPageProvider({ getService }: FtrProviderContext) {
2020
async setQuery(query: any) {
2121
await monacoEditor.setCodeEditorValue(JSON.stringify(query), 0);
2222
},
23+
async setStringQuery(query: any) {
24+
await monacoEditor.setCodeEditorValue(query, 0);
25+
},
2326
async getQuery() {
2427
return JSON.parse(await monacoEditor.getCodeEditorValue(0));
2528
},
@@ -49,5 +52,8 @@ export function SearchProfilerPageProvider({ getService }: FtrProviderContext) {
4952
const text = await notification.getVisibleText();
5053
return text.includes('Unable to profile');
5154
},
55+
async editorHasJsonParseErrorNotification() {
56+
return await testSubjects.exists('jsonParseErrorToast');
57+
},
5258
};
5359
}

0 commit comments

Comments
 (0)