Skip to content

Commit cf03af7

Browse files
authored
[Monitoring] Kibana settings api (#21100) (#21742)
* Kibana settings api * Use different version of this utility * Adding settings api test * Fix these tests * Update test
1 parent 5be6038 commit cf03af7

File tree

5 files changed

+106
-0
lines changed

5 files changed

+106
-0
lines changed

x-pack/plugins/xpack_main/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
CONFIG_TELEMETRY,
2222
CONFIG_TELEMETRY_DESC,
2323
} from './common/constants';
24+
import { settingsRoute } from './server/routes/api/v1/settings';
2425

2526
export { callClusterFactory } from './server/lib/call_cluster_factory';
2627

@@ -110,6 +111,7 @@ export const xpackMain = (kibana) => {
110111
// register routes
111112
xpackInfoRoute(server);
112113
telemetryRoute(server);
114+
settingsRoute(server, this.kbnServer);
113115
}
114116
});
115117
};
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
import { wrap as wrapError } from 'boom';
8+
import { KIBANA_SETTINGS_TYPE } from '../../../../../monitoring/common/constants';
9+
import { getKibanaInfoForStats } from '../../../../../monitoring/server/kibana_monitoring/lib';
10+
11+
const getClusterUuid = async callCluster => {
12+
const { cluster_uuid: uuid } = await callCluster('info', { filterPath: 'cluster_uuid', });
13+
return uuid;
14+
};
15+
16+
export function settingsRoute(server, kbnServer) {
17+
server.route({
18+
path: '/api/settings',
19+
method: 'GET',
20+
async handler(req, reply) {
21+
const { server } = req;
22+
const { callWithRequest } = server.plugins.elasticsearch.getCluster('data');
23+
const callCluster = (...args) => callWithRequest(req, ...args); // All queries from HTTP API must use authentication headers from the request
24+
25+
try {
26+
const { collectorSet } = server.usage;
27+
const settingsCollector = collectorSet.getCollectorByType(KIBANA_SETTINGS_TYPE);
28+
29+
const settings = await settingsCollector.fetch(callCluster);
30+
const uuid = await getClusterUuid(callCluster);
31+
32+
const kibana = getKibanaInfoForStats(server, kbnServer);
33+
reply({
34+
cluster_uuid: uuid,
35+
settings: {
36+
...settings,
37+
kibana,
38+
}
39+
});
40+
} catch(err) {
41+
req.log(['error'], err); // FIXME doesn't seem to log anything useful if ES times out
42+
if (err.isBoom) {
43+
reply(err);
44+
} else {
45+
reply(wrapError(err, err.statusCode, err.message));
46+
}
47+
}
48+
}
49+
});
50+
}

x-pack/test/api_integration/apis/xpack_main/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@
77
export default function ({ loadTestFile }) {
88
describe('xpack_main', () => {
99
loadTestFile(require.resolve('./telemetry'));
10+
loadTestFile(require.resolve('./settings'));
1011
});
1112
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
export default function ({ loadTestFile }) {
8+
describe('Settings', () => {
9+
loadTestFile(require.resolve('./settings'));
10+
});
11+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
import expect from 'expect.js';
8+
9+
export default function ({ getService }) {
10+
const supertest = getService('supertest');
11+
const esArchiver = getService('esArchiver');
12+
13+
describe('/api/settings', () => {
14+
describe('with trial license clusters', () => {
15+
const archive = 'monitoring/multicluster';
16+
17+
before('load clusters archive', () => {
18+
return esArchiver.load(archive);
19+
});
20+
21+
after('unload clusters archive', () => {
22+
return esArchiver.unload(archive);
23+
});
24+
25+
it('should load multiple clusters', async () => {
26+
const { body } = await supertest
27+
.get('/api/settings')
28+
.set('kbn-xsrf', 'xxx')
29+
.expect(200);
30+
expect(body.cluster_uuid.length > 1).to.eql(true);
31+
expect(body.settings.kibana.uuid.length > 0).to.eql(true);
32+
expect(body.settings.kibana.name.length > 0).to.eql(true);
33+
expect(body.settings.kibana.index.length > 0).to.eql(true);
34+
expect(body.settings.kibana.host.length > 0).to.eql(true);
35+
expect(body.settings.kibana.transport_address.length > 0).to.eql(true);
36+
expect(body.settings.kibana.version.length > 0).to.eql(true);
37+
expect(body.settings.kibana.status.length > 0).to.eql(true);
38+
});
39+
});
40+
});
41+
}
42+

0 commit comments

Comments
 (0)