Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Elasticsearch client: no longer default to using meta: true #124488

Merged
merged 87 commits into from
Feb 12, 2022
Merged
Show file tree
Hide file tree
Changes from 82 commits
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
c83c373
Use `Client` interface instead of `KibanaClient`
pgayvallet Feb 2, 2022
5328d1c
get rid of getKibanaEsClient and convertToKibanaClient
pgayvallet Feb 2, 2022
2571f5c
get rid of last KibanaClient usages
pgayvallet Feb 2, 2022
a246a83
update usages and types in @kbn/securitysolution-es-utils
pgayvallet Feb 2, 2022
6ed6cd1
fix some violations
pgayvallet Feb 2, 2022
d2859f0
add sugar method around client mock
pgayvallet Feb 2, 2022
9224aac
update SO repository calls
pgayvallet Feb 3, 2022
b9358c4
adapt more core usages
pgayvallet Feb 3, 2022
9852202
export mock types
pgayvallet Feb 3, 2022
868c74f
batch 1
pgayvallet Feb 3, 2022
31dbf95
batch 2
pgayvallet Feb 3, 2022
c41319b
batch 3
pgayvallet Feb 3, 2022
629ccde
batch 4
pgayvallet Feb 3, 2022
1aeecd2
batch 5
pgayvallet Feb 4, 2022
875954a
batch 6
pgayvallet Feb 4, 2022
772d6bc
batch 7
pgayvallet Feb 4, 2022
6c4b848
batch 8
pgayvallet Feb 4, 2022
c756eae
batch 9
pgayvallet Feb 4, 2022
a3034af
security - batch 1
pgayvallet Feb 4, 2022
a0b099e
security - batch 2
pgayvallet Feb 4, 2022
a7fa5af
security - batch 3
pgayvallet Feb 7, 2022
910b494
last batch of initial violations
pgayvallet Feb 7, 2022
b15851f
fix resolve_time_pattern
pgayvallet Feb 7, 2022
053c39d
update generated doc
pgayvallet Feb 7, 2022
e3d78da
fix /internal/index-pattern-management/preview_scripted_field endpoint
pgayvallet Feb 7, 2022
4ae873d
fix monitoring's getLegacyClusterShim
pgayvallet Feb 7, 2022
289ffbc
fix /api/snapshot_restore/privileges route
pgayvallet Feb 7, 2022
98a4fe2
fix UptimeESClient
pgayvallet Feb 7, 2022
45d5c5f
fix transforms/_nodes endpoint
pgayvallet Feb 7, 2022
b04b02f
lint
pgayvallet Feb 7, 2022
405391e
unit test fix - batch 1
pgayvallet Feb 7, 2022
14e7372
unit test fix - batch 2
pgayvallet Feb 7, 2022
55f5331
unit test fix - batch 3
pgayvallet Feb 7, 2022
68f6a3c
integration test fix - batch 1
pgayvallet Feb 7, 2022
3f463e7
lint
pgayvallet Feb 7, 2022
888e4f1
adapt ML client
pgayvallet Feb 7, 2022
5241f90
unit test fix - batch 4
pgayvallet Feb 7, 2022
3f97913
fix uptime test helper
pgayvallet Feb 7, 2022
8974120
fix /api/transform/transforms/{transformId}/_update route
pgayvallet Feb 7, 2022
6e19eab
fix ES client FTR test
pgayvallet Feb 7, 2022
3488980
fix uptime unit test
pgayvallet Feb 7, 2022
bb6a7b8
fix type errors on last unit tests
pgayvallet Feb 7, 2022
96c68c0
fix RollupSearchStrategy call
pgayvallet Feb 7, 2022
dd2b4b1
fix /internal/security/fields/{query} route
pgayvallet Feb 7, 2022
34f93ae
fix GET /api/index_lifecycle_management/policies route
pgayvallet Feb 7, 2022
52827f1
fix mlClient.getDataFrameAnalytics
pgayvallet Feb 7, 2022
557a098
fix APMEventClient
pgayvallet Feb 7, 2022
70dee69
fix security solution getBootstrapIndexExists
pgayvallet Feb 7, 2022
987e260
fix data_enhanced's getSearchStatus
pgayvallet Feb 7, 2022
0366a72
remove unused @ts-expect-error
pgayvallet Feb 8, 2022
95d0ded
fix unit tests due to latest code changes
pgayvallet Feb 8, 2022
62108e7
fix more calls in security_solution routes
pgayvallet Feb 8, 2022
c8e6017
fix more calls in ml routes
pgayvallet Feb 8, 2022
6bed516
fix POST /api/index_management/component_templates route
pgayvallet Feb 8, 2022
fc1eb4c
fix unit tests due to latest changes
pgayvallet Feb 8, 2022
510f930
fix rule_registry's ResourceInstaller.createOrUpdateIndexTemplate
pgayvallet Feb 8, 2022
780e998
fix more fleet client calls
pgayvallet Feb 8, 2022
48ff9db
fix UA's GET cloud_backup_status route
pgayvallet Feb 8, 2022
1fc5293
fix createLifecycleExecutorApiTest
pgayvallet Feb 8, 2022
c0ec117
fix hasFleetServers
pgayvallet Feb 8, 2022
0036fa2
fix unit tests due to latest changes
pgayvallet Feb 8, 2022
3f96f94
Merge remote-tracking branch 'upstream/main' into kbn-116095-use-clie…
pgayvallet Feb 8, 2022
fdd05f2
changes due to last merge
pgayvallet Feb 8, 2022
2065144
fix ml modelProvider.getModelsPipelines
pgayvallet Feb 8, 2022
5a0e3ca
fix security_solution LifecycleQuery.search
pgayvallet Feb 8, 2022
440122c
fix new CoreUsageDataService usage
pgayvallet Feb 8, 2022
16c3f73
fix security solution's StatsQuery.search
pgayvallet Feb 8, 2022
29a39f9
Merge remote-tracking branch 'upstream/main' into kbn-116095-use-clie…
pgayvallet Feb 8, 2022
0cf10d7
improve ml FTR assertions
pgayvallet Feb 8, 2022
1fd5291
fix security_solution's EventsQuery.search
pgayvallet Feb 8, 2022
991ce8e
Merge remote-tracking branch 'upstream/main' into kbn-116095-use-clie…
pgayvallet Feb 8, 2022
8d3005e
Merge remote-tracking branch 'upstream/main' into kbn-116095-use-clie…
pgayvallet Feb 8, 2022
1e518c1
fix EsClient type as we're keeping transport
pgayvallet Feb 8, 2022
5e7e67b
NITs
pgayvallet Feb 8, 2022
ee224e4
clean RepositoryEsClient type
pgayvallet Feb 8, 2022
cfad300
update generated doc
pgayvallet Feb 8, 2022
d1efec0
review comments
pgayvallet Feb 9, 2022
1ff4d92
adapt mlClient.anomalySearch signature
pgayvallet Feb 9, 2022
33f49aa
remove unnecessary .then((body) => body)
pgayvallet Feb 9, 2022
4ba1e81
nit
pgayvallet Feb 9, 2022
6aee533
add unit tests for the client mocking functions
pgayvallet Feb 9, 2022
cd3023b
Merge remote-tracking branch 'upstream/main' into kbn-116095-use-clie…
pgayvallet Feb 10, 2022
f1323ec
Merge remote-tracking branch 'upstream/main' into kbn-116095-use-clie…
pgayvallet Feb 11, 2022
e78ff71
fix new upgrade assistant /remote_clusters endpoint
pgayvallet Feb 11, 2022
ed48672
Merge remote-tracking branch 'upstream/main' into kbn-116095-use-clie…
pgayvallet Feb 11, 2022
b255557
Merge remote-tracking branch 'upstream/main' into kbn-116095-use-clie…
pgayvallet Feb 11, 2022
b1bd734
Merge remote-tracking branch 'upstream/main' into kbn-116095-use-clie…
pgayvallet Feb 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,5 @@ Client used to query the elasticsearch cluster.
<b>Signature:</b>

