-
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.
- Loading branch information
1 parent
cafc7a6
commit b833984
Showing
9 changed files
with
169 additions
and
36 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
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
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,82 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* and the Server Side Public License, v 1; you may not use this file except in | ||
* compliance with, at your election, the Elastic License or the Server Side | ||
* Public License, v 1. | ||
*/ | ||
|
||
import { take } from 'rxjs/operators'; | ||
import { ConfigService, Env } from '@kbn/config'; | ||
import { getEnvOptions, rawConfigServiceMock } from '../config/mocks'; | ||
import { getGlobalConfig, getGlobalConfig$ } from './legacy_config'; | ||
import { REPO_ROOT } from '@kbn/utils'; | ||
import { loggingSystemMock } from '../logging/logging_system.mock'; | ||
import { duration } from 'moment'; | ||
import { fromRoot } from '../utils'; | ||
import { ByteSizeValue } from '@kbn/config-schema'; | ||
import { Server } from '../server'; | ||
|
||
describe('Legacy config', () => { | ||
let env: Env; | ||
let logger: ReturnType<typeof loggingSystemMock.create>; | ||
|
||
beforeEach(() => { | ||
env = Env.createDefault(REPO_ROOT, getEnvOptions()); | ||
logger = loggingSystemMock.create(); | ||
}); | ||
|
||
const createConfigService = (rawConfig: Record<string, any> = {}): ConfigService => { | ||
const rawConfigService = rawConfigServiceMock.create({ rawConfig }); | ||
const server = new Server(rawConfigService, env, logger); | ||
server.setupCoreConfig(); | ||
return server.configService; | ||
}; | ||
|
||
describe('getGlobalConfig', () => { | ||
it('should return the global config', async () => { | ||
const configService = createConfigService(); | ||
await configService.validate(); | ||
|
||
const legacyConfig = getGlobalConfig(configService); | ||
|
||
expect(legacyConfig).toStrictEqual({ | ||
kibana: { | ||
index: '.kibana', | ||
autocompleteTerminateAfter: duration(100000), | ||
autocompleteTimeout: duration(1000), | ||
}, | ||
elasticsearch: { | ||
shardTimeout: duration(30, 's'), | ||
requestTimeout: duration(30, 's'), | ||
pingTimeout: duration(30, 's'), | ||
}, | ||
path: { data: fromRoot('data') }, | ||
savedObjects: { maxImportPayloadBytes: new ByteSizeValue(26214400) }, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('getGlobalConfig$', () => { | ||
it('should return an observable for the global config', async () => { | ||
const configService = createConfigService(); | ||
|
||
const legacyConfig = await getGlobalConfig$(configService).pipe(take(1)).toPromise(); | ||
|
||
expect(legacyConfig).toStrictEqual({ | ||
kibana: { | ||
index: '.kibana', | ||
autocompleteTerminateAfter: duration(100000), | ||
autocompleteTimeout: duration(1000), | ||
}, | ||
elasticsearch: { | ||
shardTimeout: duration(30, 's'), | ||
requestTimeout: duration(30, 's'), | ||
pingTimeout: duration(30, 's'), | ||
}, | ||
path: { data: fromRoot('data') }, | ||
savedObjects: { maxImportPayloadBytes: new ByteSizeValue(26214400) }, | ||
}); | ||
}); | ||
}); | ||
}); |
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,69 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* and the Server Side Public License, v 1; you may not use this file except in | ||
* compliance with, at your election, the Elastic License or the Server Side | ||
* Public License, v 1. | ||
*/ | ||
|
||
import { map, shareReplay } from 'rxjs/operators'; | ||
import { combineLatest, Observable } from 'rxjs'; | ||
import { PathConfigType, config as pathConfig } from '@kbn/utils'; | ||
import { pick, deepFreeze } from '@kbn/std'; | ||
import { IConfigService } from '@kbn/config'; | ||
|
||
import { SharedGlobalConfig, SharedGlobalConfigKeys } from './types'; | ||
import { KibanaConfigType, config as kibanaConfig } from '../kibana_config'; | ||
import { | ||
ElasticsearchConfigType, | ||
config as elasticsearchConfig, | ||
} from '../elasticsearch/elasticsearch_config'; | ||
import { SavedObjectsConfigType, savedObjectsConfig } from '../saved_objects/saved_objects_config'; | ||
|
||
const createGlobalConfig = ({ | ||
kibana, | ||
elasticsearch, | ||
path, | ||
savedObjects, | ||
}: { | ||
kibana: KibanaConfigType; | ||
elasticsearch: ElasticsearchConfigType; | ||
path: PathConfigType; | ||
savedObjects: SavedObjectsConfigType; | ||
}): SharedGlobalConfig => { | ||
return deepFreeze({ | ||
kibana: pick(kibana, SharedGlobalConfigKeys.kibana), | ||
elasticsearch: pick(elasticsearch, SharedGlobalConfigKeys.elasticsearch), | ||
path: pick(path, SharedGlobalConfigKeys.path), | ||
savedObjects: pick(savedObjects, SharedGlobalConfigKeys.savedObjects), | ||
}); | ||
}; | ||
|
||
export const getGlobalConfig = (configService: IConfigService): SharedGlobalConfig => { | ||
return createGlobalConfig({ | ||
kibana: configService.atPathSync<KibanaConfigType>(kibanaConfig.path), | ||
elasticsearch: configService.atPathSync<ElasticsearchConfigType>(elasticsearchConfig.path), | ||
path: configService.atPathSync<PathConfigType>(pathConfig.path), | ||
savedObjects: configService.atPathSync<SavedObjectsConfigType>(savedObjectsConfig.path), | ||
}); | ||
}; | ||
|
||
export const getGlobalConfig$ = (configService: IConfigService): Observable<SharedGlobalConfig> => { | ||
return combineLatest([ | ||
configService.atPath<KibanaConfigType>(kibanaConfig.path), | ||
configService.atPath<ElasticsearchConfigType>(elasticsearchConfig.path), | ||
configService.atPath<PathConfigType>(pathConfig.path), | ||
configService.atPath<SavedObjectsConfigType>(savedObjectsConfig.path), | ||
]).pipe( | ||
map( | ||
([kibana, elasticsearch, path, savedObjects]) => | ||
createGlobalConfig({ | ||
kibana, | ||
elasticsearch, | ||
path, | ||
savedObjects, | ||
}), | ||
shareReplay(1) | ||
) | ||
); | ||
}; |
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
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