Skip to content
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] Make UI indices space aware (support for spaces) #126378

Merged

Conversation

cauemarcondes
Copy link
Contributor

related to #126176

A few more changes had to be made to fully support the new structure of the saved object.

I added a new migration to the saved object to add the new layer (apmIndices), this will also apply when saved objects are imported.

migrateLegacyAPMIndicesToSpaceAware doesn't have to care about the structure of the saved object, since it will be already using the latest one, that happened during saved object migration.

@cauemarcondes cauemarcondes added release_note:skip Skip the PR/issue when compiling release notes backport:skip This commit does not require backporting v8.2.0 labels Feb 24, 2022
@cauemarcondes cauemarcondes requested a review from a team as a code owner February 24, 2022 19:29
@botelastic botelastic bot added the Team:APM All issues that need APM UI Team support label Feb 24, 2022
@elasticmachine
Copy link
Contributor

Pinging @elastic/apm-ui (Team:apm)

Copy link
Member

@sorenlouv sorenlouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm but I'll defer to @jportner

@cauemarcondes
Copy link
Contributor Author

@elasticmachine merge upstream

Copy link
Contributor

@jportner jportner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pulled this PR down to test it --

I exported an apm-indices object from 8.1.0 and attempted to import it into Kibana using the main branch, and I got an error:

image

That's because Kibana didn't change the shape of the object's attributes before creating it, and the mappings are set to dynamic: strict by default.

Then I switched to this branch and attempted to import it again, and it worked 🎉
I tested importing in the Default space and a custom space, and changing the object in the custom space.
I also tested the on-start migration.


Since I noticed the mappings, it reminded me of this: if you don't need to search or aggregate on these fields, then you should exclude them and use dynamic: false to reduce the size of the .kibana index mapping.

From our Saved Objects docs:

Do not use field mappings like you would use data types for the columns of a SQL database. Instead, field mappings are analogous to a SQL index. Only specify field mappings for the fields you wish to search on or query. By specifying dynamic: false in any level of your mappings, Elasticsearch will accept and store any other fields even if they are not specified in your mappings.

Since Elasticsearch has a default limit of 1000 fields per index, plugins should carefully consider the fields they add to the mappings. Similarly, Saved Object types should never use dynamic: true as this can cause an arbitrary amount of fields to be added to the .kibana index.

diff --git a/x-pack/plugins/apm/server/saved_objects/apm_indices.ts b/x-pack/plugins/apm/server/saved_objects/apm_indices.ts
index 725fdfeb63a..3f02e90a95e 100644
--- a/x-pack/plugins/apm/server/saved_objects/apm_indices.ts
+++ b/x-pack/plugins/apm/server/saved_objects/apm_indices.ts
@@ -8,7 +8,6 @@
 import { SavedObjectsType } from 'src/core/server';
 import { i18n } from '@kbn/i18n';
 import { updateApmOssIndexPaths } from './migrations/update_apm_oss_index_paths';
-import { ApmIndicesConfigName } from '..';
 
 export interface APMIndices {
   apmIndices?: {
@@ -22,32 +21,14 @@ export interface APMIndices {
   isSpaceAware?: boolean;
 }
 
-const properties: {
-  apmIndices: {
-    properties: {
-      [Property in ApmIndicesConfigName]: { type: 'keyword' };
-    };
-  };
-  isSpaceAware: { type: 'boolean' };
-} = {
-  apmIndices: {
-    properties: {
-      sourcemap: { type: 'keyword' },
-      error: { type: 'keyword' },
-      onboarding: { type: 'keyword' },
-      span: { type: 'keyword' },
-      transaction: { type: 'keyword' },
-      metric: { type: 'keyword' },
-    },
-  },
-  isSpaceAware: { type: 'boolean' },
-};
-
 export const apmIndices: SavedObjectsType = {
   name: 'apm-indices',
   hidden: false,
   namespaceType: 'single',
-  mappings: { properties },
+  mappings: {
+    dynamic: false,
+    properties: {}, // several fields exist, but we don't need to search or aggregate on them, so we exclude them from the mappings
+  },
   management: {
     importableAndExportable: true,
     icon: 'apmApp',

I also noticed what I think is an AuthZ problem for minimally privileged users but I'll talk to you about that offline!

Edit: we spoke about this, I opened a separate issue for it here: #126483

@cauemarcondes
Copy link
Contributor Author

Since I noticed the mappings, it reminded me of this: if you don't need to search or aggregate on these fields, then you should exclude them and use dynamic: false to reduce the size of the .kibana index mapping.

@jportner I just applied the changes you suggested. I decided to fix the other bug on a new PR since it is not related to this change.

Copy link
Contributor

@jportner jportner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jportner I just applied the changes you suggested. I decided to fix the other bug on a new PR since it is not related to this change.

In that case, I think this PR is good to go!

@cauemarcondes cauemarcondes enabled auto-merge (squash) February 28, 2022 19:29
@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Saved Objects .kibana field count

Every field in each saved object type adds overhead to Elasticsearch. Kibana needs to keep the total field count below Elasticsearch's default limit of 1000 fields. Only specify field mappings for the fields you wish to search on or query. See https://www.elastic.co/guide/en/kibana/master/development-plugin-saved-objects.html#_mappings

id before after diff
apm-indices 9 - -9

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@cauemarcondes cauemarcondes merged commit 0fb24a0 into elastic:main Feb 28, 2022
@cauemarcondes cauemarcondes deleted the apm-indices-space-aware-follow-up branch March 1, 2022 14:06
lucasfcosta pushed a commit to lucasfcosta/kibana that referenced this pull request Mar 8, 2022
* changing structure of the saved object when migrating

* addressing PR changes

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
lucasfcosta pushed a commit to lucasfcosta/kibana that referenced this pull request Mar 8, 2022
* changing structure of the saved object when migrating

* addressing PR changes

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport:skip This commit does not require backporting release_note:skip Skip the PR/issue when compiling release notes Team:APM All issues that need APM UI Team support v8.2.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants