Skip to content

Commit

Permalink
[UA] Account for version qualifier in APM check (#33608) (#33621)
Browse files Browse the repository at this point in the history
The semver package does not handle version qualifiers as we intend

https://www.npmjs.com/package/semver#prerelease-tags

Signed-off-by: Tyler Smalley <[email protected]>
  • Loading branch information
tylersmalley authored Mar 20, 2019
1 parent a074f74 commit 911f137
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
8 changes: 8 additions & 0 deletions x-pack/plugins/upgrade_assistant/server/lib/apm/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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-*'], {
Expand Down
12 changes: 8 additions & 4 deletions x-pack/plugins/upgrade_assistant/server/lib/apm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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',
Expand All @@ -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);
Expand Down

0 comments on commit 911f137

Please sign in to comment.