Skip to content

Commit

Permalink
fix backport
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Feb 25, 2021
1 parent 81512ed commit 5b1391a
Show file tree
Hide file tree
Showing 17 changed files with 36 additions and 455 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@ import {
EuiFlexItem,
EuiFlyoutBody,
EuiFlyoutFooter,
EuiLink,
EuiSpacer,
EuiTitle,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';

import { ReindexStatus, ReindexWarning } from '../../../../../../../../common/types';
import { ReindexStatus } from '../../../../../../../../common/types';
import { LoadingState } from '../../../../../types';
import { ReindexState } from '../polling_service';
import { ReindexProgress } from './progress';
Expand Down Expand Up @@ -78,7 +77,7 @@ export const ChecklistFlyoutStep: React.FunctionComponent<{
cancelReindex: () => void;
http: HttpSetup;
}> = ({ closeFlyout, reindexState, startReindex, cancelReindex, http, renderGlobalCallouts }) => {
const { loadingState, status, hasRequiredPrivileges, reindexWarnings } = reindexState;
const { loadingState, status, hasRequiredPrivileges } = reindexState;
const loading = loadingState === LoadingState.Loading || status === ReindexStatus.inProgress;

return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ describe('getUpgradeAssistantStatus', () => {
esClient.asCurrentUser.indices.resolveIndex.mockResolvedValue(asApiResponse(resolvedIndices));

it('calls /_migration/deprecations', async () => {
await getUpgradeAssistantStatus(esClient, false, []);
await getUpgradeAssistantStatus(esClient, false);
expect(esClient.asCurrentUser.migration.deprecations).toHaveBeenCalled();
});

it('returns the correct shape of data', async () => {
const resp = await getUpgradeAssistantStatus(esClient, false, []);
const resp = await getUpgradeAssistantStatus(esClient, false);
expect(resp).toMatchSnapshot();
});

Expand All @@ -56,7 +56,7 @@ describe('getUpgradeAssistantStatus', () => {
})
);

await expect(getUpgradeAssistantStatus(esClient, false, [])).resolves.toHaveProperty(
await expect(getUpgradeAssistantStatus(esClient, false)).resolves.toHaveProperty(
'readyForUpgrade',
false
);
Expand All @@ -72,7 +72,7 @@ describe('getUpgradeAssistantStatus', () => {
})
);

await expect(getUpgradeAssistantStatus(esClient, false, [])).resolves.toHaveProperty(
await expect(getUpgradeAssistantStatus(esClient, false)).resolves.toHaveProperty(
'readyForUpgrade',
true
);
Expand All @@ -94,7 +94,7 @@ describe('getUpgradeAssistantStatus', () => {
})
);

const result = await getUpgradeAssistantStatus(esClient, true, []);
const result = await getUpgradeAssistantStatus(esClient, true);

expect(result).toHaveProperty('readyForUpgrade', true);
expect(result).toHaveProperty('cluster', []);
Expand Down
49 changes: 17 additions & 32 deletions x-pack/plugins/upgrade_assistant/server/lib/es_migration_apis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ import {
UpgradeAssistantStatus,
} from '../../common/types';

import { isSystemIndex } from './reindexing';

import { esIndicesStateCheck } from './es_indices_state_check';

export async function getUpgradeAssistantStatus(
dataClient: IScopedClusterClient,
isCloudEnabled: boolean,
isCloudEnabled: boolean
): Promise<UpgradeAssistantStatus> {
const [{ body: deprecations }] = await Promise.all([
dataClient.asCurrentUser.migration.deprecations<DeprecationAPIResponse>(),
]);
const {
body: deprecations,
} = await dataClient.asCurrentUser.migration.deprecations<DeprecationAPIResponse>();

const cluster = getClusterDeprecations(deprecations, isCloudEnabled);
const indices = getCombinedIndexInfos(deprecations);
Expand Down Expand Up @@ -50,32 +48,19 @@ export async function getUpgradeAssistantStatus(
}

// Reformats the index deprecations to an array of deprecation warnings extended with an index field.
const getCombinedIndexInfos = (
deprecations: DeprecationAPIResponse,
) => {

return (
Object.keys(deprecations.index_settings)
.reduce((indexDeprecations, indexName) => {
return indexDeprecations.concat(
deprecations.index_settings[indexName].map(
(d) =>
({
...d,
index: indexName,
reindex: /Index created before/.test(d.message),
needsDefaultFields: /Number of fields exceeds automatic field expansion limit/.test(
d.message
),
} as EnrichedDeprecationInfo)
)
);
}, [] as EnrichedDeprecationInfo[])
// Filter out warnings for system indices until we know more about what changes are required for the
// next upgrade in a future minor version.
.filter((deprecation) => !isSystemIndex(deprecation.index!))
);
};
const getCombinedIndexInfos = (deprecations: DeprecationAPIResponse) =>
Object.keys(deprecations.index_settings).reduce((indexDeprecations, indexName) => {
return indexDeprecations.concat(
deprecations.index_settings[indexName].map(
(d) =>
({
...d,
index: indexName,
reindex: /Index created before/.test(d.message),
} as EnrichedDeprecationInfo)
)
);
}, [] as EnrichedDeprecationInfo[]);

const getClusterDeprecations = (deprecations: DeprecationAPIResponse, isCloudEnabled: boolean) => {
const combined = deprecations.cluster_settings
Expand Down

This file was deleted.

74 changes: 0 additions & 74 deletions x-pack/plugins/upgrade_assistant/server/lib/query_default_field.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
ReindexTaskFailed,
ReindexAlreadyInProgress,
MultipleReindexJobsFound,
CannotReindexSystemIndexInCurrent,
ReindexCannotBeCancelled,
ReindexIsNotInQueue,
} from './error_symbols';
Expand All @@ -35,7 +34,6 @@ export const error = {
reindexTaskFailed: createErrorFactory(ReindexTaskFailed),
reindexTaskCannotBeDeleted: createErrorFactory(ReindexTaskCannotBeDeleted),
reindexAlreadyInProgress: createErrorFactory(ReindexAlreadyInProgress),
reindexSystemIndex: createErrorFactory(CannotReindexSystemIndexInCurrent),
reindexIsNotInQueue: createErrorFactory(ReindexIsNotInQueue),
multipleReindexJobsFound: createErrorFactory(MultipleReindexJobsFound),
reindexCannotBeCancelled: createErrorFactory(ReindexCannotBeCancelled),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export const CannotCreateIndex = Symbol('CannotCreateIndex');
export const ReindexTaskFailed = Symbol('ReindexTaskFailed');
export const ReindexTaskCannotBeDeleted = Symbol('ReindexTaskCannotBeDeleted');
export const ReindexAlreadyInProgress = Symbol('ReindexAlreadyInProgress');
export const CannotReindexSystemIndexInCurrent = Symbol('CannotReindexSystemIndexInCurrent');
export const ReindexIsNotInQueue = Symbol('ReindexIsNotInQueue');
export const ReindexCannotBeCancelled = Symbol('ReindexCannotBeCancelled');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
* 2.0.
*/

export { reindexServiceFactory, isSystemIndex } from './reindex_service';
export { reindexServiceFactory } from './reindex_service';
export { ReindexWorker } from './worker';
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ describe('reindexService', () => {
clusterClient.asCurrentUser,
actions,
log,
licensingPluginSetup,
licensingPluginSetup
);

versionService.setup(mockKibanaVersion);
Expand Down Expand Up @@ -249,12 +249,6 @@ describe('reindexService', () => {
expect(actions.createReindexOp).not.toHaveBeenCalled();
});

it('fails if system index', async () => {
actions.getFlatSettings.mockResolvedValueOnce({ settings: {}, mappings: {} });
await expect(service.createReindexOperation('.myIndex')).rejects.toThrow();
expect(actions.createReindexOp).not.toHaveBeenCalled();
});

it('deletes existing operation if it failed', async () => {
clusterClient.asCurrentUser.indices.exists.mockResolvedValueOnce(asApiResponse(true));
actions.findReindexOperations.mockResolvedValueOnce({
Expand Down Expand Up @@ -977,7 +971,6 @@ describe('reindexService', () => {
expect(updatedOp.attributes.reindexTaskPercComplete).toEqual(1);
expect(clusterClient.asCurrentUser.delete).toHaveBeenCalledWith({
index: '.tasks',
type: 'task',
id: 'xyz',
});
});
Expand Down Expand Up @@ -1022,7 +1015,6 @@ describe('reindexService', () => {
expect(updatedOp.attributes.status).toEqual(ReindexStatus.cancelled);
expect(clusterClient.asCurrentUser.delete).toHaveBeenLastCalledWith({
index: '.tasks',
type: 'task',
id: 'xyz',
});
});
Expand Down
Loading

0 comments on commit 5b1391a

Please sign in to comment.