-
Notifications
You must be signed in to change notification settings - Fork 8.5k
[Task Manager] Ensure putTemplate will only create/update the index template #28540
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 21 commits
fdcd142
0a8a195
f01f89f
e55750a
640fa48
5e18822
3d39746
1196d88
a0845b1
d7b1891
1ca259b
1ccafe5
4f2b61a
a367be4
eda8508
d4bccd6
8e76fbd
d2d8ccb
bd7f717
1a9cc96
5eb15d7
d0eb5c2
5745cc7
730fe9e
537e7ca
578bc29
b659944
dcd90d8
0e5d17c
3e4a3fe
36dd212
c4d1611
5efaa93
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import xPackage from '../../package.json'; | ||
| import { getTemplateVersion } from './lib/get_template_version'; | ||
|
|
||
| export const TASK_MANAGER_API_VERSION = 1; | ||
| export const TASK_MANAGER_TEMPLATE_VERSION = getTemplateVersion(xPackage.version); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import { getTemplateVersion } from './get_template_version'; | ||
|
|
||
| describe('getTemplateVersion', () => { | ||
| it('converts a release build version string into an integer', () => { | ||
| const versionStr1 = '7.1.2'; | ||
| expect(getTemplateVersion(versionStr1)).toBe(7010299); | ||
|
|
||
| const versionStr2 = '10.1.0'; | ||
| expect(getTemplateVersion(versionStr2)).toBe(10010099); | ||
| }); | ||
|
|
||
| it('converts a alpha build version string into an integer', () => { | ||
| const versionStr1 = '7.0.0-alpha1'; | ||
| expect(getTemplateVersion(versionStr1)).toBe(7000001); | ||
|
|
||
| const versionStr2 = '7.0.0-alpha3'; | ||
| expect(getTemplateVersion(versionStr2)).toBe(7000003); | ||
| }); | ||
|
|
||
| it('converts a beta build version string into an integer', () => { | ||
| const versionStr1 = '7.0.0-beta4'; | ||
| expect(getTemplateVersion(versionStr1)).toBe(7000029); | ||
|
|
||
| const versionStr5 = '7.0.0-beta8'; | ||
| expect(getTemplateVersion(versionStr5)).toBe(7000033); | ||
| }); | ||
|
|
||
| it('converts a snapshot build version string into an integer', () => { | ||
| expect(getTemplateVersion('8.0.0-alpha1')).toBe(8000001); | ||
| expect(getTemplateVersion('8.0.0-alpha1-snapshot')).toBe(8000001); | ||
| }); | ||
|
|
||
| it('not intended to handle any version parts with 3-digits: it will create malformed integer values', () => { | ||
| expect(getTemplateVersion('60.61.1') === getTemplateVersion('6.6.101')).toBe(true); // both produce 60610199 | ||
| expect(getTemplateVersion('1.32.0') < getTemplateVersion('1.3.223423')).toBe(true); | ||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| import { padLeft } from 'lodash'; | ||
|
|
||
| /* | ||
| * The logic for ID is: XXYYZZAA, where XX is major version, YY is minor | ||
| * version, ZZ is revision, and AA is alpha/beta/rc indicator. | ||
| * | ||
| * AA values below 25 are for alpha builder (since 5.0), and above 25 and below | ||
| * 50 are beta builds, and below 99 are RC builds, with 99 indicating a release | ||
| * the (internal) format of the id is there so we can easily do after/before | ||
| * checks on the id | ||
| * | ||
| * Note: the conversion method is carried over from Elasticsearch: | ||
| * https://github.com/elastic/elasticsearch/blob/de962b2/server/src/main/java/org/elasticsearch/Version.java | ||
| */ | ||
| export function getTemplateVersion(versionStr: string): number { | ||
| // break up the string parts | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested this, and it doesn't seem to handle some edge cases. The following expression evaluates to true, but should be false (e.g. 1.32 is greater than 1.3).
Is there a reason we aren't using the semver library to handle semvers? It's what we're using in migrations, for example.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. He matched the version behavior that Elasticsearch uses, which simply doesn't allow for 3-digit, or greater, minor and patch releases. If we get into a situation where we have Kibana 6.2.100, then I think we have other issues. We could add a test that pulls in the packaged version and asserts that it isn't >= 99 so that we can be aware that the next minor / patch release will have that issue though.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would love using semver here, but the value for the version field needs to be an integer per the ES API. I took a stab at looking for whether using semver would help this code more-or-less as it is. It can be used to replace But as this function needs to produce an integer, I think it still has the same problem with 3-digit version parts that you bring up
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This thread is relevant to a call we had with @njd5475 and @chrisdavies and others
If I understand things correctly, Kibana Migrations and Saved Objects client mean we don't need to worry about BWC in our own code? That would be great! Although, for now there seem to be no features that use those capabilities other than core Kibana for the Does this sound ok?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. cc @cwurm, was on the call and had some thoughts about Saved Object client as well
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not me :)
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. sorry - I meant @weltenwort |
||
| const splitted = versionStr.split('.'); | ||
| const minorStr = splitted[2] || ''; | ||
|
|
||
| // pad each part with leading 0 to make 2 characters | ||
| const padded = splitted.map((v: string) => { | ||
| const vMatches = v.match(/\d+/); | ||
| if (vMatches) { | ||
| return padLeft(vMatches[0], 2, '0'); | ||
| } | ||
| return '00'; | ||
| }); | ||
| const [majorV, minorV, patchV] = padded; | ||
|
|
||
| // append the alpha/beta/rc indicator | ||
| let buildV; | ||
| if (minorStr.match('alpha')) { | ||
| const matches = minorStr.match(/alpha(?<alpha>\d+)/); | ||
| if (matches != null && matches.groups != null) { | ||
| const alphaVerInt = parseInt(matches.groups.alpha, 10); // alpha build indicator | ||
| buildV = padLeft(`${alphaVerInt}`, 2, '0'); | ||
| } | ||
| } else if (minorStr.match('beta')) { | ||
| const matches = minorStr.match(/beta(?<beta>\d+)/); | ||
| if (matches != null && matches.groups != null) { | ||
| const alphaVerInt = parseInt(matches.groups.beta, 10) + 25; // beta build indicator | ||
| buildV = padLeft(`${alphaVerInt}`, 2, '0'); | ||
| } | ||
| } else { | ||
| buildV = '99'; // release build indicator | ||
| } | ||
|
|
||
| const joinedParts = [majorV, minorV, patchV, buildV].join(''); | ||
| return parseInt(joinedParts, 10); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,11 +53,15 @@ export class TaskManager { | |
|
|
||
| const logger = new TaskManagerLogger((...args: any[]) => server.log(...args)); | ||
|
|
||
| /* Kibana UUID needs to be pulled live (not cached), as it takes a long time | ||
| * to initialize, and can change after startup */ | ||
| const store = new TaskStore({ | ||
| callCluster: server.plugins.elasticsearch.getCluster('admin').callWithInternalUser, | ||
| index: config.get('xpack.task_manager.index'), | ||
| maxAttempts: config.get('xpack.task_manager.max_attempts'), | ||
| supportedTypes: Object.keys(this.definitions), | ||
| logger, | ||
| getKibanaUuid: () => config.get('server.uuid'), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't look like we are using the kibana uuid. Why exactly would we want to add it if we are not using it?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is for troubleshooting. With any Kibana instance in the cluster able to claim a task, it'll be great being able to track problematic instances doing stuff to the tasks. We're doing this in the Reporting index as well, because we saw benefit in being able to track it |
||
| }); | ||
| const pool = new TaskPool({ | ||
| logger, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.