forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Telemetry] collect xpack.cloud details (elastic#31180) (elastic#31701)
* collect xpack.cloud details * add elasticsearch cluster uuid * remove cloud ID from telemetry stats * remove esUUID from telemtry stats
- Loading branch information
Showing
4 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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), | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters