Skip to content

Commit

Permalink
[Fleet] Add ability to show FQDN of agents (#150239)
Browse files Browse the repository at this point in the history
## Summary

Closes #149059 

Adds the `agent_features` agent policy field which is an array of
feature flags + other arbitrary config values. As part of this allow the
FQDN feature to be configured in the agent policy settings.

<img width="1049" alt="Screenshot 2023-02-02 at 23 59 17"
src="https://user-images.githubusercontent.com/3315046/216478081-c6316798-bcc6-422a-85b1-fa5d717a229d.png">
  • Loading branch information
hop-dev authored Feb 7, 2023
1 parent 1854c31 commit 7e9a9bc
Show file tree
Hide file tree
Showing 13 changed files with 280 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
"index-pattern": "48e77ca393c254e93256f11a7cdc0232dd754c08",
"infrastructure-monitoring-log-view": "e2c78c1076bd35e57d7c5fa1b410e5c126d12327",
"infrastructure-ui-source": "7c8dbbc0a608911f1b683a944f4a65383f6153ed",
"ingest-agent-policies": "54d586fdafae83ba326e47d1a3727b0d9c910a12",
"ingest-agent-policies": "a94bd53b8f81ca883de8a75386db04e27dda973e",
"ingest-download-sources": "1e69dabd6db5e320fe08c5bda8f35f29bafc6b54",
"ingest-outputs": "29181ecfdc7723f544325ecef7266bccbc691a54",
"ingest-package-policies": "0335a28af793ce25b4969d2156cfaf1dae2ef812",
Expand Down
18 changes: 18 additions & 0 deletions x-pack/plugins/fleet/common/openapi/bundled.json
Original file line number Diff line number Diff line change
Expand Up @@ -5807,6 +5807,24 @@
},
"agents": {
"type": "number"
},
"agent_features": {
"type": "array",
"items": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"enabled": {
"type": "boolean"
}
},
"required": [
"name",
"enabled"
]
}
}
},
"required": [
Expand Down
12 changes: 12 additions & 0 deletions x-pack/plugins/fleet/common/openapi/bundled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3704,6 +3704,18 @@ components:
type: number
agents:
type: number
agent_features:
type: array
items:
type: object
properties:
name:
type: string
enabled:
type: boolean
required:
- name
- enabled
required:
- id
- status
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ allOf:
type: number
agents:
type: number
agent_features:
type: array
items:
type: object
properties:
name:
type: string
enabled:
type: boolean
required:
- name
- enabled
required:
- id
- status
2 changes: 2 additions & 0 deletions x-pack/plugins/fleet/common/types/models/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export interface NewAgentPolicy {
download_source_id?: string | null;
fleet_server_host_id?: string | null;
schema_version?: string;
agent_features?: Array<{ name: string; enabled: boolean }>;
}

export interface AgentPolicy extends Omit<NewAgentPolicy, 'id'> {
Expand Down Expand Up @@ -112,6 +113,7 @@ export interface FullAgentPolicy {
logs: boolean;
};
download: { sourceURI: string };
features: Record<string, { enabled: boolean }>;
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ import {
EuiSuperSelect,
EuiToolTip,
EuiBadge,
EuiRadioGroup,
EuiText,
EuiFlexGroup,
EuiFlexItem,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { i18n } from '@kbn/i18n';
Expand Down Expand Up @@ -517,6 +521,89 @@ export const AgentPolicyAdvancedOptionsContent: React.FunctionComponent<Props> =
/>
</EuiFormRow>
</EuiDescribedFormGroup>
<EuiDescribedFormGroup
title={
<h4>
<FormattedMessage
id="xpack.fleet.agentPolicyForm.hostnameFormatLabel"
defaultMessage="Host name format"
/>
</h4>
}
description={
<FormattedMessage
id="xpack.fleet.agentPolicyForm.hostnameFormatLabelDescription"
defaultMessage="Select how you would like agent domain names to be displayed."
/>
}
>
<EuiFormRow fullWidth>
<EuiRadioGroup
options={[
{
id: 'hostname',
label: (
<>
<EuiFlexGroup gutterSize="xs" direction="column">
<EuiFlexItem grow={false}>
<EuiText size="s">
<b>
<FormattedMessage
id="xpack.fleet.agentPolicyForm.hostnameFormatOptionHostname"
defaultMessage="Hostname"
/>
</b>
</EuiText>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiText size="s" color="subdued">
<FormattedMessage
id="xpack.fleet.agentPolicyForm.hostnameFormatOptionHostnameExample"
defaultMessage="ex: My-Laptop"
/>
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
<EuiSpacer size="s" />
</>
),
},
{
id: 'fqdn',
label: (
<EuiFlexGroup gutterSize="xs" direction="column">
<EuiFlexItem grow={false}>
<EuiText size="s">
<b>
<FormattedMessage
id="xpack.fleet.agentPolicyForm.hostnameFormatOptionFqdn"
defaultMessage="Fully Qualified Domain Name (FQDN)"
/>
</b>
</EuiText>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiText size="s" color="subdued">
<FormattedMessage
id="xpack.fleet.agentPolicyForm.hostnameFormatOptionFqdnExample"
defaultMessage="ex: My-Laptop.admin.acme.co"
/>
</EuiText>
</EuiFlexItem>
</EuiFlexGroup>
),
},
]}
idSelected={agentPolicy.agent_features?.length ? 'fqdn' : 'hostname'}
onChange={(id: string) => {
updateAgentPolicy({
agent_features: id === 'hostname' ? [] : [{ name: 'fqdn', enabled: true }],
});
}}
name="radio group"
/>
</EuiFormRow>
</EuiDescribedFormGroup>
{isEditing && 'id' in agentPolicy && !agentPolicy.is_managed ? (
<EuiDescribedFormGroup
title={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,21 @@ import { DevtoolsRequestFlyoutButton } from '../../../../../components';
import { ExperimentalFeaturesService } from '../../../../../services';
import { generateUpdateAgentPolicyDevToolsRequest } from '../../../services';

const pickAgentPolicyKeysToSend = (agentPolicy: AgentPolicy) =>
pick(agentPolicy, [
'name',
'description',
'namespace',
'monitoring_enabled',
'unenroll_timeout',
'inactivity_timeout',
'data_output_id',
'monitoring_output_id',
'download_source_id',
'fleet_server_host_id',
'agent_features',
]);

const FormWrapper = styled.div`
max-width: 800px;
margin-right: auto;
Expand Down Expand Up @@ -77,37 +92,10 @@ export const SettingsView = memo<{ agentPolicy: AgentPolicy }>(
const submitUpdateAgentPolicy = async () => {
setIsLoading(true);
try {
const {
name,
description,
namespace,
// eslint-disable-next-line @typescript-eslint/naming-convention
monitoring_enabled,
// eslint-disable-next-line @typescript-eslint/naming-convention
unenroll_timeout,
// eslint-disable-next-line @typescript-eslint/naming-convention
inactivity_timeout,
// eslint-disable-next-line @typescript-eslint/naming-convention
data_output_id,
// eslint-disable-next-line @typescript-eslint/naming-convention
monitoring_output_id,
// eslint-disable-next-line @typescript-eslint/naming-convention
download_source_id,
// eslint-disable-next-line @typescript-eslint/naming-convention
fleet_server_host_id,
} = agentPolicy;
const { data, error } = await sendUpdateAgentPolicy(agentPolicy.id, {
name,
description,
namespace,
monitoring_enabled,
unenroll_timeout,
inactivity_timeout,
data_output_id,
monitoring_output_id,
download_source_id,
fleet_server_host_id,
});
const { data, error } = await sendUpdateAgentPolicy(
agentPolicy.id,
pickAgentPolicyKeysToSend(agentPolicy)
);
if (data) {
notifications.toasts.addSuccess(
i18n.translate('xpack.fleet.editAgentPolicy.successNotificationTitle', {
Expand Down Expand Up @@ -141,19 +129,7 @@ export const SettingsView = memo<{ agentPolicy: AgentPolicy }>(
() =>
generateUpdateAgentPolicyDevToolsRequest(
agentPolicy.id,
pick(
agentPolicy,
'name',
'description',
'namespace',
'monitoring_enabled',
'unenroll_timeout',
'inactivity_timeout',
'data_output_id',
'monitoring_output_id',
'download_source_id',
'fleet_server_host_id'
)
pickAgentPolicyKeysToSend(agentPolicy)
),
[agentPolicy]
);
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/fleet/server/saved_objects/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ const getSavedObjectTypes = (
monitoring_output_id: { type: 'keyword' },
download_source_id: { type: 'keyword' },
fleet_server_host_id: { type: 'keyword' },
agent_features: {
properties: {
name: { type: 'keyword' },
enabled: { type: 'boolean' },
},
},
},
},
migrations: {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,51 @@ describe('getFullAgentPolicy', () => {
},
});
});

it('should add + transform agent features', async () => {
mockAgentPolicy({
namespace: 'default',
revision: 1,
monitoring_enabled: ['metrics'],
agent_features: [
{ name: 'fqdn', enabled: true },
{ name: 'feature2', enabled: true },
],
});
const agentPolicy = await getFullAgentPolicy(savedObjectsClientMock.create(), 'agent-policy');

expect(agentPolicy).toMatchObject({
id: 'agent-policy',
outputs: {
default: {
type: 'elasticsearch',
hosts: ['http://127.0.0.1:9201'],
},
},
inputs: [],
revision: 1,
fleet: {
hosts: ['http://fleetserver:8220'],
},
agent: {
monitoring: {
namespace: 'default',
use_output: 'default',
enabled: true,
logs: false,
metrics: true,
},
features: {
fqdn: {
enabled: true,
},
feature2: {
enabled: true,
},
},
},
});
});
});

describe('transformOutputToFullPolicyOutput', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ export async function getFullAgentPolicy(
metrics: agentPolicy.monitoring_enabled.includes(dataTypes.Metrics),
}
: { enabled: false, logs: false, metrics: false },
features: (agentPolicy.agent_features || []).reduce((acc, { name, ...featureConfig }) => {
acc[name] = featureConfig;
return acc;
}, {} as NonNullable<FullAgentPolicy['agent']>['features']),
},
};

Expand Down
8 changes: 8 additions & 0 deletions x-pack/plugins/fleet/server/types/models/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ export const AgentPolicyBaseSchema = {
monitoring_output_id: schema.maybe(schema.nullable(schema.string())),
download_source_id: schema.maybe(schema.nullable(schema.string())),
fleet_server_host_id: schema.maybe(schema.nullable(schema.string())),
agent_features: schema.maybe(
schema.arrayOf(
schema.object({
name: schema.string(),
enabled: schema.boolean(),
})
)
),
};

export const NewAgentPolicySchema = schema.object({
Expand Down
Loading

0 comments on commit 7e9a9bc

Please sign in to comment.