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.
[APM] Collect telemetry about data/API performance
Closes elastic#50757.
- Loading branch information
1 parent
2c25520
commit 75be789
Showing
28 changed files
with
1,260 additions
and
235 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
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
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 @@ | ||
yarn.lock |
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,10 @@ | ||
{ | ||
"name": "apm-scripts", | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"license": "MIT", | ||
"dependencies": { | ||
"@octokit/rest": "^16.35.0", | ||
"console-stamp": "^0.2.9" | ||
} | ||
} |
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
21 changes: 21 additions & 0 deletions
21
x-pack/legacy/plugins/apm/scripts/upload-telemetry-data.js
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,21 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
// compile typescript on the fly | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
require('@babel/register')({ | ||
extensions: ['.ts'], | ||
plugins: [ | ||
'@babel/plugin-proposal-optional-chaining', | ||
'@babel/plugin-proposal-nullish-coalescing-operator' | ||
], | ||
presets: [ | ||
'@babel/typescript', | ||
['@babel/preset-env', { targets: { node: 'current' } }] | ||
] | ||
}); | ||
|
||
require('./upload-telemetry-data/index.ts'); |
24 changes: 24 additions & 0 deletions
24
x-pack/legacy/plugins/apm/scripts/upload-telemetry-data/download-telemetry-mapping.ts
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,24 @@ | ||
/* | ||
* 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 Ocktokit from '@octokit/rest'; | ||
|
||
export async function downloadTelemetryMapping(ocktokit: Ocktokit) { | ||
const file = await ocktokit.repos.getContents({ | ||
owner: 'elastic', | ||
repo: 'telemetry', | ||
path: 'config/templates/xpack-phone-home.json', | ||
mediaType: { | ||
format: 'application/vnd.github.VERSION.raw' | ||
} | ||
}); | ||
|
||
if (Array.isArray(file.data)) { | ||
throw new Error('Expected single response, got array'); | ||
} | ||
|
||
return JSON.parse(Buffer.from(file.data.content!, 'base64').toString()); | ||
} |
120 changes: 120 additions & 0 deletions
120
x-pack/legacy/plugins/apm/scripts/upload-telemetry-data/generate-sample-documents.ts
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,120 @@ | ||
/* | ||
* 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 { DeepPartial } from 'utility-types'; | ||
import { | ||
merge, | ||
omit, | ||
defaultsDeep, | ||
range, | ||
mapValues, | ||
isPlainObject, | ||
flatten | ||
} from 'lodash'; | ||
import uuid from 'uuid'; | ||
import { | ||
CollectTelemetryParams, | ||
collectDataTelemetry | ||
} from '../../../../../plugins/apm/server/lib/apm_telemetry/collect_data_telemetry'; | ||
|
||
interface GenerateOptions { | ||
days: number; | ||
instances: number; | ||
variation: { | ||
min: number; | ||
max: number; | ||
}; | ||
} | ||
|
||
const randomize = ( | ||
value: unknown, | ||
instanceVariation: number, | ||
dailyGrowth: number | ||
) => { | ||
if (typeof value === 'boolean') { | ||
return Math.random() > 0.5; | ||
} | ||
if (typeof value === 'number') { | ||
return Math.round(instanceVariation * dailyGrowth * value); | ||
} | ||
return value; | ||
}; | ||
|
||
const mapValuesDeep = ( | ||
obj: Record<string, any>, | ||
iterator: (value: unknown, key: string, obj: Record<string, any>) => unknown | ||
): Record<string, any> => | ||
mapValues(obj, (val, key) => | ||
isPlainObject(val) ? mapValuesDeep(val, iterator) : iterator(val, key!, obj) | ||
); | ||
|
||
export async function generateSampleDocuments( | ||
options: DeepPartial<GenerateOptions> & { | ||
collectTelemetryParams: CollectTelemetryParams; | ||
} | ||
) { | ||
const { collectTelemetryParams, ...preferredOptions } = options; | ||
|
||
const opts: GenerateOptions = defaultsDeep( | ||
{ | ||
days: 100, | ||
instances: 50, | ||
variation: { | ||
min: 0.1, | ||
max: 4 | ||
} | ||
}, | ||
preferredOptions | ||
); | ||
|
||
const sample = await collectDataTelemetry(collectTelemetryParams); | ||
|
||
const dateOfScriptExecution = new Date(); | ||
|
||
return flatten( | ||
range(0, opts.instances).map(instanceNo => { | ||
const instanceId = uuid.v4(); | ||
const defaults = { | ||
cluster_uuid: instanceId, | ||
stack_stats: { | ||
kibana: { | ||
versions: { | ||
version: '8.0.0' | ||
} | ||
} | ||
} | ||
}; | ||
|
||
const instanceVariation = | ||
Math.random() * (opts.variation.max - opts.variation.min) + | ||
opts.variation.min; | ||
|
||
return range(0, opts.days).map(dayNo => { | ||
const dailyGrowth = Math.pow(1.005, opts.days - 1 - dayNo); | ||
|
||
const timestamp = Date.UTC( | ||
dateOfScriptExecution.getFullYear(), | ||
dateOfScriptExecution.getMonth(), | ||
-dayNo | ||
); | ||
|
||
const generated = mapValuesDeep(omit(sample, 'versions'), value => | ||
randomize(value, instanceVariation, dailyGrowth) | ||
); | ||
|
||
return merge({}, defaults, { | ||
timestamp, | ||
stack_stats: { | ||
kibana: { | ||
plugins: { | ||
apm: merge({}, sample, generated) | ||
} | ||
} | ||
} | ||
}); | ||
}); | ||
}) | ||
); | ||
} |
Oops, something went wrong.