[Fleet] Expose agent logging level in agent policy settings (#180607)

Closes https://github.com/elastic/kibana/issues/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:
https://github.com/elastic/kibana/pull/180597#discussion_r1562448034
- 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](b3083bb5-703a-44c6-a00d-da9d64a2b083)
![Screenshot 2024-04-12 at 16 21
52](bd934262-86f0-4b11-b7b4-d4be72f00715)
![Screenshot 2024-04-12 at 16 22
28](4a352c82-f274-4779-9718-85135f84b0c8)
![Screenshot 2024-04-12 at 16 27
48](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>
This commit is contained in:
Cristina Amico 2024-04-15 12:05:27 +02:00 committed by GitHub
parent fd90462486
commit f1abe4f7eb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 61 additions and 23 deletions

View file

@ -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;

View file

@ -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
@ -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),
},
];

View file

@ -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';
@ -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,
}: {

View file

@ -63,7 +63,6 @@ interface Props {
agentPolicy: Partial<NewAgentPolicy | AgentPolicy>;
updateAgentPolicy: (u: Partial<NewAgentPolicy | AgentPolicy>) => void;
validation: ValidationResults;
isEditing?: boolean;
disabled?: boolean;
}
@ -71,7 +70,6 @@ export const AgentPolicyAdvancedOptionsContent: React.FunctionComponent<Props> =
agentPolicy,
updateAgentPolicy,
validation,
isEditing = false,
disabled = false,
}) => {
const { docLinks } = useStartServices();
@ -401,7 +399,6 @@ export const AgentPolicyAdvancedOptionsContent: React.FunctionComponent<Props> =
}}
/>
</EuiDescribedFormGroup>
{AgentTamperProtectionSection}
<EuiDescribedFormGroup

View file

@ -188,7 +188,6 @@ export const AgentPolicyCreateInlineForm: React.FunctionComponent<Props> = ({
agentPolicy={newAgentPolicy}
updateAgentPolicy={updateNewAgentPolicy}
validation={validation}
isEditing={false}
/>
</StyledEuiAccordion>
</>

View file

@ -141,7 +141,6 @@ export const AgentPolicyForm: React.FunctionComponent<Props> = ({
agentPolicy={agentPolicy}
updateAgentPolicy={updateAgentPolicy}
validation={validation}
isEditing={isEditing}
/>
{advancedPolicySettings ? (
@ -168,7 +167,6 @@ export const AgentPolicyForm: React.FunctionComponent<Props> = ({
agentPolicy={agentPolicy}
updateAgentPolicy={updateAgentPolicy}
validation={validation}
isEditing={isEditing}
disabled={disabled}
/>
{advancedPolicySettings ? (

View file

@ -35,8 +35,6 @@ interface Props {
withSysMonitoring: boolean;
updateSysMonitoring: (newValue: boolean) => void;
validation: ValidationResults;
isEditing?: boolean;
onDelete?: () => void;
}
export const AgentPolicyIntegrationForm: React.FunctionComponent<Props> = ({
@ -45,8 +43,6 @@ export const AgentPolicyIntegrationForm: React.FunctionComponent<Props> = ({
withSysMonitoring,
updateSysMonitoring,
validation,
isEditing = false,
onDelete = () => {},
}) => {
return (
<EuiForm>
@ -101,7 +97,6 @@ export const AgentPolicyIntegrationForm: React.FunctionComponent<Props> = ({
agentPolicy={agentPolicy}
updateAgentPolicy={updateAgentPolicy}
validation={validation}
isEditing={isEditing}
/>
</StyledEuiAccordion>
</>

View file

@ -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;

View file

@ -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);

View file

@ -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);

View file

@ -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');
@ -727,6 +728,7 @@ describe('getFullAgentPolicy', () => {
id: 'agent-policy',
agent: {
limits: { go_max_procs: 2 },
logging: { level: 'debug' },
},
});
});