Skip to content

Commit

Permalink
[8.0] Use doc link service in ILM (#122104) (#122617)
Browse files Browse the repository at this point in the history
* Use doc link service in ILM (#122104)

(cherry picked from commit b5d5ba9)

* Fixes linting
  • Loading branch information
lcawl authored Jan 11, 2022
1 parent a596b34 commit 2503fa6
Show file tree
Hide file tree
Showing 20 changed files with 92 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import React from 'react';
import { act } from 'react-dom/test-utils';
import { registerTestBed, TestBed, TestBedConfig } from '@kbn/test/jest';
import { docLinksServiceMock } from 'src/core/public/mocks';
import { KibanaContextProvider } from '../../../../../../src/plugins/kibana_react/public';
import { createBreadcrumbsMock } from '../../../public/application/services/breadcrumbs.mock';
import { licensingMock } from '../../../../licensing/public/mocks';
Expand All @@ -17,7 +18,13 @@ const breadcrumbService = createBreadcrumbsMock();

const AppWithContext = (props: any) => {
return (
<KibanaContextProvider services={{ breadcrumbService, license: licensingMock.createLicense() }}>
<KibanaContextProvider
services={{
breadcrumbService,
license: licensingMock.createLicense(),
docLinks: docLinksServiceMock.createStartContract(),
}}
>
<App {...props} />
</KibanaContextProvider>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import React from 'react';
import { registerTestBed, TestBedConfig } from '@kbn/test/jest';
import { docLinksServiceMock } from 'src/core/public/mocks';

import '../helpers/global_mocks';

Expand Down Expand Up @@ -35,6 +36,7 @@ const EditPolicyContainer = ({ appServicesContext, ...rest }: any) => {
services={{
breadcrumbService,
license: licensingMock.createLicense({ license: { type: 'enterprise' } }),
docLinks: docLinksServiceMock.createStartContract(),
getUrlForApp: () => {},
...appServicesContext,
}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { findTestSubject, takeMountedSnapshot } from '@elastic/eui/lib/test';
import {
fatalErrorsServiceMock,
injectedMetadataServiceMock,
docLinksServiceMock,
} from '../../../../src/core/public/mocks';
import { HttpService } from '../../../../src/core/public/http';
import { usageCollectionPluginMock } from '../../../../src/plugins/usage_collection/public/mocks';
Expand Down Expand Up @@ -99,7 +100,9 @@ const testSort = (headerName: string) => {

const TestComponent = ({ testPolicies }: { testPolicies: PolicyFromES[] }) => {
return (
<KibanaContextProvider services={{ getUrlForApp: () => '' }}>
<KibanaContextProvider
services={{ getUrlForApp: () => '', docLinks: docLinksServiceMock.createStartContract() }}
>
<PolicyListContextProvider>
<PolicyList updatePolicies={jest.fn()} policies={testPolicies} />
</PolicyListContextProvider>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import React from 'react';
import { render, unmountComponentAtNode } from 'react-dom';
import { I18nStart, ScopedHistory, ApplicationStart } from 'kibana/public';
import { I18nStart, ScopedHistory, ApplicationStart, DocLinksStart } from 'kibana/public';
import { UnmountCallback } from 'src/core/public';
import { CloudSetup } from '../../../cloud/public';
import { ILicense } from '../../../licensing/public';
Expand All @@ -26,13 +26,16 @@ export const renderApp = (
application: ApplicationStart,
breadcrumbService: BreadcrumbService,
license: ILicense,
docLinks: DocLinksStart,
cloud?: CloudSetup
): UnmountCallback => {
const { getUrlForApp } = application;
render(
<RedirectAppLinks application={application} className={APP_WRAPPER_CLASS}>
<I18nContext>
<KibanaContextProvider services={{ cloud, breadcrumbService, license, getUrlForApp }}>
<KibanaContextProvider
services={{ cloud, breadcrumbService, license, getUrlForApp, docLinks }}
>
<App history={history} />
</KibanaContextProvider>
</I18nContext>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import React, { ReactNode } from 'react';
import { EuiLink } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';

import { createDocLink } from '../../../services/documentation';

interface Props {
docPath: string;
text?: ReactNode;
Expand All @@ -23,7 +21,7 @@ export const LearnMoreLink: React.FunctionComponent<Props> = ({ docPath, text })
<FormattedMessage id="xpack.indexLifecycleMgmt.learnMore" defaultMessage="Learn more" />
);
return (
<EuiLink href={createDocLink(docPath)} target="_blank" external={true}>
<EuiLink href={docPath} target="_blank" external={true}>
{content}
</EuiLink>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';
import { EuiSpacer, EuiCallOut, EuiTextColor, EuiSwitch, EuiText } from '@elastic/eui';

import { useFormData } from '../../../../../../shared_imports';
import { useFormData, useKibana } from '../../../../../../shared_imports';

import { i18nTexts } from '../../../i18n_texts';

Expand Down Expand Up @@ -52,6 +52,8 @@ export const HotPhase: FunctionComponent = () => {

const showEmptyRolloverFieldsError = useRolloverValueRequiredValidation();

const { docLinks } = useKibana().services;

return (
<Phase phase="hot">
<DescribedFormRow
Expand Down Expand Up @@ -89,7 +91,7 @@ export const HotPhase: FunctionComponent = () => {
defaultMessage="Learn more"
/>
}
docPath="ilm-rollover.html"
docPath={docLinks.links.elasticsearch.ilmRollover}
/>
</p>
</EuiTextColor>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@ import { EuiLink } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { DocLinksStart } from 'src/core/public';

import { getNodeAllocationMigrationLink } from '../../../../../../../services/documentation';

export interface Props {
docLinks: DocLinksStart;
}
Expand All @@ -28,7 +25,11 @@ export const nodeAllocationMigrationGuidance = ({ docLinks }: Props) => (
defaultMessage="To allocate data to particular data nodes, {roleBasedGuidance} or configure custom node attributes in elasticsearch.yml."
values={{
roleBasedGuidance: (
<EuiLink href={getNodeAllocationMigrationLink(docLinks)} target="_blank" external={true}>
<EuiLink
href={docLinks.links.elasticsearch.migrateIndexAllocationFilters}
target="_blank"
external={true}
>
{i18n.translate(
'xpack.indexLifecycleMgmt.editPolicy.defaultToDataNodesDescription.migrationGuidanceMessage',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { get } from 'lodash';
import { FormattedMessage } from '@kbn/i18n-react';
import { EuiButtonEmpty, EuiText, EuiSpacer } from '@elastic/eui';

import { SelectField, useFormData } from '../../../../../../../../shared_imports';
import { SelectField, useFormData, useKibana } from '../../../../../../../../shared_imports';

import { UseField } from '../../../../../form';

Expand All @@ -21,18 +21,6 @@ import { NodeAttrsDetails } from './node_attrs_details';

import { SharedProps } from './types';

const learnMoreLink = (
<LearnMoreLink
text={
<FormattedMessage
id="xpack.indexLifecycleMgmt.editPolicy.learnAboutShardAllocationLink"
defaultMessage="Learn about shard allocation"
/>
}
docPath="modules-cluster.html#cluster-shard-allocation-settings"
/>
);

const i18nTexts = {
allocateToDataNodesOption: i18n.translate(
'xpack.indexLifecycleMgmt.editPolicy.nodeAllocation.allocateToDataNodesOption',
Expand All @@ -52,7 +40,8 @@ export const NodeAllocation: FunctionComponent<SharedProps> = ({
const [formData] = useFormData({
watch: [allocationNodeAttributePath],
});

const { docLinks } = useKibana().services;
const shardAllocationSettingsUrl = docLinks.links.elasticsearch.shardAllocationSettings;
const selectedAllocationNodeAttribute = get(formData, allocationNodeAttributePath);

const [selectedNodeAttrsForDetails, setSelectedNodeAttrsForDetails] = useState<string | null>(
Expand All @@ -79,15 +68,26 @@ export const NodeAllocation: FunctionComponent<SharedProps> = ({
}

nodeAllocationOptions = nodeAllocationOptions.concat(nodeOptions);

return (
<>
<EuiText size="s">
<p>
<FormattedMessage
id="xpack.indexLifecycleMgmt.editPolicy.nodeAllocation.customOption.description"
defaultMessage="Use node attributes to control shard allocation. {learnMoreLink}."
values={{ learnMoreLink }}
values={{
learnMoreLink: (
<LearnMoreLink
text={
<FormattedMessage
id="xpack.indexLifecycleMgmt.editPolicy.learnAboutShardAllocationLink"
defaultMessage="Learn about shard allocation"
/>
}
docPath={shardAllocationSettingsUrl}
/>
),
}}
/>
</p>
</EuiText>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ import { FormattedMessage } from '@kbn/i18n-react';

import uuid from 'uuid';
import { EuiCheckbox, EuiSpacer, EuiFlexGroup, EuiFlexItem, EuiIconTip } from '@elastic/eui';
import { NumericField } from '../../../../../../shared_imports';

import { NumericField, useKibana } from '../../../../../../shared_imports';
import { i18nTexts } from '../../../i18n_texts';

import { useEditPolicyContext } from '../../../edit_policy_context';
Expand All @@ -31,6 +30,8 @@ export const ForcemergeField: React.FunctionComponent<Props> = ({ phase }) => {
return policy.phases[phase]?.actions?.forcemerge != null;
}, [policy, phase]);

const { docLinks } = useKibana().services;

return (
<DescribedFormRow
title={
Expand All @@ -47,7 +48,7 @@ export const ForcemergeField: React.FunctionComponent<Props> = ({ phase }) => {
id="xpack.indexLifecycleMgmt.editPolicy.forceMerge.enableExplanationText"
defaultMessage="Reduce the number of segments in each index shard and clean up deleted documents."
/>{' '}
<LearnMoreLink docPath="ilm-forcemerge.html" />
<LearnMoreLink docPath={docLinks.links.elasticsearch.ilmForceMerge} />
</>
}
titleSize="xs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { useEditPolicyContext } from '../../../edit_policy_context';

import { UseField } from '../../../form';
import { LearnMoreLink, DescribedFormRow } from '../..';
import { useKibana } from '../../../../../../shared_imports';

interface Props {
phase: PhaseExceptDelete;
Expand All @@ -33,6 +34,8 @@ export const IndexPriorityField: FunctionComponent<Props> = ({ phase }) => {
);
}, [isNewPolicy, policy.phases, phase]);

const { docLinks } = useKibana().services;

return (
<DescribedFormRow
title={
Expand All @@ -50,7 +53,7 @@ export const IndexPriorityField: FunctionComponent<Props> = ({ phase }) => {
defaultMessage="Set the priority for recovering your indices after a node restart.
Indices with higher priorities are recovered before indices with lower priorities."
/>{' '}
<LearnMoreLink docPath="ilm-set-priority.html" />
<LearnMoreLink docPath={docLinks.links.elasticsearch.ilmSetPriority} />
</EuiTextColor>
}
titleSize="xs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import { FormattedMessage } from '@kbn/i18n-react';
import { EuiTextColor } from '@elastic/eui';
import { LearnMoreLink } from '../../learn_more_link';
import { ToggleFieldWithDescribedFormRow } from '../../described_form_row';

import { useKibana } from '../../../../../../shared_imports';
interface Props {
phase: 'hot' | 'warm' | 'cold';
}

export const ReadonlyField: React.FunctionComponent<Props> = ({ phase }) => {
const { docLinks } = useKibana().services;
return (
<ToggleFieldWithDescribedFormRow
title={
Expand All @@ -32,7 +33,7 @@ export const ReadonlyField: React.FunctionComponent<Props> = ({ phase }) => {
id="xpack.indexLifecycleMgmt.editPolicy.readonlyDescription"
defaultMessage="Enable to make the index and index metadata read only, disable to allow writes and metadata changes."
/>{' '}
<LearnMoreLink docPath="ilm-readonly.html" />
<LearnMoreLink docPath={docLinks.links.elasticsearch.ilmReadOnly} />
</EuiTextColor>
}
fullWidth
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ export interface Props {
canBeDisabled?: boolean;
}

const geti18nTexts = (phase: Props['phase']) => {
const geti18nTexts = (
phase: Props['phase'],
fullyMountedSearchableSnapshotLink: string,
partiallyMountedSearchableSnapshotLink: string
) => {
switch (phase) {
// Hot and cold phases both create fully mounted snapshots.
case 'hot':
Expand All @@ -42,7 +46,7 @@ const geti18nTexts = (phase: Props['phase']) => {
id="xpack.indexLifecycleMgmt.editPolicy.fullyMountedSearchableSnapshotField.description"
defaultMessage="Convert to a fully-mounted index that contains a complete copy of your data and is backed by a snapshot. You can reduce the number of replicas and rely on the snapshot for resiliency. {learnMoreLink}"
values={{
learnMoreLink: <LearnMoreLink docPath="ilm-searchable-snapshot.html" />,
learnMoreLink: <LearnMoreLink docPath={fullyMountedSearchableSnapshotLink} />,
}}
/>
),
Expand All @@ -66,9 +70,7 @@ const geti18nTexts = (phase: Props['phase']) => {
id="xpack.indexLifecycleMgmt.editPolicy.frozenPhase.partiallyMountedSearchableSnapshotField.description"
defaultMessage="Convert to a partially-mounted index that caches the index metadata. Data is retrieved from the snapshot as needed to process search requests. This minimizes the index footprint while keeping all of your data fully searchable. {learnMoreLink}"
values={{
learnMoreLink: (
<LearnMoreLink docPath="searchable-snapshots.html#searchable-snapshots-shared-cache" />
),
learnMoreLink: <LearnMoreLink docPath={partiallyMountedSearchableSnapshotLink} />,
}}
/>
),
Expand All @@ -85,7 +87,7 @@ export const SearchableSnapshotField: FunctionComponent<Props> = ({
canBeDisabled = true,
}) => {
const {
services: { cloud, getUrlForApp },
services: { cloud, docLinks, getUrlForApp },
} = useKibana();
const { policy, license, isNewPolicy } = useEditPolicyContext();
const { isUsingSearchableSnapshotInHotPhase } = useConfiguration();
Expand All @@ -109,8 +111,14 @@ export const SearchableSnapshotField: FunctionComponent<Props> = ({
policy.phases[phase]?.actions?.searchable_snapshot?.snapshot_repository
)
);

const i18nTexts = geti18nTexts(phase);
const fullyMountedSearchableSnapshotLink = docLinks.links.elasticsearch.ilmSearchableSnapshot;
const partiallyMountedSearchableSnapshotLink =
docLinks.links.elasticsearch.searchableSnapshotSharedCache;
const i18nTexts = geti18nTexts(
phase,
fullyMountedSearchableSnapshotLink,
partiallyMountedSearchableSnapshotLink
);

useEffect(() => {
if (isDisabledDueToLicense) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { i18nTexts } from '../../../i18n_texts';
import { LearnMoreLink, DescribedFormRow } from '../../';
import { byteSizeUnits } from '../../../constants';
import { UnitField } from './unit_field';
import { useKibana } from '../../../../../../shared_imports';

interface Props {
phase: 'hot' | 'warm';
Expand All @@ -35,6 +36,7 @@ export const ShrinkField: FunctionComponent<Props> = ({ phase }) => {
const path = `phases.${phase}.actions.shrink.${
isUsingShardSize ? 'max_primary_shard_size' : 'number_of_shards'
}`;
const { docLinks } = useKibana().services;
return (
<DescribedFormRow
title={
Expand All @@ -51,7 +53,7 @@ export const ShrinkField: FunctionComponent<Props> = ({ phase }) => {
id="xpack.indexLifecycleMgmt.editPolicy.shrinkIndexExplanationText"
defaultMessage="Shrink the index to a new index with fewer primary shards."
/>{' '}
<LearnMoreLink docPath="ilm-shrink.html" />
<LearnMoreLink docPath={docLinks.links.elasticsearch.ilmShrink} />
</EuiTextColor>
}
titleSize="xs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const waitForSnapshotFormField = 'phases.delete.actions.wait_for_snapshot.policy

export const SnapshotPoliciesField: React.FunctionComponent = () => {
const {
services: { getUrlForApp },
services: { docLinks, getUrlForApp },
} = useKibana();
const { error, isLoading, data, resendRequest } = useLoadSnapshotPolicies();
const [formData] = useFormData({
Expand Down Expand Up @@ -159,7 +159,7 @@ export const SnapshotPoliciesField: React.FunctionComponent = () => {
id="xpack.indexLifecycleMgmt.editPolicy.deletePhase.waitForSnapshotDescription"
defaultMessage="Specify a snapshot policy to be executed before the deletion of the index. This ensures that a snapshot of the deleted index is available."
/>{' '}
<LearnMoreLink docPath="ilm-wait-for-snapshot.html" />
<LearnMoreLink docPath={docLinks.links.alerting.ilmWaitForSnapshot} />
</>
}
titleSize="xs"
Expand Down
Loading

0 comments on commit 2503fa6

Please sign in to comment.