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

Surface deprecation logs from CI #117937

Closed
wants to merge 13 commits into from
Closed
Show file tree
Hide file tree
Changes from 9 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
4 changes: 2 additions & 2 deletions packages/kbn-test/src/es/es_test_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class EsTestConfig {
return process.env.TEST_ES_TRANSPORT_PORT || '9300-9400';
}

getUrlParts() {
getUrlParts(ssl?: boolean) {
// Allow setting one complete TEST_ES_URL for Es like https://elastic:changeme@myCloudInstance:9200
if (process.env.TEST_ES_URL) {
const testEsUrl = Url.parse(process.env.TEST_ES_URL);
Expand Down Expand Up @@ -65,7 +65,7 @@ class EsTestConfig {
return {
// Allow setting any individual component(s) of the URL,
// or use default values (username and password from ../kbn/users.js)
protocol: process.env.TEST_ES_PROTOCOL || 'http',
protocol: process.env.TEST_ES_PROTOCOL || ssl ? 'https' : 'http',
hostname: process.env.TEST_ES_HOSTNAME || 'localhost',
port,
auth: `${username}:${password}`,
Expand Down
36 changes: 33 additions & 3 deletions packages/kbn-test/src/es/test_es_cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@

import Path from 'path';
import { format } from 'url';
import Fs from 'fs';
import del from 'del';
// @ts-expect-error in js
import { Cluster } from '@kbn/es';
import { Client } from '@elastic/elasticsearch';
import type { KibanaClient } from '@elastic/elasticsearch/api/kibana';
import type { ToolingLog } from '@kbn/dev-utils';
import { CA_CERT_PATH, ToolingLog } from '@kbn/dev-utils';
import { CI_PARALLEL_PROCESS_PREFIX } from '../ci_parallel_process_prefix';
import { esTestConfig } from './es_test_config';

Expand Down Expand Up @@ -260,6 +261,31 @@ export function createTestEsCluster<
}

async stop() {
await this.getClient()
.search<{
'log.level': string;
message: string;
'elasticsearch.http.request.x_opaque_id': string;
}>(
{ index: '.logs-deprecation.elasticsearch-default', ignore_unavailable: true, size: 100 },
{ ignore: [404] } // The index doesn't exist if there's no deprecation logs
)
.then((res) => {
const deps = res.body.hits.hits
.filter(
(d) => d._source!['elasticsearch.http.request.x_opaque_id'] !== 'kbn-test-client'
)
.map((d) => {
return `ES DEPRECATION ${d._source!['log.level']} ${d._source!.message}`;
});

if (deps.length > 0) {
log.error(`Found ${deps.length} deprecation logs:`);
}
deps.forEach((m) => {
log.error(m);
});
});
const nodeStopPromises = [];
for (let i = 0; i < this.nodes.length; i++) {
nodeStopPromises.push(async () => {
Expand All @@ -283,7 +309,9 @@ export function createTestEsCluster<
*/
getClient(): KibanaClient {
return new Client({
node: this.getHostUrls()[0],
node: this.getHostUrls(),
headers: { 'X-Opaque-Id': 'kbn-test-client' },
...(ssl && { ssl: { ca: Fs.readFileSync(CA_CERT_PATH), rejectUnauthorized: true } }),
});
}

Expand All @@ -308,7 +336,9 @@ export function createTestEsCluster<
* in this list.
*/
getHostUrls(): string[] {
return this.ports.map((p) => format({ ...esTestConfig.getUrlParts(), port: p }));
return this.ports.map((p) =>
format({ ...esTestConfig.getUrlParts(ssl), port: p, protocol: ssl ? 'https' : 'http' })
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elastic/kibana-operations I have to override protocol here because TEST_ES_URL doesn't have the correct protocol. So although this works it feels a bit hacky.

);
}
})() as EsTestCluster<Options>;
}
Expand Down
2 changes: 2 additions & 0 deletions test/common/services/elasticsearch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function ElasticsearchProvider({ getService }: FtrProviderContext): Kiban
return new Client({
nodes: [formatUrl(config.get('servers.elasticsearch'))],
requestTimeout: config.get('timeouts.esRequestTimeout'),
headers: { 'X-Opaque-Id': 'kbn-test-client' },
});
} else {
return new Client({
Expand All @@ -32,6 +33,7 @@ export function ElasticsearchProvider({ getService }: FtrProviderContext): Kiban
},
nodes: [formatUrl(config.get('servers.elasticsearch'))],
requestTimeout: config.get('timeouts.esRequestTimeout'),
headers: { 'X-Opaque-Id': 'kbn-test-client' },
});
}
}