-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
es_deprecations_status.ts
340 lines (307 loc) · 11.5 KB
/
es_deprecations_status.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
/*
* 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.
*/
import type * as estypes from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { IScopedClusterClient } from '@kbn/core/server';
import { i18n } from '@kbn/i18n';
import { EnrichedDeprecationInfo, ESUpgradeStatus, FeatureSet } from '../../common/types';
import { esIndicesStateCheck } from './es_indices_state_check';
import {
getESSystemIndicesMigrationStatus,
convertFeaturesToIndicesArray,
} from './es_system_indices_migration';
export function getShardCapacityDeprecationInfo({
symptom,
details,
}: {
details: any;
symptom: any;
}) {
// When we dont have a details field for our indicator, we can only report
// the symptom to the user given that's the only information about the deprecation
// we have.
if (!details) {
return {
details: symptom,
message: symptom,
url: null,
resolveDuringUpgrade: false,
};
}
const causes = [];
if (details.indices_with_readonly_block > 0) {
causes.push(
i18n.translate(
'xpack.upgradeAssistant.esDeprecationsStatus.indicesWithReadonlyBlockCauseMessage',
{
defaultMessage:
'The number of indices the system enforced a read-only index block (`index.blocks.read_only_allow_delete`) on because the cluster is running out of space.',
}
)
);
}
if (details.nodes_over_high_watermark > 0) {
causes.push(
i18n.translate(
'xpack.upgradeAssistant.esDeprecationsStatus.nodesOverHighWatermarkCauseMessage',
{
defaultMessage:
'The number of nodes that are running low on disk and it is likely that they will run out of space. Their disk usage has tripped the <<cluster-routing-watermark-high, high watermark threshold>>.',
ignoreTag: true,
}
)
);
}
if (details.nodes_over_flood_stage_watermark > 0) {
causes.push(
i18n.translate(
'xpack.upgradeAssistant.esDeprecationsStatus.nodesOverFloodStageWatermarkCauseMessage',
{
defaultMessage:
'The number of nodes that have run out of disk. Their disk usage has tripped the <<cluster-routing-flood-stage, flood stagewatermark threshold>>.',
ignoreTag: true,
}
)
);
}
return {
details: symptom,
message: symptom,
url: null,
resolveDuringUpgrade: false,
correctiveAction: {
type: 'healthIndicator',
impacts: details,
cause: causes.join('\n'),
},
};
}
export async function getHealthIndicators(
dataClient: IScopedClusterClient
): Promise<EnrichedDeprecationInfo[]> {
const healthIndicators = await dataClient.asCurrentUser.healthReport();
const isStatusNotGreen = (indicator?: estypes.HealthReportBaseIndicator): boolean => {
return !!(indicator?.status && indicator?.status !== 'green');
};
// Temporarily ignoring due to untyped ES indicators
// types will be available during 8.9.0
// @ts-ignore
return [
...[
// @ts-ignore
healthIndicators.indicators.shards_capacity as estypes.HealthReportBaseIndicator,
]
.filter(isStatusNotGreen)
.flatMap(({ status, symptom, impacts, diagnosis }) => {
// eslint-disable-next-line @typescript-eslint/naming-convention
return (diagnosis || []).map(({ cause, action, help_url }) => ({
type: 'health_indicator',
details: symptom,
message: cause,
url: help_url,
isCritical: status === 'red',
resolveDuringUpgrade: false,
correctiveAction: { type: 'healthIndicator', cause, action, impacts },
}));
}),
...[healthIndicators.indicators.disk as estypes.HealthReportDiskIndicator]
.filter(isStatusNotGreen)
.flatMap(({ status, symptom, details }) => {
return {
type: 'health_indicator',
isCritical: status === 'red',
...getShardCapacityDeprecationInfo({ symptom, details }),
};
}),
];
}
export async function getESUpgradeStatus(
dataClient: IScopedClusterClient,
featureSet: FeatureSet
): Promise<ESUpgradeStatus> {
const getCombinedDeprecations = async () => {
const healthIndicators = await getHealthIndicators(dataClient);
const deprecations = await dataClient.asCurrentUser.migration.deprecations();
const indices = await getCombinedIndexInfos(deprecations, dataClient);
const systemIndices = await getESSystemIndicesMigrationStatus(dataClient.asCurrentUser);
const systemIndicesList = convertFeaturesToIndicesArray(systemIndices.features);
const enrichedDeprecations = Object.keys(deprecations).reduce(
(combinedDeprecations, deprecationType) => {
if (deprecationType === 'index_settings') {
// We need to exclude all index related deprecations for system indices since
// they are resolved separately through the system indices upgrade section in
// the Overview page.
const withoutSystemIndices = indices.filter(
(index) => !systemIndicesList.includes(index.index!)
);
combinedDeprecations = combinedDeprecations.concat(withoutSystemIndices);
} else {
const deprecationsByType = deprecations[
deprecationType as keyof estypes.MigrationDeprecationsResponse
] as estypes.MigrationDeprecationsDeprecation[];
const enrichedDeprecationInfo = deprecationsByType
.map(
({
details,
level,
message,
url,
// @ts-expect-error @elastic/elasticsearch _meta not available yet in MigrationDeprecationInfoResponse
_meta: metadata,
// @ts-expect-error @elastic/elasticsearch resolve_during_rolling_upgrade not available yet in MigrationDeprecationInfoResponse
resolve_during_rolling_upgrade: resolveDuringUpgrade,
}) => {
return {
details,
message,
url,
type: deprecationType as keyof estypes.MigrationDeprecationsResponse,
isCritical: level === 'critical',
resolveDuringUpgrade,
correctiveAction: getCorrectiveAction(message, metadata),
};
}
)
.filter(({ correctiveAction, type }) => {
/**
* This disables showing the ML deprecations in the UA if `featureSet.mlSnapshots`
* is set to `false`.
*
* This config should be set to true only on the `x.last` versions, or when
* the constant `MachineLearningField.MIN_CHECKED_SUPPORTED_SNAPSHOT_VERSION`
* is incremented to something higher than 7.0.0 in the Elasticsearch code.
*/
if (!featureSet.mlSnapshots) {
if (type === 'ml_settings' || correctiveAction?.type === 'mlSnapshot') {
return false;
}
}
/**
* This disables showing the reindexing deprecations in the UA if
* `featureSet.reindexCorrectiveActions` is set to `false`.
*/
if (!featureSet.reindexCorrectiveActions && correctiveAction?.type === 'reindex') {
return false;
}
return true;
});
combinedDeprecations = combinedDeprecations.concat(enrichedDeprecationInfo);
}
return combinedDeprecations;
},
[] as EnrichedDeprecationInfo[]
);
const enrichedHealthIndicators = healthIndicators.filter(({ status }) => {
return status !== 'green';
}) as EnrichedDeprecationInfo[];
return [...enrichedHealthIndicators, ...enrichedDeprecations];
};
const combinedDeprecations = await getCombinedDeprecations();
const criticalWarnings = combinedDeprecations.filter(({ isCritical }) => isCritical === true);
return {
totalCriticalDeprecations: criticalWarnings.length,
deprecations: combinedDeprecations,
};
}
// Reformats the index deprecations to an array of deprecation warnings extended with an index field.
const getCombinedIndexInfos = async (
deprecations: estypes.MigrationDeprecationsResponse,
dataClient: IScopedClusterClient
) => {
const indices = Object.keys(deprecations.index_settings).reduce(
(indexDeprecations, indexName) => {
return indexDeprecations.concat(
deprecations.index_settings[indexName].map(
({
details,
message,
url,
level,
// @ts-expect-error @elastic/elasticsearch _meta not available yet in MigrationDeprecationInfoResponse
_meta: metadata,
// @ts-expect-error @elastic/elasticsearch resolve_during_rolling_upgrade not available yet in MigrationDeprecationInfoResponse
resolve_during_rolling_upgrade: resolveDuringUpgrade,
}) =>
({
details,
message,
url,
index: indexName,
type: 'index_settings',
isCritical: level === 'critical',
correctiveAction: getCorrectiveAction(message, metadata, indexName),
resolveDuringUpgrade,
} as EnrichedDeprecationInfo)
)
);
},
[] as EnrichedDeprecationInfo[]
);
const indexNames = indices.map(({ index }) => index!);
// If we have found deprecation information for index/indices
// check whether the index is open or closed.
if (indexNames.length) {
const indexStates = await esIndicesStateCheck(dataClient.asCurrentUser, indexNames);
indices.forEach((indexData) => {
if (indexData.correctiveAction?.type === 'reindex') {
indexData.correctiveAction.blockerForReindexing =
indexStates[indexData.index!] === 'closed' ? 'index-closed' : undefined;
}
});
}
return indices as EnrichedDeprecationInfo[];
};
interface Action {
action_type: 'remove_settings';
objects: string[];
}
interface Actions {
actions: Action[];
}
type EsMetadata = Actions & {
[key: string]: string;
};
const getCorrectiveAction = (
message: string,
metadata: EsMetadata,
indexName?: string
): EnrichedDeprecationInfo['correctiveAction'] => {
const indexSettingDeprecation = metadata?.actions?.find(
(action) => action.action_type === 'remove_settings' && indexName
);
const clusterSettingDeprecation = metadata?.actions?.find(
(action) => action.action_type === 'remove_settings' && typeof indexName === 'undefined'
);
const requiresReindexAction = /Index created before/.test(message);
const requiresIndexSettingsAction = Boolean(indexSettingDeprecation);
const requiresClusterSettingsAction = Boolean(clusterSettingDeprecation);
const requiresMlAction = /[Mm]odel snapshot/.test(message);
if (requiresReindexAction) {
return {
type: 'reindex',
};
}
if (requiresIndexSettingsAction) {
return {
type: 'indexSetting',
deprecatedSettings: indexSettingDeprecation!.objects,
};
}
if (requiresClusterSettingsAction) {
return {
type: 'clusterSetting',
deprecatedSettings: clusterSettingDeprecation!.objects,
};
}
if (requiresMlAction) {
const { snapshot_id: snapshotId, job_id: jobId } = metadata!;
return {
type: 'mlSnapshot',
snapshotId,
jobId,
};
}
};