Skip to content

Commit

Permalink
Replace logs/metrics strings with const
Browse files Browse the repository at this point in the history
  • Loading branch information
John Schulz committed Nov 3, 2020
1 parent c2af3aa commit 61a78dd
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
import { PackagePolicy, PackagePolicyPackage } from './package_policy';
import { Output } from './output';
import { DataType, ValueOf } from '../../index';

export enum AgentPolicyStatus {
Active = 'active',
Expand All @@ -16,7 +17,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 {
DeleteAgentPolicyResponse,
Settings,
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 { AgentPolicyStatus } from '../../../common';
import { AgentPolicyStatus, 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 61a78dd

Please sign in to comment.