Bump elasticsearch-js to 8.6.0-canary.3 (#148521)

## Summary

Bump elasticsearch-js to 8.6.0-canary.3 to unblock
https://github.com/elastic/kibana/issues/145653

The updated version of elasticsearch-js comes with some type changes
that causes typescript type checking to fail. I've fixed the type errors
that were obvious/easy but left todo's for some types which were harder
for me to figure out. If any of these todo's are in your team's code,
please contribute directly to the branch to fix them.


### Checklist

Delete any items that are not applicable to this PR.

- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ]
[Documentation](https://www.elastic.co/guide/en/kibana/master/development-documentation.html)
was added for features that require explanation or tutorials
- [ ] [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
- [ ] Any UI touched in this PR is usable by keyboard only (learn more
about [keyboard accessibility](https://webaim.org/techniques/keyboard/))
- [ ] Any UI touched in this PR does not create any new axe failures
(run axe in browser:
[FF](https://addons.mozilla.org/en-US/firefox/addon/axe-devtools/),
[Chrome](https://chrome.google.com/webstore/detail/axe-web-accessibility-tes/lhdoppojpmngadmnindnejefpokejbdd?hl=en-US))
- [ ] If a plugin configuration key changed, check if it needs to be
allowlisted in the cloud and added to the [docker
list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker)
- [ ] This renders correctly on smaller devices using a responsive
layout. (You can test this [in your
browser](https://www.browserstack.com/guide/responsive-testing-on-local-server))
- [ ] This was checked for [cross-browser
compatibility](https://www.elastic.co/support/matrix#matrix_browsers)


### Risk Matrix

Delete this section if it is not applicable to this PR.

Before closing this PR, invite QA, stakeholders, and other developers to
identify risks that should be tested prior to the change/feature
release.

When forming the risk matrix, consider some of the following examples
and how they may potentially impact the change:

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Multiple Spaces—unexpected behavior in non-default Kibana Space.
| Low | High | Integration tests will verify that all features are still
supported in non-default Kibana Space and when user switches between
spaces. |
| Multiple nodes—Elasticsearch polling might have race conditions
when multiple Kibana nodes are polling for the same tasks. | High | Low
| Tasks are idempotent, so executing them multiple times will not result
in logical error, but will degrade performance. To test for this case we
add plenty of unit tests around this logic and document manual testing
procedure. |
| Code should gracefully handle cases when feature X or plugin Y are
disabled. | Medium | High | Unit tests will verify that any feature flag
or plugin combination still results in our service operational. |
| [See more potential risk
examples](https://github.com/elastic/kibana/blob/main/RISK_MATRIX.mdx) |


### For maintainers

- [ ] This was checked for breaking API changes and was [labeled
appropriately](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)

Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
Co-authored-by: Thom Heymann <thom.heymann@elastic.co>
Co-authored-by: weltenwort <stuermer@weltenwort.de>
This commit is contained in:
Rudolf Meijering 2023-01-24 13:49:30 +01:00 committed by GitHub
parent f7a1ce95a9
commit cfee703139
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 109 additions and 57 deletions

View file

@ -105,7 +105,7 @@
"@elastic/apm-rum-react": "^1.4.2",
"@elastic/charts": "51.3.0",
"@elastic/datemath": "5.0.3",
"@elastic/elasticsearch": "npm:@elastic/elasticsearch-canary@8.5.0-canary.1",
"@elastic/elasticsearch": "npm:@elastic/elasticsearch-canary@8.6.0-canary.3",
"@elastic/ems-client": "8.3.3",
"@elastic/eui": "73.0.0",
"@elastic/filesaver": "1.1.2",

View file

@ -75,7 +75,7 @@ export class PointInTimeFinder<T = unknown, A = unknown>
await this.open();
let lastResultsCount: number;
let lastHitSortValue: estypes.Id[] | undefined;
let lastHitSortValue: estypes.SortResults | undefined;
do {
const results = await this.findNext({
findOptions: this.#findOptions,
@ -142,7 +142,7 @@ export class PointInTimeFinder<T = unknown, A = unknown>
}: {
findOptions: SavedObjectsFindOptions;
id?: string;
searchAfter?: estypes.Id[];
searchAfter?: estypes.SortResults;
}) {
try {
return await this.#client.find<T, A>(
@ -167,7 +167,7 @@ export class PointInTimeFinder<T = unknown, A = unknown>
}
}
private getLastHitSortValue(res: SavedObjectsFindResponse): estypes.Id[] | undefined {
private getLastHitSortValue(res: SavedObjectsFindResponse): estypes.SortResults | undefined {
if (res.saved_objects.length < 1) {
return undefined;
}

View file

@ -25,7 +25,7 @@ interface GetSearchDslOptions {
defaultSearchOperator?: SearchOperator;
searchFields?: string[];
rootSearchFields?: string[];
searchAfter?: estypes.Id[];
searchAfter?: estypes.SortResults;
sortField?: string;
sortOrder?: estypes.SortOrder;
namespaces?: string[];

View file

@ -9,7 +9,7 @@
import type {
SortOrder,
AggregationsAggregationContainer,
Id as EsId,
SortResults,
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import type { SavedObject } from '@kbn/core-saved-objects-common';
@ -68,7 +68,7 @@ export interface SavedObjectsFindOptions {
/**
* Use the sort values from the previous page to retrieve the next page of results.
*/
searchAfter?: EsId[];
searchAfter?: SortResults;
/**
* The fields to perform the parsed query against. Unlike the `searchFields` argument, these are expected to be root fields and will not
* be modified. If used in conjunction with `searchFields`, both are concatenated together.
@ -176,7 +176,7 @@ export interface SavedObjectsFindResult<T = unknown> extends SavedObject<T> {
* await savedObjectsClient.closePointInTime(page2.pit_id);
* ```
*/
sort?: string[];
sort?: SortResults;
}
/**

View file

@ -6,6 +6,7 @@
*/
import * as rt from 'io-ts';
import { mappingRuntimeFieldRT } from '../../shared/es_request';
export const LOG_ANALYSIS_VALIDATE_INDICES_PATH =
'/api/infra/log_analysis/validation/log_entry_rate_indices';
@ -26,7 +27,7 @@ export const validationIndicesRequestPayloadRT = rt.type({
data: rt.type({
fields: rt.array(validationIndicesFieldSpecificationRT),
indices: rt.array(rt.string),
runtimeMappings: rt.UnknownRecord,
runtimeMappings: rt.record(rt.string, mappingRuntimeFieldRT),
}),
});

View file

@ -0,0 +1,52 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import * as rt from 'io-ts';
const scriptBaseRT = rt.partial({
params: rt.record(rt.string, rt.any),
});
const inlineScriptRT = rt.intersection([
scriptBaseRT,
rt.partial({
lang: rt.string,
options: rt.record(rt.string, rt.string),
}),
rt.type({
source: rt.string,
}),
]);
const storedScriptIdRT = rt.intersection([
scriptBaseRT,
rt.type({
id: rt.string,
}),
]);
const scriptRT = rt.union([inlineScriptRT, rt.string, storedScriptIdRT]);
export const mappingRuntimeFieldTypeRT = rt.keyof({
boolean: null,
date: null,
double: null,
geo_point: null,
ip: null,
keyword: null,
long: null,
});
export const mappingRuntimeFieldRT = rt.intersection([
rt.partial({
format: rt.string,
script: scriptRT,
}),
rt.type({
type: mappingRuntimeFieldTypeRT,
}),
]);

View file

@ -6,6 +6,7 @@
*/
export * from './errors';
export * from './es_request';
export * from './metric_statistics';
export * from './time_range';
export * from './timing';

View file

@ -50,7 +50,7 @@ export interface CallWithRequestParams extends estypes.RequestBase {
allow_no_indices?: boolean;
size?: number;
terminate_after?: number;
fields?: string | string[];
fields?: estypes.Fields;
path?: string;
query?: string | object;
track_total_hits?: boolean | number;
@ -92,11 +92,6 @@ export interface InfraDatabaseMultiResponse<Hit, Aggregation> extends InfraDatab
responses: Array<InfraDatabaseSearchResponse<Hit, Aggregation>>;
}
export interface InfraDatabaseFieldCapsResponse extends InfraDatabaseResponse {
indices: string[];
fields: InfraFieldsResponse;
}
export interface InfraDatabaseGetIndicesAliasResponse {
[indexName: string]: {
aliases: {

View file

@ -16,7 +16,6 @@ import { InfraConfig } from '../../../plugin';
import type { InfraPluginRequestHandlerContext } from '../../../types';
import {
CallWithRequestParams,
InfraDatabaseFieldCapsResponse,
InfraDatabaseGetIndicesAliasResponse,
InfraDatabaseGetIndicesResponse,
InfraDatabaseMultiResponse,
@ -88,11 +87,6 @@ export class KibanaFramework {
endpoint: 'msearch',
options?: CallWithRequestParams
): Promise<InfraDatabaseMultiResponse<Hit, Aggregation>>;
callWithRequest(
requestContext: InfraPluginRequestHandlerContext,
endpoint: 'fieldCaps',
options?: CallWithRequestParams
): Promise<InfraDatabaseFieldCapsResponse>;
callWithRequest(
requestContext: InfraPluginRequestHandlerContext,
endpoint: 'indices.existsAlias',
@ -118,7 +112,6 @@ export class KibanaFramework {
endpoint: string,
options?: CallWithRequestParams
): Promise<InfraDatabaseSearchResponse>;
public async callWithRequest(
requestContext: InfraPluginRequestHandlerContext,
endpoint: string,
@ -162,11 +155,6 @@ export class KibanaFramework {
...frozenIndicesParams,
} as estypes.MsearchRequest);
break;
case 'fieldCaps':
apiResult = elasticsearch.client.asCurrentUser.fieldCaps({
...params,
});
break;
case 'indices.existsAlias':
apiResult = elasticsearch.client.asCurrentUser.indices.existsAlias({
...params,

View file

@ -42,7 +42,9 @@ export const initValidateLogAnalysisIndicesRoute = ({ framework }: InfraBackendL
// Query each pattern individually, to map correctly the errors
await Promise.all(
indices.map(async (index) => {
const fieldCaps = await framework.callWithRequest(requestContext, 'fieldCaps', {
const fieldCaps = await (
await requestContext.core
).elasticsearch.client.asCurrentUser.fieldCaps({
allow_no_indices: true,
fields: fields.map((field) => field.name),
ignore_unavailable: true,

View file

@ -5,6 +5,7 @@
* 2.0.
*/
import { LicenseLicense } from '@elastic/elasticsearch/lib/api/types';
import { IScopedClusterClient } from '@kbn/core/server';
import { LicensingPluginStart } from '@kbn/licensing-plugin/server';
@ -12,13 +13,13 @@ interface PutLicenseArg {
acknowledge: boolean;
client: IScopedClusterClient;
licensing: LicensingPluginStart;
license: { [key: string]: any };
licenses: LicenseLicense[];
}
export async function putLicense({ acknowledge, client, licensing, license }: PutLicenseArg) {
export async function putLicense({ acknowledge, client, licensing, licenses }: PutLicenseArg) {
try {
const response = await client.asCurrentUser.license.post({
body: license,
licenses,
acknowledge,
});
const { acknowledged, license_status: licenseStatus } = response;

View file

@ -33,7 +33,7 @@ export function registerLicenseRoute({
acknowledge: Boolean(req.query.acknowledge),
client,
licensing,
license: req.body,
licenses: [req.body.license as any],
}),
});
} catch (error) {

View file

@ -65,7 +65,7 @@ export interface WriteNextResponseOptions {
esClient: ElasticsearchClient;
listItemIndex: string;
stream: PassThrough;
searchAfter: string[] | undefined;
searchAfter: estypes.SortResults | undefined;
stringToAppend: string | null | undefined;
}
@ -76,7 +76,7 @@ export const writeNextResponse = async ({
listItemIndex,
searchAfter,
stringToAppend,
}: WriteNextResponseOptions): Promise<string[] | undefined> => {
}: WriteNextResponseOptions): Promise<estypes.SortResults | undefined> => {
const response = await getResponse({
esClient,
listId,
@ -96,7 +96,7 @@ export const getSearchAfterFromResponse = <T>({
response,
}: {
response: estypes.SearchResponse<T>;
}): string[] | undefined =>
}): estypes.SortResults | undefined =>
response.hits.hits.length > 0
? response.hits.hits[response.hits.hits.length - 1].sort
: undefined;
@ -104,7 +104,7 @@ export const getSearchAfterFromResponse = <T>({
export interface GetResponseOptions {
esClient: ElasticsearchClient;
listId: string;
searchAfter: undefined | string[];
searchAfter: estypes.SortResults | undefined;
listItemIndex: string;
size?: number;
}

View file

@ -6,6 +6,7 @@
*/
import { get } from 'lodash';
import { ElasticsearchClient } from '@kbn/core/server';
import { estypes } from '@elastic/elasticsearch';
// elasticsearch index.max_result_window default value
const ES_MAX_RESULT_WINDOW_DEFAULT_VALUE = 1000;
@ -63,7 +64,7 @@ const getSavedObjectsList = async ({
filter,
}: {
esClient: ElasticsearchClient;
searchAfter: string[] | undefined;
searchAfter: estypes.SortResults | undefined;
kibanaIndex: string;
filterPath: string[];
filter: ESFilterProps;

View file

@ -168,9 +168,8 @@ export default function ({ getService }: FtrProviderContext) {
expect(apiResponse.body.statusCode).to.be(401);
expect(apiResponse.body.error).to.be('Unauthorized');
expect(apiResponse.body.message).to.include.string(
'[security_exception] Reason: unable to authenticate user [dummy_hacker] for REST request [/_security/_authenticate]'
'unable to authenticate user [dummy_hacker] for REST request [/_security/_authenticate]'
);
expect(apiResponse.headers['set-cookie']).to.be(undefined);
});
});

View file

@ -1503,12 +1503,12 @@
dependencies:
"@elastic/ecs-helpers" "^1.1.0"
"@elastic/elasticsearch@npm:@elastic/elasticsearch-canary@8.5.0-canary.1":
version "8.5.0-canary.1"
resolved "https://registry.yarnpkg.com/@elastic/elasticsearch-canary/-/elasticsearch-canary-8.5.0-canary.1.tgz#3e2f40bc2e58d4f1c1cc391b2d594db59c5e0cd8"
integrity sha512-WmiK5A04tUwpAdbPeLo9ONV/T6foYYa1EjGQFxTPmEPLyY9s0B14o1JAJ7OnzQe9qmDahSJksSA1xLr0LdutmA==
"@elastic/elasticsearch@npm:@elastic/elasticsearch-canary@8.6.0-canary.3":
version "8.6.0-canary.3"
resolved "https://registry.yarnpkg.com/@elastic/elasticsearch-canary/-/elasticsearch-canary-8.6.0-canary.3.tgz#dc518f5ae4bb502b08ff70e4d86fa7b859b3cbe3"
integrity sha512-NvTZrRT/d5mJZ46pDlbgdKVIhA7ac504IGVaf7OV/7wHDmXjm8d/cG2UeQd8v37zMplGq2/853uFWGlXXjD0lQ==
dependencies:
"@elastic/transport" "^8.2.0"
"@elastic/transport" "^8.3.1"
tslib "^2.4.0"
"@elastic/ems-client@8.3.3":
@ -1680,17 +1680,17 @@
undici "^5.11.0"
yaml "^2.1.3"
"@elastic/transport@^8.2.0":
version "8.2.0"
resolved "https://registry.yarnpkg.com/@elastic/transport/-/transport-8.2.0.tgz#f292cb79c918a36268dd853431e41f13544814ad"
integrity sha512-H/HmefMNQfLiBSVTmNExu2lYs5EzwipUnQB53WLr17RCTDaQX0oOLHcWpDsbKQSRhDAMPPzp5YZsZMJxuxPh7A==
"@elastic/transport@^8.3.1":
version "8.3.1"
resolved "https://registry.yarnpkg.com/@elastic/transport/-/transport-8.3.1.tgz#e7569d7df35b03108ea7aa886113800245faa17f"
integrity sha512-jv/Yp2VLvv5tSMEOF8iGrtL2YsYHbpf4s+nDsItxUTLFTzuJGpnsB/xBlfsoT2kAYEnWHiSJuqrbRcpXEI/SEQ==
dependencies:
debug "^4.3.4"
hpagent "^1.0.0"
ms "^2.1.3"
secure-json-parse "^2.4.0"
tslib "^2.4.0"
undici "^5.1.1"
undici "^5.5.1"
"@emotion/babel-plugin-jsx-pragmatic@^0.2.0":
version "0.2.0"
@ -15982,9 +15982,9 @@ hpack.js@^2.1.6:
wbuf "^1.1.0"
hpagent@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/hpagent/-/hpagent-1.0.0.tgz#c68f68b3df845687dbdc4896546713ce09cc6bee"
integrity sha512-SCleE2Uc1bM752ymxg8QXYGW0TWtAV4ZW3TqH1aOnyi6T6YW2xadCcclm5qeVjvMvfQ2RKNtZxO7uVb9CTPt1A==
version "1.2.0"
resolved "https://registry.yarnpkg.com/hpagent/-/hpagent-1.2.0.tgz#0ae417895430eb3770c03443456b8d90ca464903"
integrity sha512-A91dYTeIB6NoXG+PxTQpCCDDnfHsW9kc06Lvpu1TEe9gnd6ZFeiBoRO9JvzEv6xK7EX97/dUE8g/vBMTqTS3CA==
html-element-map@^1.2.0:
version "1.2.0"
@ -24535,9 +24535,9 @@ scss-tokenizer@^0.4.3:
source-map "^0.7.3"
secure-json-parse@^2.4.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/secure-json-parse/-/secure-json-parse-2.4.0.tgz#5aaeaaef85c7a417f76271a4f5b0cc3315ddca85"
integrity sha512-Q5Z/97nbON5t/L/sH6mY2EacfjVGwrCcSi5D3btRO2GZ8pf1K1UN7Z9H5J57hjVU2Qzxr1xO+FmBhOvEkzCMmg==
version "2.6.0"
resolved "https://registry.yarnpkg.com/secure-json-parse/-/secure-json-parse-2.6.0.tgz#95d89f84adf32d76ff7800e68a673b129fe918b0"
integrity sha512-B9osKohb6L+EZ6Kve3wHKfsAClzOC/iISA2vSuCe5Jx5NAKiwitfxx8ZKYapHXr0sYRj7UZInT7pLb3rp2Yx6A==
seedrandom@^3.0.5:
version "3.0.5"
@ -26627,11 +26627,16 @@ tslib@^1.10.0, tslib@^1.8.1, tslib@^1.9.0, tslib@^1.9.3:
resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.13.0.tgz#c881e13cc7015894ed914862d276436fa9a47043"
integrity sha512-i/6DQjL8Xf3be4K/E6Wgpekn5Qasl1usyw++dAA35Ue5orEn65VIxOA+YvNNl9HV3qv70T7CNwjODHZrLwvd1Q==
tslib@^2.0.0, tslib@^2.0.1, tslib@^2.0.3, tslib@^2.1.0, tslib@^2.2.0, tslib@^2.3.1, tslib@^2.4.0, tslib@~2.4.0:
tslib@^2.0.0, tslib@^2.0.1, tslib@^2.0.3, tslib@^2.1.0, tslib@^2.2.0, tslib@^2.3.1, tslib@~2.4.0:
version "2.4.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.0.tgz#7cecaa7f073ce680a05847aa77be941098f36dc3"
integrity sha512-d6xOpEDfsi2CZVlPQzGeux8XMwLT9hssAsaPYExaQMuYskwb+x1x7J371tWlbBdWHroy99KnVB6qIkUbs5X3UQ==
tslib@^2.4.0:
version "2.4.1"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.4.1.tgz#0d0bfbaac2880b91e22df0768e55be9753a5b17e"
integrity sha512-tGyy4dAjRIEwI7BzsB0lynWgOpfqjUdq91XXAlIWD2OwKBH7oCl/GZG/HT4BOHrTlPMOASlMQ7veyTqpmRcrNA==
tslib@~2.1.0:
version "2.1.0"
resolved "https://registry.yarnpkg.com/tslib/-/tslib-2.1.0.tgz#da60860f1c2ecaa5703ab7d39bc05b6bf988b97a"
@ -26802,13 +26807,20 @@ unc-path-regex@^0.1.2:
resolved "https://registry.yarnpkg.com/unc-path-regex/-/unc-path-regex-0.1.2.tgz#e73dd3d7b0d7c5ed86fbac6b0ae7d8c6a69d50fa"
integrity sha1-5z3T17DXxe2G+6xrCufYxqadUPo=
undici@^5.1.1, undici@^5.11.0:
undici@^5.11.0:
version "5.11.0"
resolved "https://registry.yarnpkg.com/undici/-/undici-5.11.0.tgz#1db25f285821828fc09d3804b9e2e934ae86fc13"
integrity sha512-oWjWJHzFet0Ow4YZBkyiJwiK5vWqEYoH7BINzJAJOLedZ++JpAlCbUktW2GQ2DS2FpKmxD/JMtWUUWl1BtghGw==
dependencies:
busboy "^1.6.0"
undici@^5.5.1:
version "5.14.0"
resolved "https://registry.yarnpkg.com/undici/-/undici-5.14.0.tgz#1169d0cdee06a4ffdd30810f6228d57998884d00"
integrity sha512-yJlHYw6yXPPsuOH0x2Ib1Km61vu4hLiRRQoafs+WUgX1vO64vgnxiCEN9dpIrhZyHFsai3F0AEj4P9zy19enEQ==
dependencies:
busboy "^1.6.0"
unfetch@^4.2.0:
version "4.2.0"
resolved "https://registry.yarnpkg.com/unfetch/-/unfetch-4.2.0.tgz#7e21b0ef7d363d8d9af0fb929a5555f6ef97a3be"