Skip to content

Commit

Permalink
Ignore 7.6.0 UUID if found
Browse files Browse the repository at this point in the history
  • Loading branch information
joshdover committed Feb 28, 2020
1 parent 0efd204 commit cd28676
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 8 deletions.
64 changes: 59 additions & 5 deletions src/core/server/uuid/resolve_uuid.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import { join } from 'path';
import { readFile, writeFile } from './fs';
import { resolveInstanceUuid } from './resolve_uuid';
import { resolveInstanceUuid, UUID_7_6_0_BUG } from './resolve_uuid';
import { configServiceMock } from '../config/config_service.mock';
import { loggingServiceMock } from '../logging/logging_service.mock';
import { BehaviorSubject } from 'rxjs';
Expand Down Expand Up @@ -123,10 +123,10 @@ describe('resolveInstanceUuid', () => {
expect(writeFile).not.toHaveBeenCalled();
expect(logger.debug).toHaveBeenCalledTimes(1);
expect(logger.debug.mock.calls[0]).toMatchInlineSnapshot(`
Array [
"Updating Kibana instance UUID to: CONFIG_UUID (was: FILE_UUID)",
]
`);
Array [
"Updating Kibana instance UUID to: CONFIG_UUID (was: FILE_UUID)",
]
`);
});
});
});
Expand Down Expand Up @@ -198,6 +198,60 @@ describe('resolveInstanceUuid', () => {
});
});

describe('when file is present with 7.6.0 UUID', () => {
describe('when config property is not set', () => {
it('writes new uuid to file and returns new uuid', async () => {
mockReadFile({ uuid: UUID_7_6_0_BUG });
configService = getConfigService(undefined);
const uuid = await resolveInstanceUuid({ configService, logger, syncToFile: true });
expect(uuid).not.toEqual(UUID_7_6_0_BUG);
expect(uuid).toEqual('NEW_UUID');
expect(writeFile).toHaveBeenCalledWith(
join('data-folder', 'uuid'),
'NEW_UUID',
expect.any(Object)
);
expect(logger.debug).toHaveBeenCalledTimes(2);
expect(logger.debug.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"UUID from 7.6.0 bug detected, ignoring file UUID",
],
Array [
"Setting new Kibana instance UUID: NEW_UUID",
],
]
`);
});
});

describe('when config property is set', () => {
it('writes config uuid to file and returns config uuid', async () => {
mockReadFile({ uuid: UUID_7_6_0_BUG });
configService = getConfigService(DEFAULT_CONFIG_UUID);
const uuid = await resolveInstanceUuid({ configService, logger, syncToFile: true });
expect(uuid).not.toEqual(UUID_7_6_0_BUG);
expect(uuid).toEqual(DEFAULT_CONFIG_UUID);
expect(writeFile).toHaveBeenCalledWith(
join('data-folder', 'uuid'),
DEFAULT_CONFIG_UUID,
expect.any(Object)
);
expect(logger.debug).toHaveBeenCalledTimes(2);
expect(logger.debug.mock.calls).toMatchInlineSnapshot(`
Array [
Array [
"UUID from 7.6.0 bug detected, ignoring file UUID",
],
Array [
"Setting new Kibana instance UUID: CONFIG_UUID",
],
]
`);
});
});
});

describe('when file is not present and config property is not set', () => {
describe('when syncToFile is true', () => {
it('generates a new uuid and write it to file', async () => {
Expand Down
18 changes: 15 additions & 3 deletions src/core/server/uuid/resolve_uuid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ import { Logger } from '../logging';

const FILE_ENCODING = 'utf8';
const FILE_NAME = 'uuid';
/**
* This UUID was inadvertantly shipped in the 7.6.0 distributable and should be deleted if found.
* See https://github.com/elastic/kibana/issues/57673 for more info.
*/
export const UUID_7_6_0_BUG = `ce42b997-a913-4d58-be46-bb1937feedd6`;

export async function resolveInstanceUuid({
configService,
Expand All @@ -51,7 +56,7 @@ export async function resolveInstanceUuid({

const uuidFilePath = join(pathConfig.data, FILE_NAME);

const uuidFromFile = await readUuidFromFile(uuidFilePath);
const uuidFromFile = await readUuidFromFile(uuidFilePath, logger);
const uuidFromConfig = serverConfig.uuid;

if (uuidFromConfig) {
Expand Down Expand Up @@ -82,10 +87,17 @@ export async function resolveInstanceUuid({
return uuidFromFile;
}

async function readUuidFromFile(filepath: string): Promise<string | undefined> {
async function readUuidFromFile(filepath: string, logger: Logger): Promise<string | undefined> {
try {
const content = await readFile(filepath);
return content.toString(FILE_ENCODING);
const decoded = content.toString(FILE_ENCODING);

if (decoded === UUID_7_6_0_BUG) {
logger.debug(`UUID from 7.6.0 bug detected, ignoring file UUID`);
return undefined;
} else {
return decoded;
}
} catch (e) {
if (e.code === 'ENOENT') {
// non-existent uuid file is ok, we will create it.
Expand Down

0 comments on commit cd28676

Please sign in to comment.