Remove xpack usage module (#21099)

This commit is contained in:
Tim Sullivan 2018-07-24 08:52:29 -07:00 committed by GitHub
parent 3bc65f142c
commit 5caf9f2baa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,54 +0,0 @@
/*
* 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';
const getClusterUuid = async callCluster => {
const { cluster_uuid: uuid } = await callCluster('info', { filterPath: 'cluster_uuid', });
return uuid;
};
/*
* @return {Object} data from usage stats collectors registered with Monitoring CollectorSet
* @throws {Error} if the Monitoring CollectorSet is not ready
*/
const getUsage = async (callCluster, server) => {
const { collectorSet } = server.usage;
const usage = await collectorSet.bulkFetchUsage(callCluster);
const usageObject = collectorSet.toObject(usage);
return collectorSet.toApiFieldNames(usageObject);
};
export function xpackUsageRoute(server) {
server.route({
path: '/api/_xpack/usage',
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 [ clusterUuid, xpackUsage ] = await Promise.all([
getClusterUuid(callCluster),
getUsage(callCluster, server),
]);
reply({
cluster_uuid: clusterUuid,
...xpackUsage
});
} 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));
}
}
}
});
}