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

[Ingest Manager] Replace logs/metrics strings with const #82424

Merged
merged 5 commits into from
Nov 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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