Kbn 176803 cleanup 8.14 md5 check (#183416)

## Summary

Follow-up of #176803

Now that `8.14` has been branched and it is about to be released, we can
remove the test that ensures the `HASH_TO_VERSION_MAP` is aligned.

This PR also rolls back a few changes on the map that shouldn't have
been performed, as they belong to `8.15.0`.
This commit is contained in:
Gerard Soldevila 2024-05-15 11:37:42 +02:00 committed by GitHub
parent f9460d19f9
commit ed2e59fea9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 2 additions and 82 deletions

View file

@ -130,7 +130,6 @@ export const DEFAULT_INDEX_TYPES_MAP: IndexTypesMap = {
export const HASH_TO_VERSION_MAP = {
'action_task_params|3d1b76c39bfb2cc8296b024d73854724': '10.0.0',
'action|0be88ebcc8560a075b6898236a202eb1': '10.0.0',
'ad_hoc_run_params|6aa8806a2e27d3be492a1da0d7721845': '10.0.0',
'alert|96a5a144778243a9f4fece0e71c2197f': '10.0.0',
'api_key_pending_invalidation|16f515278a295f6245149ad7c5ddedb7': '10.0.0',
'apm-custom-dashboards|561810b957ac3c09fcfc08f32f168e97': '10.0.0',
@ -182,10 +181,10 @@ export const HASH_TO_VERSION_MAP = {
'infrastructure-monitoring-log-view|c50526fc6040c5355ed027d34d05b35c': '10.0.0',
'infrastructure-ui-source|3d1b76c39bfb2cc8296b024d73854724': '10.0.0',
'ingest_manager_settings|b91ffb075799c78ffd7dbd51a279c8c9': '10.1.0',
'ingest-agent-policies|0ab9774bc7728d0c0f37d841570f2872': '10.2.0',
'ingest-agent-policies|0fd93cd11c019b118e93a9157c22057b': '10.1.0',
'ingest-download-sources|0b0f6828e59805bd07a650d80817c342': '10.0.0',
'ingest-outputs|b1237f7fdc0967709e75d65d208ace05': '10.6.0',
'ingest-package-policies|ca63c4c5a946704f045803a6b975dbc6': '10.9.0',
'ingest-package-policies|a1a074bad36e68d54f98d2158d60f879': '10.0.0',
'inventory-view|3d1b76c39bfb2cc8296b024d73854724': '10.0.0',
'kql-telemetry|3d1b76c39bfb2cc8296b024d73854724': '10.0.0',
'legacy-url-alias|0750774cf16475f88f2361e99cc5c8f0': '8.2.0',

View file

@ -1,79 +0,0 @@
/*
* 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.
*/
/*
* This file contains logic to build and diff the index mappings for a migration.
*/
import crypto from 'crypto';
import { mapValues } from 'lodash';
import {
getLatestMappingsVirtualVersionMap,
HASH_TO_VERSION_MAP,
} from '@kbn/core-saved-objects-base-server-internal';
import { buildTypesMappings } from '@kbn/core-saved-objects-migration-server-internal';
import { getCurrentVersionTypeRegistry } from '../kibana_migrator_test_kit';
describe('transition from md5 hashes to model versions', () => {
// this short-lived test is here to ensure no changes are introduced after the creation of the HASH_TO_VERSION_MAP
it('ensures the hashToVersionMap does not miss any mappings changes', async () => {
const typeRegistry = await getCurrentVersionTypeRegistry({ oss: false });
const mappingProperties = buildTypesMappings(typeRegistry.getAllTypes());
const hashes = md5Values(mappingProperties);
const versions = getLatestMappingsVirtualVersionMap(typeRegistry.getAllTypes());
const currentHashToVersionMap = Object.entries(hashes).reduce<Record<string, string>>(
(acc, [type, hash]) => {
acc[`${type}|${hash}`] = versions[type];
return acc;
},
{}
);
expect(currentHashToVersionMap).toEqual(HASH_TO_VERSION_MAP);
});
});
// Convert an object to an md5 hash string, using a stable serialization (canonicalStringify)
function md5Object(obj: any) {
return crypto.createHash('md5').update(canonicalStringify(obj)).digest('hex');
}
// JSON.stringify is non-canonical, meaning the same object may produce slightly
// different JSON, depending on compiler optimizations (e.g. object keys
// are not guaranteed to be sorted). This function consistently produces the same
// string, if passed an object of the same shape. If the outpuf of this function
// changes from one release to another, migrations will run, so it's important
// that this function remains stable across releases.
function canonicalStringify(obj: any): string {
if (Array.isArray(obj)) {
return `[${obj.map(canonicalStringify)}]`;
}
if (!obj || typeof obj !== 'object') {
return JSON.stringify(obj);
}
const keys = Object.keys(obj);
// This is important for properly handling Date
if (!keys.length) {
return JSON.stringify(obj);
}
const sortedObj = keys
.sort((a, b) => a.localeCompare(b))
.map((k) => `${k}: ${canonicalStringify(obj[k])}`);
return `{${sortedObj}}`;
}
// Convert an object's values to md5 hash strings
function md5Values(obj: any) {
return mapValues(obj, md5Object);
}