Skip to content

Commit

Permalink
Merge branch 'master' into copy-pass-3
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Sep 22, 2021
2 parents 7f47dab + 1456257 commit f322f66
Show file tree
Hide file tree
Showing 86 changed files with 8,309 additions and 1,411 deletions.
2 changes: 1 addition & 1 deletion src/core/server/http/router/socket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ describe('KibanaSocket', () => {
});
const socket = new KibanaSocket(tlsSocket);

expect(socket.renegotiate({})).resolves.toBe(result);
await expect(socket.renegotiate({})).rejects.toBe(result);
expect(spy).toBeCalledTimes(1);
});

Expand Down
8 changes: 4 additions & 4 deletions src/core/server/saved_objects/migrationsv2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
- [REINDEX_SOURCE_TO_TEMP_READ](#reindex_source_to_temp_read)
- [Next action](#next-action-11)
- [New control state](#new-control-state-11)
- [REINDEX_SOURCE_TO_TEMP_INDEX](#reindex_source_to_temp_index)
- [REINDEX_SOURCE_TO_TEMP_TRANSFORM](#REINDEX_SOURCE_TO_TEMP_TRANSFORM)
- [Next action](#next-action-12)
- [New control state](#new-control-state-12)
- [REINDEX_SOURCE_TO_TEMP_INDEX_BULK](#reindex_source_to_temp_index_bulk)
Expand Down Expand Up @@ -284,11 +284,11 @@ Read the next batch of outdated documents from the source index by using search

### New control state
1. If the batch contained > 0 documents
`REINDEX_SOURCE_TO_TEMP_INDEX`
`REINDEX_SOURCE_TO_TEMP_TRANSFORM`
2. If there are no more documents returned
`REINDEX_SOURCE_TO_TEMP_CLOSE_PIT`

## REINDEX_SOURCE_TO_TEMP_INDEX
## REINDEX_SOURCE_TO_TEMP_TRANSFORM
### Next action
`transformRawDocs`

Expand Down Expand Up @@ -357,7 +357,7 @@ documents.
If another instance has a disabled plugin it will reindex that plugin's
documents without transforming them. Because this instance doesn't know which
plugins were disabled by the instance that performed the
`REINDEX_SOURCE_TO_TEMP_INDEX` step, we need to search for outdated documents
`REINDEX_SOURCE_TO_TEMP_TRANSFORM` step, we need to search for outdated documents
and transform them to ensure that everything is up to date.

### New control state
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type { ElasticsearchClient } from '../../elasticsearch';
import { getErrorMessage, getRequestDebugMeta } from '../../elasticsearch';
import { Model, Next, stateActionMachine } from './state_action_machine';
import { cleanup } from './migrations_state_machine_cleanup';
import { ReindexSourceToTempIndex, ReindexSourceToTempIndexBulk, State } from './types';
import { ReindexSourceToTempTransform, ReindexSourceToTempIndexBulk, State } from './types';
import { SavedObjectsRawDoc } from '../serialization';

interface StateTransitionLogMeta extends LogMeta {
Expand Down Expand Up @@ -115,7 +115,9 @@ export async function migrationStateActionMachine({
const redactedNewState = {
...newState,
...{
outdatedDocuments: ((newState as ReindexSourceToTempIndex).outdatedDocuments ?? []).map(
outdatedDocuments: (
(newState as ReindexSourceToTempTransform).outdatedDocuments ?? []
).map(
(doc) =>
({
_id: doc._id,
Expand Down
32 changes: 16 additions & 16 deletions src/core/server/saved_objects/migrationsv2/model/model.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import type {
ReindexSourceToTempOpenPit,
ReindexSourceToTempRead,
ReindexSourceToTempClosePit,
ReindexSourceToTempIndex,
ReindexSourceToTempTransform,
RefreshTarget,
UpdateTargetMappingsState,
UpdateTargetMappingsWaitForTaskState,
Expand Down Expand Up @@ -962,16 +962,16 @@ describe('migrations v2 model', () => {
progress: createInitialProgress(),
};

it('REINDEX_SOURCE_TO_TEMP_READ -> REINDEX_SOURCE_TO_TEMP_INDEX if the index has outdated documents to reindex', () => {
it('REINDEX_SOURCE_TO_TEMP_READ -> REINDEX_SOURCE_TO_TEMP_TRANSFORM if the index has outdated documents to reindex', () => {
const outdatedDocuments = [{ _id: '1', _source: { type: 'vis' } }];
const lastHitSortValue = [123456];
const res: ResponseType<'REINDEX_SOURCE_TO_TEMP_READ'> = Either.right({
outdatedDocuments,
lastHitSortValue,
totalHits: 1,
});
const newState = model(state, res) as ReindexSourceToTempIndex;
expect(newState.controlState).toBe('REINDEX_SOURCE_TO_TEMP_INDEX');
const newState = model(state, res) as ReindexSourceToTempTransform;
expect(newState.controlState).toBe('REINDEX_SOURCE_TO_TEMP_TRANSFORM');
expect(newState.outdatedDocuments).toBe(outdatedDocuments);
expect(newState.lastHitSortValue).toBe(lastHitSortValue);
expect(newState.progress.processed).toBe(undefined);
Expand Down Expand Up @@ -1032,16 +1032,16 @@ describe('migrations v2 model', () => {

it('REINDEX_SOURCE_TO_TEMP_CLOSE_PIT -> SET_TEMP_WRITE_BLOCK if action succeeded', () => {
const res: ResponseType<'REINDEX_SOURCE_TO_TEMP_CLOSE_PIT'> = Either.right({});
const newState = model(state, res) as ReindexSourceToTempIndex;
const newState = model(state, res) as ReindexSourceToTempTransform;
expect(newState.controlState).toBe('SET_TEMP_WRITE_BLOCK');
expect(newState.sourceIndex).toEqual(state.sourceIndex);
});
});

describe('REINDEX_SOURCE_TO_TEMP_INDEX', () => {
const state: ReindexSourceToTempIndex = {
describe('REINDEX_SOURCE_TO_TEMP_TRANSFORM', () => {
const state: ReindexSourceToTempTransform = {
...baseState,
controlState: 'REINDEX_SOURCE_TO_TEMP_INDEX',
controlState: 'REINDEX_SOURCE_TO_TEMP_TRANSFORM',
outdatedDocuments: [],
versionIndexReadyActions: Option.none,
sourceIndex: Option.some('.kibana') as Option.Some<string>,
Expand All @@ -1059,8 +1059,8 @@ describe('migrations v2 model', () => {
},
] as SavedObjectsRawDoc[];

it('REINDEX_SOURCE_TO_TEMP_INDEX -> REINDEX_SOURCE_TO_TEMP_INDEX_BULK if action succeeded', () => {
const res: ResponseType<'REINDEX_SOURCE_TO_TEMP_INDEX'> = Either.right({
it('REINDEX_SOURCE_TO_TEMP_TRANSFORM -> REINDEX_SOURCE_TO_TEMP_INDEX_BULK if action succeeded', () => {
const res: ResponseType<'REINDEX_SOURCE_TO_TEMP_TRANSFORM'> = Either.right({
processedDocs,
});
const newState = model(state, res) as ReindexSourceToTempIndexBulk;
Expand All @@ -1071,7 +1071,7 @@ describe('migrations v2 model', () => {
});

it('increments the progress.processed counter', () => {
const res: ResponseType<'REINDEX_SOURCE_TO_TEMP_INDEX'> = Either.right({
const res: ResponseType<'REINDEX_SOURCE_TO_TEMP_TRANSFORM'> = Either.right({
processedDocs,
});

Expand All @@ -1089,24 +1089,24 @@ describe('migrations v2 model', () => {
expect(newState.progress.processed).toBe(2);
});

it('REINDEX_SOURCE_TO_TEMP_INDEX -> REINDEX_SOURCE_TO_TEMP_READ if action succeeded but we have carried through previous failures', () => {
const res: ResponseType<'REINDEX_SOURCE_TO_TEMP_INDEX'> = Either.right({
it('REINDEX_SOURCE_TO_TEMP_TRANSFORM -> REINDEX_SOURCE_TO_TEMP_READ if action succeeded but we have carried through previous failures', () => {
const res: ResponseType<'REINDEX_SOURCE_TO_TEMP_TRANSFORM'> = Either.right({
processedDocs,
});
const testState = {
...state,
corruptDocumentIds: ['a:b'],
transformErrors: [],
};
const newState = model(testState, res) as ReindexSourceToTempIndex;
const newState = model(testState, res) as ReindexSourceToTempTransform;
expect(newState.controlState).toEqual('REINDEX_SOURCE_TO_TEMP_READ');
expect(newState.corruptDocumentIds.length).toEqual(1);
expect(newState.transformErrors.length).toEqual(0);
expect(newState.progress.processed).toBe(0);
});

it('REINDEX_SOURCE_TO_TEMP_INDEX -> REINDEX_SOURCE_TO_TEMP_READ when response is left documents_transform_failed', () => {
const res: ResponseType<'REINDEX_SOURCE_TO_TEMP_INDEX'> = Either.left({
it('REINDEX_SOURCE_TO_TEMP_TRANSFORM -> REINDEX_SOURCE_TO_TEMP_READ when response is left documents_transform_failed', () => {
const res: ResponseType<'REINDEX_SOURCE_TO_TEMP_TRANSFORM'> = Either.left({
type: 'documents_transform_failed',
corruptDocumentIds: ['a:b'],
transformErrors: [],
Expand Down
6 changes: 3 additions & 3 deletions src/core/server/saved_objects/migrationsv2/model/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ export const model = (currentState: State, resW: ResponseType<AllActionStates>):
if (res.right.outdatedDocuments.length > 0) {
return {
...stateP,
controlState: 'REINDEX_SOURCE_TO_TEMP_INDEX',
controlState: 'REINDEX_SOURCE_TO_TEMP_TRANSFORM',
outdatedDocuments: res.right.outdatedDocuments,
lastHitSortValue: res.right.lastHitSortValue,
progress,
Expand Down Expand Up @@ -489,11 +489,11 @@ export const model = (currentState: State, resW: ResponseType<AllActionStates>):
} else {
throwBadResponse(stateP, res);
}
} else if (stateP.controlState === 'REINDEX_SOURCE_TO_TEMP_INDEX') {
} else if (stateP.controlState === 'REINDEX_SOURCE_TO_TEMP_TRANSFORM') {
// We follow a similar control flow as for
// outdated document search -> outdated document transform -> transform documents bulk index
// collecting issues along the way rather than failing
// REINDEX_SOURCE_TO_TEMP_INDEX handles the document transforms
// REINDEX_SOURCE_TO_TEMP_TRANSFORM handles the document transforms
const res = resW as ExcludeRetryableEsError<ResponseType<typeof stateP.controlState>>;

// Increment the processed documents, no matter what the results are.
Expand Down
4 changes: 2 additions & 2 deletions src/core/server/saved_objects/migrationsv2/next.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import type {
ReindexSourceToTempOpenPit,
ReindexSourceToTempRead,
ReindexSourceToTempClosePit,
ReindexSourceToTempIndex,
ReindexSourceToTempTransform,
MarkVersionIndexReady,
InitState,
LegacyCreateReindexTargetState,
Expand Down Expand Up @@ -105,7 +105,7 @@ export const nextActionMap = (client: ElasticsearchClient, transformRawDocs: Tra
}),
REINDEX_SOURCE_TO_TEMP_CLOSE_PIT: (state: ReindexSourceToTempClosePit) =>
Actions.closePit({ client, pitId: state.sourceIndexPitId }),
REINDEX_SOURCE_TO_TEMP_INDEX: (state: ReindexSourceToTempIndex) =>
REINDEX_SOURCE_TO_TEMP_TRANSFORM: (state: ReindexSourceToTempTransform) =>
Actions.transformDocs({ transformRawDocs, outdatedDocuments: state.outdatedDocuments }),
REINDEX_SOURCE_TO_TEMP_INDEX_BULK: (state: ReindexSourceToTempIndexBulk) =>
Actions.bulkOverwriteTransformedDocuments({
Expand Down
6 changes: 3 additions & 3 deletions src/core/server/saved_objects/migrationsv2/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ export interface ReindexSourceToTempClosePit extends PostInitState {
readonly sourceIndexPitId: string;
}

export interface ReindexSourceToTempIndex extends PostInitState {
readonly controlState: 'REINDEX_SOURCE_TO_TEMP_INDEX';
export interface ReindexSourceToTempTransform extends PostInitState {
readonly controlState: 'REINDEX_SOURCE_TO_TEMP_TRANSFORM';
readonly outdatedDocuments: SavedObjectsRawDoc[];
readonly sourceIndexPitId: string;
readonly lastHitSortValue: number[] | undefined;
Expand Down Expand Up @@ -434,7 +434,7 @@ export type State = Readonly<
| ReindexSourceToTempOpenPit
| ReindexSourceToTempRead
| ReindexSourceToTempClosePit
| ReindexSourceToTempIndex
| ReindexSourceToTempTransform
| ReindexSourceToTempIndexBulk
| SetTempWriteBlock
| CloneTempToSource
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ export class VegaMapView extends VegaBaseView {
const { zoom, maxZoom, minZoom } = validateZoomSettings(
this._parser.mapConfig,
defaults,
this.onWarn
this.onWarn.bind(this)
);
const { signals } = this._vegaStateRestorer.restore() || {};

Expand Down
16 changes: 13 additions & 3 deletions x-pack/plugins/cases/common/api/cases/case.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,11 @@ const CaseBasicRt = rt.type({
owner: rt.string,
});

export const CaseExternalServiceBasicRt = rt.type({
connector_id: rt.union([rt.string, rt.null]),
/**
* This represents the push to service UserAction. It lacks the connector_id because that is stored in a different field
* within the user action object in the API response.
*/
export const CaseUserActionExternalServiceRt = rt.type({
connector_name: rt.string,
external_id: rt.string,
external_title: rt.string,
Expand All @@ -97,7 +100,14 @@ export const CaseExternalServiceBasicRt = rt.type({
pushed_by: UserRT,
});

const CaseFullExternalServiceRt = rt.union([CaseExternalServiceBasicRt, rt.null]);
export const CaseExternalServiceBasicRt = rt.intersection([
rt.type({
connector_id: rt.union([rt.string, rt.null]),
}),
CaseUserActionExternalServiceRt,
]);

export const CaseFullExternalServiceRt = rt.union([CaseExternalServiceBasicRt, rt.null]);

export const CaseAttributesRt = rt.intersection([
CaseBasicRt,
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/cases/common/api/cases/user_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ const UserActionRt = rt.union([
rt.literal('push-to-service'),
]);

// TO DO change state to status
const CaseUserActionBasicRT = rt.type({
action_field: UserActionFieldRt,
action: UserActionRt,
Expand All @@ -51,6 +50,8 @@ const CaseUserActionResponseRT = rt.intersection([
action_id: rt.string,
case_id: rt.string,
comment_id: rt.union([rt.string, rt.null]),
new_val_connector_id: rt.union([rt.string, rt.null]),
old_val_connector_id: rt.union([rt.string, rt.null]),
}),
rt.partial({ sub_case_id: rt.string }),
]);
Expand Down
12 changes: 10 additions & 2 deletions x-pack/plugins/cases/common/api/connectors/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,22 @@ export const ConnectorTypeFieldsRt = rt.union([
ConnectorSwimlaneTypeFieldsRt,
]);

/**
* This type represents the connector's format when it is encoded within a user action.
*/
export const CaseUserActionConnectorRt = rt.intersection([
rt.type({ name: rt.string }),
ConnectorTypeFieldsRt,
]);

export const CaseConnectorRt = rt.intersection([
rt.type({
id: rt.string,
name: rt.string,
}),
ConnectorTypeFieldsRt,
CaseUserActionConnectorRt,
]);

export type CaseUserActionConnector = rt.TypeOf<typeof CaseUserActionConnectorRt>;
export type CaseConnector = rt.TypeOf<typeof CaseConnectorRt>;
export type ConnectorTypeFields = rt.TypeOf<typeof ConnectorTypeFieldsRt>;
export type ConnectorJiraTypeFields = rt.TypeOf<typeof ConnectorJiraTypeFieldsRt>;
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/cases/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ export * from './constants';
export * from './api';
export * from './ui/types';
export * from './utils/connectors_api';
export * from './utils/user_actions';
2 changes: 2 additions & 0 deletions x-pack/plugins/cases/common/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,9 @@ export interface CaseUserActions {
caseId: string;
commentId: string | null;
newValue: string | null;
newValConnectorId: string | null;
oldValue: string | null;
oldValConnectorId: string | null;
}

export interface CaseExternalService {
Expand Down
18 changes: 18 additions & 0 deletions x-pack/plugins/cases/common/utils/user_actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

export function isCreateConnector(action?: string, actionFields?: string[]): boolean {
return action === 'create' && actionFields != null && actionFields.includes('connector');
}

export function isUpdateConnector(action?: string, actionFields?: string[]): boolean {
return action === 'update' && actionFields != null && actionFields.includes('connector');
}

export function isPush(action?: string, actionFields?: string[]): boolean {
return action === 'push-to-service' && actionFields != null && actionFields.includes('pushed');
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@
* 2.0.
*/

export { timelinesMigrations } from './timelines';
export { notesMigrations } from './notes';
export * from './parsers';
Loading

0 comments on commit f322f66

Please sign in to comment.