```typescript
export declare type ElasticsearchClient = Omit<KibanaClient, 'connectionPool' | 'transport' | 'serializer' | 'extend' | 'child' | 'close' | 'diagnostic'> & {
transport: {
request<TResponse = unknown>(params: TransportRequestParams, options?: TransportRequestOptions): Promise<TransportResult<TResponse>>;
};
};
export declare type ElasticsearchClient = Omit<Client, 'connectionPool' | 'serializer' | 'extend' | 'child' | 'close' | 'diagnostic'>;
```
2 changes: 1 addition & 1 deletion examples/preboot_example/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export class PrebootExamplePlugin implements PrebootPlugin {

try {
return response.ok({
body: (await scopedClient.asCurrentUser.security.authenticate()).body,
body: await scopedClient.asCurrentUser.security.authenticate(),
});
} catch (err) {
return response.customError({ statusCode: 500, body: getDetailedErrorMessage(err) });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
// Copied from src/core/server/elasticsearch/client/types.ts
// as these types aren't part of any package yet. Once they are, remove this completely

import type { KibanaClient } from '@elastic/elasticsearch/lib/api/kibana';
import type { Client } from '@elastic/elasticsearch';

/**
* Client used to query the elasticsearch cluster.
* @deprecated At some point use the one from src/core/server/elasticsearch/client/types.ts when it is made into a package. If it never is, then keep using this one.
* @public
*/
export type ElasticsearchClient = Omit<
KibanaClient,
'connectionPool' | 'transport' | 'serializer' | 'extend' | 'child' | 'close' | 'diagnostic'
Client,
'connectionPool' | 'serializer' | 'extend' | 'child' | 'close' | 'diagnostic'
>;
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const getBootstrapIndexExists = async (
index: string
): Promise<boolean> => {
try {
const { body } = await esClient.indices.getAlias({
const body = await esClient.indices.getAlias({
index: `${index}-*`,
name: index,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,6 @@

import type { ElasticsearchClient } from '../elasticsearch_client';

interface AliasesResponse {
[indexName: string]: {
aliases: {
[aliasName: string]: {
is_write_index: boolean;
};
};
};
}

interface IndexAlias {
alias: string;
index: string;
Expand All @@ -39,7 +29,7 @@ export const getIndexAliases = async ({
esClient: ElasticsearchClient;
alias: string;
}): Promise<IndexAlias[]> => {
const response = await esClient.indices.getAlias<AliasesResponse>(
const response = await esClient.indices.getAlias(
{
name: alias,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const getIndexCount = async ({
esClient: ElasticsearchClient;
index: string;
}): Promise<number> => {
const response = await esClient.count<{ count: number }>(
const response = await esClient.count(
{
index,
},
Expand Down
35 changes: 0 additions & 35 deletions packages/kbn-test/src/es/client_to_kibana_client.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/kbn-test/src/es/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
export { createTestEsCluster } from './test_es_cluster';
export type { CreateTestEsClusterOptions, EsTestCluster, ICluster } from './test_es_cluster';
export { esTestConfig } from './es_test_config';
export { convertToKibanaClient } from './client_to_kibana_client';
export { createEsClientForTesting, createEsClientForFtrConfig } from './es_client_for_testing';
export type { EsClientForTestingOptions } from './es_client_for_testing';
10 changes: 0 additions & 10 deletions packages/kbn-test/src/es/test_es_cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ import del from 'del';
// @ts-expect-error in js
import { Cluster } from '@kbn/es';
import { Client, HttpConnection } from '@elastic/elasticsearch';
import type { KibanaClient } from '@elastic/elasticsearch/lib/api/kibana';
import type { ToolingLog } from '@kbn/dev-utils';
import { CI_PARALLEL_PROCESS_PREFIX } from '../ci_parallel_process_prefix';
import { esTestConfig } from './es_test_config';
import { convertToKibanaClient } from './client_to_kibana_client';

import { KIBANA_ROOT } from '../';

Expand Down Expand Up @@ -53,7 +51,6 @@ export interface ICluster {
stop: () => Promise<void>;
cleanup: () => Promise<void>;
getClient: () => Client;
getKibanaEsClient: () => KibanaClient;
getHostUrls: () => string[];
}

Expand Down Expand Up @@ -289,13 +286,6 @@ export function createTestEsCluster<
});
}

/**
* Returns an ES Client to the configured cluster
*/
getKibanaEsClient(): KibanaClient {
return convertToKibanaClient(this.getClient());
}

getUrl() {
if (this.nodes.length > 1) {
throw new Error(
Expand Down
1 change: 0 additions & 1 deletion packages/kbn-test/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export type {
export {
esTestConfig,
createTestEsCluster,
convertToKibanaClient,
createEsClientForTesting,
createEsClientForFtrConfig,
} from './es';
Expand Down
5 changes: 1 addition & 4 deletions src/core/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import { Action } from 'history';
import Boom from '@hapi/boom';
import { ByteSizeValue } from '@kbn/config-schema';
import type { Client } from '@elastic/elasticsearch';
import { ConfigPath } from '@kbn/config';
import { DetailedPeerCertificate } from 'tls';
import type { DocLinks } from '@kbn/doc-links';
Expand All @@ -24,7 +25,6 @@ import { History as History_2 } from 'history';
import { Href } from 'history';
import { IconType } from '@elastic/eui';
import { IncomingHttpHeaders } from 'http';
import type { KibanaClient } from '@elastic/elasticsearch/lib/api/kibana';
import { Location as Location_2 } from 'history';
import { LocationDescriptorObject } from 'history';
import { Logger } from '@kbn/logging';
Expand All @@ -44,9 +44,6 @@ import * as Rx from 'rxjs';
import { SchemaTypeError } from '@kbn/config-schema';
import type { ThemeVersion } from '@kbn/ui-shared-deps-npm';
import { TransitionPromptHook } from 'history';
import type { TransportRequestOptions } from '@elastic/elasticsearch';
import type { TransportRequestParams } from '@elastic/elasticsearch';
import type { TransportResult } from '@elastic/elasticsearch';
import { Type } from '@kbn/config-schema';
import { TypeOf } from '@kbn/config-schema';
import { UiCounterMetricType } from '@kbn/analytics';
Expand Down
64 changes: 27 additions & 37 deletions src/core/server/core_usage_data/core_usage_data_service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,47 +207,37 @@ describe('CoreUsageDataService', () => {
});
service.setup({ http, metrics, savedObjectsStartPromise, changedDeprecatedConfigPath$ });
const elasticsearch = elasticsearchServiceMock.createStart();
elasticsearch.client.asInternalUser.cat.indices.mockResolvedValueOnce({
body: [
{
name: '.kibana_task_manager_1',
'docs.count': '10',
'docs.deleted': '10',
'store.size': '1000',
'pri.store.size': '2000',
},
],
} as any);
elasticsearch.client.asInternalUser.count.mockResolvedValueOnce({
body: {
count: '15',
elasticsearch.client.asInternalUser.cat.indices.mockResponseOnce([
{
name: '.kibana_task_manager_1',
'docs.count': '10',
'docs.deleted': '10',
'store.size': '1000',
'pri.store.size': '2000',
},
] as any);
elasticsearch.client.asInternalUser.count.mockResponseOnce({
count: '15',
} as any);
elasticsearch.client.asInternalUser.cat.indices.mockResolvedValueOnce({
body: [
{
name: '.kibana_1',
'docs.count': '20',
'docs.deleted': '20',
'store.size': '2000',
'pri.store.size': '4000',
},
],
} as any);
elasticsearch.client.asInternalUser.count.mockResolvedValueOnce({
body: {
count: '10',
elasticsearch.client.asInternalUser.cat.indices.mockResponseOnce([
{
name: '.kibana_1',
'docs.count': '20',
'docs.deleted': '20',
'store.size': '2000',
'pri.store.size': '4000',
},
] as any);
elasticsearch.client.asInternalUser.count.mockResponseOnce({
count: '10',
} as any);
elasticsearch.client.asInternalUser.search.mockResolvedValueOnce({
body: {
hits: { total: { value: 6 } },
aggregations: {
aliases: {
buckets: {
active: { doc_count: 1 },
disabled: { doc_count: 2 },
},
elasticsearch.client.asInternalUser.search.mockResponseOnce({
hits: { total: { value: 6 } },
aggregations: {
aliases: {
buckets: {
active: { doc_count: 1 },
disabled: { doc_count: 2 },
},
},
},
Expand Down
8 changes: 4 additions & 4 deletions src/core/server/core_usage_data/core_usage_data_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,12 @@ export class CoreUsageDataService
// to map back from the index to the alias. So we have to make an API
// call for every alias. The document count is the lucene document count.
const catIndicesResults = await elasticsearch.client.asInternalUser.cat
.indices<any[]>({
.indices({
index,
format: 'JSON',
bytes: 'b',
})
.then(({ body }) => {
.then((body) => {
const stats = body[0];

return {
Expand All @@ -160,7 +160,7 @@ export class CoreUsageDataService
.count({
index,
})
.then(({ body }) => {
.then((body) => {
return {
savedObjectsDocsCount: body.count ? body.count : 0,
};
Expand All @@ -182,7 +182,7 @@ export class CoreUsageDataService
private async getSavedObjectAliasUsageData(elasticsearch: ElasticsearchServiceStart) {
// Note: this agg can be changed to use `savedObjectsRepository.find` in the future after `filters` is supported.
// See src/core/server/saved_objects/service/lib/aggregations/aggs_types/bucket_aggs.ts for supported aggregations.
const { body: resp } = await elasticsearch.client.asInternalUser.search<
const resp = await elasticsearch.client.asInternalUser.search<
unknown,
{ aliases: UsageDataAggs }
>({
Expand Down
6 changes: 3 additions & 3 deletions src/core/server/elasticsearch/client/cluster_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Side Public License, v 1.
*/

import type { KibanaClient } from '@elastic/elasticsearch/lib/api/kibana';
import type { Client } from '@elastic/elasticsearch';
import { Logger } from '../../logging';
import { IAuthHeadersStorage, Headers, isKibanaRequest, isRealRequest } from '../../http';
import { ensureRawRequest, filterHeaders } from '../../http/router';
Expand Down Expand Up @@ -60,12 +60,12 @@ export interface ICustomClusterClient extends IClusterClient {
export class ClusterClient implements ICustomClusterClient {
private readonly config: ElasticsearchClientConfig;
private readonly authHeaders?: IAuthHeadersStorage;
private readonly rootScopedClient: KibanaClient;
private readonly rootScopedClient: Client;
private readonly getUnauthorizedErrorHandler: () => UnauthorizedErrorHandler | undefined;
private readonly getExecutionContext: () => string | undefined;
private isClosed = false;

public readonly asInternalUser: KibanaClient;
public readonly asInternalUser: Client;

constructor({
config,
Expand Down
5 changes: 2 additions & 3 deletions src/core/server/elasticsearch/client/configure_client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
*/

import { Client, HttpConnection } from '@elastic/elasticsearch';
import type { KibanaClient } from '@elastic/elasticsearch/lib/api/kibana';
import { Logger } from '../../logging';
import { parseClientOptions, ElasticsearchClientConfig } from './client_config';
import { instrumentEsQueryAndDeprecationLogger } from './log_query_and_deprecation';
Expand All @@ -28,7 +27,7 @@ export const configureClient = (
scoped?: boolean;
getExecutionContext?: () => string | undefined;
}
): KibanaClient => {
): Client => {
const clientOptions = parseClientOptions(config, scoped);
const KibanaTransport = createTransport({ getExecutionContext });

Expand All @@ -40,5 +39,5 @@ export const configureClient = (

instrumentEsQueryAndDeprecationLogger({ logger, client, type });

return client as KibanaClient;
return client;
};
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ describe('createTransport', () => {
});

describe('`meta` option', () => {
it('adds `meta: true` to the options when not provided', async () => {
it('does not adds `meta: true` to the options when not provided', async () => {
const transportClass = createTransportClass();
const transport = new transportClass(baseConstructorParams);
const requestOptions = { method: 'GET', path: '/' };
Expand All @@ -126,7 +126,7 @@ describe('createTransport', () => {
expect(transportRequestMock).toHaveBeenCalledTimes(1);
expect(transportRequestMock).toHaveBeenCalledWith(
expect.any(Object),
expect.objectContaining({
expect.not.objectContaining({
meta: true,
})
);
Expand Down
5 changes: 0 additions & 5 deletions src/core/server/elasticsearch/client/create_transport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,6 @@ export const createTransport = ({
// rewrites headers['x-opaque-id'] if it presents
opts.opaqueId = opaqueId;
}
// Enforce the client to return TransportResult.
// It's required for bwc with responses in 7.x version.
if (opts.meta === undefined) {
opts.meta = true;
}

// add stored headers to the options
opts.headers = {
Expand Down
Loading