[ES|QL] Only log requests to Inspector on request complete (#191232)

## Summary

Requires https://github.com/elastic/kibana/pull/191520.
Resolves https://github.com/elastic/kibana/issues/188266.

Prior to this PR, when polling on an async ES|QL request, we would log
the response to every polling request. This PR only logs when the
request is complete.

Before:


![image](https://github.com/user-attachments/assets/fe9a763d-ef43-4f46-a096-0e08e1805f47)

After:


![image](https://github.com/user-attachments/assets/5d59f016-8b0e-4a3f-b044-17b5de97739f)


### Checklist

- [x] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios
- [x] [Flaky Test
Runner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1) was
used on any tests changed
([build](https://buildkite.com/elastic/kibana-flaky-test-suite-runner/builds/6823))
This commit is contained in:
Lukas Olson 2024-08-29 17:01:54 +02:00 committed by GitHub
parent ec0230b1cc
commit c71c0df37f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 40 additions and 2 deletions

View file

@ -23,7 +23,12 @@ import { buildEsQuery, type Filter } from '@kbn/es-query';
import type { ESQLSearchParams, ESQLSearchResponse } from '@kbn/es-types';
import { getEsQueryConfig } from '../../es_query';
import { getTime } from '../../query';
import { ESQL_ASYNC_SEARCH_STRATEGY, ESQL_TABLE_TYPE, KibanaContext } from '..';
import {
ESQL_ASYNC_SEARCH_STRATEGY,
ESQL_TABLE_TYPE,
isRunningResponse,
type KibanaContext,
} from '..';
import { UiSettingsCommon } from '../..';
declare global {
@ -251,7 +256,9 @@ export const getEsqlFn = ({ getStartDependencies }: EsqlFnArguments) => {
return throwError(() => error);
}),
tap({
next({ rawResponse, requestParams }) {
next(response) {
if (isRunningResponse(response)) return;
const { rawResponse, requestParams } = response;
logInspectorRequest()
.stats({
hits: {

View file

@ -114,6 +114,7 @@ export class RequestSelector extends Component<RequestSelectorProps> {
}
>
<EuiBadge
data-test-subj="inspectorRequestTotalTime"
color={selectedRequest.status === RequestStatus.OK ? 'success' : 'danger'}
iconType={selectedRequest.status === RequestStatus.OK ? 'check' : 'cross'}
>

View file

@ -325,6 +325,31 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
expect(requestNames).to.contain('Visualization');
});
});
describe('with slow queries', () => {
it('should show only one entry in inspector for table/visualization', async function () {
await PageObjects.discover.selectTextBaseLang();
const testQuery = `from kibana_sample_data_flights | limit 10`;
await monacoEditor.setCodeEditorValue(testQuery);
await browser.execute(() => {
window.ELASTIC_ESQL_DELAY_SECONDS = 5;
});
await testSubjects.click('querySubmitButton');
await PageObjects.header.waitUntilLoadingHasFinished();
await browser.execute(() => {
window.ELASTIC_ESQL_DELAY_SECONDS = undefined;
});
await inspector.open();
const requestNames = (await inspector.getRequestNames()).split(',');
const requestTotalTime = await inspector.getRequestTotalTime();
expect(requestTotalTime).to.be.greaterThan(5000);
expect(requestNames.length).to.be(2);
expect(requestNames).to.contain('Table');
expect(requestNames).to.contain('Visualization');
});
});
});
describe('query history', () => {

View file

@ -328,4 +328,9 @@ export class InspectorService extends FtrService {
return value === comboBoxOptions;
}
public async getRequestTotalTime() {
const [ms] = (await this.testSubjects.getVisibleText('inspectorRequestTotalTime')).split('ms');
return parseFloat(ms);
}
}