Skip to content

Commit

Permalink
Fix SO management fulltext search (#154409)
Browse files Browse the repository at this point in the history
## Summary

Fix #154244
Related / workaround for #130616

Very old issue that happened again, this time for the `slo` type because
of mapping incompatibilities with default searchable fields (and a
limitation in our code we still did not address)

- Fix the `slo` SO type mapping for the `name` field (keyword => text)
- Add a integration test failing if any management type has incorrect
mappings for searchable fields (mostly a workaround rather than fixing
the root problem, but at least it will avoid that kind of scenario for
the time being)
  • Loading branch information
pgayvallet authored Apr 6, 2023
1 parent 595c6e0 commit 8de96ea
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"siem-ui-timeline": "e9d6b3a9fd7af6dc502293c21cbdb309409f3996",
"siem-ui-timeline-note": "13c9d4c142f96624a93a623c6d7cba7e1ae9b5a6",
"siem-ui-timeline-pinned-event": "96a43d59b9e2fc11f12255a0cb47ef0a3d83af4c",
"slo": "ee0e16abebba5779c37277bc3fe8da1fe1207b7a",
"slo": "aefffabdb35d15a6c388634af2cee1fa59ede83c",
"space": "7fc578a1f9f7708cb07479f03953d664ad9f1dae",
"spaces-usage-stats": "084bd0f080f94fb5735d7f3cf12f13ec92f36bad",
"synthetics-monitor": "7136a2669a65323c56da849f26c369cdeeb3b381",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* 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 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/

import { createRoot } from '@kbn/core-test-helpers-kbn-server';

describe('SO default search fields', () => {
let root: ReturnType<typeof createRoot>;

afterEach(() => {
try {
root?.shutdown();
} catch (e) {
/* trap */
}
});

interface InvalidMappingTuple {
type: string;
field: string;
}

// identify / avoid scenarios of https://github.com/elastic/kibana/issues/130616
it('make sure management types have the correct mappings for default search fields', async () => {
root = createRoot({}, { oss: false });
await root.preboot();
const setup = await root.setup();

const allTypes = setup.savedObjects.getTypeRegistry().getAllTypes();

const defaultSearchFields = [
...allTypes.reduce((fieldSet, type) => {
if (type.management?.defaultSearchField) {
fieldSet.add(type.management.defaultSearchField);
}
return fieldSet;
}, new Set<string>()),
];

const invalidMappings: InvalidMappingTuple[] = [];

const managementTypes = setup.savedObjects
.getTypeRegistry()
.getImportableAndExportableTypes()
.filter((type) => type.management!.visibleInManagement ?? true);

managementTypes.forEach((type) => {
const mappingProps = type.mappings.properties;
defaultSearchFields.forEach((searchField) => {
if (mappingProps[searchField]) {
const fieldDef = mappingProps[searchField];
if (fieldDef.type !== 'text') {
invalidMappings.push({
type: type.name,
field: searchField,
});
}
}
});
});

if (invalidMappings.length > 0) {
// `fail()` no longer exists...
expect(
`fields registered as defaultSearchField by any type must be registered as text. Invalid mappings found: ${JSON.stringify(
invalidMappings
)}`
).toEqual('');
}
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,18 @@ const previouslyRegisteredTypes = [
].sort();

describe('SO type registrations', () => {
let root: ReturnType<typeof createRoot>;

afterEach(() => {
try {
root?.shutdown();
} catch (e) {
/* trap */
}
});

it('does not remove types from registrations without updating excludeOnUpgradeQuery', async () => {
const root = createRoot({}, { oss: false });
root = createRoot({}, { oss: false });
await root.preboot();
const setup = await root.setup();
const currentlyRegisteredTypes = setup.savedObjects
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/observability/server/saved_objects/slo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export const slo: SavedObjectsType = {
dynamic: false,
properties: {
id: { type: 'keyword' },
name: { type: 'keyword' },
name: { type: 'text' },
description: { type: 'text' },
indicator: {
properties: {
Expand Down

0 comments on commit 8de96ea

Please sign in to comment.