Skip to content

Commit

Permalink
Migrates elasticsearch client in the settings usage collector (#86397)
Browse files Browse the repository at this point in the history
  • Loading branch information
TinaHeiligers authored Dec 18, 2020
1 parent 5376d6c commit 0155974
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 8 additions & 2 deletions x-pack/plugins/xpack_legacy/server/routes/settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,20 @@ import { registerSettingsRoute } from './settings';
type HttpService = ReturnType<typeof createHttpServer>;
type HttpSetup = UnwrapPromise<ReturnType<HttpService['setup']>>;

export function mockGetClusterInfo(clusterInfo: any) {
const esClient = elasticsearchServiceMock.createScopedClusterClient().asCurrentUser;
// @ts-ignore we only care about the response body
esClient.info.mockResolvedValue({ body: { ...clusterInfo } });
return esClient;
}
describe('/api/settings', () => {
let server: HttpService;
let httpSetup: HttpSetup;
let overallStatus$: BehaviorSubject<ServiceStatus>;
let mockApiCaller: jest.Mocked<LegacyAPICaller>;

beforeEach(async () => {
mockApiCaller = jest.fn().mockResolvedValue({ cluster_uuid: 'yyy-yyyyy' });
mockApiCaller = jest.fn();
server = createHttpServer();
httpSetup = await server.setup({
context: contextServiceMock.createSetupContract({
Expand All @@ -43,7 +49,7 @@ describe('/api/settings', () => {
},
},
client: {
asCurrentUser: elasticsearchServiceMock.createScopedClusterClient().asCurrentUser,
asCurrentUser: mockGetClusterInfo({ cluster_uuid: 'yyy-yyyyy' }),
},
},
savedObjects: {
Expand Down
7 changes: 3 additions & 4 deletions x-pack/plugins/xpack_legacy/server/routes/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,9 @@ export function registerSettingsRoute({
const settings =
(await settingsCollector.fetch(collectorFetchContext)) ??
settingsCollector.getEmailValueStructure(null);
const { cluster_uuid: uuid } = await callAsCurrentUser('info', {
filterPath: 'cluster_uuid',
});

const { body } = await collectorFetchContext.esClient.info({ filter_path: 'cluster_uuid' });
const uuid: string = body.cluster_uuid;

const overallStatus = await overallStatus$.pipe(first()).toPromise();

Expand All @@ -76,7 +76,6 @@ export function registerSettingsRoute({
snapshot: SNAPSHOT_REGEX.test(config.kibanaVersion),
status: ServiceStatusToLegacyState[overallStatus.level.toString()],
};

return res.ok({
body: {
cluster_uuid: uuid,
Expand Down

0 comments on commit 0155974

Please sign in to comment.