From b8863f159ff630eb3a4f8556b4fe68e35b83bd6e Mon Sep 17 00:00:00 2001 From: Rudolf Meijering Date: Tue, 7 Dec 2021 13:34:39 +0100 Subject: [PATCH] Use event.meta.request.params.headers to include Client constructor headers --- .../client/log_query_and_deprecation.test.ts | 21 ++++++++++++------- .../client/log_query_and_deprecation.ts | 4 ++-- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/src/core/server/elasticsearch/client/log_query_and_deprecation.test.ts b/src/core/server/elasticsearch/client/log_query_and_deprecation.test.ts index 80df5c5d2a4ec..ba2cb9c5a73b1 100644 --- a/src/core/server/elasticsearch/client/log_query_and_deprecation.test.ts +++ b/src/core/server/elasticsearch/client/log_query_and_deprecation.test.ts @@ -9,12 +9,19 @@ import { Buffer } from 'buffer'; import { Readable } from 'stream'; -import { errors, TransportRequestOptions, TransportRequestParams } from '@elastic/elasticsearch'; +import { + Client, + ConnectionRequestParams, + errors, + TransportRequestOptions, + TransportRequestParams, +} from '@elastic/elasticsearch'; import type { DiagnosticResult, RequestBody } from '@elastic/elasticsearch'; import { parseClientOptionsMock, ClientMock } from './configure_client.test.mocks'; import { loggingSystemMock } from '../../logging/logging_system.mock'; import { instrumentEsQueryAndDeprecationLogger } from './log_query_and_deprecation'; +import { KibanaClient } from '@elastic/elasticsearch/lib/api/kibana'; const createApiResponse = ({ body, @@ -28,7 +35,7 @@ const createApiResponse = ({ statusCode?: number; headers?: Record; warnings?: string[]; - params?: TransportRequestParams; + params?: TransportRequestParams | ConnectionRequestParams; requestOptions?: TransportRequestOptions; }): DiagnosticResult => { return { @@ -52,7 +59,7 @@ const createFakeClient = () => { nodes: ['http://localhost'], // Enforcing `nodes` because it's mandatory }); jest.spyOn(client.diagnostic, 'on'); - return client; + return client as Client; }; describe('instrumentQueryAndDeprecationLogger', () => { @@ -480,12 +487,12 @@ describe('instrumentQueryAndDeprecationLogger', () => { const response = createApiResponse({ statusCode: 400, warnings: ['GET /_path is deprecated'], - // Set the request header to indicate to Elasticsearch that this is a request over which users have no control - requestOptions: { headers: { 'x-elastic-product-origin': 'kibana' } }, params: { method: 'GET', path: '/_path', querystring: { hello: 'dolly' }, + // Set the request header to indicate to Elasticsearch that this is a request over which users have no control + headers: { 'x-elastic-product-origin': 'kibana' }, }, body: { error: { @@ -547,12 +554,12 @@ describe('instrumentQueryAndDeprecationLogger', () => { const response = createApiResponse({ statusCode: 200, warnings: ['GET /_path is deprecated'], - // Set the request header to indicate to Elasticsearch that this is a request over which users have no control - requestOptions: { headers: { 'x-elastic-product-origin': 'kibana' } }, params: { method: 'GET', path: '/_path', querystring: { hello: 'dolly' }, + // Set the request header to indicate to Elasticsearch that this is a request over which users have no control + headers: { 'x-elastic-product-origin': 'kibana' }, }, body: { hits: [ diff --git a/src/core/server/elasticsearch/client/log_query_and_deprecation.ts b/src/core/server/elasticsearch/client/log_query_and_deprecation.ts index 33a511e23f311..4d1989fc5a2fc 100644 --- a/src/core/server/elasticsearch/client/log_query_and_deprecation.ts +++ b/src/core/server/elasticsearch/client/log_query_and_deprecation.ts @@ -115,8 +115,8 @@ export const instrumentEsQueryAndDeprecationLogger = ({ // Kibana requests will be hidden from the upgrade assistant UI and are // only logged to help developers maintain their plugins const requestOrigin = - (event.meta.request.options.headers != null && - (event.meta.request.options.headers[ + (event.meta.request.params.headers != null && + (event.meta.request.params.headers[ 'x-elastic-product-origin' ] as unknown as string)) === 'kibana' ? 'kibana'