Skip to content

Commit

Permalink
[Ingest Manager] Replace logs/metrics strings with const (#82424) (#8…
Browse files Browse the repository at this point in the history
…2674)

## Summary

Use new runtime & type values added in #82231 (related to #82188 ) instead of strings. Same results. Stronger type safety.

Some before/after pics below:

<img width="680" alt="Screen Shot 2020-11-03 at 6 40 04 AM" src="https://user-images.githubusercontent.com/57655/97989501-9ff2c500-1dac-11eb-8a2d-96ddadfe2477.png">
<img width="525" alt="Screen Shot 2020-11-03 at 6 40 19 AM" src="https://user-images.githubusercontent.com/57655/97989503-a08b5b80-1dac-11eb-97ee-371a0487fbd3.png">

<img width="790" alt="Screen Shot 2020-11-03 at 7 47 42 AM" src="https://user-images.githubusercontent.com/57655/97989505-a08b5b80-1dac-11eb-9db9-54a2719a85b2.png">
<img width="738" alt="Screen Shot 2020-11-03 at 7 47 34 AM" src="https://user-images.githubusercontent.com/57655/97989504-a08b5b80-1dac-11eb-8d1d-692feafd5fe3.png">


<img width="778" alt="Screen Shot 2020-11-03 at 7 54 17 AM" src="https://user-images.githubusercontent.com/57655/97989507-a123f200-1dac-11eb-879d-ab9be4e060eb.png">
<img width="813" alt="Screen Shot 2020-11-03 at 7 54 45 AM" src="https://user-images.githubusercontent.com/57655/97989508-a123f200-1dac-11eb-8725-c44068d6b233.png">
  • Loading branch information
John Schulz authored Nov 5, 2020
1 parent 7c113de commit bfa5c27
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { agentPolicyStatuses } from '../../constants';
import { ValueOf } from '../../types';
import { DataType, ValueOf } from '../../types';
import { PackagePolicy, PackagePolicyPackage } from './package_policy';
import { Output } from './output';

Expand All @@ -15,7 +15,7 @@ export interface NewAgentPolicy {
namespace: string;
description?: string;
is_default?: boolean;
monitoring_enabled?: Array<'logs' | 'metrics'>;
monitoring_enabled?: Array<ValueOf<DataType>>;
}

export interface AgentPolicy extends NewAgentPolicy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import styled from 'styled-components';
import { dataTypes } from '../../../../../../common';
import { NewAgentPolicy, AgentPolicy } from '../../../types';
import { isValidNamespace } from '../../../services';
import { AgentPolicyDeleteProvider } from './agent_policy_delete_provider';
Expand Down Expand Up @@ -211,7 +212,7 @@ export const AgentPolicyForm: React.FunctionComponent<Props> = ({
<EuiCheckboxGroup
options={[
{
id: 'logs',
id: dataTypes.Logs,
label: (
<>
<FormattedMessage
Expand All @@ -233,7 +234,7 @@ export const AgentPolicyForm: React.FunctionComponent<Props> = ({
),
},
{
id: 'metrics',
id: dataTypes.Metrics,
label: (
<>
<FormattedMessage
Expand Down Expand Up @@ -263,7 +264,7 @@ export const AgentPolicyForm: React.FunctionComponent<Props> = ({
{ logs: false, metrics: false }
)}
onChange={(id) => {
if (id !== 'logs' && id !== 'metrics') {
if (id !== dataTypes.Logs && id !== dataTypes.Metrics) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
EuiFlyoutProps,
EuiSpacer,
} from '@elastic/eui';
import { dataTypes } from '../../../../../../../common';
import { NewAgentPolicy, AgentPolicy } from '../../../../types';
import { useCapabilities, useCore, sendCreateAgentPolicy } from '../../../../hooks';
import { AgentPolicyForm, agentPolicyFormValidation } from '../../components';
Expand All @@ -44,7 +45,7 @@ export const CreateAgentPolicyFlyout: React.FunctionComponent<Props> = ({
description: '',
namespace: 'default',
is_default: undefined,
monitoring_enabled: ['logs', 'metrics'],
monitoring_enabled: Object.values(dataTypes),
});
const [isLoading, setIsLoading] = useState<boolean>(false);
const [withSysMonitoring, setWithSysMonitoring] = useState<boolean>(true);
Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/ingest_manager/server/services/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
Settings,
agentPolicyStatuses,
storedPackagePoliciesToAgentInputs,
dataTypes,
} from '../../common';
import { AgentPolicyNameExistsError } from '../errors';
import { createAgentPolicyAction, listAgents } from './agents';
Expand Down Expand Up @@ -538,8 +539,8 @@ class AgentPolicyService {
monitoring: {
use_output: defaultOutput.name,
enabled: true,
logs: agentPolicy.monitoring_enabled.indexOf('logs') >= 0,
metrics: agentPolicy.monitoring_enabled.indexOf('metrics') >= 0,
logs: agentPolicy.monitoring_enabled.includes(dataTypes.Logs),
metrics: agentPolicy.monitoring_enabled.includes(dataTypes.Metrics),
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@
*/
import { schema } from '@kbn/config-schema';
import { PackagePolicySchema, NamespaceSchema } from './package_policy';
import { agentPolicyStatuses } from '../../../common';
import { agentPolicyStatuses, dataTypes } from '../../../common';

const AgentPolicyBaseSchema = {
name: schema.string({ minLength: 1 }),
namespace: NamespaceSchema,
description: schema.maybe(schema.string()),
monitoring_enabled: schema.maybe(
schema.arrayOf(schema.oneOf([schema.literal('logs'), schema.literal('metrics')]))
schema.arrayOf(
schema.oneOf([schema.literal(dataTypes.Logs), schema.literal(dataTypes.Metrics)])
)
),
};

Expand Down

0 comments on commit bfa5c27

Please sign in to comment.