-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Telemetry] Separate the license retrieval from the stats in the usage collectors #57332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
afharo
merged 13 commits into
elastic:master
from
afharo:telemetry/merge-oss-and-xpack-collectors
Feb 25, 2020
Merged
Changes from 6 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
d4a81ad
[Telemetry] Merge OSS and XPack usage collectors
afharo 122731b
Merge branch 'master' of github.com:elastic/kibana into telemetry/mer…
afharo 97f46f5
Merge branch 'master' of github.com:elastic/kibana into telemetry/mer…
afharo 35068e1
Merge branch 'master' of github.com:elastic/kibana into telemetry/mer…
afharo 3631357
Merge branch 'master' of github.com:elastic/kibana into telemetry/mer…
afharo 25d3da5
Create X-Pack collector again
afharo b573500
Merge branch 'master' of github.com:elastic/kibana into telemetry/mer…
afharo 0ce1cad
Separate the license retrieval from the stats
afharo 555afc2
Fix telemetry tests with new fields
afharo c8ffa9b
Use Promise.all to retrieve license and stats at the same time
afharo 1891137
Merge branch 'master' of github.com:elastic/kibana into telemetry/mer…
afharo e28ea25
Fix moment mock
afharo 6b7393f
Merge branch 'master' into telemetry/merge-oss-and-xpack-collectors
elasticmachine File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
121 changes: 121 additions & 0 deletions
121
...ns/xpack_main/server/telemetry_collection/__snapshots__/get_stats_with_xpack.test.ts.snap
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -7,4 +7,5 @@ | |
| /** | ||
| * The timeout used by each request, whenever a timeout can be specified. | ||
| */ | ||
|
|
||
| export const TIMEOUT = '30s'; | ||
115 changes: 115 additions & 0 deletions
115
x-pack/legacy/plugins/xpack_main/server/telemetry_collection/get_stats_with_xpack.test.ts
This file contains hidden or 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,115 @@ | ||
| /* | ||
| * 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 { getStatsWithXpack } from './get_stats_with_xpack'; | ||
|
|
||
| const kibana = { | ||
| kibana: { | ||
| great: 'googlymoogly', | ||
| versions: [{ version: '8675309', count: 1 }], | ||
| }, | ||
| kibana_stats: { | ||
| os: { | ||
| platform: 'rocky', | ||
| platformRelease: 'iv', | ||
| }, | ||
| }, | ||
| localization: { | ||
| locale: 'en', | ||
| labelsCount: 0, | ||
| integrities: {}, | ||
| }, | ||
| sun: { chances: 5 }, | ||
| clouds: { chances: 95 }, | ||
| rain: { chances: 2 }, | ||
| snow: { chances: 0 }, | ||
| }; | ||
|
|
||
| const getMockServer = (getCluster = jest.fn()) => ({ | ||
| log(tags: string[], message: string) { | ||
| // eslint-disable-next-line no-console | ||
| console.log({ tags, message }); | ||
| }, | ||
| config() { | ||
| return { | ||
| get(item: string) { | ||
| switch (item) { | ||
| case 'pkg.version': | ||
| return '8675309-snapshot'; | ||
| default: | ||
| throw Error(`unexpected config.get('${item}') received.`); | ||
| } | ||
| }, | ||
| }; | ||
| }, | ||
| plugins: { | ||
| elasticsearch: { getCluster }, | ||
| }, | ||
| }); | ||
|
|
||
| const mockUsageCollection = (kibanaUsage = kibana) => ({ | ||
| bulkFetch: () => kibanaUsage, | ||
| toObject: (data: any) => data, | ||
| }); | ||
|
|
||
| describe('Telemetry Collection: Get Aggregated Stats', () => { | ||
| test('OSS-like telemetry (no license nor X-Pack telemetry)', async () => { | ||
| const callCluster = jest.fn(async (method: string, options: { path?: string }) => { | ||
| switch (method) { | ||
| case 'transport.request': | ||
| if (options.path === '/_license' || options.path === '/_xpack/usage') { | ||
| // eslint-disable-next-line no-throw-literal | ||
| throw { statusCode: 404 }; | ||
| } | ||
| return {}; | ||
| case 'info': | ||
| return { cluster_uuid: 'test', cluster_name: 'test', version: { number: '8.0.0' } }; | ||
| default: | ||
| return {}; | ||
| } | ||
| }); | ||
| const usageCollection = mockUsageCollection(); | ||
| const server = getMockServer(); | ||
|
|
||
| const stats = await getStatsWithXpack([{ clusterUuid: '1234' }], { | ||
| callCluster, | ||
| usageCollection, | ||
| server, | ||
| } as any); | ||
| expect(stats[0].license).toBe(undefined); | ||
| expect(stats.map(({ timestamp, ...rest }) => rest)).toMatchSnapshot(); | ||
| }); | ||
|
|
||
| test('X-Pack telemetry (license + X-Pack)', async () => { | ||
| const callCluster = jest.fn(async (method: string, options: { path?: string }) => { | ||
| switch (method) { | ||
| case 'transport.request': | ||
| if (options.path === '/_license') { | ||
| return { | ||
| license: { type: 'basic' }, | ||
| }; | ||
| } | ||
| if (options.path === '/_xpack/usage') { | ||
| return {}; | ||
| } | ||
| case 'info': | ||
| return { cluster_uuid: 'test', cluster_name: 'test', version: { number: '8.0.0' } }; | ||
| default: | ||
| return {}; | ||
| } | ||
| }); | ||
| const usageCollection = mockUsageCollection(); | ||
| const server = getMockServer(); | ||
|
|
||
| const stats = await getStatsWithXpack([{ clusterUuid: '1234' }], { | ||
| callCluster, | ||
| usageCollection, | ||
| server, | ||
| } as any); | ||
| expect(stats[0].license).toStrictEqual({ type: 'basic' }); | ||
| expect(stats.map(({ timestamp, ...rest }) => rest)).toMatchSnapshot(); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.