mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
* [Telemetry] collect xpack.cloud details (#31180) * collect xpack.cloud details * add elasticsearch cluster uuid * remove cloud ID from telemetry stats * remove esUUID from telemtry stats * add stack_stats.kibana.plugins.cloud.isCloudEnabled
This commit is contained in:
parent
4e0b72d035
commit
a5537ee3b4
4 changed files with 110 additions and 0 deletions
7
x-pack/plugins/cloud/constants.ts
Normal file
7
x-pack/plugins/cloud/constants.ts
Normal file
|
@ -0,0 +1,7 @@
|
|||
/*
|
||||
* 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 const KIBANA_CLOUD_STATS_TYPE = 'cloud';
|
58
x-pack/plugins/cloud/get_cloud_usage_collector.test.ts
Normal file
58
x-pack/plugins/cloud/get_cloud_usage_collector.test.ts
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*
|
||||
* 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 sinon from 'sinon';
|
||||
import {
|
||||
createCollectorFetch,
|
||||
getCloudUsageCollector,
|
||||
KibanaHapiServer,
|
||||
} from './get_cloud_usage_collector';
|
||||
|
||||
const CLOUD_ID_STAGING =
|
||||
'staging:dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyRjZWM2ZjI2MWE3NGJmMjRjZTMzYmI4ODExYjg0Mjk0ZiRjNmMyY2E2ZDA0MjI0OWFmMGNjN2Q3YTllOTYyNTc0Mw==';
|
||||
const CLOUD_ID =
|
||||
'dXMtZWFzdC0xLmF3cy5mb3VuZC5pbyRjZWM2ZjI2MWE3NGJmMjRjZTMzYmI4ODExYjg0Mjk0ZiRjNmMyY2E2ZDA0MjI0OWFmMGNjN2Q3YTllOTYyNTc0Mw==';
|
||||
|
||||
const getMockServer = (cloudId?: string) => ({
|
||||
usage: { collectorSet: { makeUsageCollector: sinon.stub() } },
|
||||
config() {
|
||||
return {
|
||||
get(path: string) {
|
||||
switch (path) {
|
||||
case 'xpack.cloud':
|
||||
return { id: cloudId };
|
||||
default:
|
||||
throw Error(`server.config().get(${path}) should not be called by this collector.`);
|
||||
}
|
||||
},
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
describe('Cloud usage collector', () => {
|
||||
describe('collector', () => {
|
||||
it('returns `isCloudEnabled: false` if `xpack.cloud.id` is not defined', async () => {
|
||||
const collector = await createCollectorFetch(getMockServer())();
|
||||
expect(collector.isCloudEnabled).toBe(false);
|
||||
});
|
||||
|
||||
it('returns `isCloudEnabled: true` if `xpack.cloud.id` is defined', async () => {
|
||||
const stagingCollector = await createCollectorFetch(getMockServer(CLOUD_ID))();
|
||||
const collector = await createCollectorFetch(getMockServer(CLOUD_ID_STAGING))();
|
||||
expect(collector.isCloudEnabled).toBe(true);
|
||||
expect(stagingCollector.isCloudEnabled).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('getCloudUsageCollector', () => {
|
||||
it('returns calls `collectorSet.makeUsageCollector`', () => {
|
||||
const mockServer = getMockServer();
|
||||
getCloudUsageCollector((mockServer as any) as KibanaHapiServer);
|
||||
const { makeUsageCollector } = mockServer.usage.collectorSet;
|
||||
expect(makeUsageCollector.calledOnce).toBe(true);
|
||||
});
|
||||
});
|
42
x-pack/plugins/cloud/get_cloud_usage_collector.ts
Normal file
42
x-pack/plugins/cloud/get_cloud_usage_collector.ts
Normal file
|
@ -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 { Server } from 'hapi';
|
||||
import { KIBANA_CLOUD_STATS_TYPE } from './constants';
|
||||
|
||||
export interface UsageStats {
|
||||
isCloudEnabled: boolean;
|
||||
}
|
||||
|
||||
export interface KibanaHapiServer extends Server {
|
||||
usage: {
|
||||
collectorSet: {
|
||||
makeUsageCollector: any;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
export function createCollectorFetch(server: any) {
|
||||
return async function fetchUsageStats(): Promise<UsageStats> {
|
||||
const { id } = server.config().get(`xpack.cloud`);
|
||||
|
||||
return {
|
||||
isCloudEnabled: !!id,
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
* @param {Object} server
|
||||
* @return {Object} kibana usage stats type collection object
|
||||
*/
|
||||
export function getCloudUsageCollector(server: KibanaHapiServer) {
|
||||
const { collectorSet } = server.usage;
|
||||
return collectorSet.makeUsageCollector({
|
||||
type: KIBANA_CLOUD_STATS_TYPE,
|
||||
fetch: createCollectorFetch(server),
|
||||
});
|
||||
}
|
|
@ -4,6 +4,8 @@
|
|||
* you may not use this file except in compliance with the Elastic License.
|
||||
*/
|
||||
|
||||
import { getCloudUsageCollector } from './get_cloud_usage_collector';
|
||||
|
||||
export const cloud = kibana => {
|
||||
return new kibana.Plugin({
|
||||
id: 'cloud',
|
||||
|
@ -38,6 +40,7 @@ export const cloud = kibana => {
|
|||
server.expose('config', {
|
||||
isCloudEnabled: !!config.id
|
||||
});
|
||||
server.usage.collectorSet.register(getCloudUsageCollector(server));
|
||||
}
|
||||
});
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue