Skip to content

Commit

Permalink
[Fleet] Expose agent logging level in agent policy settings (#180607)
Browse files Browse the repository at this point in the history
Closes #158861

## Summary
Expose agent logging level in agent policy settings. 
The new setting is added via the new settings framework and will show up
under "advanced settings". It's currently hidden until the agent
supports it.

### Testing
Enable the settings config:
#180597 (comment)
- Go to the agent policy settings form
- Under advanced settings there is a new dropdown "Agent logging level".
Choose a value and save the policy
- The new value should be retained after saving
- Go to the agent policies tab and select action "View policy"
- The new field should be visible under `agent.logging.level`

<details>
  <summary> Screenshots</summary>
  
![Screenshot 2024-04-12 at 16 21
46](https://github.com/elastic/kibana/assets/16084106/b3083bb5-703a-44c6-a00d-da9d64a2b083)
![Screenshot 2024-04-12 at 16 21
52](https://github.com/elastic/kibana/assets/16084106/bd934262-86f0-4b11-b7b4-d4be72f00715)
![Screenshot 2024-04-12 at 16 22
28](https://github.com/elastic/kibana/assets/16084106/4a352c82-f274-4779-9718-85135f84b0c8)
![Screenshot 2024-04-12 at 16 27
48](https://github.com/elastic/kibana/assets/16084106/11e20051-f91b-44c1-b795-76ef6804cf78)

</details>

### Checklist
- [ ] Any text added follows [EUI's writing
guidelines](https://elastic.github.io/eui/#/guidelines/writing), uses
sentence case text and includes [i18n
support](https://github.com/elastic/kibana/blob/main/packages/kbn-i18n/README.md)
- [ ] [Unit or functional
tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)
were updated or added to match the most common scenarios

---------

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
  • Loading branch information
criamico and kibanamachine committed Apr 15, 2024
1 parent fd90462 commit f1abe4f
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 23 deletions.
16 changes: 16 additions & 0 deletions x-pack/plugins/fleet/common/constants/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,19 @@ export const LICENSE_FOR_SCHEDULE_UPGRADE = 'platinum';
export const DEFAULT_MAX_AGENT_POLICIES_WITH_INACTIVITY_TIMEOUT = 750;

export const AGENTLESS_POLICY_ID = 'agentless'; // the policy id defined here: https://github.com/elastic/project-controller/blob/main/internal/project/security/security_kibana_config.go#L86

export const AGENT_LOG_LEVELS = {
ERROR: 'error',
WARNING: 'warning',
INFO: 'info',
DEBUG: 'debug',
};

export const DEFAULT_LOG_LEVEL = AGENT_LOG_LEVELS.INFO;

export const agentLoggingLevels = {
Info: 'info',
Debug: 'debug',
Warning: 'warning',
Error: 'error',
} as const;
19 changes: 19 additions & 0 deletions x-pack/plugins/fleet/common/settings/agent_policy_settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import { i18n } from '@kbn/i18n';
import { z } from 'zod';

import { agentLoggingLevels } from '../constants';

import type { SettingsConfig } from './types';

export const zodStringWithDurationValidation = z
Expand Down Expand Up @@ -126,4 +128,21 @@ export const AGENT_POLICY_ADVANCED_SETTINGS: SettingsConfig[] = [
})
.default({}),
},
{
name: 'agent.logging.level',
hidden: true,
title: i18n.translate('xpack.fleet.settings.agentPolicyAdvanced.agentLoggingLevelTitle', {
defaultMessage: 'Agent Logging Level',
}),
description: i18n.translate(
'xpack.fleet.settings.agentPolicyAdvanced.agentLoggingLevelDescription',
{
defaultMessage: 'Set the Agent log level. The default log level is "info".',
}
),
api_field: {
name: 'agent_logging_level',
},
schema: z.nativeEnum(agentLoggingLevels),
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import { ZodFirstPartyTypeKind } from 'zod';
import React from 'react';
import { EuiFieldNumber, EuiFieldText } from '@elastic/eui';
import { EuiFieldNumber, EuiFieldText, EuiSelect } from '@elastic/eui';

import type { SettingsConfig } from '../../../../../common/settings/types';

Expand Down Expand Up @@ -61,6 +61,27 @@ settingComponentRegistry.set(ZodFirstPartyTypeKind.ZodString, (settingsConfig) =
);
});

settingComponentRegistry.set(ZodFirstPartyTypeKind.ZodNativeEnum, (settingsConfig) => {
return (
<SettingsFieldWrapper
settingsConfig={settingsConfig}
typeName={ZodFirstPartyTypeKind.ZodString}
renderItem={({ fieldKey, fieldValue, handleChange, coercedSchema }: any) => (
<EuiSelect
data-test-subj={fieldKey}
value={fieldValue}
fullWidth
onChange={handleChange}
options={Object.keys(coercedSchema.enum).map((level) => ({
text: level,
value: coercedSchema.enum[level],
}))}
/>
)}
/>
);
});

export function ConfiguredSettings({
configuredSettings,
}: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,13 @@ interface Props {
agentPolicy: Partial<NewAgentPolicy | AgentPolicy>;
updateAgentPolicy: (u: Partial<NewAgentPolicy | AgentPolicy>) => void;
validation: ValidationResults;
isEditing?: boolean;
disabled?: boolean;
}

export const AgentPolicyAdvancedOptionsContent: React.FunctionComponent<Props> = ({
agentPolicy,
updateAgentPolicy,
validation,
isEditing = false,
disabled = false,
}) => {
const { docLinks } = useStartServices();
Expand Down Expand Up @@ -401,7 +399,6 @@ export const AgentPolicyAdvancedOptionsContent: React.FunctionComponent<Props> =
}}
/>
</EuiDescribedFormGroup>

{AgentTamperProtectionSection}

<EuiDescribedFormGroup
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,6 @@ export const AgentPolicyCreateInlineForm: React.FunctionComponent<Props> = ({
agentPolicy={newAgentPolicy}
updateAgentPolicy={updateNewAgentPolicy}
validation={validation}
isEditing={false}
/>
</StyledEuiAccordion>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ export const AgentPolicyForm: React.FunctionComponent<Props> = ({
agentPolicy={agentPolicy}
updateAgentPolicy={updateAgentPolicy}
validation={validation}
isEditing={isEditing}
/>

{advancedPolicySettings ? (
Expand All @@ -168,7 +167,6 @@ export const AgentPolicyForm: React.FunctionComponent<Props> = ({
agentPolicy={agentPolicy}
updateAgentPolicy={updateAgentPolicy}
validation={validation}
isEditing={isEditing}
disabled={disabled}
/>
{advancedPolicySettings ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ interface Props {
withSysMonitoring: boolean;
updateSysMonitoring: (newValue: boolean) => void;
validation: ValidationResults;
isEditing?: boolean;
onDelete?: () => void;
}

export const AgentPolicyIntegrationForm: React.FunctionComponent<Props> = ({
Expand All @@ -45,8 +43,6 @@ export const AgentPolicyIntegrationForm: React.FunctionComponent<Props> = ({
withSysMonitoring,
updateSysMonitoring,
validation,
isEditing = false,
onDelete = () => {},
}) => {
return (
<EuiForm>
Expand Down Expand Up @@ -101,7 +97,6 @@ export const AgentPolicyIntegrationForm: React.FunctionComponent<Props> = ({
agentPolicy={agentPolicy}
updateAgentPolicy={updateAgentPolicy}
validation={validation}
isEditing={isEditing}
/>
</StyledEuiAccordion>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,3 @@ export const DEFAULT_LOGS_STATE: AgentLogsState = {

export const STATE_STORAGE_KEY = '_q';
export const STATE_DATASET_FIELD = 'datasets';

export const AGENT_LOG_LEVELS = {
ERROR: 'error',
WARNING: 'warning',
INFO: 'info',
DEBUG: 'debug',
};

export const DEFAULT_LOG_LEVEL = AGENT_LOG_LEVELS.INFO;
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { EuiSelectableOption } from '@elastic/eui';
import { EuiPopover, EuiFilterButton, EuiSelectable } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { AGENT_LOG_LEVELS } from './constants';
import { AGENT_LOG_LEVELS } from '../../../../../../../../common/constants';

const LEVEL_VALUES = Object.values(AGENT_LOG_LEVELS);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { EuiSelect, EuiFormLabel, EuiButtonEmpty, EuiFlexItem, EuiFlexGroup } fr
import type { Agent } from '../../../../../types';
import { sendPostAgentAction, useAuthz, useStartServices } from '../../../../../hooks';

import { AGENT_LOG_LEVELS, DEFAULT_LOG_LEVEL } from './constants';
import { AGENT_LOG_LEVELS, DEFAULT_LOG_LEVEL } from '../../../../../../../../common/constants';

const LEVEL_VALUES = Object.values(AGENT_LOG_LEVELS);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,7 @@ describe('getFullAgentPolicy', () => {
mockAgentPolicy({
advanced_settings: {
agent_limits_go_max_procs: 2,
agent_logging_level: 'debug',
},
});
const agentPolicy = await getFullAgentPolicy(savedObjectsClientMock.create(), 'agent-policy');
Expand All @@ -727,6 +728,7 @@ describe('getFullAgentPolicy', () => {
id: 'agent-policy',
agent: {
limits: { go_max_procs: 2 },
logging: { level: 'debug' },
},
});
});
Expand Down

0 comments on commit f1abe4f

Please sign in to comment.