Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.14] Allow zero (0) to unset unenroll_timeout field (#103790) #103965

Merged
merged 1 commit into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,6 @@ export const AgentPolicyForm: React.FunctionComponent<Props> = ({
</EuiFormRow>
);
});
const unenrollmentTimeoutText = i18n.translate(
'xpack.fleet.agentPolicyForm.unenrollmentTimeoutLabel',
{ defaultMessage: 'Unenrollment timeout' }
);

const advancedOptionsContent = (
<>
Expand Down Expand Up @@ -303,7 +299,14 @@ export const AgentPolicyForm: React.FunctionComponent<Props> = ({
/>
</EuiDescribedFormGroup>
<EuiDescribedFormGroup
title={<h4>{unenrollmentTimeoutText}</h4>}
title={
<h4>
<FormattedMessage
id="xpack.fleet.agentPolicyForm.unenrollmentTimeoutLabel"
defaultMessage="Unenrollment timeout"
/>
</h4>
}
description={
<FormattedMessage
id="xpack.fleet.agentPolicyForm.unenrollmentTimeoutDescription"
Expand All @@ -315,12 +318,14 @@ export const AgentPolicyForm: React.FunctionComponent<Props> = ({
<EuiFieldNumber
fullWidth
disabled={agentPolicy.is_managed === true}
value={agentPolicy.unenroll_timeout}
min={1}
onChange={(e) => updateAgentPolicy({ unenroll_timeout: Number(e.target.value) })}
value={agentPolicy.unenroll_timeout || ''}
onChange={(e) => {
updateAgentPolicy({
unenroll_timeout: e.target.value ? Number(e.target.value) : 0,
});
}}
isInvalid={Boolean(touchedFields.unenroll_timeout && validation.unenroll_timeout)}
onBlur={() => setTouchedFields({ ...touchedFields, unenroll_timeout: true })}
placeholder={unenrollmentTimeoutText}
/>
</EuiFormRow>
</EuiDescribedFormGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
import React, { memo, useState } from 'react';
import { useHistory } from 'react-router-dom';
import styled from 'styled-components';
import { EuiBottomBar, EuiFlexGroup, EuiFlexItem, EuiButtonEmpty, EuiButton } from '@elastic/eui';
import {
EuiBottomBar,
EuiFlexGroup,
EuiFlexItem,
EuiButtonEmpty,
EuiButton,
EuiSpacer,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';

Expand Down Expand Up @@ -145,58 +152,62 @@ export const SettingsView = memo<{ agentPolicy: AgentPolicy }>(
/>

{hasChanges ? (
<EuiBottomBar>
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center">
<EuiFlexItem>
<FormattedMessage
id="xpack.fleet.editAgentPolicy.unsavedChangesText"
defaultMessage="You have unsaved changes"
/>
</EuiFlexItem>
<EuiFlexItem>
<EuiFlexGroup gutterSize="s" justifyContent="flexEnd">
<EuiFlexItem grow={false}>
<EuiButtonEmpty
color="ghost"
onClick={() => {
setAgentPolicy({ ...originalAgentPolicy });
setHasChanges(false);
}}
>
<FormattedMessage
id="xpack.fleet.editAgentPolicy.cancelButtonText"
defaultMessage="Cancel"
/>
</EuiButtonEmpty>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
onClick={onSubmit}
isLoading={isLoading}
isDisabled={
!hasWriteCapabilites || isLoading || Object.keys(validation).length > 0
}
iconType="save"
color="primary"
fill
>
{isLoading ? (
<FormattedMessage
id="xpack.fleet.editAgentPolicy.savingButtonText"
defaultMessage="Saving…"
/>
) : (
<>
<EuiSpacer size="xl" />
<EuiSpacer size="xl" />
<EuiBottomBar>
<EuiFlexGroup justifyContent="spaceBetween" alignItems="center">
<EuiFlexItem>
<FormattedMessage
id="xpack.fleet.editAgentPolicy.unsavedChangesText"
defaultMessage="You have unsaved changes"
/>
</EuiFlexItem>
<EuiFlexItem>
<EuiFlexGroup gutterSize="s" justifyContent="flexEnd">
<EuiFlexItem grow={false}>
<EuiButtonEmpty
color="ghost"
onClick={() => {
setAgentPolicy({ ...originalAgentPolicy });
setHasChanges(false);
}}
>
<FormattedMessage
id="xpack.fleet.editAgentPolicy.saveButtonText"
defaultMessage="Save changes"
id="xpack.fleet.editAgentPolicy.cancelButtonText"
defaultMessage="Cancel"
/>
)}
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
</EuiFlexGroup>
</EuiBottomBar>
</EuiButtonEmpty>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton
onClick={onSubmit}
isLoading={isLoading}
isDisabled={
!hasWriteCapabilites || isLoading || Object.keys(validation).length > 0
}
iconType="save"
color="primary"
fill
>
{isLoading ? (
<FormattedMessage
id="xpack.fleet.editAgentPolicy.savingButtonText"
defaultMessage="Saving…"
/>
) : (
<FormattedMessage
id="xpack.fleet.editAgentPolicy.saveButtonText"
defaultMessage="Save changes"
/>
)}
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFlexItem>
</EuiFlexGroup>
</EuiBottomBar>
</>
) : null}
</FormWrapper>
);
Expand Down
5 changes: 4 additions & 1 deletion x-pack/plugins/fleet/server/services/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,12 @@ class AgentPolicyService {
data: (fullPolicy as unknown) as FleetServerPolicy['data'],
policy_id: fullPolicy.id,
default_fleet_server: policy.is_default_fleet_server === true,
unenroll_timeout: policy.unenroll_timeout,
};

if (policy.unenroll_timeout) {
fleetServerPolicy.unenroll_timeout = policy.unenroll_timeout;
}

await esClient.create({
index: AGENT_POLICY_INDEX,
body: fleetServerPolicy,
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/fleet/server/types/models/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const AgentPolicyBaseSchema = {
namespace: NamespaceSchema,
description: schema.maybe(schema.string()),
is_managed: schema.maybe(schema.boolean()),
unenroll_timeout: schema.maybe(schema.number({ min: 1 })),
unenroll_timeout: schema.maybe(schema.number()),
monitoring_enabled: schema.maybe(
schema.arrayOf(
schema.oneOf([schema.literal(dataTypes.Logs), schema.literal(dataTypes.Metrics)])
Expand Down