Skip to content

Commit 2e4163d

Browse files
merge 7.x code
1 parent a3dfecb commit 2e4163d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+3263
-198
lines changed

x-pack/plugins/upgrade_assistant/common/types.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,12 @@ export type ReindexSavedObject = SavedObject<ReindexOperation>;
9494

9595
export enum ReindexWarning {
9696
// 6.0 -> 7.0 warnings, now unused
97-
allField = 0,
98-
booleanFields = 1,
97+
allField,
98+
booleanFields,
9999

100100
// 7.0 -> 8.0 warnings
101101
apmReindex,
102-
103-
// 8.0 -> 9.0 warnings
102+
customTypeName,
104103
}
105104

106105
export enum IndexGroup {
@@ -185,6 +184,7 @@ export interface EnrichedDeprecationInfo extends DeprecationInfo {
185184
index?: string;
186185
node?: string;
187186
reindex?: boolean;
187+
needsDefaultFields?: boolean;
188188
/**
189189
* Indicate what blockers have been detected for calling reindex
190190
* against this index.

x-pack/plugins/upgrade_assistant/kibana.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@
44
"server": true,
55
"ui": true,
66
"configPath": ["xpack", "upgrade_assistant"],
7-
"requiredPlugins": ["management", "licensing", "features"],
7+
"requiredPlugins": ["management", "licensing", "apmOss", "features"],
88
"optionalPlugins": ["cloud", "usageCollection"]
99
}

x-pack/plugins/upgrade_assistant/public/application/components/tabs.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { OverviewTab } from './tabs/overview';
1818
const promisesToResolve = () => new Promise((resolve) => setTimeout(resolve, 0));
1919

2020
const mockHttp = httpServiceMock.createSetupContract();
21-
const mockKibanaVersion = new SemVer('8.0.0');
21+
const mockKibanaVersion = new SemVer('7.0.0');
2222

2323
jest.mock('../app_context', () => {
2424
return {

x-pack/plugins/upgrade_assistant/public/application/components/tabs/checkup/__snapshots__/checkup_tab.test.tsx.snap

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

x-pack/plugins/upgrade_assistant/public/application/components/tabs/checkup/checkup_tab.test.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const defaultProps = {
2222
setSelectedTabIndex: jest.fn(),
2323
};
2424

25-
const mockKibanaVersion = new SemVer('8.0.0');
25+
const mockKibanaVersion = new SemVer('7.0.0');
2626

2727
jest.mock('../../../app_context', () => {
2828
return {

x-pack/plugins/upgrade_assistant/public/application/components/tabs/checkup/deprecations/cell.tsx

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,16 @@ import {
1717
EuiTitle,
1818
} from '@elastic/eui';
1919
import { FormattedMessage } from '@kbn/i18n/react';
20+
import { FixDefaultFieldsButton } from './default_fields/button';
2021
import { ReindexButton } from './reindex';
2122
import { AppContext } from '../../../../app_context';
2223
import { EnrichedDeprecationInfo } from '../../../../../../common/types';
2324

2425
interface DeprecationCellProps {
2526
items?: Array<{ title?: string; body: string }>;
26-
reindexIndexName?: string;
27+
indexName?: string;
28+
reindex?: boolean;
29+
needsDefaultFields?: boolean;
2730
docUrl?: string;
2831
headline?: string;
2932
healthColor?: string;
@@ -37,7 +40,9 @@ interface DeprecationCellProps {
3740
export const DeprecationCell: FunctionComponent<DeprecationCellProps> = ({
3841
headline,
3942
healthColor,
40-
reindexIndexName,
43+
indexName,
44+
reindex,
45+
needsDefaultFields,
4146
docUrl,
4247
items = [],
4348
children,
@@ -80,20 +85,28 @@ export const DeprecationCell: FunctionComponent<DeprecationCellProps> = ({
8085
))}
8186
</EuiFlexItem>
8287

83-
{reindexIndexName && (
88+
{reindex && (
8489
<EuiFlexItem grow={false}>
8590
<AppContext.Consumer>
8691
{({ http, docLinks }) => (
8792
<ReindexButton
8893
docLinks={docLinks}
8994
reindexBlocker={reindexBlocker}
90-
indexName={reindexIndexName}
95+
indexName={indexName!}
9196
http={http}
9297
/>
9398
)}
9499
</AppContext.Consumer>
95100
</EuiFlexItem>
96101
)}
102+
103+
{needsDefaultFields && (
104+
<EuiFlexItem grow={false}>
105+
<AppContext.Consumer>
106+
{({ http }) => <FixDefaultFieldsButton indexName={indexName!} http={http} />}
107+
</AppContext.Consumer>
108+
</EuiFlexItem>
109+
)}
97110
</EuiFlexGroup>
98111

99112
<EuiSpacer size="s" />
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
/*
2+
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
3+
* or more contributor license agreements. Licensed under the Elastic License
4+
* 2.0; you may not use this file except in compliance with the Elastic License
5+
* 2.0.
6+
*/
7+
8+
import React, { ReactNode } from 'react';
9+
import { HttpSetup } from 'src/core/public';
10+
11+
import { EuiButton } from '@elastic/eui';
12+
import { FormattedMessage } from '@kbn/i18n/react';
13+
import { LoadingState } from '../../../../types';
14+
15+
/**
16+
* Field types used by Metricbeat to generate the default_field setting.
17+
* Matches Beats code here:
18+
* https://github.com/elastic/beats/blob/eee127cb59b56f2ed7c7e317398c3f79c4158216/libbeat/template/processor.go#L104
19+
*/
20+
const BEAT_DEFAULT_FIELD_TYPES: ReadonlySet<string> = new Set(['keyword', 'text', 'ip']);
21+
const BEAT_OTHER_DEFAULT_FIELDS: ReadonlySet<string> = new Set(['fields.*']);
22+
23+
interface FixDefaultFieldsButtonProps {
24+
http: HttpSetup;
25+
indexName: string;
26+
}
27+
28+
interface FixDefaultFieldsButtonState {
29+
fixLoadingState?: LoadingState;
30+
}
31+
32+
/**
33+
* Renders a button if given index is a valid Metricbeat index to add a default_field setting.
34+
*/
35+
export class FixDefaultFieldsButton extends React.Component<
36+
FixDefaultFieldsButtonProps,
37+
FixDefaultFieldsButtonState
38+
> {
39+
constructor(props: FixDefaultFieldsButtonProps) {
40+
super(props);
41+
this.state = {};
42+
}
43+
44+
public render() {
45+
const { fixLoadingState } = this.state;
46+
47+
if (!this.isBeatsIndex()) {
48+
return null;
49+
}
50+
51+
const buttonProps: any = { size: 's', onClick: this.fixBeatsIndex };
52+
let buttonContent: ReactNode;
53+
54+
switch (fixLoadingState) {
55+
case LoadingState.Loading:
56+
buttonProps.disabled = true;
57+
buttonProps.isLoading = true;
58+
buttonContent = (
59+
<FormattedMessage
60+
id="xpack.upgradeAssistant.checkupTab.fixMetricbeatIndexButton.fixingLabel"
61+
defaultMessage="Fixing…"
62+
/>
63+
);
64+
break;
65+
case LoadingState.Success:
66+
buttonProps.iconSide = 'left';
67+
buttonProps.iconType = 'check';
68+
buttonProps.disabled = true;
69+
buttonContent = (
70+
<FormattedMessage
71+
id="xpack.upgradeAssistant.checkupTab.fixMetricbeatIndexButton.fixedLabel"
72+
defaultMessage="Fixed"
73+
/>
74+
);
75+
break;
76+
case LoadingState.Error:
77+
buttonProps.color = 'danger';
78+
buttonProps.iconSide = 'left';
79+
buttonProps.iconType = 'cross';
80+
buttonContent = (
81+
<FormattedMessage
82+
id="xpack.upgradeAssistant.checkupTab.fixMetricbeatIndexButton.failedLabel"
83+
defaultMessage="Failed"
84+
/>
85+
);
86+
break;
87+
default:
88+
buttonContent = (
89+
<FormattedMessage
90+
id="xpack.upgradeAssistant.checkupTab.fixMetricbeatIndexButton.reindexLabel"
91+
defaultMessage="Fix"
92+
/>
93+
);
94+
}
95+
96+
return <EuiButton {...buttonProps}>{buttonContent}</EuiButton>;
97+
}
98+
99+
private isBeatsIndex = () => {
100+
const { indexName } = this.props;
101+
return indexName.startsWith('metricbeat-') || indexName.startsWith('filebeat-');
102+
};
103+
104+
private fixBeatsIndex = async () => {
105+
if (!this.isBeatsIndex()) {
106+
return;
107+
}
108+
109+
this.setState({
110+
fixLoadingState: LoadingState.Loading,
111+
});
112+
113+
try {
114+
await this.props.http.post(
115+
`/api/upgrade_assistant/add_query_default_field/${this.props.indexName}`,
116+
{
117+
body: JSON.stringify({
118+
fieldTypes: [...BEAT_DEFAULT_FIELD_TYPES],
119+
otherFields: [...BEAT_OTHER_DEFAULT_FIELDS],
120+
}),
121+
}
122+
);
123+
124+
this.setState({
125+
fixLoadingState: LoadingState.Success,
126+
});
127+
} catch (e) {
128+
this.setState({
129+
fixLoadingState: LoadingState.Error,
130+
});
131+
}
132+
};
133+
}

x-pack/plugins/upgrade_assistant/public/application/components/tabs/checkup/deprecations/index_table.tsx

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import React from 'react';
1010

1111
import { EuiBasicTable } from '@elastic/eui';
1212
import { i18n } from '@kbn/i18n';
13+
import { FixDefaultFieldsButton } from './default_fields/button';
1314
import { ReindexButton } from './reindex';
1415
import { AppContext } from '../../../../app_context';
1516
import { EnrichedDeprecationInfo } from '../../../../../../common/types';
@@ -19,6 +20,7 @@ const PAGE_SIZES = [10, 25, 50, 100, 250, 500, 1000];
1920
export interface IndexDeprecationDetails {
2021
index: string;
2122
reindex: boolean;
23+
needsDefaultFields: boolean;
2224
blockerForReindexing?: EnrichedDeprecationInfo['blockerForReindexing'];
2325
details?: string;
2426
}
@@ -145,28 +147,38 @@ export class IndexDeprecationTable extends React.Component<
145147
// NOTE: this naive implementation assumes all indices in the table are
146148
// should show the reindex button. This should work for known usecases.
147149
const { indices } = this.props;
148-
if (!indices.find((i) => i.reindex === true)) {
150+
const showReindexButton = indices.find((i) => i.reindex === true);
151+
const showNeedsDefaultFieldsButton = indices.find((i) => i.needsDefaultFields === true);
152+
if (!showReindexButton && !showNeedsDefaultFieldsButton) {
149153
return null;
150154
}
151155

152156
return {
153157
actions: [
154158
{
155159
render(indexDep: IndexDeprecationDetails) {
156-
return (
157-
<AppContext.Consumer>
158-
{({ http, docLinks }) => {
159-
return (
160-
<ReindexButton
161-
docLinks={docLinks}
162-
reindexBlocker={indexDep.blockerForReindexing}
163-
indexName={indexDep.index!}
164-
http={http}
165-
/>
166-
);
167-
}}
168-
</AppContext.Consumer>
169-
);
160+
if (showReindexButton) {
161+
return (
162+
<AppContext.Consumer>
163+
{({ http, docLinks }) => {
164+
return (
165+
<ReindexButton
166+
docLinks={docLinks}
167+
reindexBlocker={indexDep.blockerForReindexing}
168+
indexName={indexDep.index!}
169+
http={http}
170+
/>
171+
);
172+
}}
173+
</AppContext.Consumer>
174+
);
175+
} else {
176+
return (
177+
<AppContext.Consumer>
178+
{({ http }) => <FixDefaultFieldsButton indexName={indexDep.index!} http={http} />}
179+
</AppContext.Consumer>
180+
);
181+
}
170182
},
171183
},
172184
],

x-pack/plugins/upgrade_assistant/public/application/components/tabs/checkup/deprecations/list.test.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,14 @@ describe('DeprecationList', () => {
7575
"blockerForReindexing": undefined,
7676
"details": undefined,
7777
"index": "0",
78+
"needsDefaultFields": false,
7879
"reindex": false,
7980
},
8081
Object {
8182
"blockerForReindexing": undefined,
8283
"details": undefined,
8384
"index": "1",
85+
"needsDefaultFields": false,
8486
"reindex": false,
8587
},
8688
]

x-pack/plugins/upgrade_assistant/public/application/components/tabs/checkup/deprecations/list.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ const MessageDeprecation: FunctionComponent<{ deprecation: EnrichedDeprecationIn
3535
reindexBlocker={deprecation.blockerForReindexing}
3636
headline={deprecation.message}
3737
healthColor={COLOR_MAP[deprecation.level]}
38-
reindexIndexName={deprecation.reindex ? deprecation.index! : undefined}
38+
indexName={deprecation.index}
39+
reindex={deprecation.reindex}
40+
needsDefaultFields={deprecation.needsDefaultFields}
3941
docUrl={deprecation.url}
4042
items={items}
4143
/>
@@ -96,6 +98,7 @@ export const DeprecationList: FunctionComponent<{
9698
index: dep.index!,
9799
details: dep.details,
98100
reindex: dep.reindex === true,
101+
needsDefaultFields: dep.needsDefaultFields === true,
99102
blockerForReindexing: dep.blockerForReindexing,
100103
}));
101104
return <IndexDeprecation indices={indices} deprecation={deprecations[0]} />;

0 commit comments

Comments
 (0)