kibana/x-pack/plugins/upgrade_assistant/common/types.ts
Jean-Louis Leysens 938ad37640
[Upgrade Assistant] Fix edge case where reindex op can falsely be seen as stale (#60770)
* Fix edge case where reindex op is can falsely be seen as stale

This is for multiple Kibana workers, to ensure that an item just
coming off the queue is seen as "new" we set a "startedAt" field
which will update the reindex op and give it the full timeout
window.

* Update tests to use new api too

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
2020-03-23 16:47:49 +01:00

224 lines
5.4 KiB
TypeScript

/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { DeprecationInfo } from 'src/legacy/core_plugins/elasticsearch';
import { SavedObject, SavedObjectAttributes } from 'src/core/public';
export enum ReindexStep {
// Enum values are spaced out by 10 to give us room to insert steps in between.
created = 0,
indexGroupServicesStopped = 10,
readonly = 20,
newIndexCreated = 30,
reindexStarted = 40,
reindexCompleted = 50,
aliasCreated = 60,
indexGroupServicesStarted = 70,
}
export enum ReindexStatus {
inProgress,
completed,
failed,
paused,
cancelled,
}
export const REINDEX_OP_TYPE = 'upgrade-assistant-reindex-operation';
export interface QueueSettings extends SavedObjectAttributes {
/**
* A Unix timestamp of when the reindex operation was enqueued.
*
* @remark
* This is used by the reindexing scheduler to determine execution
* order.
*/
queuedAt: number;
/**
* A Unix timestamp of when the reindex operation was started.
*
* @remark
* Updating this field is useful for _also_ updating the saved object "updated_at" field
* which is used to determine stale or abandoned reindex operations.
*
* For now this is used by the reindex worker scheduler to determine whether we have
* A queue item at the start of the queue.
*
*/
startedAt?: number;
}
export interface ReindexOptions extends SavedObjectAttributes {
/**
* Whether to treat the index as if it were closed. This instructs the
* reindex strategy to first open the index, perform reindexing and
* then close the index again.
*/
openAndClose?: boolean;
/**
* Set this key to configure a reindex operation as part of a
* batch to be run in series.
*/
queueSettings?: QueueSettings;
}
export interface ReindexOperation extends SavedObjectAttributes {
indexName: string;
newIndexName: string;
status: ReindexStatus;
lastCompletedStep: ReindexStep;
locked: string | null;
reindexTaskId: string | null;
reindexTaskPercComplete: number | null;
errorMessage: string | null;
// This field is only used for the singleton IndexConsumerType documents.
runningReindexCount: number | null;
/**
* Options for the reindexing strategy.
*
* @remark
* Marked as optional for backwards compatibility. We should still
* be able to handle older ReindexOperation objects.
*/
reindexOptions?: ReindexOptions;
}
export type ReindexSavedObject = SavedObject<ReindexOperation>;
export enum ReindexWarning {
// 6.0 -> 7.0 warnings, now unused
allField = 0,
booleanFields = 1,
// 7.0 -> 8.0 warnings
apmReindex,
// 8.0 -> 9.0 warnings
}
export enum IndexGroup {
ml = '___ML_REINDEX_LOCK___',
watcher = '___WATCHER_REINDEX_LOCK___',
}
// Telemetry types
export const UPGRADE_ASSISTANT_TYPE = 'upgrade-assistant-telemetry';
export const UPGRADE_ASSISTANT_DOC_ID = 'upgrade-assistant-telemetry';
export type UIOpenOption = 'overview' | 'cluster' | 'indices';
export type UIReindexOption = 'close' | 'open' | 'start' | 'stop';
export interface UIOpen {
overview: boolean;
cluster: boolean;
indices: boolean;
}
export interface UIReindex {
close: boolean;
open: boolean;
start: boolean;
stop: boolean;
}
export interface UpgradeAssistantTelemetrySavedObject {
ui_open: {
overview: number;
cluster: number;
indices: number;
};
ui_reindex: {
close: number;
open: number;
start: number;
stop: number;
};
}
export interface UpgradeAssistantTelemetry {
ui_open: {
overview: number;
cluster: number;
indices: number;
};
ui_reindex: {
close: number;
open: number;
start: number;
stop: number;
};
features: {
deprecation_logging: {
enabled: boolean;
};
};
}
export interface UpgradeAssistantTelemetrySavedObjectAttributes {
[key: string]: any;
}
export interface EnrichedDeprecationInfo extends DeprecationInfo {
index?: string;
node?: string;
reindex?: boolean;
/**
* Indicate what blockers have been detected for calling reindex
* against this index.
*
* @remark
* In future this could be an array of blockers.
*/
blockerForReindexing?: 'index-closed'; // 'index-closed' can be handled automatically, but requires more resources, user should be warned
}
export interface UpgradeAssistantStatus {
readyForUpgrade: boolean;
cluster: EnrichedDeprecationInfo[];
indices: EnrichedDeprecationInfo[];
}
export interface ClusterStateIndexAPIResponse {
state: 'open' | 'close';
settings: {
index: {
verified_before_close: string;
search: {
throttled: string;
};
number_of_shards: string;
provided_name: string;
frozen: string;
creation_date: string;
number_of_replicas: string;
uuid: string;
version: {
created: string;
};
};
};
mappings: any;
aliases: string[];
}
export interface ClusterStateAPIResponse {
cluster_name: string;
cluster_uuid: string;
metadata: {
cluster_uuid: string;
cluster_coordination: {
term: number;
last_committed_config: string[];
last_accepted_config: string[];
voting_config_exclusions: [];
};
templates: any;
indices: { [indexName: string]: ClusterStateIndexAPIResponse };
};
}