From 911f1376747cfc12d35b4c4ea05911d9ace59fac Mon Sep 17 00:00:00 2001 From: Tyler Smalley Date: Wed, 20 Mar 2019 16:53:24 -0700 Subject: [PATCH] [UA] Account for version qualifier in APM check (#33608) (#33621) The semver package does not handle version qualifiers as we intend https://www.npmjs.com/package/semver#prerelease-tags Signed-off-by: Tyler Smalley --- .../upgrade_assistant/server/lib/apm/index.test.ts | 8 ++++++++ .../upgrade_assistant/server/lib/apm/index.ts | 12 ++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/x-pack/plugins/upgrade_assistant/server/lib/apm/index.test.ts b/x-pack/plugins/upgrade_assistant/server/lib/apm/index.test.ts index 4263fec5cff11..5ec7ef872595e 100644 --- a/x-pack/plugins/upgrade_assistant/server/lib/apm/index.test.ts +++ b/x-pack/plugins/upgrade_assistant/server/lib/apm/index.test.ts @@ -101,6 +101,14 @@ describe('isLegacyApmIndex', () => { ).toEqual(false); }); + it('is false when using a version qualifier', () => { + expect( + isLegacyApmIndex('foo-1', ['foo-*'], { + _meta: { version: '7.0.0-rc1' }, + }) + ).toEqual(false); + }); + it('handles multiple index patterns', () => { expect( isLegacyApmIndex('bar-1', ['foo-*', 'bar-*'], { diff --git a/x-pack/plugins/upgrade_assistant/server/lib/apm/index.ts b/x-pack/plugins/upgrade_assistant/server/lib/apm/index.ts index 29b396e9b9eac..4563a944eab53 100644 --- a/x-pack/plugins/upgrade_assistant/server/lib/apm/index.ts +++ b/x-pack/plugins/upgrade_assistant/server/lib/apm/index.ts @@ -7,7 +7,7 @@ import { Request } from 'hapi'; import { get } from 'lodash'; import minimatch from 'minimatch'; -import semver from 'semver'; +import { SemVer } from 'semver'; import { CallClusterWithRequest } from 'src/legacy/core_plugins/elasticsearch'; import { EnrichedDeprecationInfo } from '../es_migration_apis'; @@ -26,7 +26,7 @@ export async function getDeprecatedApmIndices( }); return Object.keys(indices).reduce((deprecations: EnrichedDeprecationInfo[], index) => { - if (semver.lt(get(indices[index], 'mappings._meta.version', '0.0.0'), '7.0.0')) { + if (isLegacyApmIndex(index, indexPatterns, indices[index].mappings)) { deprecations.push({ level: 'warning', message: 'APM index needs converted to 7.x format', @@ -46,10 +46,14 @@ export const isLegacyApmIndex = ( apmIndexPatterns: string[] = [], mappings: FlatSettings['mappings'] ) => { - const clientVersion = get(mappings, '_meta.version', '0.0.0'); + const clientVersion = new SemVer(get(mappings, '_meta.version', '0.0.0')); + + if (clientVersion.compareMain('7.0.0') > -1) { + return false; + } const find = apmIndexPatterns.find(pattern => { - return minimatch(indexName, pattern) && semver.lt(clientVersion, '7.0.0'); // no client version or version < 7.0 + return minimatch(indexName, pattern); }); return Boolean(find);