Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Jan 26, 2021
1 parent b70b7df commit b204850
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

import { IconColor } from '@elastic/eui';
import { invert } from 'lodash';
import { MIGRATION_DEPRECATION_LEVEL } from '../../../../../common/types';
import { DeprecationInfo } from '../../../../../common/types';

export const LEVEL_MAP: { [level: string]: number } = {
warning: 0,
critical: 1,
};

export const REVERSE_LEVEL_MAP: { [idx: number]: MIGRATION_DEPRECATION_LEVEL } = invert(
export const REVERSE_LEVEL_MAP: { [idx: number]: DeprecationInfo['level'] } = invert(
LEVEL_MAP
) as any;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import React, { FunctionComponent } from 'react';
import { EuiBadge, EuiToolTip } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { DeprecationInfo, MIGRATION_DEPRECATION_LEVEL } from '../../../../../../common/types';
import { DeprecationInfo } from '../../../../../../common/types';
import { COLOR_MAP, LEVEL_MAP, REVERSE_LEVEL_MAP } from '../constants';

const LocalizedLevels: { [level: string]: string } = {
Expand All @@ -36,7 +36,7 @@ interface DeprecationHealthProps {
single?: boolean;
}

const SingleHealth: FunctionComponent<{ level: MIGRATION_DEPRECATION_LEVEL; label: string }> = ({
const SingleHealth: FunctionComponent<{ level: DeprecationInfo['level']; label: string }> = ({
level,
label,
}) => (
Expand Down Expand Up @@ -80,7 +80,7 @@ export const DeprecationHealth: FunctionComponent<DeprecationHealthProps> = ({
.map(([numLevel, stringLevel]) => (
<SingleHealth
key={stringLevel}
level={stringLevel as MIGRATION_DEPRECATION_LEVEL}
level={stringLevel as DeprecationInfo['level']}
label={`${countByLevel[numLevel]} ${LocalizedLevels[stringLevel]}`}
/>
))}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export const esVersionCheck = async (
ctx: RequestHandlerContext,
response: KibanaResponseFactory
) => {
const client = ctx.core.elasticsearch.client;
const { client } = ctx.core.elasticsearch;
let allNodeVersions: SemVer[];

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -734,9 +734,7 @@ describe('reindexService', () => {
expect(updatedOp.attributes.status).toEqual(ReindexStatus.failed);
expect(updatedOp.attributes.errorMessage!.includes(`Can't lock!`)).toBeTruthy();
expect(log.error).toHaveBeenCalledWith(expect.any(String));
expect(clusterClient.asCurrentUser.watcher.stop).not.toHaveBeenCalledWith({
enabled: true,
});
expect(clusterClient.asCurrentUser.watcher.stop).not.toHaveBeenCalled();
});

it('fails if watcher endpoint fails', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,12 +286,12 @@ export const reindexServiceFactory = (
*/
const setReadonly = async (reindexOp: ReindexSavedObject) => {
const { indexName } = reindexOp.attributes;
const { body } = await esClient.indices.putSettings({
const { body: putReadonly } = await esClient.indices.putSettings({
index: indexName,
body: { 'index.blocks.write': true },
});

if (!body.acknowledged) {
if (!putReadonly.acknowledged) {
throw new Error(`Index could not be set to readonly.`);
}

Expand All @@ -312,15 +312,15 @@ export const reindexServiceFactory = (

const { settings, mappings } = transformFlatSettings(flatSettings);

const { body } = await esClient.indices.create({
const { body: createIndex } = await esClient.indices.create({
index: newIndexName,
body: {
settings,
mappings,
},
});

if (!body.acknowledged) {
if (!createIndex.acknowledged) {
throw error.cannotCreateIndex(`Index could not be created: ${newIndexName}`);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ describe('deprecation logging API', () => {

describe('GET /api/upgrade_assistant/deprecation_logging', () => {
it('returns isEnabled', async () => {
(routeHandlerContextMock.core.elasticsearch.client
.callAsCurrentUser as jest.Mock).mockResolvedValue({
default: { logger: { deprecation: 'WARN' } },
(routeHandlerContextMock.core.elasticsearch.client.asCurrentUser.cluster
.getSettings as jest.Mock).mockResolvedValue({
body: { default: { logger: { deprecation: 'WARN' } } },
});
const resp = await routeDependencies.router.getHandler({
method: 'get',
Expand All @@ -51,8 +51,8 @@ describe('deprecation logging API', () => {
});

it('returns an error if it throws', async () => {
(routeHandlerContextMock.core.elasticsearch.client
.callAsCurrentUser as jest.Mock).mockRejectedValue(new Error(`scary error!`));
(routeHandlerContextMock.core.elasticsearch.client.asCurrentUser.cluster
.getSettings as jest.Mock).mockRejectedValue(new Error(`scary error!`));
const resp = await routeDependencies.router.getHandler({
method: 'get',
pathPattern: '/api/upgrade_assistant/deprecation_logging',
Expand All @@ -64,21 +64,21 @@ describe('deprecation logging API', () => {

describe('PUT /api/upgrade_assistant/deprecation_logging', () => {
it('returns isEnabled', async () => {
(routeHandlerContextMock.core.elasticsearch.client
.callAsCurrentUser as jest.Mock).mockResolvedValue({
default: { logger: { deprecation: 'ERROR' } },
(routeHandlerContextMock.core.elasticsearch.client.asCurrentUser.cluster
.putSettings as jest.Mock).mockResolvedValue({
body: { default: { logger: { deprecation: 'ERROR' } } },
});
const resp = await routeDependencies.router.getHandler({
method: 'get',
method: 'put',
pathPattern: '/api/upgrade_assistant/deprecation_logging',
})(routeHandlerContextMock, createRequestMock(), kibanaResponseFactory);
})(routeHandlerContextMock, { body: { isEnabled: true } }, kibanaResponseFactory);

expect(resp.payload).toEqual({ isEnabled: false });
});

it('returns an error if it throws', async () => {
(routeHandlerContextMock.core.elasticsearch.client
.callAsCurrentUser as jest.Mock).mockRejectedValue(new Error(`scary error!`));
(routeHandlerContextMock.core.elasticsearch.client.asCurrentUser.cluster
.putSettings as jest.Mock).mockRejectedValue(new Error(`scary error!`));
const resp = await routeDependencies.router.getHandler({
method: 'put',
pathPattern: '/api/upgrade_assistant/deprecation_logging',
Expand Down

0 comments on commit b204850

Please sign in to comment.