-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[SavedObjects] Create serverless utils for jest integration tests #164157
Changes from all commits
95d0d28
0263712
6574294
67ba949
cee9fed
4c5f8d6
9ebb55d
5130179
3319e5f
6fcf045
0efae80
6446381
cf66e67
fab26f8
d336c1e
11d496a
56b80f2
60b28ed
f8429e7
5d8c454
8157d88
3cad9bb
f0cd6a4
40037b4
718e7f0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 { defaultsDeep } from 'lodash'; | ||
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 { createRoot, type TestElasticsearchUtils, type TestKibanaUtils } from './create_root'; | ||
|
||
export type TestServerlessESUtils = Pick<TestElasticsearchUtils, 'stop' | 'es'>; | ||
export type TestServerlessKibanaUtils = TestKibanaUtils; | ||
export interface TestServerlessUtils { | ||
startES: () => Promise<TestServerlessESUtils>; | ||
startKibana: (abortSignal?: AbortSignal) => Promise<TestServerlessKibanaUtils>; | ||
} | ||
|
||
/** | ||
* See docs in {@link TestUtils}. This function provides the same utilities but | ||
* configured for serverless. | ||
* | ||
* @note requires a Docker installation to be running | ||
*/ | ||
export function createTestServerlessInstances({ | ||
adjustTimeout, | ||
}: { | ||
adjustTimeout: (timeout: number) => void; | ||
}): TestServerlessUtils { | ||
const esUtils = createServerlessES(); | ||
const kbUtils = createServerlessKibana(); | ||
adjustTimeout?.(120_000); | ||
return { | ||
startES: async () => { | ||
const { stop } = await esUtils.start(); | ||
return { | ||
es: esUtils.es, | ||
stop, | ||
}; | ||
}, | ||
startKibana: async (abortSignal) => { | ||
abortSignal?.addEventListener('abort', async () => await kbUtils.shutdown()); | ||
await kbUtils.preboot(); | ||
const coreSetup = await kbUtils.setup(); | ||
const coreStart = await kbUtils.start(); | ||
return { | ||
root: kbUtils, | ||
coreSetup, | ||
coreStart, | ||
stop: kbUtils.shutdown.bind(kbUtils), | ||
}; | ||
}, | ||
}; | ||
} | ||
|
||
function createServerlessES() { | ||
const log = new ToolingLog({ | ||
level: 'info', | ||
writeTo: process.stdout, | ||
}); | ||
const es = new Cluster({ log }); | ||
return { | ||
es, | ||
start: async () => { | ||
await es.runServerless({ | ||
basePath: Path.join(REPO_ROOT, '.es/es_test_serverless'), | ||
}); | ||
return { | ||
stop: async () => { | ||
// hack to stop the ES cluster | ||
await execa('docker', ['container', 'stop', 'es01', 'es02', 'es03']); | ||
}, | ||
}; | ||
}, | ||
}; | ||
} | ||
|
||
const defaults = { | ||
server: { | ||
restrictInternalApis: true, | ||
versioned: { | ||
versionResolution: 'newest', | ||
strictClientVersionCheck: false, | ||
}, | ||
}, | ||
migrations: { | ||
algorithm: 'zdt', | ||
}, | ||
elasticsearch: { | ||
serviceAccountToken: 'BEEF', | ||
}, | ||
}; | ||
function createServerlessKibana(settings = {}, cliArgs: Partial<CliArgs> = {}) { | ||
return createRoot(defaultsDeep(settings, defaults), { ...cliArgs, serverless: true }); | ||
} | ||
Comment on lines
+98
to
+100
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, great point, this still needs to be figured out a bit. I added some basic config that we'll need in serverless in the meantime:
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
module.exports = { | ||
// TODO replace the line below with | ||
// preset: '@kbn/test/jest_integration_node | ||
// to do so, we must fix all integration tests first | ||
// see https://github.com/elastic/kibana/pull/130255/ | ||
preset: '@kbn/test/jest_integration', | ||
rootDir: '../../../../../../..', | ||
roots: ['<rootDir>/src/core/server/integration_tests/saved_objects/serverless/migrations'], | ||
// must override to match all test given there is no `integration_tests` subfolder | ||
testMatch: ['**/*.test.{js,mjs,ts,tsx}'], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* 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 { | ||
request, | ||
TestServerlessESUtils, | ||
TestServerlessKibanaUtils, | ||
createTestServerlessInstances, | ||
} from '@kbn/core-test-helpers-kbn-server'; | ||
|
||
/** | ||
* Until we merge https://github.com/elastic/kibana/pull/162673 this test should remain skipped. | ||
*/ | ||
describe.skip('smoke', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried to get this working on CI, but it is currently timing out. It seems as though the instance might be too small to start 3 ES containers. We should also wait for QA to figure this out for FTRs. |
||
let serverlessES: TestServerlessESUtils; | ||
let serverlessKibana: TestServerlessKibanaUtils; | ||
let root: TestServerlessKibanaUtils['root']; | ||
beforeEach(async () => { | ||
const { startES, startKibana } = createTestServerlessInstances({ | ||
adjustTimeout: jest.setTimeout, | ||
}); | ||
serverlessES = await startES(); | ||
serverlessKibana = await startKibana(); | ||
root = serverlessKibana.root; | ||
}); | ||
afterEach(async () => { | ||
await serverlessES?.stop(); | ||
await serverlessKibana?.stop(); | ||
}); | ||
test('it can start Kibana and ES serverless', async () => { | ||
const { body } = await request.get(root, '/api/status').expect(200); | ||
expect(body).toMatchObject({ status: { overall: { level: 'available' } } }); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seemed easiest to just create a separate function rather than adding a flag to the existing
createTestServers
logic.However, we mirror the existing API as closely as possible so that these helpers can be easily substituted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why didn't you name it
createTestServerlessServers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you said the quiet part out loud 🤫
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but in all seriousness: if you have a better idea for a name I'll gladly accept 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Na, naming is hard, it's fine. We can rename later if we really want so.