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

[UII] Allow to reset log level for agents >= 8.15.0 #183434

Merged
merged 10 commits into from
May 16, 2024
17 changes: 5 additions & 12 deletions x-pack/plugins/fleet/common/constants/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,10 @@ 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',
info: 'info',
debug: 'debug',
warning: 'warning',
error: 'error',
};

export const DEFAULT_LOG_LEVEL = AGENT_LOG_LEVELS.INFO;

export const agentLoggingLevels = {
Info: 'info',
Debug: 'debug',
Warning: 'warning',
Error: 'error',
} as const;
export const DEFAULT_LOG_LEVEL = AGENT_LOG_LEVELS.info;
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/openapi/bundled.json
Original file line number Diff line number Diff line change
Expand Up @@ -7294,6 +7294,7 @@
"properties": {
"log_level": {
"type": "string",
"nullable": true,
"enum": [
"debug",
"info",
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/openapi/bundled.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4674,6 +4674,7 @@ components:
properties:
log_level:
type: string
nullable: true
enum:
- debug
- info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ oneOf:
properties:
log_level:
type: string
nullable: true
enum:
- debug
- info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import React from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n-react';
import { EuiCode } from '@elastic/eui';

import { z } from 'zod';

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

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

Expand Down Expand Up @@ -130,20 +133,19 @@ export const AGENT_POLICY_ADVANCED_SETTINGS: SettingsConfig[] = [
},
{
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:
'Sets the log level for all the agents on the policy. The default log level is "info".',
}
description: (
<FormattedMessage
id="xpack.fleet.settings.agentPolicyAdvanced.agentLoggingLevelDescription"
defaultMessage="Sets the log level for all the agents on the policy. The default log level is {level}."
values={{ level: <EuiCode>{DEFAULT_LOG_LEVEL}</EuiCode> }}
/>
),
api_field: {
name: 'agent_logging_level',
},
schema: z.nativeEnum(agentLoggingLevels).default(agentLoggingLevels.Info),
schema: z.nativeEnum(AGENT_LOG_LEVELS).default(DEFAULT_LOG_LEVEL),
},
];
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,15 @@ describe('AgentLogsUI', () => {
},
} as any);
});
const renderComponent = () => {
const renderComponent = (
opts = {
agentVersion: '8.11.0',
}
) => {
const renderer = createFleetTestRendererMock();
const agent = {
id: 'agent1',
local_metadata: { elastic: { agent: { version: '8.11' } } },
local_metadata: { elastic: { agent: { version: opts.agentVersion, log_level: 'debug' } } },
} as any;
const state = {
datasets: ['elastic_agent'],
Expand Down Expand Up @@ -125,4 +129,35 @@ describe('AgentLogsUI', () => {
`http://localhost:5620/app/discover#/?_g=(filters:!(),refreshInterval:(pause:!t,value:60000),time:(from:'2023-20-04T14:00:00.340Z',to:'2023-20-04T14:20:00.340Z'))&_a=(columns:!(event.dataset,message),index:'logs-*',query:(language:kuery,query:'elastic_agent.id:agent1 and (data_stream.dataset:elastic_agent) and (log.level:info or log.level:error)'))`
);
});

it('should show log level dropdown with correct value', () => {
mockStartServices();
const result = renderComponent();
const logLevelDropdown = result.getByTestId('selectAgentLogLevel');
expect(logLevelDropdown.getElementsByTagName('option').length).toBe(4);
expect(logLevelDropdown).toHaveDisplayValue('debug');
});

it('should always show apply log level changes button', () => {
mockStartServices();
const result = renderComponent();
const applyLogLevelBtn = result.getByTestId('applyLogLevelBtn');
expect(applyLogLevelBtn).toBeInTheDocument();
expect(applyLogLevelBtn).not.toHaveAttribute('disabled');
});

it('should hide reset log level button for agents version < 8.15.0', () => {
mockStartServices();
const result = renderComponent();
const resetLogLevelBtn = result.queryByTestId('resetLogLevelBtn');
expect(resetLogLevelBtn).not.toBeInTheDocument();
});

it('should show reset log level button for agents version >= 8.15.0', () => {
mockStartServices();
const result = renderComponent({ agentVersion: '8.15.0' });
const resetLogLevelBtn = result.getByTestId('resetLogLevelBtn');
expect(resetLogLevelBtn).toBeInTheDocument();
expect(resetLogLevelBtn).not.toHaveAttribute('disabled');
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,10 @@ export const AgentLogsUI: React.FunctionComponent<AgentLogsProps> = memo(
</EuiPanel>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<SelectLogLevel agent={agent} />
<SelectLogLevel
agent={agent}
agentPolicyLogLevel={agentPolicy?.advanced_settings?.agent_logging_level}
/>
</EuiFlexItem>
</WrapperFlexGroup>
);
Expand Down
Loading
Loading