Skip to content

Commit fe91276

Browse files
[APM] Aggregated transactions telemetry (#71594) (#72077)
Add a task to gather transasctions telemetry as described in #71593. Also: * Fix typo in mapping for country code mapping * Add back `mergeTelemetryMapping` function to fix broken `upload-telemetry-data` script. Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
1 parent 2404331 commit fe91276

9 files changed

Lines changed: 460 additions & 14 deletions

File tree

x-pack/plugins/apm/common/__snapshots__/apm_telemetry.test.ts.snap

Lines changed: 82 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugins/apm/common/__snapshots__/elasticsearch_fieldnames.test.ts.snap

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugins/apm/common/apm_telemetry.test.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
* you may not use this file except in compliance with the Elastic License.
55
*/
66

7-
import { getApmTelemetryMapping } from './apm_telemetry';
7+
import {
8+
getApmTelemetryMapping,
9+
mergeApmTelemetryMapping,
10+
} from './apm_telemetry';
811

912
// Add this snapshot serializer for this test. The default snapshot serializer
1013
// prints "Object" next to objects in the JSON output, but we want to be able to
@@ -43,4 +46,43 @@ describe('APM telemetry helpers', () => {
4346
}).toMatchSnapshot();
4447
});
4548
});
49+
50+
describe('mergeApmTelemetryMapping', () => {
51+
describe('with an invalid mapping', () => {
52+
it('throws an error', () => {
53+
expect(() => mergeApmTelemetryMapping({})).toThrowError();
54+
});
55+
});
56+
57+
describe('with a valid mapping', () => {
58+
it('merges the mapping', () => {
59+
// This is "valid" in the sense that it has all of the deep fields
60+
// needed to merge. It's not a valid mapping opbject.
61+
const validTelemetryMapping = {
62+
mappings: {
63+
properties: {
64+
stack_stats: {
65+
properties: {
66+
kibana: {
67+
properties: {
68+
plugins: {
69+
properties: {
70+
apm: getApmTelemetryMapping(),
71+
},
72+
},
73+
},
74+
},
75+
},
76+
},
77+
},
78+
},
79+
};
80+
81+
expect(
82+
mergeApmTelemetryMapping(validTelemetryMapping)?.mappings.properties
83+
.stack_stats.properties.kibana.properties.plugins.properties.apm
84+
).toEqual(getApmTelemetryMapping());
85+
});
86+
});
87+
});
4688
});

x-pack/plugins/apm/common/apm_telemetry.ts

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6+
import { produce } from 'immer';
67
import { AGENT_NAMES } from './agent_name';
78

89
/**
@@ -73,6 +74,13 @@ export function getApmTelemetryMapping() {
7374
},
7475
};
7576

77+
const aggregatedTransactionsProperties = {
78+
properties: {
79+
expected_metric_document_count: long,
80+
transaction_count: long,
81+
},
82+
};
83+
7684
return {
7785
properties: {
7886
agents: {
@@ -90,6 +98,16 @@ export function getApmTelemetryMapping() {
9098
{}
9199
),
92100
},
101+
aggregated_transactions: {
102+
properties: {
103+
current_implementation: aggregatedTransactionsProperties,
104+
no_observer_name: aggregatedTransactionsProperties,
105+
no_rum: aggregatedTransactionsProperties,
106+
no_rum_no_observer_name: aggregatedTransactionsProperties,
107+
only_rum: aggregatedTransactionsProperties,
108+
only_rum_no_observer_name: aggregatedTransactionsProperties,
109+
},
110+
},
93111
cloud: {
94112
properties: {
95113
availability_zone: keyword,
@@ -117,8 +135,8 @@ export function getApmTelemetryMapping() {
117135
client: {
118136
properties: {
119137
geo: {
120-
properites: {
121-
country_iso_code: { rum: oneDayProperties },
138+
properties: {
139+
country_iso_code: { properties: { rum: oneDayProperties } },
122140
},
123141
},
124142
},
@@ -204,6 +222,7 @@ export function getApmTelemetryMapping() {
204222
},
205223
tasks: {
206224
properties: {
225+
aggregated_transactions: tookProperties,
207226
agent_configuration: tookProperties,
208227
agents: tookProperties,
209228
cardinality: tookProperties,
@@ -230,3 +249,16 @@ export function getApmTelemetryMapping() {
230249
},
231250
};
232251
}
252+
253+
/**
254+
* Merge a telemetry mapping object (from https://github.com/elastic/telemetry/blob/master/config/templates/xpack-phone-home.json)
255+
* with the output from `getApmTelemetryMapping`.
256+
*/
257+
export function mergeApmTelemetryMapping(
258+
xpackPhoneHomeMapping: Record<string, any>
259+
) {
260+
return produce(xpackPhoneHomeMapping, (draft: Record<string, any>) => {
261+
draft.mappings.properties.stack_stats.properties.kibana.properties.plugins.properties.apm = getApmTelemetryMapping();
262+
return draft;
263+
});
264+
}

x-pack/plugins/apm/common/elasticsearch_fieldnames.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ describe('Transaction', () => {
1515
'@timestamp': new Date().toString(),
1616
'@metadata': 'whatever',
1717
observer: {
18+
name: 'an observer',
1819
version: 'whatever',
1920
version_major: 8,
2021
},
@@ -71,6 +72,7 @@ describe('Span', () => {
7172
'@timestamp': new Date().toString(),
7273
'@metadata': 'whatever',
7374
observer: {
75+
name: 'an observer',
7476
version: 'whatever',
7577
version_major: 8,
7678
},
@@ -123,6 +125,7 @@ describe('Error', () => {
123125
const errorDoc: APMError = {
124126
'@metadata': 'whatever',
125127
observer: {
128+
name: 'an observer',
126129
version: 'whatever',
127130
version_major: 8,
128131
},

x-pack/plugins/apm/common/elasticsearch_fieldnames.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const USER_AGENT_NAME = 'user_agent.name';
3131

3232
export const DESTINATION_ADDRESS = 'destination.address';
3333

34+
export const OBSERVER_NAME = 'observer.name';
3435
export const OBSERVER_VERSION_MAJOR = 'observer.version_major';
3536
export const OBSERVER_LISTENING = 'observer.listening';
3637
export const PROCESSOR_EVENT = 'processor.event';

0 commit comments

Comments
 (0)