Skip to content
/ kibana Public
forked from elastic/kibana

Commit

Permalink
[APM] Aggregated transactions telemetry (elastic#71594)
Browse files Browse the repository at this point in the history
Add a task to gather transasctions telemetry as described in elastic#71593.

Also:

* Fix typo in mapping for country code mapping
* Add back `mergeTelemetryMapping` function to fix broken `upload-telemetry-data` script.
  • Loading branch information
smith committed Jul 16, 2020
1 parent e800029 commit 0b33030
Show file tree
Hide file tree
Showing 9 changed files with 460 additions and 14 deletions.
87 changes: 82 additions & 5 deletions x-pack/plugins/apm/common/__snapshots__/apm_telemetry.test.ts.snap

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 43 additions & 1 deletion x-pack/plugins/apm/common/apm_telemetry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { getApmTelemetryMapping } from './apm_telemetry';
import {
getApmTelemetryMapping,
mergeApmTelemetryMapping,
} from './apm_telemetry';

// Add this snapshot serializer for this test. The default snapshot serializer
// prints "Object" next to objects in the JSON output, but we want to be able to
Expand Down Expand Up @@ -43,4 +46,43 @@ describe('APM telemetry helpers', () => {
}).toMatchSnapshot();
});
});

describe('mergeApmTelemetryMapping', () => {
describe('with an invalid mapping', () => {
it('throws an error', () => {
expect(() => mergeApmTelemetryMapping({})).toThrowError();
});
});

describe('with a valid mapping', () => {
it('merges the mapping', () => {
// This is "valid" in the sense that it has all of the deep fields
// needed to merge. It's not a valid mapping opbject.
const validTelemetryMapping = {
mappings: {
properties: {
stack_stats: {
properties: {
kibana: {
properties: {
plugins: {
properties: {
apm: getApmTelemetryMapping(),
},
},
},
},
},
},
},
},
};

expect(
mergeApmTelemetryMapping(validTelemetryMapping)?.mappings.properties
.stack_stats.properties.kibana.properties.plugins.properties.apm
).toEqual(getApmTelemetryMapping());
});
});
});
});
36 changes: 34 additions & 2 deletions x-pack/plugins/apm/common/apm_telemetry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { produce } from 'immer';
import { AGENT_NAMES } from './agent_name';

/**
Expand Down Expand Up @@ -73,6 +74,13 @@ export function getApmTelemetryMapping() {
},
};

const aggregatedTransactionsProperties = {
properties: {
expected_metric_document_count: long,
transaction_count: long,
},
};

return {
properties: {
agents: {
Expand All @@ -90,6 +98,16 @@ export function getApmTelemetryMapping() {
{}
),
},
aggregated_transactions: {
properties: {
current_implementation: aggregatedTransactionsProperties,
no_observer_name: aggregatedTransactionsProperties,
no_rum: aggregatedTransactionsProperties,
no_rum_no_observer_name: aggregatedTransactionsProperties,
only_rum: aggregatedTransactionsProperties,
only_rum_no_observer_name: aggregatedTransactionsProperties,
},
},
cloud: {
properties: {
availability_zone: keyword,
Expand Down Expand Up @@ -117,8 +135,8 @@ export function getApmTelemetryMapping() {
client: {
properties: {
geo: {
properites: {
country_iso_code: { rum: oneDayProperties },
properties: {
country_iso_code: { properties: { rum: oneDayProperties } },
},
},
},
Expand Down Expand Up @@ -204,6 +222,7 @@ export function getApmTelemetryMapping() {
},
tasks: {
properties: {
aggregated_transactions: tookProperties,
agent_configuration: tookProperties,
agents: tookProperties,
cardinality: tookProperties,
Expand All @@ -230,3 +249,16 @@ export function getApmTelemetryMapping() {
},
};
}

/**
* Merge a telemetry mapping object (from https://github.com/elastic/telemetry/blob/master/config/templates/xpack-phone-home.json)
* with the output from `getApmTelemetryMapping`.
*/
export function mergeApmTelemetryMapping(
xpackPhoneHomeMapping: Record<string, any>
) {
return produce(xpackPhoneHomeMapping, (draft: Record<string, any>) => {
draft.mappings.properties.stack_stats.properties.kibana.properties.plugins.properties.apm = getApmTelemetryMapping();
return draft;
});
}
3 changes: 3 additions & 0 deletions x-pack/plugins/apm/common/elasticsearch_fieldnames.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe('Transaction', () => {
'@timestamp': new Date().toString(),
'@metadata': 'whatever',
observer: {
name: 'an observer',
version: 'whatever',
version_major: 8,
},
Expand Down Expand Up @@ -71,6 +72,7 @@ describe('Span', () => {
'@timestamp': new Date().toString(),
'@metadata': 'whatever',
observer: {
name: 'an observer',
version: 'whatever',
version_major: 8,
},
Expand Down Expand Up @@ -123,6 +125,7 @@ describe('Error', () => {
const errorDoc: APMError = {
'@metadata': 'whatever',
observer: {
name: 'an observer',
version: 'whatever',
version_major: 8,
},
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/apm/common/elasticsearch_fieldnames.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export const USER_AGENT_NAME = 'user_agent.name';

export const DESTINATION_ADDRESS = 'destination.address';

export const OBSERVER_NAME = 'observer.name';
export const OBSERVER_VERSION_MAJOR = 'observer.version_major';
export const OBSERVER_LISTENING = 'observer.listening';
export const PROCESSOR_EVENT = 'processor.event';
Expand Down
Loading

0 comments on commit 0b33030

Please sign in to comment.