mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
# Backport This will backport the following commits from `main` to `8.x`: - [Added versioning to inventory_view_saved_object (#207007)](https://github.com/elastic/kibana/pull/207007) <!--- Backport version: 9.6.4 --> ### Questions ? Please refer to the [Backport tool documentation](https://github.com/sorenlouv/backport) <!--BACKPORT [{"author":{"name":"Bryce Buchanan","email":"75274611+bryce-b@users.noreply.github.com"},"sourceCommit":{"committedDate":"2025-01-27T18:09:32Z","message":"Added versioning to inventory_view_saved_object (#207007)\n\n## Summary\r\n\r\nFixes #187254 \r\nStrict checks on the attribute `legend.steps` was added to the inventory\r\nview API in v8.10 (#160852), but they were not defined in the\r\nsaved object type for that data, resulting in older versions migrating\r\nbad data, and being unable to use the API. This PR adds versioning to\r\nthe Inventory view saved object type that constrains legend.steps to\r\nbetween 2 and 18, per the strict typing added in #160852\r\n\r\n#### Open questions\r\nShould we add notes to all versions of kibana between v8.10 and oldest\r\nversion available for backport describing this bug?\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies following conditions. \r\n\r\nReviewers should verify this PR satisfies this list as well.\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [x] The PR description includes the appropriate Release Notes section,\r\nand the correct `release_note:*` label is applied per the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"a108c632a459240f9c27262395e2584f92d43779","branchLabelMapping":{"^v9.0.0$":"main","^v8.18.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Core","release_note:fix","backport missing","v9.0.0","Team:obs-ux-infra_services"],"title":"Added versioning to inventory_view_saved_object","number":207007,"url":"https://github.com/elastic/kibana/pull/207007","mergeCommit":{"message":"Added versioning to inventory_view_saved_object (#207007)\n\n## Summary\r\n\r\nFixes #187254 \r\nStrict checks on the attribute `legend.steps` was added to the inventory\r\nview API in v8.10 (#160852), but they were not defined in the\r\nsaved object type for that data, resulting in older versions migrating\r\nbad data, and being unable to use the API. This PR adds versioning to\r\nthe Inventory view saved object type that constrains legend.steps to\r\nbetween 2 and 18, per the strict typing added in #160852\r\n\r\n#### Open questions\r\nShould we add notes to all versions of kibana between v8.10 and oldest\r\nversion available for backport describing this bug?\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies following conditions. \r\n\r\nReviewers should verify this PR satisfies this list as well.\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [x] The PR description includes the appropriate Release Notes section,\r\nand the correct `release_note:*` label is applied per the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"a108c632a459240f9c27262395e2584f92d43779"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/207007","number":207007,"mergeCommit":{"message":"Added versioning to inventory_view_saved_object (#207007)\n\n## Summary\r\n\r\nFixes #187254 \r\nStrict checks on the attribute `legend.steps` was added to the inventory\r\nview API in v8.10 (#160852), but they were not defined in the\r\nsaved object type for that data, resulting in older versions migrating\r\nbad data, and being unable to use the API. This PR adds versioning to\r\nthe Inventory view saved object type that constrains legend.steps to\r\nbetween 2 and 18, per the strict typing added in #160852\r\n\r\n#### Open questions\r\nShould we add notes to all versions of kibana between v8.10 and oldest\r\nversion available for backport describing this bug?\r\n\r\n### Checklist\r\n\r\nCheck the PR satisfies following conditions. \r\n\r\nReviewers should verify this PR satisfies this list as well.\r\n\r\n- [x] [Unit or functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere updated or added to match the most common scenarios\r\n- [x] The PR description includes the appropriate Release Notes section,\r\nand the correct `release_note:*` label is applied per the\r\n[guidelines](https://www.elastic.co/guide/en/kibana/master/contributing.html#kibana-release-notes-process)\r\n\r\n---------\r\n\r\nCo-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>","sha":"a108c632a459240f9c27262395e2584f92d43779"}}]}] BACKPORT-->
This commit is contained in:
parent
e056274ad0
commit
89c59d3ee6
4 changed files with 96 additions and 1 deletions
|
@ -126,7 +126,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
|
|||
"ingest-outputs": "daafff49255ab700e07491376fe89f04fc998b91",
|
||||
"ingest-package-policies": "870f8c21fe3602f31075430a1fdfb052c62d4a14",
|
||||
"ingest_manager_settings": "111a616eb72627c002029c19feb9e6c439a10505",
|
||||
"inventory-view": "b8683c8e352a286b4aca1ab21003115a4800af83",
|
||||
"inventory-view": "fd2b7fe713956f261018dded00d8f8c986417763",
|
||||
"kql-telemetry": "93c1d16c1a0dfca9c8842062cf5ef8f62ae401ad",
|
||||
"legacy-url-alias": "9b8cca3fbb2da46fd12823d3cd38fdf1c9f24bc8",
|
||||
"lens": "5cfa2c52b979b4f8df56dd13c477e152183468b9",
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
/*
|
||||
* 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.
|
||||
*/
|
||||
import {
|
||||
createModelVersionTestMigrator,
|
||||
type ModelVersionTestMigrator,
|
||||
} from '@kbn/core-test-helpers-model-versions';
|
||||
|
||||
import { inventoryViewSavedObjectType } from './inventory_view_saved_object';
|
||||
|
||||
describe('invetoryViewSavedObject model version transformation', () => {
|
||||
let migrator: ModelVersionTestMigrator;
|
||||
beforeEach(() => {
|
||||
migrator = createModelVersionTestMigrator({ type: inventoryViewSavedObjectType });
|
||||
});
|
||||
|
||||
describe('model veresion 2', () => {
|
||||
const inventoryViewV2 = {
|
||||
id: 'someId',
|
||||
type: 'inventory-view',
|
||||
attributes: {
|
||||
metric: { type: 'cpu' },
|
||||
sort: { by: 'name', direction: 'desc' },
|
||||
groupBy: [],
|
||||
nodeType: 'host',
|
||||
view: 'map',
|
||||
customOptions: [],
|
||||
customMetrics: [],
|
||||
boundsOverride: { min: 0, max: 1 },
|
||||
autoBounds: true,
|
||||
accountId: '',
|
||||
region: '',
|
||||
autoReload: false,
|
||||
filterQuery: { expression: '', kind: 'kuery' },
|
||||
legend: { palette: 'cool', reverseColors: false, steps: 18 },
|
||||
timelineOpen: false,
|
||||
name: 'test',
|
||||
},
|
||||
references: [],
|
||||
};
|
||||
|
||||
it('should clamp legend.steps to 18 when converting from v1 to v2', () => {
|
||||
const inventoryViewV1 = JSON.parse(JSON.stringify(inventoryViewV2));
|
||||
inventoryViewV1.attributes.legend.steps = 20;
|
||||
const migrated = migrator.migrate({
|
||||
document: {
|
||||
...inventoryViewV1,
|
||||
attributes: {
|
||||
...inventoryViewV1.attributes,
|
||||
},
|
||||
},
|
||||
fromVersion: 1,
|
||||
toVersion: 2,
|
||||
});
|
||||
expect(migrated.attributes).toEqual(inventoryViewV2.attributes);
|
||||
});
|
||||
});
|
||||
});
|
|
@ -5,6 +5,7 @@
|
|||
* 2.0.
|
||||
*/
|
||||
|
||||
import { schema } from '@kbn/config-schema';
|
||||
import { fold } from 'fp-ts/lib/Either';
|
||||
import { pipe } from 'fp-ts/lib/pipeable';
|
||||
import type { SavedObject, SavedObjectsType } from '@kbn/core/server';
|
||||
|
@ -21,6 +22,11 @@ const getInventoryViewTitle = (savedObject: SavedObject<unknown>) =>
|
|||
)
|
||||
);
|
||||
|
||||
const schemaV1 = schema.object({}, { unknowns: 'allow' });
|
||||
const schemaV2 = schema.object({
|
||||
legend: schema.object({ steps: schema.number({ max: 18, min: 2 }) }),
|
||||
});
|
||||
|
||||
export const inventoryViewSavedObjectType: SavedObjectsType = {
|
||||
name: inventoryViewSavedObjectName,
|
||||
hidden: false,
|
||||
|
@ -36,4 +42,31 @@ export const inventoryViewSavedObjectType: SavedObjectsType = {
|
|||
dynamic: false,
|
||||
properties: {},
|
||||
},
|
||||
modelVersions: {
|
||||
1: {
|
||||
changes: [],
|
||||
schemas: {
|
||||
create: schemaV1,
|
||||
},
|
||||
},
|
||||
2: {
|
||||
changes: [
|
||||
{
|
||||
type: 'unsafe_transform',
|
||||
transformFn: (document) => {
|
||||
if (document.attributes.legend.steps > 18) {
|
||||
document.attributes.legend.steps = 18;
|
||||
} else if (document.attributes.legend.steps < 2) {
|
||||
document.attributes.legend.steps = 2;
|
||||
}
|
||||
return { document };
|
||||
},
|
||||
},
|
||||
],
|
||||
schemas: {
|
||||
forwardCompatibility: schemaV2.extends({}, { unknowns: 'ignore' }),
|
||||
create: schemaV2,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
|
|
@ -119,6 +119,7 @@
|
|||
"@kbn/config",
|
||||
"@kbn/response-ops-rule-params",
|
||||
"@kbn/charts-theme",
|
||||
"@kbn/core-test-helpers-model-versions",
|
||||
"@kbn/traced-es-client",
|
||||
"@kbn/observability-utils-common"
|
||||
],
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue