From 0cd9a45ccaf99ac903a48fa3b91735d77508319f Mon Sep 17 00:00:00 2001 From: Tim Sullivan Date: Thu, 19 Jul 2018 13:46:52 -0700 Subject: [PATCH] Remove /api/_xpack/usage and /api/_kibana/v1/stats (#20800) /api/_xpack/usage was added as a target for 6.4.0 but it will not be used. Instead, the /api/stats response will include usage info on everything that gets registered with the usage service in /src/server/usage /api/_kibana/v1/stats is a GET API that was added in 6.2, during a point where we thought providing usage stats through a public API would be OK for capturing internally, with the benefit of having it be visible. However, we've pivoted away from that idea because it doesn't line up too well with the existing flow of data, where usage stats are combined with the "Kibana stats" such as process uptime and number of requests. We want to shift how we collect stats from Kibana, but it will be gradual. It might be a while before we have an architecture that makes sense for a standalone public API for the usage stats This endpoint was never documented, and isn't used anywhere in the code. It does incur a maintenance cost though. Therefore, instead of waiting for a next major version to remove this API, I'm removing it for 6.4. It will be marked in the release notes as a breaking change. Since it was never documented, it should not provide a problem. --- .../api_debug/apis/kibana_stats/index.js | 4 +- x-pack/plugins/xpack_main/index.js | 4 -- .../xpack_main/server/routes/api/v1/index.js | 2 - .../server/routes/api/v1/kibana_stats.js | 47 ------------------- .../api_integration/apis/xpack_main/index.js | 1 - .../apis/xpack_main/usage/index.js | 12 ----- .../apis/xpack_main/usage/usage.js | 39 --------------- .../api_integration/services/usage_api.js | 16 ++----- x-pack/test/reporting/api/usage.js | 24 ---------- 9 files changed, 6 insertions(+), 143 deletions(-) delete mode 100644 x-pack/plugins/xpack_main/server/routes/api/v1/kibana_stats.js delete mode 100644 x-pack/test/api_integration/apis/xpack_main/usage/index.js delete mode 100644 x-pack/test/api_integration/apis/xpack_main/usage/usage.js diff --git a/x-pack/dev-tools/api_debug/apis/kibana_stats/index.js b/x-pack/dev-tools/api_debug/apis/kibana_stats/index.js index 9a8aac93d5017..14857a5e29e3c 100644 --- a/x-pack/dev-tools/api_debug/apis/kibana_stats/index.js +++ b/x-pack/dev-tools/api_debug/apis/kibana_stats/index.js @@ -5,6 +5,6 @@ */ export const name = 'kibana_stats'; -export const description = 'Get the Kibana usage stats from the Kibana server'; +export const description = 'Get the extended Kibana usage stats from the Kibana server'; export const method = 'GET'; -export const path = '/api/_kibana/v1/stats'; +export const path = '/api/stats?extended=true'; diff --git a/x-pack/plugins/xpack_main/index.js b/x-pack/plugins/xpack_main/index.js index d5b4fe4804da1..07adba08b2524 100644 --- a/x-pack/plugins/xpack_main/index.js +++ b/x-pack/plugins/xpack_main/index.js @@ -15,8 +15,6 @@ import { replaceInjectedVars } from './server/lib/replace_injected_vars'; import { setupXPackMain } from './server/lib/setup_xpack_main'; import { xpackInfoRoute, - xpackUsageRoute, - kibanaStatsRoute, telemetryRoute, } from './server/routes/api/v1'; import { @@ -111,8 +109,6 @@ export const xpackMain = (kibana) => { // register routes xpackInfoRoute(server); - xpackUsageRoute(server); // To replace kibanaStatsRoute - kibanaStatsRoute(server); // Only used internally. Remove in the next major. telemetryRoute(server); } }); diff --git a/x-pack/plugins/xpack_main/server/routes/api/v1/index.js b/x-pack/plugins/xpack_main/server/routes/api/v1/index.js index 9bedeaf371e29..cb565ee8129b6 100644 --- a/x-pack/plugins/xpack_main/server/routes/api/v1/index.js +++ b/x-pack/plugins/xpack_main/server/routes/api/v1/index.js @@ -5,6 +5,4 @@ */ export { xpackInfoRoute } from './xpack_info'; -export { kibanaStatsRoute } from './kibana_stats'; -export { xpackUsageRoute } from './xpack_usage'; export { telemetryRoute } from './telemetry'; diff --git a/x-pack/plugins/xpack_main/server/routes/api/v1/kibana_stats.js b/x-pack/plugins/xpack_main/server/routes/api/v1/kibana_stats.js deleted file mode 100644 index 0ee49cb07214b..0000000000000 --- a/x-pack/plugins/xpack_main/server/routes/api/v1/kibana_stats.js +++ /dev/null @@ -1,47 +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. - */ - -/* - * TODO: remove this API in 7.0 - */ -import { wrap } from 'boom'; -import { callClusterFactory } from '../../../lib/call_cluster_factory'; -import { getKibanaUsageCollector } from '../../../../../monitoring/server/kibana_monitoring/collectors'; -import { getReportingUsageCollector } from '../../../../../reporting/server/usage'; - -export function kibanaStatsRoute(server) { - server.route({ - path: '/api/_kibana/v1/stats', - method: 'GET', - handler: async (req, reply) => { - const server = req.server; - // require that http authentication headers from req are used to read ES data - const callCluster = callClusterFactory(server).getCallClusterWithReq(req); - - try { - const kibanaUsageCollector = getKibanaUsageCollector(server); - const reportingUsageCollector = getReportingUsageCollector(server); - - const [ kibana, reporting ] = await Promise.all([ - kibanaUsageCollector.fetch(callCluster), - reportingUsageCollector.fetch(callCluster), - ]); - - reply({ - kibana, - reporting, - }); - } catch(err) { - req.log(['error'], err); - - if (err.isBoom) { - return reply(err); - } - reply(wrap(err, err.statusCode, err.message)); - } - } - }); -} diff --git a/x-pack/test/api_integration/apis/xpack_main/index.js b/x-pack/test/api_integration/apis/xpack_main/index.js index 696e027b52eeb..48af7b25eefe7 100644 --- a/x-pack/test/api_integration/apis/xpack_main/index.js +++ b/x-pack/test/api_integration/apis/xpack_main/index.js @@ -7,6 +7,5 @@ export default function ({ loadTestFile }) { describe('xpack_main', () => { loadTestFile(require.resolve('./telemetry')); - loadTestFile(require.resolve('./usage')); }); } diff --git a/x-pack/test/api_integration/apis/xpack_main/usage/index.js b/x-pack/test/api_integration/apis/xpack_main/usage/index.js deleted file mode 100644 index 1c342deade18a..0000000000000 --- a/x-pack/test/api_integration/apis/xpack_main/usage/index.js +++ /dev/null @@ -1,12 +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. - */ - -export default function ({ loadTestFile }) { - describe('X-Pack Usage', () => { - loadTestFile(require.resolve('./usage')); - }); -} - diff --git a/x-pack/test/api_integration/apis/xpack_main/usage/usage.js b/x-pack/test/api_integration/apis/xpack_main/usage/usage.js deleted file mode 100644 index 24f572f99d52c..0000000000000 --- a/x-pack/test/api_integration/apis/xpack_main/usage/usage.js +++ /dev/null @@ -1,39 +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 expect from 'expect.js'; - -export default function ({ getService }) { - const esArchiver = getService('esArchiver'); - const usageAPI = getService('usageAPI'); - - describe('/api/_xpack/usage', () => { - before('load archives', async () => { - await esArchiver.load('../../../../test/functional/fixtures/es_archiver/dashboard/current/kibana'); - }); - - after(async () => { - await esArchiver.unload('../../../../test/functional/fixtures/es_archiver/dashboard/current/kibana'); - }); - - it('should reject without authentication headers passed', async () => { - const rejected = await usageAPI.getUsageStatsNoAuth(); - expect(rejected).to.eql({ statusCode: 401, error: 'Unauthorized' }); - }); - - it('should return xpack usage data', async () => { - const usage = await usageAPI.getUsageStats(); - - expect(usage.cluster_uuid).to.be.a('string'); - expect(usage.kibana.dashboard.total).to.be(26); - expect(usage.kibana.visualization.total).to.be(47); - expect(usage.kibana.search.total).to.be(5); - expect(usage.kibana.index_pattern.total).to.be(3); - expect(usage.kibana.timelion_sheet.total).to.be(0); - expect(usage.kibana.graph_workspace.total).to.be(0); - }); - }); -} diff --git a/x-pack/test/api_integration/services/usage_api.js b/x-pack/test/api_integration/services/usage_api.js index 7a53fbfe9391c..e58db15ae86f6 100644 --- a/x-pack/test/api_integration/services/usage_api.js +++ b/x-pack/test/api_integration/services/usage_api.js @@ -12,26 +12,18 @@ export function UsageAPIProvider({ getService }) { return { async getUsageStatsNoAuth() { const { body } = await supertestNoAuth - .get('/api/_xpack/usage') + .get('/api/stats?extended=true') .set('kbn-xsrf', 'xxx') .expect(401); - return body; + return body.usage; }, async getUsageStats() { const { body } = await supertest - .get('/api/_xpack/usage') + .get('/api/stats?extended=true') .set('kbn-xsrf', 'xxx') .expect(200); - return body; - }, - - async getUsageStatsFromDeprecatedPre64Endpoint() { - const { body } = await supertest - .get('/api/_kibana/v1/stats') - .set('kbn-xsrf', 'xxx') - .expect(200); - return body; + return body.usage; }, }; } diff --git a/x-pack/test/reporting/api/usage.js b/x-pack/test/reporting/api/usage.js index 8bfed1b2d5594..a2c207c76f63a 100644 --- a/x-pack/test/reporting/api/usage.js +++ b/x-pack/test/reporting/api/usage.js @@ -123,29 +123,5 @@ export default function ({ getService }) { reportingAPI.expectAllTimeJobTypeTotalStats(usage, 'printable_pdf', 23); }); }); - - /* Have to skip this test because the usage stats returned by the legacy - * endpoint aren't snake_cased in the legacy usage api. This will be - * completely removed in the next PR, when the legacy endpoint is removed - */ - describe.skip('deprecated API', () => { - it('shows correct stats', async () => { - const usage = await usageAPI.getUsageStatsFromDeprecatedPre64Endpoint(); - - reportingAPI.expectRecentPdfAppStats(usage, 'visualization', 2); - reportingAPI.expectRecentPdfAppStats(usage, 'dashboard', 2); - reportingAPI.expectRecentPdfLayoutStats(usage, 'preserve_layout', 2); - reportingAPI.expectRecentPdfLayoutStats(usage, 'print', 2); - reportingAPI.expectRecentJobTypeTotalStats(usage, 'csv', 1); - reportingAPI.expectRecentJobTypeTotalStats(usage, 'printable_pdf', 4); - - reportingAPI.expectAllTimePdfAppStats(usage, 'visualization', 5); - reportingAPI.expectAllTimePdfAppStats(usage, 'dashboard', 5); - reportingAPI.expectAllTimePdfLayoutStats(usage, 'preserve_layout', 5); - reportingAPI.expectAllTimePdfLayoutStats(usage, 'print', 5); - reportingAPI.expectAllTimeJobTypeTotalStats(usage, 'csv', 4); - reportingAPI.expectAllTimeJobTypeTotalStats(usage, 'printable_pdf', 23); - }); - }); }); }