[FTR] Support for new and old es clients (#47377)

* Add dep for new es client,
refactor all mentions of the old client
to the new.
This commit is contained in:
Tre 2019-10-08 09:53:24 -06:00 committed by GitHub
parent 726a84f28c
commit 1947608378
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
35 changed files with 83 additions and 63 deletions

View file

@ -267,6 +267,7 @@
"@babel/parser": "^7.5.5",
"@babel/plugin-syntax-dynamic-import": "^7.2.0",
"@babel/types": "^7.5.5",
"@elastic/elasticsearch": "^7.4.0",
"@elastic/eslint-config-kibana": "0.15.0",
"@elastic/eslint-plugin-eui": "0.0.2",
"@elastic/github-checks-reporter": "0.0.20b3",

View file

@ -25,7 +25,7 @@ import { stat, readFileSync } from 'fs';
import { snakeCase } from 'lodash';
import del from 'del';
import { withProcRunner, ToolingLog } from '@kbn/dev-utils';
import { createEsTestCluster } from '@kbn/test';
import { createLegacyEsTestCluster } from '@kbn/test';
import execa from 'execa';
const statP = util.promisify(stat);
@ -83,7 +83,7 @@ describe(`running the plugin-generator via 'node scripts/generate_plugin.js plug
it(`'yarn start' should result in the spec plugin being initialized on kibana's stdout`, async () => {
const log = new ToolingLog();
const es = createEsTestCluster({ license: 'basic', log });
const es = createLegacyEsTestCluster({ license: 'basic', log });
await es.start();
await withProcRunner(log, async proc => {
await proc.run('kibana', {

View file

@ -19,7 +19,7 @@
import { resolve } from 'path';
import { KIBANA_ROOT } from './paths';
import { createEsTestCluster } from '../../es';
import { createLegacyEsTestCluster } from '../../legacy_es';
import { setupUsers, DEFAULT_SUPERUSER_PASS } from './auth';
@ -31,7 +31,7 @@ export async function runElasticsearch({ config, options }) {
const esEnvVars = config.get('esTestCluster.serverEnvVars');
const isSecurityEnabled = esArgs.includes('xpack.security.enabled=true');
const cluster = createEsTestCluster({
const cluster = createLegacyEsTestCluster({
port: config.get('servers.elasticsearch.port'),
password: isSecurityEnabled
? DEFAULT_SUPERUSER_PASS

View file

@ -27,7 +27,7 @@ export { runTests, startServers } from './functional_tests/tasks';
export { OPTIMIZE_BUNDLE_DIR, KIBANA_ROOT } from './functional_tests/lib/paths';
// @ts-ignore not typed yet
export { esTestConfig, createEsTestCluster } from './es';
export { esTestConfig, createLegacyEsTestCluster } from './legacy_es';
// @ts-ignore not typed yet
export { kbnTestConfig, kibanaServerTestUser, kibanaTestUser, adminTestUser } from './kbn';

View file

@ -17,5 +17,5 @@
* under the License.
*/
export { createEsTestCluster } from './es_test_cluster.js';
export { createLegacyEsTestCluster } from './legacy_es_test_cluster.js';
export { esTestConfig } from './es_test_config';

View file

@ -23,12 +23,13 @@ import { get } from 'lodash';
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 * as legacyElasticsearch from 'elasticsearch';
const path = require('path');
const del = require('del');
export function createEsTestCluster(options = {}) {
export function createLegacyEsTestCluster(options = {}) {
const {
port = esTestConfig.getPort(),
password = 'changeme',
@ -111,7 +112,7 @@ export function createEsTestCluster(options = {}) {
* Returns an ES Client to the configured cluster
*/
getClient() {
return new elasticsearch.Client({
return new legacyElasticsearch.Client({
host: this.getUrl(),
});
}

View file

@ -16,7 +16,8 @@
* specific language governing permissions and limitations
* under the License.
*/
import elasticsearch from 'elasticsearch';
import * as legacyElasticsearch from 'elasticsearch';
import { retryCallCluster } from './retry_call_cluster';
describe('retryCallCluster', () => {
@ -26,7 +27,7 @@ describe('retryCallCluster', () => {
let i = 0;
callEsApi.mockImplementation(() => {
return i++ <= 2
? Promise.reject(new elasticsearch.errors.NoConnections())
? Promise.reject(new legacyElasticsearch.errors.NoConnections())
: Promise.resolve('success');
});
const retried = retryCallCluster(callEsApi);
@ -45,7 +46,7 @@ describe('retryCallCluster', () => {
: i === 2
? Promise.resolve('success')
: i === 3 || i === 4
? Promise.reject(new elasticsearch.errors.NoConnections())
? Promise.reject(new legacyElasticsearch.errors.NoConnections())
: i === 5
? Promise.reject(new Error('unknown error'))
: null;

View file

@ -19,7 +19,8 @@
import { retryWhen, concatMap } from 'rxjs/operators';
import { defer, throwError, iif, timer } from 'rxjs';
import elasticsearch from 'elasticsearch';
import * as legacyElasticsearch from 'elasticsearch';
import { CallAPIOptions } from '.';
/**
@ -45,7 +46,7 @@ export function retryCallCluster(
errors.pipe(
concatMap((error, i) =>
iif(
() => error instanceof elasticsearch.errors.NoConnections,
() => error instanceof legacyElasticsearch.errors.NoConnections,
timer(1000),
throwError(error)
)

View file

@ -23,7 +23,7 @@ import { SavedObjectsService, SavedObjectsSetupDeps } from './saved_objects_serv
import { mockCoreContext } from '../core_context.mock';
import { KibanaMigrator } from './migrations/kibana/kibana_migrator';
import { of } from 'rxjs';
import elasticsearch from 'elasticsearch';
import * as legacyElasticsearch from 'elasticsearch';
import { Env } from '../config';
import { configServiceMock } from '../mocks';
@ -41,7 +41,7 @@ describe('SavedObjectsService', () => {
.fn()
.mockImplementation(() =>
i++ <= 2
? Promise.reject(new elasticsearch.errors.NoConnections())
? Promise.reject(new legacyElasticsearch.errors.NoConnections())
: Promise.resolve('success')
),
};

View file

@ -17,7 +17,7 @@
* under the License.
*/
import elasticsearch from 'elasticsearch';
import * as legacyElasticsearch from 'elasticsearch';
import { get } from 'lodash';
const {
@ -34,7 +34,7 @@ const {
413: RequestEntityTooLarge,
NotFound,
BadRequest,
} = elasticsearch.errors;
} = legacyElasticsearch.errors;
import { SavedObjectsErrorHelpers } from './errors';

View file

@ -22,7 +22,7 @@ import { delay } from 'bluebird';
import { SavedObjectsRepository } from './repository';
import * as getSearchDslNS from './search_dsl/search_dsl';
import { SavedObjectsErrorHelpers } from './errors';
import elasticsearch from 'elasticsearch';
import * as legacyElasticsearch from 'elasticsearch';
import { SavedObjectsSchema } from '../../schema';
import { SavedObjectsSerializer } from '../../serialization';
import { getRootPropertiesObjects } from '../../mappings/lib/get_root_properties_objects';
@ -2148,7 +2148,7 @@ describe('SavedObjectsRepository', () => {
it('can throw es errors and have them decorated as SavedObjectsClient errors', async () => {
expect.assertions(4);
const es401 = new elasticsearch.errors[401]();
const es401 = new legacyElasticsearch.errors[401]();
expect(SavedObjectsErrorHelpers.isNotAuthorizedError(es401)).toBe(false);
onBeforeWrite.mockImplementation(() => {
throw es401;

View file

@ -29,7 +29,7 @@ import { format as formatUrl } from 'url';
import readline from 'readline';
import { Command } from 'commander';
import elasticsearch from 'elasticsearch';
import * as legacyElasticsearch from 'elasticsearch';
import { EsArchiver } from './es_archiver';
import { ToolingLog } from '@kbn/dev-utils';
@ -139,7 +139,7 @@ async function execute(fn) {
}
// run!
const client = new elasticsearch.Client({
const client = new legacyElasticsearch.Client({
host: cmd.esUrl,
log: cmd.verbose ? 'trace' : []
});

View file

@ -19,7 +19,7 @@
import { ToolingLog } from '@kbn/dev-utils';
import {
createEsTestCluster,
createLegacyEsTestCluster,
DEFAULT_SUPERUSER_PASS,
esTestConfig,
kbnTestConfig,
@ -205,7 +205,7 @@ export function createTestServers({
log.info('starting elasticsearch');
log.indent(4);
const es = createEsTestCluster(
const es = createLegacyEsTestCluster(
defaultsDeep({}, get(settings, 'es', {}), {
log,
license,

View file

@ -17,13 +17,13 @@
* under the License.
*/
import { EsProvider } from './es';
import { LegacyEsProvider } from './legacy_es';
import { EsArchiverProvider } from './es_archiver';
import { KibanaServerProvider } from './kibana_server';
import { RetryProvider } from './retry';
export const services = {
es: EsProvider,
es: LegacyEsProvider,
esArchiver: EsArchiverProvider,
kibanaServer: KibanaServerProvider,
retry: RetryProvider,

View file

@ -19,15 +19,15 @@
import { format as formatUrl } from 'url';
import elasticsearch from 'elasticsearch';
import * as legacyElasticsearch from 'elasticsearch';
import { DEFAULT_API_VERSION } from '../../../src/core/server/elasticsearch/elasticsearch_config';
import { FtrProviderContext } from '../ftr_provider_context';
export function EsProvider({ getService }: FtrProviderContext): elasticsearch.Client {
export function LegacyEsProvider({ getService }: FtrProviderContext): legacyElasticsearch.Client {
const config = getService('config');
return new elasticsearch.Client({
return new legacyElasticsearch.Client({
apiVersion: DEFAULT_API_VERSION,
host: formatUrl(config.get('servers.elasticsearch')),
requestTimeout: config.get('timeouts.esRequestTimeout'),

View file

@ -6,7 +6,7 @@
// file.skip
// @ts-ignore
import { createEsTestCluster } from '@kbn/test';
import { createLegacyEsTestCluster } from '@kbn/test';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { Root } from 'src/core/server/root';
// @ts-ignore
@ -14,7 +14,7 @@ import * as kbnTestServer from '../../../../../../../../../src/test_utils/kbn_se
import { DatabaseKbnESPlugin } from '../adapter_types';
import { KibanaDatabaseAdapter } from '../kibana_database_adapter';
import { contractTests } from './test_contract';
const es = createEsTestCluster({});
const es = createLegacyEsTestCluster({});
let legacyServer: any;
let rootServer: Root;

View file

@ -10,7 +10,7 @@ import { createWorkerFactory } from './create_worker';
// @ts-ignore
import { Esqueue } from './esqueue';
// @ts-ignore
import { ClientMock } from './esqueue/__tests__/fixtures/elasticsearch';
import { ClientMock } from './esqueue/__tests__/fixtures/legacy_elasticsearch';
const configGetStub = sinon.stub();
configGetStub.withArgs('xpack.reporting.queue').returns({

View file

@ -1,5 +1,6 @@
import { uniqueId, times, random } from 'lodash';
import elasticsearch from 'elasticsearch';
import * as legacyElasticsearch from 'elasticsearch';
import { constants } from '../../constants';
export function ClientMock() {
@ -25,7 +26,7 @@ export function ClientMock() {
}
if (endpoint === 'get') {
if (params === elasticsearch.errors.NotFound) return elasticsearch.errors.NotFound;
if (params === legacyElasticsearch.errors.NotFound) return legacyElasticsearch.errors.NotFound;
const _source = {
jobtype: 'jobtype',

View file

@ -7,7 +7,7 @@
import expect from '@kbn/expect';
import sinon from 'sinon';
import { createIndex } from '../../helpers/create_index';
import { ClientMock } from '../fixtures/elasticsearch';
import { ClientMock } from '../fixtures/legacy_elasticsearch';
import { constants } from '../../constants';
describe('Create Index', function () {

View file

@ -10,7 +10,7 @@ import sinon from 'sinon';
import proxyquire from 'proxyquire';
import { noop, times } from 'lodash';
import { constants } from '../constants';
import { ClientMock } from './fixtures/elasticsearch';
import { ClientMock } from './fixtures/legacy_elasticsearch';
import { JobMock } from './fixtures/job';
import { WorkerMock } from './fixtures/worker';

View file

@ -9,7 +9,7 @@ import expect from '@kbn/expect';
import sinon from 'sinon';
import proxyquire from 'proxyquire';
import { QueueMock } from './fixtures/queue';
import { ClientMock } from './fixtures/elasticsearch';
import { ClientMock } from './fixtures/legacy_elasticsearch';
import { constants } from '../constants';
const createIndexMock = sinon.stub();

View file

@ -8,7 +8,7 @@ import expect from '@kbn/expect';
import sinon from 'sinon';
import moment from 'moment';
import { noop, random, get, find, identity } from 'lodash';
import { ClientMock } from './fixtures/elasticsearch';
import { ClientMock } from './fixtures/legacy_elasticsearch';
import { QueueMock } from './fixtures/queue';
import { formatJobObject, getUpdatedDocPath, Worker } from '../worker';
import { constants } from '../constants';

View file

@ -10,7 +10,7 @@ import { services as kibanaCommonServices } from '../../../../test/common/servic
import { SecurityServiceProvider, SpacesServiceProvider } from '../../common/services';
// @ts-ignore not ts yet
import { EsProvider } from './es';
import { LegacyEsProvider } from './legacy_es';
// @ts-ignore not ts yet
import { EsSupertestWithoutAuthProvider } from './es_supertest_without_auth';
// @ts-ignore not ts yet
@ -33,7 +33,7 @@ export const services = {
kibanaServer: kibanaCommonServices.kibanaServer,
retry: kibanaCommonServices.retry,
es: EsProvider,
es: LegacyEsProvider,
esSupertestWithoutAuth: EsSupertestWithoutAuthProvider,
infraOpsGraphQLClient: InfraOpsGraphQLClientProvider,
infraOpsGraphQLClientFactory: InfraOpsGraphQLClientFactoryProvider,

View file

@ -6,15 +6,16 @@
import { format as formatUrl } from 'url';
import elasticsearch from 'elasticsearch';
import * as legacyElasticsearch from 'elasticsearch';
import shieldPlugin from '../../../legacy/server/lib/esjs_shield_plugin';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { DEFAULT_API_VERSION } from '../../../../src/core/server/elasticsearch/elasticsearch_config';
export function EsProvider({ getService }) {
export function LegacyEsProvider({ getService }) {
const config = getService('config');
return new elasticsearch.Client({
return new legacyElasticsearch.Client({
apiVersion: DEFAULT_API_VERSION,
host: formatUrl(config.get('servers.elasticsearch')),
requestTimeout: config.get('timeouts.esRequestTimeout'),

View file

@ -5,14 +5,14 @@
*/
// @ts-ignore not ts yet
import { EsProvider } from './es';
import { LegacyEsProvider } from './legacy_es';
import { services as apiIntegrationServices } from '../../../api_integration/services';
import { services as kibanaApiIntegrationServices } from '../../../../../test/api_integration/services';
import { services as kibanaFunctionalServices } from '../../../../../test/functional/services';
export const services = {
es: EsProvider,
es: LegacyEsProvider,
esSupertestWithoutAuth: apiIntegrationServices.esSupertestWithoutAuth,
supertest: kibanaApiIntegrationServices.supertest,
supertestWithoutAuth: apiIntegrationServices.supertestWithoutAuth,

View file

@ -6,13 +6,14 @@
import { format as formatUrl } from 'url';
import elasticsearch from 'elasticsearch';
import * as legacyElasticsearch from 'elasticsearch';
import shieldPlugin from '../../../../legacy/server/lib/esjs_shield_plugin';
export function EsProvider({ getService }) {
export function LegacyEsProvider({ getService }) {
const config = getService('config');
return new elasticsearch.Client({
return new legacyElasticsearch.Client({
host: formatUrl(config.get('servers.elasticsearch')),
requestTimeout: config.get('timeouts.esRequestTimeout'),
plugins: [shieldPlugin],

View file

@ -9,7 +9,7 @@ import { resolveKibanaPath } from '@kbn/plugin-helpers';
import path from 'path';
import { TestInvoker } from './lib/types';
// @ts-ignore
import { EsProvider } from './services/es';
import { LegacyEsProvider } from './services/legacy_es';
interface CreateTestConfigOptions {
license: string;
@ -34,7 +34,7 @@ export function createTestConfig(name: string, options: CreateTestConfigOptions)
testFiles: [require.resolve(`../${name}/apis/`)],
servers: config.xpack.api.get('servers'),
services: {
es: EsProvider,
es: LegacyEsProvider,
esSupertestWithoutAuth: config.xpack.api.get('services.esSupertestWithoutAuth'),
supertest: config.kibana.api.get('services.supertest'),
supertestWithoutAuth: config.xpack.api.get('services.supertestWithoutAuth'),

View file

@ -6,13 +6,14 @@
import { format as formatUrl } from 'url';
import elasticsearch from 'elasticsearch';
import * as legacyElasticsearch from 'elasticsearch';
import shieldPlugin from '../../../../legacy/server/lib/esjs_shield_plugin';
export function EsProvider({ getService }) {
export function LegacyEsProvider({ getService }) {
const config = getService('config');
return new elasticsearch.Client({
return new legacyElasticsearch.Client({
host: formatUrl(config.get('servers.elasticsearch')),
requestTimeout: config.get('timeouts.esRequestTimeout'),
plugins: [shieldPlugin]

View file

@ -6,7 +6,7 @@
import path from 'path';
import {
EsProvider,
LegacyEsProvider,
} from './services';
export default async function ({ readConfigFile }) {
@ -21,7 +21,7 @@ export default async function ({ readConfigFile }) {
servers: xPackFunctionalTestsConfig.get('servers'),
services: {
supertest: kibanaAPITestsConfig.get('services.supertest'),
es: EsProvider,
es: LegacyEsProvider,
esArchiver: kibanaCommonConfig.get('services.esArchiver'),
},
esArchiver: xPackFunctionalTestsConfig.get('esArchiver'),

View file

@ -4,4 +4,4 @@
* you may not use this file except in compliance with the Elastic License.
*/
export { EsProvider } from './es';
export { LegacyEsProvider } from './legacy_es';

View file

@ -6,12 +6,12 @@
import { format as formatUrl } from 'url';
import elasticsearch from 'elasticsearch';
import * as legacyElasticsearch from 'elasticsearch';
export function EsProvider({ getService }) {
export function LegacyEsProvider({ getService }) {
const config = getService('config');
return new elasticsearch.Client({
return new legacyElasticsearch.Client({
host: formatUrl(config.get('servers.elasticsearch')),
requestTimeout: config.get('timeouts.esRequestTimeout'),
});

View file

@ -10,7 +10,7 @@ import { createKibanaServer } from './servers';
import { getEsArchiver } from './services/es_archiver';
import { EsArchiver } from 'src/es_archiver';
import * as path from 'path';
import elasticsearch from 'elasticsearch';
import * as legacyElasticsearch from 'elasticsearch';
const { callWhenOnline, memorize } = Slapshot;
@ -50,7 +50,7 @@ describe.skip('Example contract tests', () => {
const dataInES: any = await memorize('sample_data', () => {
// To keep things simple in this example, getting the connection infor the the JEST contract test ES server
const esConfig = JSON.parse(process.env.__JEST__ESServer || '');
const client = new elasticsearch.Client({
const client = new legacyElasticsearch.Client({
hosts: esConfig.hosts,
httpAuth: esConfig.username ? `${esConfig.username}:${esConfig.password}` : undefined,
});

View file

@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import elasticsearch from 'elasticsearch';
import * as legacyElasticsearch from 'elasticsearch';
import { ToolingLog } from '@kbn/dev-utils';
import { resolve } from 'path';
import * as fs from 'fs';
@ -37,7 +37,7 @@ export const getEsArchiver = (options: {
writeTo: process.stdout,
});
const client = new elasticsearch.Client({
const client = new legacyElasticsearch.Client({
hosts: esConfig.hosts,
httpAuth: esConfig.username ? `${esConfig.username}:${esConfig.password}` : undefined,
log: options.logLevel,

View file

@ -1118,6 +1118,18 @@
once "^1.4.0"
pump "^3.0.0"
"@elastic/elasticsearch@^7.4.0":
version "7.4.0"
resolved "https://registry.yarnpkg.com/@elastic/elasticsearch/-/elasticsearch-7.4.0.tgz#57f4066acf25e9d4e9b4f6376088433aae6f25d4"
integrity sha512-HpEKHH6mHQRvea3lw4NNJw9ZUS1KmkpwWKHucaHi1svDn+/fEAwY0wD8egL1vZJo4ZmWfCQMjVqGL+Hoy1HYRw==
dependencies:
debug "^4.1.1"
decompress-response "^4.2.0"
into-stream "^5.1.0"
ms "^2.1.1"
once "^1.4.0"
pump "^3.0.0"
"@elastic/eslint-plugin-eui@0.0.2":
version "0.0.2"
resolved "https://registry.yarnpkg.com/@elastic/eslint-plugin-eui/-/eslint-plugin-eui-0.0.2.tgz#56b9ef03984a05cc213772ae3713ea8ef47b0314"