Skip to content

Commit

Permalink
Use event.meta.request.params.headers to include Client constructor h…
Browse files Browse the repository at this point in the history
…eaders
  • Loading branch information
rudolf committed Dec 7, 2021
1 parent bf49c56 commit b8863f1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <T>({
body,
Expand All @@ -28,7 +35,7 @@ const createApiResponse = <T>({
statusCode?: number;
headers?: Record<string, string>;
warnings?: string[];
params?: TransportRequestParams;
params?: TransportRequestParams | ConnectionRequestParams;
requestOptions?: TransportRequestOptions;
}): DiagnosticResult<T> => {
return {
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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: {
Expand Down Expand Up @@ -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: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down

0 comments on commit b8863f1

Please sign in to comment.