Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions x-pack/plugins/xpack_main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -110,6 +111,7 @@ export const xpackMain = (kibana) => {
// register routes
xpackInfoRoute(server);
telemetryRoute(server);
settingsRoute(server, this.kbnServer);
}
});
};
52 changes: 52 additions & 0 deletions x-pack/plugins/xpack_main/server/routes/api/v1/settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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 { getKibanaInfoForStats } from '../../../../../../../src/server/status/lib';
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like CI is failing on this line:

15:25:10    │ debg   error  [22:25:10.553] [fatal] Error: Cannot find module '../../../../../../../src/server/status/lib'
15:25:10    │ debg      at Function.Module._resolveFilename (module.js:547:15)
15:25:10    │ debg      at Function.Module._load (module.js:474:25)
15:25:10    │ debg      at Module.require (module.js:596:17)
15:25:10    │ debg      at require (internal/module.js:11:18)
15:25:10    │ debg      at Object.<anonymous> (/var/lib/jenkins/workspace/elastic+kibana+pull-request+multijob-x-pack/kibana/build/kibana/node_modules/x-pack/plugins/xpack_main/server/routes/api/v1/settings.js:8:1)
...

import { KIBANA_SETTINGS_TYPE } from '../../../../../monitoring/common/constants';

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);

console.log('uuid', uuid);
Copy link
Contributor

Choose a reason for hiding this comment

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

Debugging statement.


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
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this FIXME for addressing in this PR itself or a follow up PR?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good question. It's a comment copied over from the other api endpoint. Let's say it will be addressed in a follow up PR

Copy link
Member

Choose a reason for hiding this comment

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

I suspect the follow PR would need to address this problem everywhere

if (err.isBoom) {
reply(err);
} else {
reply(wrapError(err, err.statusCode, err.message));
}
}
}
});
}