forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add button for adding
index.query.default_field
setting to metricbe…
…at indices (elastic#32829) * Add button for adding `index.query.default_field` setting to metricbeat indices * Add button to 'group by index' view * Refactor to more generic API * Remove comment * Update functional tests
- Loading branch information
Showing
14 changed files
with
11,240 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
...s/upgrade_assistant/public/components/tabs/checkup/deprecations/default_fields/button.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
/* | ||
* 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 React, { ReactNode } from 'react'; | ||
|
||
import { EuiButton } from '@elastic/eui'; | ||
import { FormattedMessage } from '@kbn/i18n/react'; | ||
import { kfetch } from 'ui/kfetch'; | ||
import { LoadingState } from '../../../../types'; | ||
|
||
/** | ||
* Field types used by Metricbeat to generate the default_field setting. | ||
* Matches Beats code here: | ||
* https://github.com/elastic/beats/blob/eee127cb59b56f2ed7c7e317398c3f79c4158216/libbeat/template/processor.go#L104 | ||
*/ | ||
const METRICBEAT_DEFAULT_FIELD_TYPES: ReadonlySet<string> = new Set(['keyword', 'text', 'ip']); | ||
const METRICBEAT_OTHER_DEFAULT_FIELDS: ReadonlySet<string> = new Set(['fields.*']); | ||
|
||
interface FixDefaultFieldsButtonProps { | ||
indexName: string; | ||
} | ||
|
||
interface FixDefaultFieldsButtonState { | ||
fixLoadingState?: LoadingState; | ||
} | ||
|
||
/** | ||
* Renders a button if given index is a valid Metricbeat index to add a default_field setting. | ||
*/ | ||
export class FixDefaultFieldsButton extends React.Component< | ||
FixDefaultFieldsButtonProps, | ||
FixDefaultFieldsButtonState | ||
> { | ||
constructor(props: FixDefaultFieldsButtonProps) { | ||
super(props); | ||
this.state = {}; | ||
} | ||
|
||
public render() { | ||
const { fixLoadingState } = this.state; | ||
|
||
if (!this.isMetricbeatIndex()) { | ||
return null; | ||
} | ||
|
||
const buttonProps: any = { size: 's', onClick: this.fixMetricbeatIndex }; | ||
let buttonContent: ReactNode; | ||
|
||
switch (fixLoadingState) { | ||
case LoadingState.Loading: | ||
buttonProps.disabled = true; | ||
buttonProps.isLoading = true; | ||
buttonContent = ( | ||
<FormattedMessage | ||
id="xpack.upgradeAssistant.checkupTab.fixMetricbeatIndexButton.fixingLabel" | ||
defaultMessage="Fixing…" | ||
/> | ||
); | ||
break; | ||
case LoadingState.Success: | ||
buttonProps.iconSide = 'left'; | ||
buttonProps.iconType = 'check'; | ||
buttonProps.disabled = true; | ||
buttonContent = ( | ||
<FormattedMessage | ||
id="xpack.upgradeAssistant.checkupTab.fixMetricbeatIndexButton.fixedLabel" | ||
defaultMessage="Fixed" | ||
/> | ||
); | ||
break; | ||
case LoadingState.Error: | ||
buttonProps.color = 'danger'; | ||
buttonProps.iconSide = 'left'; | ||
buttonProps.iconType = 'cross'; | ||
buttonContent = ( | ||
<FormattedMessage | ||
id="xpack.upgradeAssistant.checkupTab.fixMetricbeatIndexButton.failedLabel" | ||
defaultMessage="Failed" | ||
/> | ||
); | ||
break; | ||
default: | ||
buttonContent = ( | ||
<FormattedMessage | ||
id="xpack.upgradeAssistant.checkupTab.fixMetricbeatIndexButton.reindexLabel" | ||
defaultMessage="Fix" | ||
/> | ||
); | ||
} | ||
|
||
return <EuiButton {...buttonProps}>{buttonContent}</EuiButton>; | ||
} | ||
|
||
private isMetricbeatIndex = () => { | ||
return this.props.indexName.startsWith('metricbeat-'); | ||
}; | ||
|
||
private fixMetricbeatIndex = async () => { | ||
if (!this.isMetricbeatIndex()) { | ||
return; | ||
} | ||
|
||
this.setState({ | ||
fixLoadingState: LoadingState.Loading, | ||
}); | ||
|
||
try { | ||
await kfetch({ | ||
pathname: `/api/upgrade_assistant/add_query_default_field/${this.props.indexName}`, | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
fieldTypes: [...METRICBEAT_DEFAULT_FIELD_TYPES], | ||
otherFields: [...METRICBEAT_OTHER_DEFAULT_FIELDS], | ||
}), | ||
}); | ||
|
||
this.setState({ | ||
fixLoadingState: LoadingState.Success, | ||
}); | ||
} catch (e) { | ||
this.setState({ | ||
fixLoadingState: LoadingState.Error, | ||
}); | ||
} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.