Skip to content

Commit abeeefa

Browse files
Merge branch '7.x' into backport/7.x/pr-64809
2 parents 7e8c287 + 1c0e76b commit abeeefa

File tree

29 files changed

+262
-111
lines changed

29 files changed

+262
-111
lines changed

.eslintignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ target
2525
/src/plugins/vis_type_timelion/public/_generated_/**
2626
/src/plugins/vis_type_timelion/public/webpackShims/jquery.flot.*
2727
/x-pack/legacy/plugins/**/__tests__/fixtures/**
28-
/x-pack/legacy/plugins/apm/e2e/cypress/**/snapshots.js
28+
/x-pack/plugins/apm/e2e/cypress/**/snapshots.js
2929
/x-pack/legacy/plugins/canvas/canvas_plugin
3030
/x-pack/legacy/plugins/canvas/canvas_plugin_src/lib/flot-charts
3131
/x-pack/legacy/plugins/canvas/shareable_runtime/build

.eslintrc.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ module.exports = {
310310
{
311311
files: [
312312
'x-pack/test/functional/apps/**/*.js',
313-
'x-pack/legacy/plugins/apm/**/*.js',
313+
'x-pack/plugins/apm/**/*.js',
314314
'test/*/config.ts',
315315
'test/*/config_open.ts',
316316
'test/*/{tests,test_suites,apis,apps}/**/*',
@@ -397,7 +397,7 @@ module.exports = {
397397
'x-pack/**/*.test.js',
398398
'x-pack/test_utils/**/*',
399399
'x-pack/gulpfile.js',
400-
'x-pack/legacy/plugins/apm/public/utils/testHelpers.js',
400+
'x-pack/plugins/apm/public/utils/testHelpers.js',
401401
],
402402
rules: {
403403
'import/no-extraneous-dependencies': [
@@ -523,15 +523,15 @@ module.exports = {
523523
* APM overrides
524524
*/
525525
{
526-
files: ['x-pack/legacy/plugins/apm/**/*.js'],
526+
files: ['x-pack/plugins/apm/**/*.js'],
527527
rules: {
528528
'no-unused-vars': ['error', { ignoreRestSiblings: true }],
529529
'no-console': ['warn', { allow: ['error'] }],
530530
},
531531
},
532532
{
533533
plugins: ['react-hooks'],
534-
files: ['x-pack/legacy/plugins/apm/**/*.{ts,tsx}'],
534+
files: ['x-pack/plugins/apm/**/*.{ts,tsx}'],
535535
rules: {
536536
'react-hooks/rules-of-hooks': 'error', // Checks rules of Hooks
537537
'react-hooks/exhaustive-deps': ['error', { additionalHooks: '^useFetcher$' }],

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,6 @@ package-lock.json
4444
*.sublime-*
4545
npm-debug.log*
4646
.tern-project
47-
x-pack/legacy/plugins/apm/tsconfig.json
47+
x-pack/plugins/apm/tsconfig.json
4848
apm.tsconfig.json
49-
/x-pack/legacy/plugins/apm/e2e/snapshots.js
49+
/x-pack/plugins/apm/e2e/snapshots.js
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
import { decodeCloudId } from './decode_cloud_id';
7+
8+
describe('Ingest Manager - decodeCloudId', () => {
9+
it('parses various CloudID formats', () => {
10+
const tests = [
11+
{
12+
cloudID:
13+
'staging:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyRjZWM2ZjI2MWE3NGJmMjRjZTMzYmI4ODExYjg0Mjk0ZiRjNmMyY2E2ZDA0MjI0OWFmMGNjN2Q3YTllOTYyNTc0Mw==',
14+
expectedEsURL: 'https://cec6f261a74bf24ce33bb8811b84294f.us-east-1.aws.found.io:443',
15+
expectedKibanaURL: 'https://c6c2ca6d042249af0cc7d7a9e9625743.us-east-1.aws.found.io:443',
16+
},
17+
{
18+
cloudID:
19+
'dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyRjZWM2ZjI2MWE3NGJmMjRjZTMzYmI4ODExYjg0Mjk0ZiRjNmMyY2E2ZDA0MjI0OWFmMGNjN2Q3YTllOTYyNTc0Mw==',
20+
expectedEsURL: 'https://cec6f261a74bf24ce33bb8811b84294f.us-east-1.aws.found.io:443',
21+
expectedKibanaURL: 'https://c6c2ca6d042249af0cc7d7a9e9625743.us-east-1.aws.found.io:443',
22+
},
23+
{
24+
cloudID:
25+
':dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyRjZWM2ZjI2MWE3NGJmMjRjZTMzYmI4ODExYjg0Mjk0ZiRjNmMyY2E2ZDA0MjI0OWFmMGNjN2Q3YTllOTYyNTc0Mw==',
26+
expectedEsURL: 'https://cec6f261a74bf24ce33bb8811b84294f.us-east-1.aws.found.io:443',
27+
expectedKibanaURL: 'https://c6c2ca6d042249af0cc7d7a9e9625743.us-east-1.aws.found.io:443',
28+
},
29+
{
30+
cloudID:
31+
'gcp-cluster:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvJDhhMDI4M2FmMDQxZjE5NWY3NzI5YmMwNGM2NmEwZmNlJDBjZDVjZDU2OGVlYmU1M2M4OWViN2NhZTViYWM4YjM3',
32+
expectedEsURL: 'https://8a0283af041f195f7729bc04c66a0fce.us-central1.gcp.cloud.es.io:443',
33+
expectedKibanaURL:
34+
'https://0cd5cd568eebe53c89eb7cae5bac8b37.us-central1.gcp.cloud.es.io:443',
35+
},
36+
{
37+
cloudID:
38+
'custom-port:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvOjkyNDMkYWMzMWViYjkwMjQxNzczMTU3MDQzYzM0ZmQyNmZkNDYkYTRjMDYyMzBlNDhjOGZjZTdiZTg4YTA3NGEzYmIzZTA=',
39+
expectedEsURL: 'https://ac31ebb90241773157043c34fd26fd46.us-central1.gcp.cloud.es.io:9243',
40+
expectedKibanaURL:
41+
'https://a4c06230e48c8fce7be88a074a3bb3e0.us-central1.gcp.cloud.es.io:9243',
42+
},
43+
{
44+
cloudID:
45+
'different-es-kb-port:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvJGFjMzFlYmI5MDI0MTc3MzE1NzA0M2MzNGZkMjZmZDQ2OjkyNDMkYTRjMDYyMzBlNDhjOGZjZTdiZTg4YTA3NGEzYmIzZTA6OTI0NA==',
46+
expectedEsURL: 'https://ac31ebb90241773157043c34fd26fd46.us-central1.gcp.cloud.es.io:9243',
47+
expectedKibanaURL:
48+
'https://a4c06230e48c8fce7be88a074a3bb3e0.us-central1.gcp.cloud.es.io:9244',
49+
},
50+
{
51+
cloudID:
52+
'only-kb-set:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvJGFjMzFlYmI5MDI0MTc3MzE1NzA0M2MzNGZkMjZmZDQ2JGE0YzA2MjMwZTQ4YzhmY2U3YmU4OGEwNzRhM2JiM2UwOjkyNDQ=',
53+
expectedEsURL: 'https://ac31ebb90241773157043c34fd26fd46.us-central1.gcp.cloud.es.io:443',
54+
expectedKibanaURL:
55+
'https://a4c06230e48c8fce7be88a074a3bb3e0.us-central1.gcp.cloud.es.io:9244',
56+
},
57+
{
58+
cloudID:
59+
'host-and-kb-set:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvOjkyNDMkYWMzMWViYjkwMjQxNzczMTU3MDQzYzM0ZmQyNmZkNDYkYTRjMDYyMzBlNDhjOGZjZTdiZTg4YTA3NGEzYmIzZTA6OTI0NA==',
60+
expectedEsURL: 'https://ac31ebb90241773157043c34fd26fd46.us-central1.gcp.cloud.es.io:9243',
61+
expectedKibanaURL:
62+
'https://a4c06230e48c8fce7be88a074a3bb3e0.us-central1.gcp.cloud.es.io:9244',
63+
},
64+
{
65+
cloudID:
66+
'extra-items:dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvJGFjMzFlYmI5MDI0MTc3MzE1NzA0M2MzNGZkMjZmZDQ2JGE0YzA2MjMwZTQ4YzhmY2U3YmU4OGEwNzRhM2JiM2UwJGFub3RoZXJpZCRhbmRhbm90aGVy',
67+
expectedEsURL: 'https://ac31ebb90241773157043c34fd26fd46.us-central1.gcp.cloud.es.io:443',
68+
expectedKibanaURL:
69+
'https://a4c06230e48c8fce7be88a074a3bb3e0.us-central1.gcp.cloud.es.io:443',
70+
},
71+
];
72+
73+
for (const test of tests) {
74+
const decoded = decodeCloudId(test.cloudID);
75+
expect(decoded).toBeTruthy();
76+
expect(decoded?.elasticsearchUrl === test.expectedEsURL).toBe(true);
77+
expect(decoded?.kibanaUrl === test.expectedKibanaURL).toBe(true);
78+
}
79+
});
80+
81+
it('returns undefined for invalid formats', () => {
82+
const tests = [
83+
{
84+
cloudID:
85+
'staging:garbagedXMtZWFzdC0xLmF3cy5mb3VuZC5pbyRjZWM2ZjI2MWE3NGJmMjRjZTMzYmI4ODExYjg0Mjk0ZiRjNmMyY2E2ZDA0MjI0OWFmMGNjN2Q3YTllOTYyNTc0Mw==',
86+
errorMsg: 'base64 decoding failed',
87+
},
88+
{
89+
cloudID: 'dXMtY2VudHJhbDEuZ2NwLmNsb3VkLmVzLmlvJDhhMDI4M2FmMDQxZjE5NWY3NzI5YmMwNGM2NmEwZg==',
90+
errorMsg: 'Expected at least 3 parts',
91+
},
92+
];
93+
94+
for (const test of tests) {
95+
const decoded = decodeCloudId(test.cloudID);
96+
expect(decoded).toBe(undefined);
97+
// decodeCloudId currently only logs; not throws errors
98+
}
99+
});
100+
});
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License;
4+
* you may not use this file except in compliance with the Elastic License.
5+
*/
6+
7+
// decodeCloudId decodes the c.id into c.esURL and c.kibURL
8+
export function decodeCloudId(
9+
cid: string
10+
):
11+
| {
12+
host: string;
13+
defaultPort: string;
14+
elasticsearchUrl: string;
15+
kibanaUrl: string;
16+
}
17+
| undefined {
18+
// 1. Ignore anything before `:`.
19+
const id = cid.split(':').pop();
20+
if (!id) {
21+
// throw new Error(`Unable to decode ${id}`);
22+
// eslint-disable-next-line no-console
23+
console.debug(`Unable to decode ${id}`);
24+
return;
25+
}
26+
27+
// 2. base64 decode
28+
let decoded: string | undefined;
29+
try {
30+
decoded = Buffer.from(id, 'base64').toString('utf8');
31+
} catch {
32+
// throw new Error(`base64 decoding failed on ${id}`);
33+
// eslint-disable-next-line no-console
34+
console.debug(`base64 decoding failed on ${id}`);
35+
return;
36+
}
37+
38+
// 3. separate based on `$`
39+
const words = decoded.split('$');
40+
if (words.length < 3) {
41+
// throw new Error(`Expected at least 3 parts in ${decoded}`);
42+
// eslint-disable-next-line no-console
43+
console.debug(`Expected at least 3 parts in ${decoded}`);
44+
return;
45+
}
46+
// 4. extract port from the ES and Kibana host
47+
const [host, defaultPort] = extractPortFromName(words[0]);
48+
const [esId, esPort] = extractPortFromName(words[1], defaultPort);
49+
const [kbId, kbPort] = extractPortFromName(words[2], defaultPort);
50+
// 5. form the URLs
51+
const esUrl = `https://${esId}.${host}:${esPort}`;
52+
const kbUrl = `https://${kbId}.${host}:${kbPort}`;
53+
return {
54+
host,
55+
defaultPort,
56+
elasticsearchUrl: esUrl,
57+
kibanaUrl: kbUrl,
58+
};
59+
}
60+
// extractPortFromName takes a string in the form `id:port` and returns the
61+
// Id and the port. If there's no `:`, the default port is returned
62+
function extractPortFromName(word: string, defaultPort = '443') {
63+
const [host, port = defaultPort] = word.split(':');
64+
return [host, port];
65+
}

x-pack/plugins/ingest_manager/common/services/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ export * from './routes';
99
export { packageToConfigDatasourceInputs, packageToConfigDatasource } from './package_to_config';
1010
export { storedDatasourceToAgentDatasource } from './datasource_to_agent_datasource';
1111
export { AgentStatusKueryHelper };
12+
export { decodeCloudId } from './decode_cloud_id';

x-pack/plugins/ingest_manager/common/types/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ export interface IngestManagerConfigType {
1515
fleet: {
1616
enabled: boolean;
1717
tlsCheckDisabled: boolean;
18-
defaultOutputHost: string;
1918
kibana: {
2019
host?: string;
2120
ca_sha256?: string;

x-pack/plugins/ingest_manager/server/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const config = {
3232
ca_sha256: schema.maybe(schema.string()),
3333
}),
3434
elasticsearch: schema.object({
35-
host: schema.string({ defaultValue: 'http://localhost:9200' }),
35+
host: schema.maybe(schema.string()),
3636
ca_sha256: schema.maybe(schema.string()),
3737
}),
3838
}),

x-pack/plugins/ingest_manager/server/plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ export class IngestManagerPlugin
165165
const config = await this.config$.pipe(first()).toPromise();
166166

167167
// Register routes
168+
registerSetupRoutes(router, config);
168169
registerAgentConfigRoutes(router);
169170
registerDatasourceRoutes(router);
170171
registerOutputRoutes(router);
@@ -177,7 +178,6 @@ export class IngestManagerPlugin
177178
}
178179

179180
if (config.fleet.enabled) {
180-
registerSetupRoutes(router);
181181
registerAgentRoutes(router);
182182
registerEnrollmentApiKeyRoutes(router);
183183
registerInstallScriptRoutes({

x-pack/plugins/ingest_manager/server/routes/setup/index.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
import { IRouter } from 'src/core/server';
77

88
import { PLUGIN_ID, FLEET_SETUP_API_ROUTES, SETUP_API_ROUTE } from '../../constants';
9+
import { IngestManagerConfigType } from '../../../common';
910
import {
1011
getFleetStatusHandler,
1112
createFleetSetupHandler,
1213
ingestManagerSetupHandler,
1314
} from './handlers';
1415

15-
export const registerRoutes = (router: IRouter) => {
16+
export const registerRoutes = (router: IRouter, config: IngestManagerConfigType) => {
1617
// Ingest manager setup
1718
router.post(
1819
{
@@ -24,6 +25,11 @@ export const registerRoutes = (router: IRouter) => {
2425
},
2526
ingestManagerSetupHandler
2627
);
28+
29+
if (!config.fleet.enabled) {
30+
return;
31+
}
32+
2733
// Get Fleet setup
2834
router.get(
2935
{

0 commit comments

Comments
 (0)