Skip to content

Commit

Permalink
Add SLM status to policy list
Browse files Browse the repository at this point in the history
  • Loading branch information
SoniaSanzV committed Dec 4, 2024
1 parent 2b8e981 commit 8f60b42
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export enum SNAPSHOT_STATE {
PARTIAL = 'PARTIAL',
}

export enum SLM_STATE {
RUNNING = 'RUNNING',
STOPPING = 'STOPPING',
STOPPED = 'STOPPED',
}

const INDEX_SETTING_SUGGESTIONS: string[] = [
'index.number_of_shards',
'index.shard.check_on_startup',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ import { SlmPolicy } from '../../../../../common/types';
import { APP_SLM_CLUSTER_PRIVILEGES } from '../../../../../common';
import { BASE_PATH, UIM_POLICY_LIST_LOAD } from '../../../constants';
import { useDecodedParams } from '../../../lib';
import { useLoadPolicies, useLoadRetentionSettings } from '../../../services/http';
import {
useLoadPolicies,
useLoadRetentionSettings,
useLoadSlmStatus,
} from '../../../services/http';
import { linkToAddPolicy, linkToPolicy } from '../../../services/navigation';
import { useAppContext, useServices } from '../../../app_context';

import { PolicyDetails } from './policy_details';
import { PolicyTable } from './policy_table';
import { PolicyRetentionSchedule } from './policy_retention_schedule';
import { SlmStatus } from './slm_status';

interface MatchParams {
policyName?: SlmPolicy['name'];
Expand Down Expand Up @@ -61,6 +66,8 @@ export const PolicyList: React.FunctionComponent<RouteComponentProps<MatchParams
resendRequest: reloadRetentionSettings,
} = useLoadRetentionSettings();

const { data: slmStatus } = useLoadSlmStatus();

const openPolicyDetailsUrl = (newPolicyName: SlmPolicy['name']): string => {
return linkToPolicy(newPolicyName);
};
Expand Down Expand Up @@ -190,6 +197,8 @@ export const PolicyList: React.FunctionComponent<RouteComponentProps<MatchParams
/>
) : null}

<SlmStatus status={slmStatus?.operation_mode} />

<PolicyTable
policies={policies || []}
reload={reload}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*
* 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.
*/

export { SlmStatus } from './slm_status';
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* 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 React from 'react';
import { FormattedMessage } from '@kbn/i18n-react';
import { EuiFlexGroup, EuiFlexItem, EuiIcon, EuiPanel, EuiSpacer, EuiText } from '@elastic/eui';

import { SLM_STATE } from '../../../../constants';
import { useServices } from '../../../../app_context';

interface Props {
status: string;
}

export const SlmStatus: React.FunctionComponent<Props> = ({ status }) => {
const { i18n } = useServices();

const statusMap: any = {
[SLM_STATE.RUNNING]: {
icon: <EuiIcon color="success" type="dot" />,
label: i18n.translate('xpack.snapshotRestore.slmstatus.runninglable', {
defaultMessage: 'Running',
}),
},
[SLM_STATE.STOPPING]: {
icon: <EuiIcon color="warning" type="dot" />,
label: i18n.translate('xpack.snapshotRestore.slmstatus.stoppinglable', {
defaultMessage: 'Stopping',
}),
},
[SLM_STATE.STOPPED]: {
icon: <EuiIcon color="disabled" type="dot" />,
label: i18n.translate('xpack.snapshotRestore.slmstatus.stoppedlable', {
defaultMessage: 'Stopped',
}),
},
};

if (!statusMap[status]) {
// Returns empty if no status
return <></>;
}

const { icon, label } = statusMap[status];

return (
<>
<EuiPanel hasBorder={true}>
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center">
<EuiFlexItem grow={false}>
<EuiText>
<EuiFlexGroup>
<FormattedMessage
id="xpack.snapshotRestore.slmstatus.title"
defaultMessage="SLM status: {slmStatus}"
values={{
slmStatus: (
<EuiFlexGroup gutterSize="xs" alignItems="center" responsive={false}>
<EuiFlexItem grow={false}>{icon}</EuiFlexItem>
<EuiFlexItem grow={false}>{label}</EuiFlexItem>
</EuiFlexGroup>
),
}}
/>
</EuiFlexGroup>
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
</EuiPanel>
<EuiSpacer />
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,10 @@ export const executeRetention = async () => {
uiMetricService.trackUiMetric(UIM_RETENTION_EXECUTE);
return result;
};

export const useLoadSlmStatus = () => {
return useRequest({
path: `${API_BASE_PATH}policies/slm_status`,
method: 'get',
});
};
16 changes: 16 additions & 0 deletions x-pack/plugins/snapshot_restore/server/routes/api/policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,20 @@ export function registerPolicyRoutes({
return res.ok({ body: response });
})
);

// Get snapshot lifecycle management status
router.get(
{ path: addBasePath('policies/slm_status'), validate: false },
license.guardApiRoute(async (ctx, req, res) => {
const { client: clusterClient } = (await ctx.core).elasticsearch;

try {
const response = await clusterClient.asCurrentUser.slm.getStatus();

return res.ok({ body: response });
} catch (e) {
return handleEsError({ error: e, response: res });
}
})
);
}

0 comments on commit 8f60b42

Please sign in to comment.