-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/master' into migrate/url-short…
…ener
- Loading branch information
Showing
81 changed files
with
954 additions
and
811 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,7 +198,7 @@ | |
"lodash": "npm:@elastic/[email protected]", | ||
"lodash.clonedeep": "^4.5.0", | ||
"lru-cache": "4.1.5", | ||
"markdown-it": "^8.4.1", | ||
"markdown-it": "^10.0.0", | ||
"mini-css-extract-plugin": "0.8.0", | ||
"minimatch": "^3.0.4", | ||
"moment": "^2.24.0", | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { spawnSync } from 'child_process'; | ||
import { resolve } from 'path'; | ||
|
||
const ROOT_DIR = resolve(__dirname, '../../../../'); | ||
const INVALID_CONFIG_PATH = resolve(__dirname, '__fixtures__/invalid_config.yml'); | ||
|
||
interface LogEntry { | ||
message: string; | ||
tags: string[]; | ||
type: string; | ||
} | ||
|
||
describe('cli invalid config support', function() { | ||
it( | ||
'exits with statusCode 64 and logs a single line when config is invalid', | ||
function() { | ||
// Unused keys only throw once LegacyService starts, so disable migrations so that Core | ||
// will finish the start lifecycle without a running Elasticsearch instance. | ||
const { error, status, stdout } = spawnSync( | ||
process.execPath, | ||
['src/cli', '--config', INVALID_CONFIG_PATH, '--migrations.skip=true'], | ||
{ | ||
cwd: ROOT_DIR, | ||
} | ||
); | ||
|
||
const [fatalLogLine] = stdout | ||
.toString('utf8') | ||
.split('\n') | ||
.filter(Boolean) | ||
.map(line => JSON.parse(line) as LogEntry) | ||
.filter(line => line.tags.includes('fatal')) | ||
.map(obj => ({ | ||
...obj, | ||
pid: '## PID ##', | ||
'@timestamp': '## @timestamp ##', | ||
error: '## Error with stack trace ##', | ||
})); | ||
|
||
expect(error).toBe(undefined); | ||
expect(status).toBe(64); | ||
expect(fatalLogLine.message).toContain( | ||
'Error: Unknown configuration key(s): "unknown.key", "other.unknown.key", "other.third", "some.flat.key", ' + | ||
'"some.array". Check for spelling errors and ensure that expected plugins are installed.' | ||
); | ||
expect(fatalLogLine.tags).toEqual(['fatal', 'root']); | ||
expect(fatalLogLine.type).toEqual('log'); | ||
}, | ||
20 * 1000 | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
src/core/server/legacy/config/ensure_valid_configuration.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { ensureValidConfiguration } from './ensure_valid_configuration'; | ||
import { getUnusedConfigKeys } from './get_unused_config_keys'; | ||
import { configServiceMock } from '../../config/config_service.mock'; | ||
|
||
jest.mock('./get_unused_config_keys'); | ||
|
||
describe('ensureValidConfiguration', () => { | ||
let configService: ReturnType<typeof configServiceMock.create>; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
configService = configServiceMock.create(); | ||
configService.getUsedPaths.mockReturnValue(Promise.resolve(['core', 'elastic'])); | ||
|
||
(getUnusedConfigKeys as any).mockImplementation(() => []); | ||
}); | ||
|
||
it('calls getUnusedConfigKeys with correct parameters', async () => { | ||
await ensureValidConfiguration( | ||
configService as any, | ||
{ | ||
settings: 'settings', | ||
pluginSpecs: 'pluginSpecs', | ||
disabledPluginSpecs: 'disabledPluginSpecs', | ||
pluginExtendedConfig: 'pluginExtendedConfig', | ||
uiExports: 'uiExports', | ||
} as any | ||
); | ||
expect(getUnusedConfigKeys).toHaveBeenCalledTimes(1); | ||
expect(getUnusedConfigKeys).toHaveBeenCalledWith({ | ||
coreHandledConfigPaths: ['core', 'elastic'], | ||
pluginSpecs: 'pluginSpecs', | ||
disabledPluginSpecs: 'disabledPluginSpecs', | ||
inputSettings: 'settings', | ||
legacyConfig: 'pluginExtendedConfig', | ||
}); | ||
}); | ||
|
||
it('returns normally when there is no unused keys', async () => { | ||
await expect( | ||
ensureValidConfiguration(configService as any, {} as any) | ||
).resolves.toBeUndefined(); | ||
|
||
expect(getUnusedConfigKeys).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('throws when there are some unused keys', async () => { | ||
(getUnusedConfigKeys as any).mockImplementation(() => ['some.key', 'some.other.key']); | ||
|
||
await expect( | ||
ensureValidConfiguration(configService as any, {} as any) | ||
).rejects.toMatchInlineSnapshot( | ||
`[Error: Unknown configuration key(s): "some.key", "some.other.key". Check for spelling errors and ensure that expected plugins are installed.]` | ||
); | ||
}); | ||
}); |
50 changes: 50 additions & 0 deletions
50
src/core/server/legacy/config/ensure_valid_configuration.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
import { getUnusedConfigKeys } from './get_unused_config_keys'; | ||
import { ConfigService } from '../../config'; | ||
import { LegacyServiceDiscoverPlugins } from '../legacy_service'; | ||
import { CriticalError } from '../../errors'; | ||
|
||
export async function ensureValidConfiguration( | ||
configService: ConfigService, | ||
{ pluginSpecs, disabledPluginSpecs, pluginExtendedConfig, settings }: LegacyServiceDiscoverPlugins | ||
) { | ||
const unusedConfigKeys = await getUnusedConfigKeys({ | ||
coreHandledConfigPaths: await configService.getUsedPaths(), | ||
pluginSpecs, | ||
disabledPluginSpecs, | ||
inputSettings: settings, | ||
legacyConfig: pluginExtendedConfig, | ||
}); | ||
|
||
if (unusedConfigKeys.length > 0) { | ||
const message = `Unknown configuration key(s): ${unusedConfigKeys | ||
.map(key => `"${key}"`) | ||
.join(', ')}. Check for spelling errors and ensure that expected plugins are installed.`; | ||
throw new InvalidConfigurationError(message); | ||
} | ||
} | ||
|
||
class InvalidConfigurationError extends CriticalError { | ||
constructor(message: string) { | ||
super(message, 'InvalidConfig', 64); | ||
Object.setPrototypeOf(this, InvalidConfigurationError.prototype); | ||
} | ||
} |
Oops, something went wrong.