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

WIP: elasticsearch-js next #27051

Closed
wants to merge 80 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
1f8250b
WIP: elasticsearch-js next
delvedor Dec 12, 2018
4e5be1c
Updated to use the latest version of the client
delvedor Dec 12, 2018
142a2c0
Fixed linter
delvedor Dec 13, 2018
d6abfe1
Merge branch 'master' of https://github.com/elastic/kibana into next-…
delvedor Dec 17, 2018
f0495c6
Bumped @elastic/elasticsearch
delvedor Dec 17, 2018
a3bafbf
Updated imports
delvedor Dec 18, 2018
b5417a3
Updated parse_config
delvedor Dec 18, 2018
1559479
Handled not standard result
delvedor Dec 18, 2018
1ef16a3
Updated decorate_es_error to use new error classes
delvedor Dec 18, 2018
5951dee
Updated monitoring to use the new client errors
delvedor Dec 18, 2018
c2ba3bd
Updated typescript declaration
delvedor Dec 18, 2018
9f2442b
Fixed test
delvedor Dec 18, 2018
1ebbe21
Updated lockfile
delvedor Dec 18, 2018
a5b53cb
Merge branch 'master' of https://github.com/elastic/kibana into next-…
delvedor Dec 18, 2018
4e5eca4
Merge branch 'master' of https://github.com/elastic/kibana into next-…
delvedor Dec 18, 2018
93b0235
Updated test
delvedor Dec 18, 2018
3bdee12
Add additional @elastic/elasticsearch typings
timroes Jan 11, 2019
81859c8
Updated lockfile
delvedor Jan 11, 2019
9cf7889
Updated @elastic/elasticsearch typings definition
delvedor Jan 11, 2019
4f967a6
Updated types to use RequestParams
delvedor Jan 11, 2019
6afb06d
Fix type augmention issue
timroes Jan 15, 2019
0680355
Add missing buildSourcePattern
timroes Jan 16, 2019
c28c7aa
Merge branch 'master' of https://github.com/elastic/kibana into next-…
delvedor Jan 21, 2019
ed9a3e7
Merge branch 'next-es-client' of https://github.com/delvedor/kibana i…
delvedor Jan 21, 2019
bc516e9
Updated lockfile
delvedor Jan 21, 2019
239d1ca
Removed dlls folder
delvedor Jan 21, 2019
0e76dea
Updated apm typings
delvedor Jan 21, 2019
250b4c4
Clean old css files
delvedor Jan 21, 2019
6a9299a
Clean old css files
delvedor Jan 21, 2019
ab890f4
Updated url import
delvedor Jan 21, 2019
3fadbff
Updated lockfile
delvedor Jan 22, 2019
2d90e64
Added client type definition also inside x-pack
delvedor Jan 23, 2019
05c79bc
Fix linter
delvedor Jan 24, 2019
fc5adf0
Updated client parameters
delvedor Jan 24, 2019
0443032
Updated debug logs
delvedor Jan 24, 2019
a1ef8ea
Updated legacy kibana error handler
delvedor Jan 24, 2019
941d1be
Updated test
delvedor Jan 24, 2019
d70c8e2
Updated client usage
delvedor Jan 24, 2019
0560873
Updated client usage
delvedor Jan 25, 2019
67bc751
Updated client usage
delvedor Jan 25, 2019
422ecfc
Updated test
delvedor Jan 25, 2019
d0448d0
Updated callCluster utility
delvedor Jan 25, 2019
44ef102
Updated test
delvedor Jan 25, 2019
668668a
Updated lockfile
delvedor Jan 29, 2019
ec2414d
Fix linter
delvedor Jan 30, 2019
8e81922
Updated lockfile
delvedor Jan 30, 2019
3c3bbfc
Updated lockfile
delvedor Jan 30, 2019
85e3005
Updated error handling
delvedor Jan 30, 2019
c502c69
Updated test
delvedor Jan 31, 2019
4729301
Updated client usage
delvedor Jan 31, 2019
26c874f
Merge branch 'master' of https://github.com/elastic/kibana into next-…
delvedor Jan 31, 2019
db4bb74
Updated typings and import
delvedor Jan 31, 2019
a12fcf6
Updated lockfile
delvedor Jan 31, 2019
5a4c053
Updated client extensions
delvedor Jan 31, 2019
36483b6
Merge branch 'master' of github.com:elastic/kibana into pr/27051
Jan 31, 2019
4746071
fixes for sample data tests
Jan 31, 2019
b6f5336
update transport.request calls to pass query directly in params
Jan 31, 2019
4dbb30e
query values in transport.request need to be wrapped in querystring: {}
Jan 31, 2019
30a9ab2
escape xml without triggering max call stack overflow
Jan 31, 2019
8d21048
Use the client ccr APIs
delvedor Jan 31, 2019
77fc7ee
Use the client ml APIs
delvedor Jan 31, 2019
9269960
Use the client monitoring APIs
delvedor Jan 31, 2019
87425ff
Use the client rollup APIs
delvedor Jan 31, 2019
0466ae0
update all uses of es ftr service
Jan 31, 2019
111805c
Use the client watcher APIs
delvedor Jan 31, 2019
fc9e5e8
Use the extended client APIs
delvedor Jan 31, 2019
a85e5ca
Fixed linter
delvedor Jan 31, 2019
47f8ea7
Merge branch 'next-es-client' of https://github.com/delvedor/kibana i…
delvedor Jan 31, 2019
f8387f8
fix escapeCdata, multi-exec requires a capturing group in regex
Jan 31, 2019
9051abb
Updated test
delvedor Feb 1, 2019
29a26d4
Updated esqueue to use the new client response
delvedor Feb 1, 2019
2f960ad
Merge branch 'master' of https://github.com/elastic/kibana into next-…
delvedor Feb 1, 2019
8c1f514
Merge branch 'next-es-client' of https://github.com/delvedor/kibana i…
delvedor Feb 1, 2019
12735b2
Updated username parameter
delvedor Feb 1, 2019
76c6504
Updated ignore usage
delvedor Feb 1, 2019
89fa7d4
Log errors only
delvedor Feb 1, 2019
c1cabf5
Updated mock
delvedor Feb 1, 2019
c19167b
Merge branch 'master' of https://github.com/elastic/kibana into next-…
delvedor Feb 11, 2019
a74ad30
Merge branch 'master' of https://github.com/elastic/kibana into next-…
delvedor Feb 11, 2019
dbffda3
Updated lockfile
delvedor Feb 11, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
},
"dependencies": {
"@elastic/datemath": "5.0.2",
"@elastic/elasticsearch": "elastic/elasticsearch-js#next",
"@elastic/eui": "6.10.1",
"@elastic/filesaver": "1.1.2",
"@elastic/good": "8.1.1-kibana2",
Expand Down Expand Up @@ -137,7 +138,6 @@
"d3-cloud": "1.2.1",
"del": "^3.0.0",
"dragula": "3.7.0",
"elasticsearch": "^15.4.1",
"elasticsearch-browser": "^15.4.1",
"encode-uri-query": "1.0.0",
"execa": "^1.0.0",
Expand Down
15 changes: 11 additions & 4 deletions packages/kbn-test/src/es/es_test_cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import toPath from 'lodash/internal/toPath';
import { Cluster } from '@kbn/es';
import { esTestConfig } from './es_test_config';
import { KIBANA_ROOT } from '../';
import elasticsearch from 'elasticsearch';
import elasticsearch from '@elastic/elasticsearch';
const path = require('path');
const del = require('del');

Expand Down Expand Up @@ -105,7 +105,7 @@ export function createEsTestCluster(options = {}) {
*/
getClient() {
return new elasticsearch.Client({
host: this.getUrl(),
node: this.getUrl(),
});
}

Expand All @@ -130,13 +130,20 @@ export function createEsTestCluster(options = {}) {
* @return {Function}
*/
function createCallCluster(esClient) {
return function callCluster(method, params) {
return async function callCluster(method, params) {
const path = toPath(method);
const contextPath = path.slice(0, -1);

const action = get(esClient, path);
const context = contextPath.length ? get(esClient, contextPath) : esClient;

return action.call(context, params);
const { ignore, headers, requestTimeout, maxRetries, ...esParams } = params;
const { body } = await action.call(context, esParams, {
ignore,
headers,
maxRetries,
requestTimeout,
});
return body;
};
}
28 changes: 28 additions & 0 deletions src/dev/xml.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { escapeCdata } from './xml';

it('returns original string when there is no invalid XML character', () => {
expect(escapeCdata('foo')).toBe('foo');
});

it('strips ansi escape sequences, including \\b', () => {
expect(escapeCdata('foo')).toBe('foo');
});
19 changes: 15 additions & 4 deletions src/dev/xml.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,27 @@ import stripAnsi from 'strip-ansi';

// create a regular expression using regenerate() that selects any character that is explicitly allowed by https://www.w3.org/TR/xml/#NT-Char
const validXmlCharsRE = new RegExp(
`(?:${regenerate()
`((?:${regenerate()
.add(0x9, 0xa, 0xd)
.addRange(0x20, 0xd7ff)
.addRange(0xe000, 0xfffd)
.addRange(0x10000, 0x10ffff)
.toString()})*`,
.toString()})+)`,
'g'
);

export function escapeCdata(input: string) {
const match = stripAnsi(input).match(validXmlCharsRE) || [];
return match.join('');
let escaped = '';

const inputWithoutAnsi = stripAnsi(input);
while (true) {
const match = validXmlCharsRE.exec(inputWithoutAnsi);
if (!match) {
break;
}

escaped += match[0];
}

return escaped;
}
7 changes: 4 additions & 3 deletions src/es_archiver/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { format as formatUrl } from 'url';
import readline from 'readline';

import { Command } from 'commander';
import elasticsearch from 'elasticsearch';
import elasticsearch from '@elastic/elasticsearch';

import { EsArchiver } from './es_archiver';
import { ToolingLog } from '@kbn/dev-utils';
Expand Down Expand Up @@ -132,7 +132,7 @@ async function execute(fn) {

// run!
const client = new elasticsearch.Client({
host: cmd.esUrl,
node: cmd.esUrl,
log: cmd.verbose ? 'trace' : []
});

Expand All @@ -148,6 +148,7 @@ async function execute(fn) {
await client.close();
}
} catch (err) {
console.log('FATAL ERROR', err.stack);
console.log(err);
// console.log('FATAL ERROR', err.stack);
}
}
3 changes: 2 additions & 1 deletion src/es_archiver/lib/docs/__tests__/stubs.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export const createStubClient = (responses = []) => {
}

const response = responses.shift();
return await response(name, params);
const body = await response(name, params);
return { body };
});

return {
Expand Down
6 changes: 4 additions & 2 deletions src/es_archiver/lib/docs/generate_doc_records_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,21 @@ export function createGenerateDocRecordsStream(client, stats) {

while (!resp || remainingHits > 0) {
if (!resp) {
resp = await client.search({
const result = await client.search({
index: index,
scroll: SCROLL_TIMEOUT,
size: SCROLL_SIZE,
_source: true,
rest_total_hits_as_int: true
});
resp = result.body;
remainingHits = resp.hits.total;
} else {
resp = await client.scroll({
const result = await client.scroll({
scrollId: resp._scroll_id,
scroll: SCROLL_TIMEOUT
});
resp = result.body;
}

for (const hit of resp.hits.hits) {
Expand Down
2 changes: 1 addition & 1 deletion src/es_archiver/lib/docs/index_doc_records_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export function createIndexDocRecordsStream(client, stats) {
);
});

const resp = await client.bulk({ body });
const { body: resp } = await client.bulk({ body });
if (resp.errors) {
throw new Error(`Failed to index all documents: ${JSON.stringify(resp, null, 2)}`);
}
Expand Down
3 changes: 2 additions & 1 deletion src/es_archiver/lib/indices/__tests__/create_index_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@ describe('esArchiver: createCreateIndexStream()', () => {
]);

expect(client.indices.getAlias.calledOnce).to.be.ok();
expect(client.indices.getAlias.args[0][0]).to.eql({ name: 'existing-index', ignore: [404] });
expect(client.indices.getAlias.args[0][0]).to.eql({ name: 'existing-index' });
expect(client.indices.getAlias.args[0][1]).to.eql({ ignore: [404] });
expect(client.indices.delete.calledOnce).to.be.ok();
expect(client.indices.delete.args[0][0]).to.eql({ index: ['actual-index'] });
sinon.assert.callCount(client.indices.create, 3); // one failed create because of existing
Expand Down
20 changes: 11 additions & 9 deletions src/es_archiver/lib/indices/__tests__/stubs.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ export const createStubClient = (existingIndices = [], aliases = {}) => ({
}

return {
[index]: {
mappings: {},
settings: {},
body: {
[index]: {
mappings: {},
settings: {},
}
}
};
}),
Expand All @@ -78,14 +80,14 @@ export const createStubClient = (existingIndices = [], aliases = {}) => ({
getAlias: sinon.spy(async ({ index, name }) => {
if (index && existingIndices.indexOf(index) >= 0) {
const result = indexAlias(aliases, index);
return { [index]: { aliases: result ? { [result]: {} } : {} } };
return { body: { [index]: { aliases: result ? { [result]: {} } : {} } } };
}

if (name && aliases[name]) {
return { [aliases[name]]: { aliases: { [name]: {} } } };
return { body: { [aliases[name]]: { aliases: { [name]: {} } } } };
}

return { status: 404 };
return { body: { status: 404 } };
}),
updateAliases: sinon.spy(async ({ body }) => {
body.actions.forEach(({ add: { index, alias } }) => {
Expand All @@ -95,14 +97,14 @@ export const createStubClient = (existingIndices = [], aliases = {}) => ({
existingIndices.push({ index, alias });
});

return { ok: true };
return { body: { ok: true } };
}),
create: sinon.spy(async ({ index }) => {
if (existingIndices.includes(index) || aliases.hasOwnProperty(index)) {
throw createEsClientError('resource_already_exists_exception');
} else {
existingIndices.push(index);
return { ok: true };
return { body: { ok: true } };
}
}),
delete: sinon.spy(async ({ index }) => {
Expand All @@ -116,7 +118,7 @@ export const createStubClient = (existingIndices = [], aliases = {}) => ({
}
});
indices.forEach(ix => existingIndices.splice(existingIndices.indexOf(ix), 1));
return { ok: true };
return { body: { ok: true } };
} else {
throw createEsClientError('index_not_found_exception');
}
Expand Down
12 changes: 7 additions & 5 deletions src/es_archiver/lib/indices/delete_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export async function deleteIndex(options) {
} = options;

const getIndicesToDelete = async () => {
const aliasInfo = await client.indices.getAlias({ name: index, ignore: [404] });
const { body: aliasInfo } = await client.indices.getAlias({ name: index }, { ignore: [404] });
return aliasInfo.status === 404 ? index : Object.keys(aliasInfo);
};

Expand Down Expand Up @@ -82,24 +82,26 @@ export function isDeleteWhileSnapshotInProgressError(error) {
*/
export async function waitForSnapshotCompletion(client, index, log) {
const isSnapshotPending = async (repository, snapshot) => {
const { snapshots: [status] } = await client.snapshot.status({
const result = await client.snapshot.status({
repository,
snapshot,
});

const { snapshots: [status] } = result.body;
log.debug(`Snapshot ${repository}/${snapshot} is ${status.state}`);
return PENDING_SNAPSHOT_STATUSES.includes(status.state);
};

const getInProgressSnapshots = async (repository) => {
const { snapshots: inProgressSnapshots } = await client.snapshot.get({
const result = await client.snapshot.get({
repository,
snapshot: '_current'
});
const { snapshots: inProgressSnapshots } = result.body;
return inProgressSnapshots;
};

for (const repository of Object.keys(await client.snapshot.getRepository())) {
const { body } = await client.snapshot.getRepository();
for (const repository of Object.keys(body)) {
const allInProgress = await getInProgressSnapshots(repository);
const found = allInProgress.find(s => s.indices.includes(index));

Expand Down
7 changes: 5 additions & 2 deletions src/es_archiver/lib/indices/generate_index_records_stream.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function createGenerateIndexRecordsStream(client, stats) {
readableObjectMode: true,
async transform(indexOrAlias, enc, callback) {
try {
const resp = await client.indices.get({
const { body: resp } = await client.indices.get({
index: indexOrAlias,
filterPath: [
'*.settings',
Expand All @@ -39,7 +39,10 @@ export function createGenerateIndexRecordsStream(client, stats) {
});

for (const [index, { settings, mappings }] of Object.entries(resp)) {
const { [index]: { aliases } } = await client.indices.getAlias({ index });
const result = await client.indices.getAlias({ index });
const { [index]: { aliases } } = result.body;
const { settings, mappings } = resp[index];


stats.archivedIndex(index, { settings, mappings });
this.push({
Expand Down
14 changes: 12 additions & 2 deletions src/es_archiver/lib/indices/kibana_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,17 @@ export async function migrateKibanaIndex({ client, log }) {
const ready = async () => undefined;
const elasticsearch = {
getCluster: () => ({
callWithInternalUser: (path, ...args) => _.get(client, path).call(client, ...args),
callWithInternalUser: async (path, clientParams) => {
const {
ignore,
headers,
requestTimeout,
maxRetries,
...esParams
} = clientParams;
const result = await _.get(client, path).call(client, esParams, { ignore, headers, requestTimeout, maxRetries });
return result && result.body ? result.body : result;
},
}),
waitUntilReady: ready,
};
Expand Down Expand Up @@ -160,7 +170,7 @@ export async function createDefaultSpace({ index, client }) {
* @param {string} index
*/
async function fetchKibanaIndices(client) {
const kibanaIndices = await client.cat.indices({ index: '.kibana*', format: 'json' });
const { body: kibanaIndices } = await client.cat.indices({ index: '.kibana*', format: 'json' });
const isKibanaIndex = (index) => (/^\.kibana(:?_\d*)?$/).test(index);
return kibanaIndices.map(x => x.index).filter(isKibanaIndex);
}
Expand Down
11 changes: 7 additions & 4 deletions src/legacy/core_plugins/elasticsearch/lib/__tests__/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@
import expect from 'expect.js';
import { Cluster } from '../cluster';
import sinon from 'sinon';
import { errors as esErrors } from 'elasticsearch';
import { errors as esErrors } from '@elastic/elasticsearch';
import { set, partial } from 'lodash';

describe('plugins/elasticsearch', function () {
describe('cluster', function () {
let cluster;
const config = {
url: 'http://localhost:9200',
hosts: ['http://localhost:9200'],
ssl: { verificationMode: 'full' },
requestHeadersWhitelist: [ 'authorization' ]
};
Expand Down Expand Up @@ -128,8 +128,11 @@ describe('plugins/elasticsearch', function () {
cluster.callWithRequest(request, 'nodes.info');

sinon.assert.calledOnce(client.nodes.info);
expect(client.nodes.info.getCall(0).args[0]).to.eql({
headers: headers
expect(client.nodes.info.getCall(0).args[1]).to.eql({
headers: headers,
ignore: undefined,
maxRetries: undefined,
requestTimeout: undefined
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ describe('plugins/elasticsearch', function () {
describe('createCluster', () => {
let cluster;
const config = {
url: 'http://localhost:9200',
hosts: ['http://localhost:9200'],
ssl: {
verificationMode: 'none'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import Promise from 'bluebird';
import sinon from 'sinon';
import expect from 'expect.js';

const NoConnections = require('elasticsearch').errors.NoConnections;
const NoConnections = require('@elastic/elasticsearch').errors.NoLivingConnectionsError;

import mappings from './fixtures/mappings';
import healthCheck from '../health_check';
Expand Down
Loading