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

Serverless migration actions tests #164842

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,19 @@
* Side Public License, v 1.
*/
import { defaultsDeep } from 'lodash';
import pRetry from 'p-retry';
import { Cluster } from '@kbn/es';
import Path from 'path';
import { REPO_ROOT } from '@kbn/repo-info';
import { ToolingLog } from '@kbn/tooling-log';
import execa from 'execa';
import { CliArgs } from '@kbn/config';
import { Client, HttpConnection } from '@elastic/elasticsearch';
import { createRoot, type TestElasticsearchUtils, type TestKibanaUtils } from './create_root';

export type TestServerlessESUtils = Pick<TestElasticsearchUtils, 'stop' | 'es'>;
export interface TestServerlessESUtils extends Pick<TestElasticsearchUtils, 'stop'> {
es: { getClient: () => Client };
}
export type TestServerlessKibanaUtils = TestKibanaUtils;
export interface TestServerlessUtils {
startES: () => Promise<TestServerlessESUtils>;
Expand All @@ -38,8 +42,13 @@ export function createTestServerlessInstances({
return {
startES: async () => {
const { stop } = await esUtils.start();
const client = new Client({ node: 'http://localhost:9200', Connection: HttpConnection });
await pRetry(() => client.ping(), { retries: 10 });
const es = {
getClient: () => client,
};
return {
es: esUtils.es,
es,
stop,
};
},
Expand Down Expand Up @@ -90,10 +99,32 @@ const defaults = {
},
migrations: {
algorithm: 'zdt',
zdt: {
runOnRoles: ['ui'],
},
},
elasticsearch: {
serviceAccountToken: 'BEEF',
},
// Log ES deprecations to surface these in CI
logging: {
loggers: [
{
name: 'root',
level: 'error',
appenders: ['console'],
},
{
name: 'elasticsearch.deprecation',
level: 'all',
appenders: ['deprecation'],
},
],
appenders: {
deprecation: { type: 'console', layout: { type: 'json' } },
console: { type: 'console', layout: { type: 'pattern' } },
},
},
};
function createServerlessKibana(settings = {}, cliArgs: Partial<CliArgs> = {}) {
return createRoot(defaultsDeep(settings, defaults), { ...cliArgs, serverless: true });
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { type Client } from '@elastic/elasticsearch';
import {
type TestServerlessESUtils,
createTestServerlessInstances,
} from '@kbn/core-test-helpers-kbn-server';

import * as ZDTActions from '@kbn/core-saved-objects-migration-server-internal/src/zdt/actions';

const TEST_INDEX_A = '.some_index_1';
const TEST_INDEX_A_ALIAS = '.some_index';
const TEST_INDEX_B = '.some_other_index_1';
const TEST_INDICES = [TEST_INDEX_A, TEST_INDEX_B];

/**
* The intention with this set of tests is to ensure that we are able to run all ZDT actions against serverless ES. Do
* not add tests here to ensure that sequences of actions work as expected. These should be added elsewhere.
*/
describe.skip('ZDT migration actions', () => {
let serverlessES: TestServerlessESUtils;
let client: Client;
beforeAll(async () => {
const { startES } = createTestServerlessInstances({
adjustTimeout: jest.setTimeout,
});
serverlessES = await startES();
client = serverlessES.es.getClient();
});
afterAll(async () => {
await serverlessES?.stop();
});
afterEach(async () => {
await client.indices.delete({
index: TEST_INDICES,
ignore_unavailable: true,
});
});

function runCreateIndexTask(indexName = TEST_INDEX_A) {
return ZDTActions.createIndex({
client,
indexName,
mappings: { dynamic: false, properties: { test: { type: 'text' } } },
aliases: [TEST_INDEX_A_ALIAS],
timeout: '1s',
})();
}
function runUpdateIndexMappingsTask(index = TEST_INDEX_A) {
return ZDTActions.updateAndPickupMappings({
batchSize: 10,
client,
index,
mappings: { dynamic: false, properties: { test: { type: 'text' } } },
query: { match_all: {} },
})();
}
test('init', async () => {
const task = ZDTActions.init({ client, indices: [TEST_INDEX_A, TEST_INDEX_B] });
await expect(task()).resolves.toMatchInlineSnapshot(`
Object {
"_tag": "Right",
"right": Object {},
}
`);
});
test('createIndex', async () => {
await expect(runCreateIndexTask()).resolves.toMatchInlineSnapshot(`
Object {
"_tag": "Right",
"right": "create_index_succeeded",
}
`);
});
test('updateIndexMappings', async () => {
await runCreateIndexTask();
await expect(runUpdateIndexMappingsTask()).resolves.toMatchObject({
right: { taskId: expect.any(String) },
});
});
test('waitForPickupUpdatedMappingsTask', async () => {
await runCreateIndexTask();
const {
right: { taskId },
} = (await runUpdateIndexMappingsTask()) as any;
const task = ZDTActions.waitForPickupUpdatedMappingsTask({ client, taskId, timeout: '30s' });
expect(task()).resolves.toMatchInlineSnapshot(`
Object {
"_tag": "Right",
"right": "pickup_updated_mappings_succeeded",
}
`);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,19 @@ describe.skip('smoke', () => {
let serverlessES: TestServerlessESUtils;
let serverlessKibana: TestServerlessKibanaUtils;
let root: TestServerlessKibanaUtils['root'];
beforeEach(async () => {
beforeAll(async () => {
const { startES, startKibana } = createTestServerlessInstances({
adjustTimeout: jest.setTimeout,
});
serverlessES = await startES();
serverlessKibana = await startKibana();
root = serverlessKibana.root;
});
afterEach(async () => {
afterAll(async () => {
await serverlessES.es.getClient().indices.delete({
index: ['.kibana', '.kibana_task_manager', '.kibana_1', '.kibana_2'],
ignore_unavailable: true,
});
await serverlessES?.stop();
await serverlessKibana?.stop();
});
Expand Down