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

90 lines
2.8 KiB
TypeScript
Raw Normal View History

[APM] Improvements to data telemetry (#70524) Make some changes to how we deal with data telemetry in APM and reduce the number of fields we're storing in Saved Objects in the .kibana index. Add a telemetry doc in dev_docs explaining how telemetry is collected and how to make updates. (In this PR the docs only cover data telemetry, but there's a space for the behavioral telemetry docs.) Stop storing the mapping for the data telemetry in the Saved Object but instead use `{ dynamic: false }`. This reduces the number of fields used by APM in the .kibana index (as requested in #43673.) Before: ```bash > curl -s -X GET "admin:changeme@localhost:9200/.kibana/_field_caps?fields=*&pretty=true" | jq '.fields|length' 653 ``` After: ```bash > curl -s -X GET "admin:changeme@localhost:9200/.kibana/_field_caps?fields=*&pretty=true" | jq '.fields|length' 415 ``` We don't need the mapping anymore for storing the saved object, but we still do need to update the telemetry repository when the mapping changes, and the `upload-telemetry-data` script uses that mapping when generating data. For these purposes the mapping in now defined in TypeScript in a function in common/apm_telemetry.ts. It's broken down into some variables that and put together as the same mapping object that was there before, but having it in this form should make it easier to update. A new script, `merge-telemetry-mapping`, takes the telemetry repository's xpack-phone-home.json mapping, merges in the result of our mapping and replaces the file. The result can be committed to the telemetry repo, making it easier to make changes to the mapping. References #61583 Fixes #67032
2020-07-07 18:19:59 +02:00
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
[APM] Improvements to data telemetry (#70524) Make some changes to how we deal with data telemetry in APM and reduce the number of fields we're storing in Saved Objects in the .kibana index. Add a telemetry doc in dev_docs explaining how telemetry is collected and how to make updates. (In this PR the docs only cover data telemetry, but there's a space for the behavioral telemetry docs.) Stop storing the mapping for the data telemetry in the Saved Object but instead use `{ dynamic: false }`. This reduces the number of fields used by APM in the .kibana index (as requested in #43673.) Before: ```bash > curl -s -X GET "admin:changeme@localhost:9200/.kibana/_field_caps?fields=*&pretty=true" | jq '.fields|length' 653 ``` After: ```bash > curl -s -X GET "admin:changeme@localhost:9200/.kibana/_field_caps?fields=*&pretty=true" | jq '.fields|length' 415 ``` We don't need the mapping anymore for storing the saved object, but we still do need to update the telemetry repository when the mapping changes, and the `upload-telemetry-data` script uses that mapping when generating data. For these purposes the mapping in now defined in TypeScript in a function in common/apm_telemetry.ts. It's broken down into some variables that and put together as the same mapping object that was there before, but having it in this form should make it easier to update. A new script, `merge-telemetry-mapping`, takes the telemetry repository's xpack-phone-home.json mapping, merges in the result of our mapping and replaces the file. The result can be committed to the telemetry repo, making it easier to make changes to the mapping. References #61583 Fixes #67032
2020-07-07 18:19:59 +02:00
*/
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
// Use the output from this JSON snapshot to share with the telemetry team. When
// new fields are added to the mapping, we'll have a diff in the snapshot.
expect.addSnapshotSerializer({
print: (contents) => {
return JSON.stringify(contents, null, 2);
},
test: () => true,
});
[APM] Improvements to data telemetry (#70524) Make some changes to how we deal with data telemetry in APM and reduce the number of fields we're storing in Saved Objects in the .kibana index. Add a telemetry doc in dev_docs explaining how telemetry is collected and how to make updates. (In this PR the docs only cover data telemetry, but there's a space for the behavioral telemetry docs.) Stop storing the mapping for the data telemetry in the Saved Object but instead use `{ dynamic: false }`. This reduces the number of fields used by APM in the .kibana index (as requested in #43673.) Before: ```bash > curl -s -X GET "admin:changeme@localhost:9200/.kibana/_field_caps?fields=*&pretty=true" | jq '.fields|length' 653 ``` After: ```bash > curl -s -X GET "admin:changeme@localhost:9200/.kibana/_field_caps?fields=*&pretty=true" | jq '.fields|length' 415 ``` We don't need the mapping anymore for storing the saved object, but we still do need to update the telemetry repository when the mapping changes, and the `upload-telemetry-data` script uses that mapping when generating data. For these purposes the mapping in now defined in TypeScript in a function in common/apm_telemetry.ts. It's broken down into some variables that and put together as the same mapping object that was there before, but having it in this form should make it easier to update. A new script, `merge-telemetry-mapping`, takes the telemetry repository's xpack-phone-home.json mapping, merges in the result of our mapping and replaces the file. The result can be committed to the telemetry repo, making it easier to make changes to the mapping. References #61583 Fixes #67032
2020-07-07 18:19:59 +02:00
describe('APM telemetry helpers', () => {
describe('getApmTelemetry', () => {
// This test creates a snapshot with the JSON of our full telemetry mapping
// that can be PUT in a query to the index on the telemetry cluster. Sharing
// the contents of the snapshot with the telemetry team can provide them with
// useful information about changes to our telmetry.
[APM] Improvements to data telemetry (#70524) Make some changes to how we deal with data telemetry in APM and reduce the number of fields we're storing in Saved Objects in the .kibana index. Add a telemetry doc in dev_docs explaining how telemetry is collected and how to make updates. (In this PR the docs only cover data telemetry, but there's a space for the behavioral telemetry docs.) Stop storing the mapping for the data telemetry in the Saved Object but instead use `{ dynamic: false }`. This reduces the number of fields used by APM in the .kibana index (as requested in #43673.) Before: ```bash > curl -s -X GET "admin:changeme@localhost:9200/.kibana/_field_caps?fields=*&pretty=true" | jq '.fields|length' 653 ``` After: ```bash > curl -s -X GET "admin:changeme@localhost:9200/.kibana/_field_caps?fields=*&pretty=true" | jq '.fields|length' 415 ``` We don't need the mapping anymore for storing the saved object, but we still do need to update the telemetry repository when the mapping changes, and the `upload-telemetry-data` script uses that mapping when generating data. For these purposes the mapping in now defined in TypeScript in a function in common/apm_telemetry.ts. It's broken down into some variables that and put together as the same mapping object that was there before, but having it in this form should make it easier to update. A new script, `merge-telemetry-mapping`, takes the telemetry repository's xpack-phone-home.json mapping, merges in the result of our mapping and replaces the file. The result can be committed to the telemetry repo, making it easier to make changes to the mapping. References #61583 Fixes #67032
2020-07-07 18:19:59 +02:00
it('generates a JSON object with the telemetry mapping', () => {
expect({
properties: {
stack_stats: {
[APM] Improvements to data telemetry (#70524) Make some changes to how we deal with data telemetry in APM and reduce the number of fields we're storing in Saved Objects in the .kibana index. Add a telemetry doc in dev_docs explaining how telemetry is collected and how to make updates. (In this PR the docs only cover data telemetry, but there's a space for the behavioral telemetry docs.) Stop storing the mapping for the data telemetry in the Saved Object but instead use `{ dynamic: false }`. This reduces the number of fields used by APM in the .kibana index (as requested in #43673.) Before: ```bash > curl -s -X GET "admin:changeme@localhost:9200/.kibana/_field_caps?fields=*&pretty=true" | jq '.fields|length' 653 ``` After: ```bash > curl -s -X GET "admin:changeme@localhost:9200/.kibana/_field_caps?fields=*&pretty=true" | jq '.fields|length' 415 ``` We don't need the mapping anymore for storing the saved object, but we still do need to update the telemetry repository when the mapping changes, and the `upload-telemetry-data` script uses that mapping when generating data. For these purposes the mapping in now defined in TypeScript in a function in common/apm_telemetry.ts. It's broken down into some variables that and put together as the same mapping object that was there before, but having it in this form should make it easier to update. A new script, `merge-telemetry-mapping`, takes the telemetry repository's xpack-phone-home.json mapping, merges in the result of our mapping and replaces the file. The result can be committed to the telemetry repo, making it easier to make changes to the mapping. References #61583 Fixes #67032
2020-07-07 18:19:59 +02:00
properties: {
kibana: {
[APM] Improvements to data telemetry (#70524) Make some changes to how we deal with data telemetry in APM and reduce the number of fields we're storing in Saved Objects in the .kibana index. Add a telemetry doc in dev_docs explaining how telemetry is collected and how to make updates. (In this PR the docs only cover data telemetry, but there's a space for the behavioral telemetry docs.) Stop storing the mapping for the data telemetry in the Saved Object but instead use `{ dynamic: false }`. This reduces the number of fields used by APM in the .kibana index (as requested in #43673.) Before: ```bash > curl -s -X GET "admin:changeme@localhost:9200/.kibana/_field_caps?fields=*&pretty=true" | jq '.fields|length' 653 ``` After: ```bash > curl -s -X GET "admin:changeme@localhost:9200/.kibana/_field_caps?fields=*&pretty=true" | jq '.fields|length' 415 ``` We don't need the mapping anymore for storing the saved object, but we still do need to update the telemetry repository when the mapping changes, and the `upload-telemetry-data` script uses that mapping when generating data. For these purposes the mapping in now defined in TypeScript in a function in common/apm_telemetry.ts. It's broken down into some variables that and put together as the same mapping object that was there before, but having it in this form should make it easier to update. A new script, `merge-telemetry-mapping`, takes the telemetry repository's xpack-phone-home.json mapping, merges in the result of our mapping and replaces the file. The result can be committed to the telemetry repo, making it easier to make changes to the mapping. References #61583 Fixes #67032
2020-07-07 18:19:59 +02:00
properties: {
plugins: {
properties: {
apm: getApmTelemetryMapping(),
},
[APM] Improvements to data telemetry (#70524) Make some changes to how we deal with data telemetry in APM and reduce the number of fields we're storing in Saved Objects in the .kibana index. Add a telemetry doc in dev_docs explaining how telemetry is collected and how to make updates. (In this PR the docs only cover data telemetry, but there's a space for the behavioral telemetry docs.) Stop storing the mapping for the data telemetry in the Saved Object but instead use `{ dynamic: false }`. This reduces the number of fields used by APM in the .kibana index (as requested in #43673.) Before: ```bash > curl -s -X GET "admin:changeme@localhost:9200/.kibana/_field_caps?fields=*&pretty=true" | jq '.fields|length' 653 ``` After: ```bash > curl -s -X GET "admin:changeme@localhost:9200/.kibana/_field_caps?fields=*&pretty=true" | jq '.fields|length' 415 ``` We don't need the mapping anymore for storing the saved object, but we still do need to update the telemetry repository when the mapping changes, and the `upload-telemetry-data` script uses that mapping when generating data. For these purposes the mapping in now defined in TypeScript in a function in common/apm_telemetry.ts. It's broken down into some variables that and put together as the same mapping object that was there before, but having it in this form should make it easier to update. A new script, `merge-telemetry-mapping`, takes the telemetry repository's xpack-phone-home.json mapping, merges in the result of our mapping and replaces the file. The result can be committed to the telemetry repo, making it easier to make changes to the mapping. References #61583 Fixes #67032
2020-07-07 18:19:59 +02:00
},
},
},
},
},
},
}).toMatchSnapshot();
[APM] Improvements to data telemetry (#70524) Make some changes to how we deal with data telemetry in APM and reduce the number of fields we're storing in Saved Objects in the .kibana index. Add a telemetry doc in dev_docs explaining how telemetry is collected and how to make updates. (In this PR the docs only cover data telemetry, but there's a space for the behavioral telemetry docs.) Stop storing the mapping for the data telemetry in the Saved Object but instead use `{ dynamic: false }`. This reduces the number of fields used by APM in the .kibana index (as requested in #43673.) Before: ```bash > curl -s -X GET "admin:changeme@localhost:9200/.kibana/_field_caps?fields=*&pretty=true" | jq '.fields|length' 653 ``` After: ```bash > curl -s -X GET "admin:changeme@localhost:9200/.kibana/_field_caps?fields=*&pretty=true" | jq '.fields|length' 415 ``` We don't need the mapping anymore for storing the saved object, but we still do need to update the telemetry repository when the mapping changes, and the `upload-telemetry-data` script uses that mapping when generating data. For these purposes the mapping in now defined in TypeScript in a function in common/apm_telemetry.ts. It's broken down into some variables that and put together as the same mapping object that was there before, but having it in this form should make it easier to update. A new script, `merge-telemetry-mapping`, takes the telemetry repository's xpack-phone-home.json mapping, merges in the result of our mapping and replaces the file. The result can be committed to the telemetry repo, making it easier to make changes to the mapping. References #61583 Fixes #67032
2020-07-07 18:19:59 +02:00
});
});
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());
});
});
});
[APM] Improvements to data telemetry (#70524) Make some changes to how we deal with data telemetry in APM and reduce the number of fields we're storing in Saved Objects in the .kibana index. Add a telemetry doc in dev_docs explaining how telemetry is collected and how to make updates. (In this PR the docs only cover data telemetry, but there's a space for the behavioral telemetry docs.) Stop storing the mapping for the data telemetry in the Saved Object but instead use `{ dynamic: false }`. This reduces the number of fields used by APM in the .kibana index (as requested in #43673.) Before: ```bash > curl -s -X GET "admin:changeme@localhost:9200/.kibana/_field_caps?fields=*&pretty=true" | jq '.fields|length' 653 ``` After: ```bash > curl -s -X GET "admin:changeme@localhost:9200/.kibana/_field_caps?fields=*&pretty=true" | jq '.fields|length' 415 ``` We don't need the mapping anymore for storing the saved object, but we still do need to update the telemetry repository when the mapping changes, and the `upload-telemetry-data` script uses that mapping when generating data. For these purposes the mapping in now defined in TypeScript in a function in common/apm_telemetry.ts. It's broken down into some variables that and put together as the same mapping object that was there before, but having it in this form should make it easier to update. A new script, `merge-telemetry-mapping`, takes the telemetry repository's xpack-phone-home.json mapping, merges in the result of our mapping and replaces the file. The result can be committed to the telemetry repo, making it easier to make changes to the mapping. References #61583 Fixes #67032
2020-07-07 18:19:59 +02:00
});