-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[APM] Improvements to data telemetry #70524
Merged
Merged
Changes from 1 commit
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
710d640
[APM] Improvements to data telemetry
smith 432536f
Merge remote-tracking branch 'upstream/master' into nls/cloud-telem
smith abf6426
export merge function
smith 0f66097
some changes to upload script
smith f27863b
Merge remote-tracking branch 'upstream/master' into nls/cloud-telem
smith 6f447cd
fix snapshot
smith daa72a7
Merge remote-tracking branch 'upstream/master' into nls/cloud-telem
smith 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
913 changes: 913 additions & 0 deletions
913
x-pack/plugins/apm/common/__snapshots__/apm_telemetry.test.ts.snap
Large diffs are not rendered by default.
Oops, something went wrong.
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,13 @@ | ||
/* | ||
* 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 { getApmTelemetryMapping } from './apm_telemetry'; | ||
|
||
describe('getApmTelemetry', () => { | ||
it('generates a JSON object with the telemetry mapping', () => { | ||
expect(getApmTelemetryMapping()).toMatchSnapshot(); | ||
}); | ||
}); |
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,215 @@ | ||
/* | ||
* 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 { AGENT_NAMES } from './agent_name'; | ||
|
||
/** | ||
* Generate an object containing the mapping used for APM telemetry. Can be used | ||
* with the `upload-telemetry-data` script or to update the mapping in the | ||
* telemetry repository. | ||
* | ||
* This function breaks things up to make the mapping easier to understand. | ||
*/ | ||
export function getApmTelemetryMapping() { | ||
const keyword = { | ||
type: 'keyword', | ||
ignore_above: 1024, | ||
}; | ||
|
||
const long = { | ||
type: 'long', | ||
}; | ||
|
||
const allProperties = { | ||
properties: { | ||
all: long, | ||
}, | ||
}; | ||
|
||
const oneDayProperties = { | ||
properties: { | ||
'1d': long, | ||
}, | ||
}; | ||
|
||
const oneDayAllProperties = { | ||
properties: { | ||
'1d': long, | ||
all: long, | ||
}, | ||
}; | ||
|
||
const msProperties = { | ||
properties: { | ||
ms: long, | ||
}, | ||
}; | ||
|
||
const tookProperties = { | ||
properties: { | ||
took: msProperties, | ||
}, | ||
}; | ||
|
||
const compositeNameVersionProperties = { | ||
properties: { | ||
composite: keyword, | ||
name: keyword, | ||
version: keyword, | ||
}, | ||
}; | ||
|
||
const agentProperties = { | ||
properties: { version: keyword }, | ||
}; | ||
|
||
const serviceProperties = { | ||
properties: { | ||
framework: compositeNameVersionProperties, | ||
language: compositeNameVersionProperties, | ||
runtime: compositeNameVersionProperties, | ||
}, | ||
}; | ||
|
||
return { | ||
properties: { | ||
agents: { | ||
properties: AGENT_NAMES.reduce<Record<string, any>>( | ||
(previousValue, currentValue) => { | ||
previousValue[currentValue] = { | ||
properties: { | ||
agent: agentProperties, | ||
service: serviceProperties, | ||
}, | ||
}; | ||
|
||
return previousValue; | ||
}, | ||
{} | ||
), | ||
}, | ||
counts: { | ||
properties: { | ||
agent_configuration: allProperties, | ||
error: oneDayAllProperties, | ||
max_error_groups_per_service: oneDayProperties, | ||
max_transaction_groups_per_service: oneDayProperties, | ||
metric: oneDayAllProperties, | ||
onboarding: oneDayAllProperties, | ||
services: oneDayProperties, | ||
sourcemap: oneDayAllProperties, | ||
span: oneDayAllProperties, | ||
traces: oneDayProperties, | ||
transaction: oneDayAllProperties, | ||
}, | ||
}, | ||
cardinality: { | ||
properties: { | ||
user_agent: { | ||
properties: { | ||
original: { | ||
properties: { | ||
all_agents: oneDayProperties, | ||
rum: oneDayProperties, | ||
}, | ||
}, | ||
}, | ||
}, | ||
transaction: { | ||
properties: { | ||
name: { | ||
properties: { | ||
all_agents: oneDayProperties, | ||
rum: oneDayProperties, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
has_any_services: { | ||
type: 'boolean', | ||
}, | ||
indices: { | ||
properties: { | ||
all: { | ||
properties: { | ||
total: { | ||
properties: { | ||
docs: { | ||
properties: { | ||
count: long, | ||
}, | ||
}, | ||
store: { | ||
properties: { | ||
size_in_bytes: long, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
shards: { | ||
properties: { | ||
total: long, | ||
}, | ||
}, | ||
}, | ||
}, | ||
integrations: { | ||
properties: { | ||
ml: { | ||
properties: { | ||
all_jobs_count: long, | ||
}, | ||
}, | ||
}, | ||
}, | ||
retainment: { | ||
properties: { | ||
error: msProperties, | ||
metric: msProperties, | ||
onboarding: msProperties, | ||
span: msProperties, | ||
transaction: msProperties, | ||
}, | ||
}, | ||
services_per_agent: { | ||
properties: AGENT_NAMES.reduce<Record<string, any>>( | ||
(previousValue, currentValue) => { | ||
previousValue[currentValue] = { ...long, null_value: 0 }; | ||
return previousValue; | ||
}, | ||
{} | ||
), | ||
}, | ||
tasks: { | ||
properties: { | ||
agent_configuration: tookProperties, | ||
agents: tookProperties, | ||
cardinality: tookProperties, | ||
groupings: tookProperties, | ||
indices_stats: tookProperties, | ||
integrations: tookProperties, | ||
processor_events: tookProperties, | ||
services: tookProperties, | ||
versions: tookProperties, | ||
}, | ||
}, | ||
version: { | ||
properties: { | ||
apm_server: { | ||
properties: { | ||
major: long, | ||
minor: long, | ||
patch: long, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}; | ||
} |
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 @@ | ||
# APM Telemetry | ||
|
||
In order to learn about our customers' usage and experience of APM, we collect | ||
two types of telemetry, which we'll refer to here as "Data Telemetry" and | ||
"Behavioral Telemetry." | ||
|
||
This document will explain how they are collected and how to make changes to | ||
them. | ||
|
||
[The telemetry repository has information about accessing the clusters](https://github.com/elastic/telemetry#kibana-access). | ||
Telemetry data is uploaded to the "xpack-phone-home" indices. | ||
|
||
## Data Telemetry | ||
|
||
Information that can be derived from a cluster's APM indices is queried and sent | ||
to the telemetry cluster using the | ||
[Usage Collection plugin](../../../../src/plugins/usage_collection/README.md). | ||
|
||
During the APM server-side plugin's setup phase a | ||
[Saved Object](https://www.elastic.co/guide/en/kibana/master/managing-saved-objects.html) | ||
for APM telemetry is registered and a | ||
[task manager](../../task_manager/server/README.md) task is registered and started. | ||
The task periodically queries the APM indices and saves the results in the Saved | ||
Object, and the usage collector periodically gets the data from the saved object | ||
and uploads it to the telemetry cluster. | ||
|
||
Once uploaded to the telemetry cluster, the data telemetry is stored in | ||
`stack_stats.kibana.plugins.apm` in the xpack-phone-home index. | ||
|
||
### Generating sample data | ||
|
||
The script in `scripts/upload-telemetry-data` can generate sample telemetry data and upload it to a cluster of your choosing. | ||
|
||
### Updating Data Telemetry Mappings | ||
|
||
In order for fields to be searchable on the telemetry cluster, they need to be | ||
added to the cluster's mapping. The mapping is defined in | ||
[the telemetry repository's xpack-phone-home template](https://github.com/elastic/telemetry/blob/master/config/templates/xpack-phone-home.json). | ||
|
||
The mapping for the telemetry data is here under `stack_stats.kibana.plugins.apm`. | ||
|
||
The mapping used there can be generated with the output of the [`getTelemetryMapping`](../common/apm_telemetry.ts) function. | ||
|
||
To make a change to the mapping, edit this function, run the tests to update the snapshots, then use the `merge_telemetry_mapping` script to merge the data into the telemetry repository. | ||
|
||
If the [telemetry repository](https://github.com/elastic/telemetry) is cloned as a sibling to the kibana directory, you can run the following from x-pack/plugins/apm: | ||
|
||
```bash | ||
node ./scripts/merge-telemetry-mapping.js ../../../../telemetry/config/templates/xpack-phone-home.json | ||
``` | ||
|
||
this will replace the contents of the mapping in the repository checkout with the updated mapping. You can then [follow the telemetry team's instructions](https://github.com/elastic/telemetry#mappings) for opening a pull request with the mapping changes. | ||
|
||
## Behavioral Telemetry | ||
|
||
Behavioral telemetry is recorded with the ui_metrics and application_usage methods from the Usage Collection plugin. | ||
|
||
Please fill this in with more details. |
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 |
---|---|---|
|
@@ -66,8 +66,9 @@ export interface ApmPluginStartDeps { | |
} | ||
|
||
export class ApmPlugin implements Plugin<ApmPluginSetup, ApmPluginStart> { | ||
private readonly initializerContext: PluginInitializerContext<ConfigSchema>; | ||
constructor(initializerContext: PluginInitializerContext<ConfigSchema>) { | ||
constructor( | ||
private readonly initializerContext: PluginInitializerContext<ConfigSchema> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change is not related to anything else in this PR but lets us remove a line of code. |
||
) { | ||
this.initializerContext = initializerContext; | ||
} | ||
public setup(core: CoreSetup, plugins: ApmPluginSetupDeps) { | ||
|
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,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('./merge-telemetry-mapping/index.ts'); |
34 changes: 34 additions & 0 deletions
34
x-pack/plugins/apm/scripts/merge-telemetry-mapping/index.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,34 @@ | ||
/* | ||
* 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 { readFileSync, truncateSync, writeFileSync } from 'fs'; | ||
import produce from 'immer'; | ||
import { resolve } from 'path'; | ||
import { argv } from 'yargs'; | ||
import { getApmTelemetryMapping } from '../../common/apm_telemetry'; | ||
|
||
function errorExit(error?: Error) { | ||
console.error(`usage: ${argv.$0} /path/to/xpack-phone-home.json`); // eslint-disable-line no-console | ||
if (error) { | ||
throw error; | ||
} | ||
process.exit(1); | ||
} | ||
|
||
try { | ||
const filename = resolve(argv._[0]); | ||
const xpackPhoneHomeMapping = JSON.parse(readFileSync(filename, 'utf-8')); | ||
|
||
const newMapping = produce(xpackPhoneHomeMapping, (draft) => { | ||
draft.mappings.properties.stack_stats.properties.kibana.properties.plugins.properties.apm = getApmTelemetryMapping(); | ||
return draft; | ||
}); | ||
|
||
truncateSync(filename); | ||
writeFileSync(filename, JSON.stringify(newMapping, null, 2)); | ||
} catch (error) { | ||
errorExit(error); | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has been alphabetized so the mapping output stays consistent with what already exists, and there were two "java"s here.