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

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

Merged
merged 12 commits into from
Apr 15, 2024
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 = {
juliaElastic marked this conversation as resolved.
Show resolved Hide resolved
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),
criamico marked this conversation as resolved.
Show resolved Hide resolved
},
];
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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This field was not used anymore so I removed it

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;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, the linter catched unused props

}

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
Loading