mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[Monitoring] Kibana settings api (#21100)
* Kibana settings api * Use different version of this utility * Adding settings api test * Fix these tests * Update test
This commit is contained in:
parent
2f4dd53dd7
commit
871d283ead
5 changed files with 106 additions and 0 deletions
|
@ -21,6 +21,7 @@ import {
|
|||
CONFIG_TELEMETRY,
|
||||
CONFIG_TELEMETRY_DESC,
|
||||
} from './common/constants';
|
||||
import { settingsRoute } from './server/routes/api/v1/settings';
|
||||
|
||||
export { callClusterFactory } from './server/lib/call_cluster_factory';
|
||||
|
||||
|
@ -110,6 +111,7 @@ export const xpackMain = (kibana) => {
|
|||
// register routes
|
||||
xpackInfoRoute(server);
|
||||
telemetryRoute(server);
|
||||
settingsRoute(server, this.kbnServer);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
50
x-pack/plugins/xpack_main/server/routes/api/v1/settings.js
Normal file
50
x-pack/plugins/xpack_main/server/routes/api/v1/settings.js
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { wrap as wrapError } from 'boom';
|
||||
import { KIBANA_SETTINGS_TYPE } from '../../../../../monitoring/common/constants';
|
||||
import { getKibanaInfoForStats } from '../../../../../monitoring/server/kibana_monitoring/lib';
|
||||
|
||||
const getClusterUuid = async callCluster => {
|
||||
const { cluster_uuid: uuid } = await callCluster('info', { filterPath: 'cluster_uuid', });
|
||||
return uuid;
|
||||
};
|
||||
|
||||
export function settingsRoute(server, kbnServer) {
|
||||
server.route({
|
||||
path: '/api/settings',
|
||||
method: 'GET',
|
||||
async handler(req, reply) {
|
||||
const { server } = req;
|
||||
const { callWithRequest } = server.plugins.elasticsearch.getCluster('data');
|
||||
const callCluster = (...args) => callWithRequest(req, ...args); // All queries from HTTP API must use authentication headers from the request
|
||||
|
||||
try {
|
||||
const { collectorSet } = server.usage;
|
||||
const settingsCollector = collectorSet.getCollectorByType(KIBANA_SETTINGS_TYPE);
|
||||
|
||||
const settings = await settingsCollector.fetch(callCluster);
|
||||
const uuid = await getClusterUuid(callCluster);
|
||||
|
||||
const kibana = getKibanaInfoForStats(server, kbnServer);
|
||||
reply({
|
||||
cluster_uuid: uuid,
|
||||
settings: {
|
||||
...settings,
|
||||
kibana,
|
||||
}
|
||||
});
|
||||
} catch(err) {
|
||||
req.log(['error'], err); // FIXME doesn't seem to log anything useful if ES times out
|
||||
if (err.isBoom) {
|
||||
reply(err);
|
||||
} else {
|
||||
reply(wrapError(err, err.statusCode, err.message));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
|
@ -7,5 +7,6 @@
|
|||
export default function ({ loadTestFile }) {
|
||||
describe('xpack_main', () => {
|
||||
loadTestFile(require.resolve('./telemetry'));
|
||||
loadTestFile(require.resolve('./settings'));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
export default function ({ loadTestFile }) {
|
||||
describe('Settings', () => {
|
||||
loadTestFile(require.resolve('./settings'));
|
||||
});
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License;
|
||||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import expect from 'expect.js';
|
||||
|
||||
export default function ({ getService }) {
|
||||
const supertest = getService('supertest');
|
||||
const esArchiver = getService('esArchiver');
|
||||
|
||||
describe('/api/settings', () => {
|
||||
describe('with trial license clusters', () => {
|
||||
const archive = 'monitoring/multicluster';
|
||||
|
||||
before('load clusters archive', () => {
|
||||
return esArchiver.load(archive);
|
||||
});
|
||||
|
||||
after('unload clusters archive', () => {
|
||||
return esArchiver.unload(archive);
|
||||
});
|
||||
|
||||
it('should load multiple clusters', async () => {
|
||||
const { body } = await supertest
|
||||
.get('/api/settings')
|
||||
.set('kbn-xsrf', 'xxx')
|
||||
.expect(200);
|
||||
expect(body.cluster_uuid.length > 1).to.eql(true);
|
||||
expect(body.settings.kibana.uuid.length > 0).to.eql(true);
|
||||
expect(body.settings.kibana.name.length > 0).to.eql(true);
|
||||
expect(body.settings.kibana.index.length > 0).to.eql(true);
|
||||
expect(body.settings.kibana.host.length > 0).to.eql(true);
|
||||
expect(body.settings.kibana.transport_address.length > 0).to.eql(true);
|
||||
expect(body.settings.kibana.version.length > 0).to.eql(true);
|
||||
expect(body.settings.kibana.status.length > 0).to.eql(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue