From a2621da267defb3d7eb3e57b9140abc82513b5bf Mon Sep 17 00:00:00 2001 From: Oliver Gupte Date: Wed, 17 Nov 2021 12:33:04 -0500 Subject: [PATCH 01/25] wip --- .../agent_instructions_accordion.tsx | 154 +++++++------ .../apm_agents/runtime_attachment.stories.tsx | 29 +++ .../apm_agents/runtime_attachment.tsx | 204 ++++++++++++++++++ 3 files changed, 326 insertions(+), 61 deletions(-) create mode 100644 x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment.stories.tsx create mode 100644 x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment.tsx diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx index 8f66658785b97..fcdd3e29b7aa0 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx @@ -12,6 +12,8 @@ import { EuiSpacer, EuiText, EuiCodeBlock, + EuiTabbedContent, + EuiBetaBadge, } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import React from 'react'; @@ -25,6 +27,7 @@ import { AgentIcon } from '../../shared/agent_icon'; import { NewPackagePolicy } from '../apm_policy_form/typings'; import { getCommands } from '../../../tutorial/config_agent/commands/get_commands'; import { replaceTemplateStrings } from './replace_template_strings'; +import { RuntimeAttachment } from './runtime_attachment'; function AccordionButtonContent({ agentName, @@ -116,6 +119,63 @@ export function AgentInstructionsAccordion({ const apmServerUrl = vars?.url.value; const secretToken = vars?.secret_token.value; const steps = createAgentInstructions(apmServerUrl, secretToken); + const stepsElements = steps.map( + ( + { title: stepTitle, textPre, textPost, customComponentName, commands }, + index + ) => { + const commandBlock = replaceTemplateStrings( + Array.isArray(commands) ? commands.join('\n') : commands || '', + docLinks + ); + return ( +
+ +

{stepTitle}

+
+ + + {textPre && ( + + )} + {commandBlock && ( + <> + + + {commandBlock} + + + )} + {customComponentName === 'TutorialConfigAgent' && ( + + )} + {customComponentName === 'TutorialConfigAgentRumScript' && ( + + )} + {textPost && ( + <> + + + + )} + + +
+ ); + } + ); return ( - {steps.map( - ( + + + {stepsElements} + + ), }, - index - ) => { - const commandBlock = replaceTemplateStrings( - Array.isArray(commands) ? commands.join('\n') : commands || '', - docLinks - ); - return ( -
- -

{stepTitle}

-
- - - {textPre && ( - - )} - {commandBlock && ( - <> - - - {commandBlock} - - - )} - {customComponentName === 'TutorialConfigAgent' && ( - - )} - {customComponentName === 'TutorialConfigAgentRumScript' && ( - - )} - {textPost && ( - <> - - - - )} - - -
- ); - } - )} + { + id: 'auto-attachment', + name: ( + + Auto-Attachment + + + + + ), + content: ( + <> + + + + ), + }, + ]} + />
); } diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment.stories.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment.stories.tsx new file mode 100644 index 0000000000000..7cc130f789931 --- /dev/null +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment.stories.tsx @@ -0,0 +1,29 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { Meta, Story } from '@storybook/react'; +import React from 'react'; +import { RuntimeAttachment } from './runtime_attachment'; + +const stories: Meta<{}> = { + title: 'fleet/RuntimeAttachment', + component: RuntimeAttachment, + decorators: [ + (StoryComponent) => { + return ( +
+ +
+ ); + }, + ], +}; +export default stories; + +export const CreatingInApmFromInventory: Story = () => { + return ; +}; diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment.tsx new file mode 100644 index 0000000000000..99fd6fbb0a159 --- /dev/null +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment.tsx @@ -0,0 +1,204 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { + EuiCallOut, + EuiSpacer, + EuiSwitch, + EuiText, + EuiFlexGroup, + EuiFlexItem, + EuiButton, + EuiDragDropContext, + EuiDroppable, + EuiDraggable, + EuiPanel, + EuiIcon, + euiDragDropReorder, + EuiBadge, +} from '@elastic/eui'; +import React, { useState } from 'react'; +// import { +// NewPackagePolicy, +// PackagePolicy, +// PackagePolicyEditExtensionComponentProps, +// } from '../apm_policy_form/typings'; + +interface Props { + // policy: PackagePolicy; + // newPolicy: NewPackagePolicy; + // onChange: PackagePolicyEditExtensionComponentProps['onChange']; +} + +function DiscoveryRule({ + order, + include, + ruleKey, + ruleValue, +}: { + order: number; + include: boolean; + ruleKey: string; + ruleValue: string; +}) { + return ( + + + {order} + + + {include ? ( + Include + ) : ( + Exclude + )} + + + + + +

{ruleKey}

+
+
+ + {ruleValue} + +
+
+ + + + {}} + style={{ cursor: 'pointer' }} + /> + + + {}} + style={{ cursor: 'pointer' }} + /> + + + +
+ ); +} + +export function RuntimeAttachment({}: Props) { + const [list, setList] = useState([ + { + id: 'main java-opbeans-10010', + content: { + include: true, + key: 'main', + value: 'java-opbeans-10010', + }, + }, + { + id: 'pid 10948653898867', + content: { + include: false, + key: 'pid', + value: '10948653898867', + }, + }, + ]); + const onDragEnd = ({ source, destination }) => { + if (source && destination) { + const items = euiDragDropReorder(list, source.index, destination.index); + + setList(items); + } + }; + return ( +
+ + + {}} + /> + + +

Attach the Java agent to running and starting Java applications.

+
+ + +

Discovery rules

+
+ + + + + + Add rule + + + + + + {list.map(({ content, id }, idx) => ( + + {(provided) => ( + + + +
+ +
+
+ + + +
+
+ )} +
+ ))} +
+
+
+ ); +} From 1fe9086171a48fb87f6e7f9232631f5dd4056d69 Mon Sep 17 00:00:00 2001 From: Oliver Gupte Date: Wed, 17 Nov 2021 22:48:40 -0500 Subject: [PATCH 02/25] wip --- .../agent_instructions_accordion.tsx | 2 +- .../apm_agents/runtime_attachment.tsx | 55 ++++++++++++------- 2 files changed, 35 insertions(+), 22 deletions(-) diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx index fcdd3e29b7aa0..ba22f732ec619 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx @@ -206,7 +206,7 @@ export function AgentInstructionsAccordion({ > Auto-Attachment - + ), diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment.tsx index 99fd6fbb0a159..1d7b87dfd6a00 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment.tsx @@ -5,6 +5,7 @@ * 2.0. */ +import { DropResult } from '@elastic/eui'; import { EuiCallOut, EuiSpacer, @@ -112,7 +113,7 @@ export function RuntimeAttachment({}: Props) { }, }, ]); - const onDragEnd = ({ source, destination }) => { + const onDragEnd = ({ source, destination }: DropResult) => { if (source && destination) { const items = euiDragDropReorder(list, source.index, destination.index); @@ -122,14 +123,16 @@ export function RuntimeAttachment({}: Props) { return (
{}} /> @@ -141,14 +144,19 @@ export function RuntimeAttachment({}: Props) {

Discovery rules

- + + + + + - + +

+ For every running JVM, the discovery rules are evaluated in the + order they are provided. The first matching rule determines the + outcome. Learn more in the docs. +

+
Add rule @@ -156,11 +164,7 @@ export function RuntimeAttachment({}: Props) {
- + {list.map(({ content, id }, idx) => ( {(provided) => ( - +
+ + + + Everything else + + + Exclude + + + All + + +
); } From 43eddabe0940cc993293b53ec6203c1878fa350b Mon Sep 17 00:00:00 2001 From: Oliver Gupte Date: Thu, 18 Nov 2021 10:09:11 -0500 Subject: [PATCH 03/25] wip --- .../apm_agents/runtime_attachment.tsx | 217 ------------------ .../default_discovery_rule.tsx | 26 +++ .../runtime_attachment/discovery_rule.tsx | 94 ++++++++ .../edit_discovery_rule.tsx | 95 ++++++++ .../apm_agents/runtime_attachment/index.tsx | 153 ++++++++++++ .../runtime_attachment.stories.tsx | 2 +- .../runtime_attachment/runtime_attachment.tsx | 181 +++++++++++++++ 7 files changed, 550 insertions(+), 218 deletions(-) delete mode 100644 x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment.tsx create mode 100644 x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/default_discovery_rule.tsx create mode 100644 x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx create mode 100644 x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx create mode 100644 x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx rename x-pack/plugins/apm/public/components/fleet_integration/apm_agents/{ => runtime_attachment}/runtime_attachment.stories.tsx (92%) create mode 100644 x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment.tsx deleted file mode 100644 index 1d7b87dfd6a00..0000000000000 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment.tsx +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License - * 2.0; you may not use this file except in compliance with the Elastic License - * 2.0. - */ - -import { DropResult } from '@elastic/eui'; -import { - EuiCallOut, - EuiSpacer, - EuiSwitch, - EuiText, - EuiFlexGroup, - EuiFlexItem, - EuiButton, - EuiDragDropContext, - EuiDroppable, - EuiDraggable, - EuiPanel, - EuiIcon, - euiDragDropReorder, - EuiBadge, -} from '@elastic/eui'; -import React, { useState } from 'react'; -// import { -// NewPackagePolicy, -// PackagePolicy, -// PackagePolicyEditExtensionComponentProps, -// } from '../apm_policy_form/typings'; - -interface Props { - // policy: PackagePolicy; - // newPolicy: NewPackagePolicy; - // onChange: PackagePolicyEditExtensionComponentProps['onChange']; -} - -function DiscoveryRule({ - order, - include, - ruleKey, - ruleValue, -}: { - order: number; - include: boolean; - ruleKey: string; - ruleValue: string; -}) { - return ( - - - {order} - - - {include ? ( - Include - ) : ( - Exclude - )} - - - - - -

{ruleKey}

-
-
- - {ruleValue} - -
-
- - - - {}} - style={{ cursor: 'pointer' }} - /> - - - {}} - style={{ cursor: 'pointer' }} - /> - - - -
- ); -} - -export function RuntimeAttachment({}: Props) { - const [list, setList] = useState([ - { - id: 'main java-opbeans-10010', - content: { - include: true, - key: 'main', - value: 'java-opbeans-10010', - }, - }, - { - id: 'pid 10948653898867', - content: { - include: false, - key: 'pid', - value: '10948653898867', - }, - }, - ]); - const onDragEnd = ({ source, destination }: DropResult) => { - if (source && destination) { - const items = euiDragDropReorder(list, source.index, destination.index); - - setList(items); - } - }; - return ( -
- - - {}} - /> - - -

Attach the Java agent to running and starting Java applications.

-
- - -

Discovery rules

-
- - - - - - - -

- For every running JVM, the discovery rules are evaluated in the - order they are provided. The first matching rule determines the - outcome. Learn more in the docs. -

-
-
- - Add rule - -
- - - - {list.map(({ content, id }, idx) => ( - - {(provided) => ( - - - -
- -
-
- - - -
-
- )} -
- ))} -
-
- - - - Everything else - - - Exclude - - - All - - - -
- ); -} diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/default_discovery_rule.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/default_discovery_rule.tsx new file mode 100644 index 0000000000000..cb60a5a36fa2a --- /dev/null +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/default_discovery_rule.tsx @@ -0,0 +1,26 @@ +import { + EuiText, + EuiFlexGroup, + EuiFlexItem, + EuiPanel, + EuiBadge, +} from '@elastic/eui'; +import React from 'react'; + +export function DefaultDiscoveryRule() { + return ( + + + + Everything else + + + Exclude + + + All + + + + ); +} diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx new file mode 100644 index 0000000000000..b55d1a3d0ba83 --- /dev/null +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx @@ -0,0 +1,94 @@ +import { + EuiText, + EuiFlexGroup, + EuiFlexItem, + EuiIcon, + EuiBadge, + EuiPanel, + DraggableProvidedDragHandleProps, +} from '@elastic/eui'; +import React from 'react'; + +interface Props { + id: string; + order: number; + include: boolean; + ruleKey: string; + ruleValue: string; + providedDragHandleProps?: DraggableProvidedDragHandleProps; + onDelete: (discoveryItemId: string) => void; + onEdit: (discoveryItemId: null | string) => void; +} + +export function DiscoveryRule({ + id, + order, + include, + ruleKey, + ruleValue, + providedDragHandleProps, + onDelete, + onEdit, +}: Props) { + return ( + + + +
+ +
+
+ + + + {order} + + + {include ? ( + Include + ) : ( + Exclude + )} + + + + + +

{ruleKey}

+
+
+ + {ruleValue} + +
+
+ + + + { + onEdit(id); + }} + style={{ cursor: 'pointer' }} + /> + + + { + onDelete(id); + }} + style={{ cursor: 'pointer' }} + /> + + + +
+
+
+
+ ); +} diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx new file mode 100644 index 0000000000000..dab9c13204433 --- /dev/null +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx @@ -0,0 +1,95 @@ +import { + EuiFlexGroup, + EuiFlexItem, + EuiPanel, + EuiButton, + EuiButtonEmpty, + EuiFormFieldset, + EuiSelect, + EuiFieldText, + EuiFormRow, +} from '@elastic/eui'; +import React from 'react'; + +interface Props { + id: string; + onChangeOperation: (discoveryItemId: string) => void; + operation: string; + onChangeType: (discoveryItemId: string) => void; + type: string; + onChangeProbe: (discoveryItemId: string) => void; + probe: string; + onCancel: () => void; + onSubmit: () => void; +} + +export function EditDiscoveryRule({ + id, + onChangeOperation, + operation, + onChangeType, + type, + onChangeProbe, + probe, + onCancel, + onSubmit, +}: Props) { + return ( + + + + + { + onChangeOperation( + e.target.selectedIndex === 0 ? 'Include' : 'Exclude' + ); + }} + /> + + + + + + { + onChangeType(e.target.selectedIndex === 0 ? 'main' : 'pid'); + }} + /> + + + + + + + onChangeProbe(e.target.value)} + /> + + + + + + + Cancel + + + + {id === 'new' ? 'Add' : 'Save'} + + + + + ); +} diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx new file mode 100644 index 0000000000000..ab8c70e3d64c7 --- /dev/null +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx @@ -0,0 +1,153 @@ +import React, { useState, useCallback } from 'react'; +import { RuntimeAttachment as RuntimeAttachmentStateless } from './runtime_attachment'; +// import { +// NewPackagePolicy, +// PackagePolicy, +// PackagePolicyEditExtensionComponentProps, +// } from '../apm_policy_form/typings'; + +interface Props { + // policy: PackagePolicy; + // newPolicy: NewPackagePolicy; + // onChange: PackagePolicyEditExtensionComponentProps['onChange']; +} + +export function RuntimeAttachment(props: Props) { + const [isEnabled, setIsEnabled] = useState(true); + const [list, setList] = useState([ + { + id: 'main java-opbeans-10010', + content: { + include: true, + key: 'main', + value: 'java-opbeans-10010', + }, + }, + { + id: 'pid 10948653898867', + content: { + include: false, + key: 'pid', + value: '10948653898867', + }, + }, + ]); + const [editItemId, setEditItemId] = useState(null); + + const onToggleEnable = useCallback(() => { + setIsEnabled(!isEnabled); + setList([]); + }, [isEnabled]); + + const onDelete = useCallback( + (discoveryItemId: string) => { + const filteredList = list.filter(({ id }) => id !== discoveryItemId); + setList(filteredList); + }, + [list] + ); + + const onEdit = useCallback( + (discoveryItemId: string | null) => { + const editingDiscoveryRule = list.find( + ({ id }) => id === discoveryItemId + ); + if (editingDiscoveryRule) { + const { + content: { include, key, value }, + } = editingDiscoveryRule; + setStagedOperationText(include ? 'Include' : 'Exclude'); + setStagedTypeText(key); + setStagedProbeText(value); + setEditItemId(discoveryItemId); + } + }, + [list] + ); + + const [stagedOperationText, setStagedOperationText] = useState(''); + const onChangeOperation = useCallback((operationText: string) => { + setStagedOperationText(operationText); + }, []); + + const [stagedTypeText, setStagedTypeText] = useState(''); + const onChangeType = useCallback((operationText: string) => { + setStagedTypeText(operationText); + }, []); + + const [stagedProbeText, setStagedProbeText] = useState(''); + const onChangeProbe = useCallback((operationText: string) => { + setStagedProbeText(operationText); + }, []); + + const onCancel = useCallback(() => { + if (editItemId === 'new') { + onDelete('new'); + } + setEditItemId(null); + }, [editItemId, onDelete]); + + const onSubmit = useCallback(() => { + const editItemIndex = list.findIndex(({ id }) => id === editItemId); + const editItem = list[editItemIndex]; + const nextList = [ + ...list.slice(0, editItemIndex), + { + id: + editItem.id === 'new' + ? Math.random().toString(16).substr(2) + : editItem.id, + content: { + include: stagedOperationText === 'Include', + key: stagedTypeText, + value: stagedProbeText, + }, + }, + ...list.slice(editItemIndex + 1), + ]; + setList(nextList); + setEditItemId(null); + }, [editItemId, stagedOperationText, stagedTypeText, stagedProbeText, list]); + + const onAddRule = useCallback(() => { + const operationText = 'Include'; + const typeText = 'main'; + const valueText = ''; + setStagedOperationText(operationText); + setStagedTypeText(typeText); + setStagedProbeText(valueText); + const nextList = [ + { + id: 'new', + content: { + include: false, + key: '', + value: '', + }, + }, + ...list, + ]; + setList(nextList); + setEditItemId('new'); + }, [list]); + return ( + + ); +} diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment.stories.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.stories.tsx similarity index 92% rename from x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment.stories.tsx rename to x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.stories.tsx index 7cc130f789931..3337fa4f4df01 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment.stories.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.stories.tsx @@ -7,7 +7,7 @@ import { Meta, Story } from '@storybook/react'; import React from 'react'; -import { RuntimeAttachment } from './runtime_attachment'; +import { RuntimeAttachment } from '.'; const stories: Meta<{}> = { title: 'fleet/RuntimeAttachment', diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx new file mode 100644 index 0000000000000..7d50fb7ebd4cb --- /dev/null +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx @@ -0,0 +1,181 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { DropResult } from '@elastic/eui'; +import { + EuiCallOut, + EuiSpacer, + EuiSwitch, + EuiText, + EuiFlexGroup, + EuiFlexItem, + EuiButton, + EuiDragDropContext, + EuiDroppable, + EuiDraggable, + EuiIcon, + euiDragDropReorder, +} from '@elastic/eui'; +import React from 'react'; +import { DiscoveryRule } from './discovery_rule'; +import { DefaultDiscoveryRule } from './default_discovery_rule'; +import { EditDiscoveryRule } from './edit_discovery_rule'; + +interface DiscoveryRuleItem { + id: string; + content: { + include: boolean; + key: string; + value: string; + }; +} + +interface Props { + isEnabled: boolean; + onToggleEnable: () => void; + list: DiscoveryRuleItem[]; + setList: (discoveryRuleItems: DiscoveryRuleItem[]) => void; + onDelete: (discoveryItemId: string) => void; + editItemId: null | string; + onEdit: (discoveryItemId: null | string) => void; + onChangeOperation: (operationText: string) => void; + stagedOperationText: string; + onChangeType: (typeText: string) => void; + stagedTypeText: string; + onChangeProbe: (probeText: string) => void; + stagedProbeText: string; + onCancel: () => void; + onSubmit: () => void; + onAddRule: () => void; +} + +export function RuntimeAttachment({ + isEnabled, + onToggleEnable, + list, + setList, + onDelete, + editItemId, + onEdit, + onChangeOperation, + stagedOperationText, + onChangeType, + stagedTypeText, + onChangeProbe, + stagedProbeText, + onCancel, + onSubmit, + onAddRule, +}: Props) { + const onDragEnd = ({ source, destination }: DropResult) => { + if (source && destination) { + const items = euiDragDropReorder(list, source.index, destination.index); + + setList(items); + } + }; + return ( +
+ + + + + +

Attach the Java agent to running and starting Java applications.

+
+ {isEnabled && ( + <> + + +

Discovery rules

+
+ + + + + + + +

+ For every running JVM, the discovery rules are evaluated in + the order they are provided. The first matching rule + determines the outcome. Learn more in the docs. +

+
+
+ + + Add rule + + +
+ + + + {list.map(({ content, id }, idx) => ( + + {(provided) => + id === editItemId ? ( + + ) : ( + + ) + } + + ))} + + + + + )} + +
+ ); +} From 858c670fdbf9025512d148ba131073c5cdcb37a8 Mon Sep 17 00:00:00 2001 From: Oliver Gupte Date: Thu, 18 Nov 2021 14:38:40 -0500 Subject: [PATCH 04/25] wip --- .../agent_instructions_accordion.tsx | 4 +- .../default_discovery_rule.tsx | 2 +- .../runtime_attachment/discovery_rule.tsx | 20 +- .../edit_discovery_rule.tsx | 29 +-- .../apm_agents/runtime_attachment/index.tsx | 174 ++++++++++-------- .../runtime_attachment.stories.tsx | 22 ++- .../runtime_attachment/runtime_attachment.tsx | 95 +++++----- .../java_runtime_attachment.tsx | 42 +++++ 8 files changed, 238 insertions(+), 150 deletions(-) create mode 100644 x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx index ba22f732ec619..64ca630691d78 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx @@ -27,7 +27,7 @@ import { AgentIcon } from '../../shared/agent_icon'; import { NewPackagePolicy } from '../apm_policy_form/typings'; import { getCommands } from '../../../tutorial/config_agent/commands/get_commands'; import { replaceTemplateStrings } from './replace_template_strings'; -import { RuntimeAttachment } from './runtime_attachment'; +import { JavaRuntimeAttachment } from './runtime_attachment/supported_agents/java_runtime_attachment'; function AccordionButtonContent({ agentName, @@ -213,7 +213,7 @@ export function AgentInstructionsAccordion({ content: ( <> - + ), }, diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/default_discovery_rule.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/default_discovery_rule.tsx index cb60a5a36fa2a..9ac2547ec47de 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/default_discovery_rule.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/default_discovery_rule.tsx @@ -9,7 +9,7 @@ import React from 'react'; export function DefaultDiscoveryRule() { return ( - + Everything else diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx index b55d1a3d0ba83..2af85e286675c 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx @@ -12,20 +12,20 @@ import React from 'react'; interface Props { id: string; order: number; - include: boolean; - ruleKey: string; - ruleValue: string; + operation: string; + type: string; + probe: string; providedDragHandleProps?: DraggableProvidedDragHandleProps; onDelete: (discoveryItemId: string) => void; - onEdit: (discoveryItemId: null | string) => void; + onEdit: (discoveryItemId: string) => void; } export function DiscoveryRule({ id, order, - include, - ruleKey, - ruleValue, + operation, + type, + probe, providedDragHandleProps, onDelete, onEdit, @@ -44,7 +44,7 @@ export function DiscoveryRule({ {order} - {include ? ( + {operation === 'Include' ? ( Include ) : ( Exclude @@ -54,11 +54,11 @@ export function DiscoveryRule({ -

{ruleKey}

+

{type}

- {ruleValue} + {probe}
diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx index dab9c13204433..f2fdcf6e6177f 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx @@ -10,6 +10,7 @@ import { EuiFormRow, } from '@elastic/eui'; import React from 'react'; +import { STAGED_DISCOVERY_RULE_ID } from '.'; interface Props { id: string; @@ -21,6 +22,8 @@ interface Props { probe: string; onCancel: () => void; onSubmit: () => void; + operations: string[]; + types: string[]; } export function EditDiscoveryRule({ @@ -33,6 +36,8 @@ export function EditDiscoveryRule({ probe, onCancel, onSubmit, + operations, + types, }: Props) { return ( @@ -40,15 +45,13 @@ export function EditDiscoveryRule({ ({ + text: operation, + value: operation, + }))} value={operation} onChange={(e) => { - onChangeOperation( - e.target.selectedIndex === 0 ? 'Include' : 'Exclude' - ); + onChangeOperation(operations[e.target.selectedIndex]); }} /> @@ -57,13 +60,13 @@ export function EditDiscoveryRule({ ({ + text: type, + value: type, + }))} value={type} onChange={(e) => { - onChangeType(e.target.selectedIndex === 0 ? 'main' : 'pid'); + onChangeType(types[e.target.selectedIndex]); }} /> @@ -86,7 +89,7 @@ export function EditDiscoveryRule({ - {id === 'new' ? 'Add' : 'Save'} + {id === STAGED_DISCOVERY_RULE_ID ? 'Add' : 'Save'}
diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx index ab8c70e3d64c7..9919bc8c4d095 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx @@ -1,68 +1,75 @@ -import React, { useState, useCallback } from 'react'; +import { htmlIdGenerator } from '@elastic/eui'; +import React, { useState, useCallback, ReactNode } from 'react'; import { RuntimeAttachment as RuntimeAttachmentStateless } from './runtime_attachment'; -// import { -// NewPackagePolicy, -// PackagePolicy, -// PackagePolicyEditExtensionComponentProps, -// } from '../apm_policy_form/typings'; + +export const STAGED_DISCOVERY_RULE_ID = 'STAGED_DISCOVERY_RULE_ID'; + +interface IDiscoveryRule { + operation: string; + type: string; + probe: string; +} + +export type IDiscoveryRuleList = Array<{ + id: string; + discoveryRule: IDiscoveryRule; +}>; interface Props { - // policy: PackagePolicy; - // newPolicy: NewPackagePolicy; - // onChange: PackagePolicyEditExtensionComponentProps['onChange']; + operations: string[]; + types: string[]; + onChange?: () => void; + toggleDescription: ReactNode; + discoveryRulesDescription: ReactNode; + showUnsavedWarning?: boolean; + initialDiscoveryRules?: IDiscoveryRule[]; } export function RuntimeAttachment(props: Props) { + const { initialDiscoveryRules = [] } = props; const [isEnabled, setIsEnabled] = useState(true); - const [list, setList] = useState([ - { - id: 'main java-opbeans-10010', - content: { - include: true, - key: 'main', - value: 'java-opbeans-10010', - }, - }, - { - id: 'pid 10948653898867', - content: { - include: false, - key: 'pid', - value: '10948653898867', - }, - }, - ]); - const [editItemId, setEditItemId] = useState(null); + const [discoveryRuleList, setDiscoveryRuleList] = + useState( + initialDiscoveryRules.map((discoveryRule) => ({ + id: generateId(), + discoveryRule, + })) + ); + const [editDiscoveryRuleId, setEditDiscoveryRuleId] = useState( + null + ); const onToggleEnable = useCallback(() => { setIsEnabled(!isEnabled); - setList([]); + setDiscoveryRuleList([]); }, [isEnabled]); const onDelete = useCallback( - (discoveryItemId: string) => { - const filteredList = list.filter(({ id }) => id !== discoveryItemId); - setList(filteredList); + (discoveryRuleId: string) => { + const filteredDiscoveryRuleList = discoveryRuleList.filter( + ({ id }) => id !== discoveryRuleId + ); + setDiscoveryRuleList(filteredDiscoveryRuleList); }, - [list] + [discoveryRuleList] ); const onEdit = useCallback( - (discoveryItemId: string | null) => { - const editingDiscoveryRule = list.find( - ({ id }) => id === discoveryItemId + (discoveryRuleId: string) => { + const editingDiscoveryRule = discoveryRuleList.find( + ({ id }) => id === discoveryRuleId ); if (editingDiscoveryRule) { const { - content: { include, key, value }, + discoveryRule: { operation, type, probe }, } = editingDiscoveryRule; - setStagedOperationText(include ? 'Include' : 'Exclude'); - setStagedTypeText(key); - setStagedProbeText(value); - setEditItemId(discoveryItemId); + setStagedOperationText(operation); + setStagedTypeText(type); + setStagedProbeText(probe); + setEditDiscoveryRuleId(discoveryRuleId); } }, - [list] + [discoveryRuleList] ); const [stagedOperationText, setStagedOperationText] = useState(''); @@ -81,63 +88,71 @@ export function RuntimeAttachment(props: Props) { }, []); const onCancel = useCallback(() => { - if (editItemId === 'new') { - onDelete('new'); + if (editDiscoveryRuleId === STAGED_DISCOVERY_RULE_ID) { + onDelete(STAGED_DISCOVERY_RULE_ID); } - setEditItemId(null); - }, [editItemId, onDelete]); + setEditDiscoveryRuleId(null); + }, [editDiscoveryRuleId, onDelete]); const onSubmit = useCallback(() => { - const editItemIndex = list.findIndex(({ id }) => id === editItemId); - const editItem = list[editItemIndex]; - const nextList = [ - ...list.slice(0, editItemIndex), + const editDiscoveryRuleIndex = discoveryRuleList.findIndex( + ({ id }) => id === editDiscoveryRuleId + ); + const editDiscoveryRule = discoveryRuleList[editDiscoveryRuleIndex]; + const nextDiscoveryRuleList = [ + ...discoveryRuleList.slice(0, editDiscoveryRuleIndex), { id: - editItem.id === 'new' - ? Math.random().toString(16).substr(2) - : editItem.id, - content: { - include: stagedOperationText === 'Include', - key: stagedTypeText, - value: stagedProbeText, + editDiscoveryRule.id === STAGED_DISCOVERY_RULE_ID + ? generateId() + : editDiscoveryRule.id, + discoveryRule: { + operation: stagedOperationText, + type: stagedTypeText, + probe: stagedProbeText, }, }, - ...list.slice(editItemIndex + 1), + ...discoveryRuleList.slice(editDiscoveryRuleIndex + 1), ]; - setList(nextList); - setEditItemId(null); - }, [editItemId, stagedOperationText, stagedTypeText, stagedProbeText, list]); + setDiscoveryRuleList(nextDiscoveryRuleList); + setEditDiscoveryRuleId(null); + }, [ + editDiscoveryRuleId, + stagedOperationText, + stagedTypeText, + stagedProbeText, + discoveryRuleList, + ]); const onAddRule = useCallback(() => { - const operationText = 'Include'; - const typeText = 'main'; + const operationText = props.operations[0]; + const typeText = props.types[0]; const valueText = ''; setStagedOperationText(operationText); setStagedTypeText(typeText); setStagedProbeText(valueText); - const nextList = [ + const nextDiscoveryRuleList = [ { - id: 'new', - content: { - include: false, - key: '', - value: '', + id: STAGED_DISCOVERY_RULE_ID, + discoveryRule: { + operation: operationText, + type: typeText, + probe: valueText, }, }, - ...list, + ...discoveryRuleList, ]; - setList(nextList); - setEditItemId('new'); - }, [list]); + setDiscoveryRuleList(nextDiscoveryRuleList); + setEditDiscoveryRuleId(STAGED_DISCOVERY_RULE_ID); + }, [discoveryRuleList]); return ( ); } + +const generateId = htmlIdGenerator(); diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.stories.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.stories.tsx index 3337fa4f4df01..56dce86e67add 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.stories.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.stories.tsx @@ -8,9 +8,10 @@ import { Meta, Story } from '@storybook/react'; import React from 'react'; import { RuntimeAttachment } from '.'; +import { JavaRuntimeAttachment } from './supported_agents/java_runtime_attachment'; const stories: Meta<{}> = { - title: 'fleet/RuntimeAttachment', + title: 'fleet/Runtime agent attachment', component: RuntimeAttachment, decorators: [ (StoryComponent) => { @@ -24,6 +25,21 @@ const stories: Meta<{}> = { }; export default stories; -export const CreatingInApmFromInventory: Story = () => { - return ; +export const RuntimeAttachmentExample: Story = () => { + return ( + {}} + toggleDescription="Attach the Java agent to running and starting Java applications." + discoveryRulesDescription="For every running JVM, the discovery rules are evaluated in the order they are provided. The first matching rule determines the outcome. Learn more in the docs" + showUnsavedWarning={true} + /> + ); }; +RuntimeAttachmentExample.storyName = 'RuntimeAttachment'; + +export const JavaRuntimeAttachmentExample: Story = () => { + return {}} />; +}; +JavaRuntimeAttachmentExample.storyName = 'JavaRuntimeAttachment'; diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx index 7d50fb7ebd4cb..3392708022d95 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx @@ -20,28 +20,20 @@ import { EuiIcon, euiDragDropReorder, } from '@elastic/eui'; -import React from 'react'; +import React, { ReactNode } from 'react'; import { DiscoveryRule } from './discovery_rule'; import { DefaultDiscoveryRule } from './default_discovery_rule'; import { EditDiscoveryRule } from './edit_discovery_rule'; - -interface DiscoveryRuleItem { - id: string; - content: { - include: boolean; - key: string; - value: string; - }; -} +import { IDiscoveryRuleList } from '.'; interface Props { isEnabled: boolean; onToggleEnable: () => void; - list: DiscoveryRuleItem[]; - setList: (discoveryRuleItems: DiscoveryRuleItem[]) => void; + discoveryRuleList: IDiscoveryRuleList; + setDiscoveryRuleList: (discoveryRuleItems: IDiscoveryRuleList) => void; onDelete: (discoveryItemId: string) => void; - editItemId: null | string; - onEdit: (discoveryItemId: null | string) => void; + editDiscoveryRuleId: null | string; + onEdit: (discoveryItemId: string) => void; onChangeOperation: (operationText: string) => void; stagedOperationText: string; onChangeType: (typeText: string) => void; @@ -51,15 +43,20 @@ interface Props { onCancel: () => void; onSubmit: () => void; onAddRule: () => void; + operations: string[]; + types: string[]; + toggleDescription: ReactNode; + discoveryRulesDescription: ReactNode; + showUnsavedWarning?: boolean; } export function RuntimeAttachment({ isEnabled, onToggleEnable, - list, - setList, + discoveryRuleList, + setDiscoveryRuleList, onDelete, - editItemId, + editDiscoveryRuleId, onEdit, onChangeOperation, stagedOperationText, @@ -70,25 +67,38 @@ export function RuntimeAttachment({ onCancel, onSubmit, onAddRule, + operations, + types, + toggleDescription, + discoveryRulesDescription, + showUnsavedWarning, }: Props) { const onDragEnd = ({ source, destination }: DropResult) => { if (source && destination) { - const items = euiDragDropReorder(list, source.index, destination.index); + const items = euiDragDropReorder( + discoveryRuleList, + source.index, + destination.index + ); - setList(items); + setDiscoveryRuleList(items); } }; return (
- - + {showUnsavedWarning && ( + <> + + + + )} -

Attach the Java agent to running and starting Java applications.

+

{toggleDescription}

{isEnabled && ( <> @@ -111,17 +121,13 @@ export function RuntimeAttachment({ -

- For every running JVM, the discovery rules are evaluated in - the order they are provided. The first matching rule - determines the outcome. Learn more in the docs. -

+

{discoveryRulesDescription}

Add rule @@ -130,11 +136,8 @@ export function RuntimeAttachment({ - - {list.map(({ content, id }, idx) => ( + + {discoveryRuleList.map(({ discoveryRule, id }, idx) => ( {(provided) => - id === editItemId ? ( + id === editDiscoveryRuleId ? ( ) : ( void; +} +export function JavaRuntimeAttachment(props: Props) { + return ( + { + if (props.onChange) { + props.onChange(...args); + } + }} + toggleDescription="Attach the Java agent to running and starting Java applications." + discoveryRulesDescription="For every running JVM, the discovery rules are evaluated in the order they are provided. The first matching rule determines the outcome. Learn more in the docs" + showUnsavedWarning={true} + initialDiscoveryRules={[ + { + operation: 'Include', + type: 'main', + probe: 'java-opbeans-10010', + }, + { + operation: 'Exclude', + type: 'pid', + probe: '10948653898867', + }, + ]} + /> + ); +} From 4ec12b14d8d9fcf0ef53da5ab03f2a505cc3c7e5 Mon Sep 17 00:00:00 2001 From: Oliver Gupte Date: Thu, 18 Nov 2021 22:22:04 -0500 Subject: [PATCH 05/25] wip --- .../runtime_attachment/discovery_rule.tsx | 29 ++++++++--- .../edit_discovery_rule.tsx | 49 +++++++++++++------ .../apm_agents/runtime_attachment/index.tsx | 48 +++++++++++++----- .../runtime_attachment.stories.tsx | 19 ++++++- .../runtime_attachment/runtime_attachment.tsx | 12 ++--- .../java_runtime_attachment.tsx | 26 ++++++++-- 6 files changed, 135 insertions(+), 48 deletions(-) diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx index 2af85e286675c..661ebb88338d0 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx @@ -7,7 +7,8 @@ import { EuiPanel, DraggableProvidedDragHandleProps, } from '@elastic/eui'; -import React from 'react'; +import React, { useMemo } from 'react'; +import { Operation } from '.'; interface Props { id: string; @@ -18,6 +19,7 @@ interface Props { providedDragHandleProps?: DraggableProvidedDragHandleProps; onDelete: (discoveryItemId: string) => void; onEdit: (discoveryItemId: string) => void; + operationTypes: Operation[]; } export function DiscoveryRule({ @@ -29,7 +31,22 @@ export function DiscoveryRule({ providedDragHandleProps, onDelete, onEdit, + operationTypes, }: Props) { + const operationTypesLabels = useMemo(() => { + return operationTypes.reduce((acc, { operation, types }) => { + return { + ...acc, + [operation.value]: { + label: operation.label, + types: types.reduce((memo, { value, label }) => { + return { ...memo, [value]: label }; + }, {}), + }, + }; + }, {} as { [operationValue: string]: { label: string; types: { [typeValue: string]: string } } }); + }, [operationTypes]); + return ( @@ -44,17 +61,15 @@ export function DiscoveryRule({ {order} - {operation === 'Include' ? ( - Include - ) : ( - Exclude - )} + + {operationTypesLabels[operation].label} + -

{type}

+

{operationTypesLabels[operation].types[type]}

diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx index f2fdcf6e6177f..3c1e34a51b7ee 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx @@ -10,7 +10,11 @@ import { EuiFormRow, } from '@elastic/eui'; import React from 'react'; -import { STAGED_DISCOVERY_RULE_ID } from '.'; +import { + Operation, + DISCOVERY_RULE_TYPE_ALL, + STAGED_DISCOVERY_RULE_ID, +} from '.'; interface Props { id: string; @@ -22,8 +26,7 @@ interface Props { probe: string; onCancel: () => void; onSubmit: () => void; - operations: string[]; - types: string[]; + operationTypes: Operation[]; } export function EditDiscoveryRule({ @@ -36,8 +39,7 @@ export function EditDiscoveryRule({ probe, onCancel, onSubmit, - operations, - types, + operationTypes, }: Props) { return ( @@ -45,13 +47,13 @@ export function EditDiscoveryRule({ ({ - text: operation, - value: operation, + options={operationTypes.map(({ operation }) => ({ + text: operation.label, + value: operation.value, }))} value={operation} onChange={(e) => { - onChangeOperation(operations[e.target.selectedIndex]); + onChangeOperation(e.target.value); }} /> @@ -60,20 +62,31 @@ export function EditDiscoveryRule({ ({ - text: type, - value: type, - }))} + options={operationTypes + .find( + ({ operation: definedOperation }) => + definedOperation.value === operation + ) + ?.types.map((type) => ({ + text: type.label, + value: type.value, + }))} value={type} onChange={(e) => { - onChangeType(types[e.target.selectedIndex]); + onChangeType(e.target.value); }} /> - + Cancel - + {id === STAGED_DISCOVERY_RULE_ID ? 'Add' : 'Save'} diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx index 9919bc8c4d095..43f08748a04f5 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx @@ -3,6 +3,7 @@ import React, { useState, useCallback, ReactNode } from 'react'; import { RuntimeAttachment as RuntimeAttachmentStateless } from './runtime_attachment'; export const STAGED_DISCOVERY_RULE_ID = 'STAGED_DISCOVERY_RULE_ID'; +export const DISCOVERY_RULE_TYPE_ALL = 'all'; interface IDiscoveryRule { operation: string; @@ -16,13 +17,22 @@ export type IDiscoveryRuleList = Array<{ }>; interface Props { - operations: string[]; - types: string[]; onChange?: () => void; toggleDescription: ReactNode; discoveryRulesDescription: ReactNode; showUnsavedWarning?: boolean; initialDiscoveryRules?: IDiscoveryRule[]; + operationTypes: Operation[]; +} + +interface Option { + value: string; + label: string; +} + +export interface Operation { + operation: Option; + types: Option[]; } export function RuntimeAttachment(props: Props) { @@ -73,16 +83,32 @@ export function RuntimeAttachment(props: Props) { ); const [stagedOperationText, setStagedOperationText] = useState(''); - const onChangeOperation = useCallback((operationText: string) => { - setStagedOperationText(operationText); - }, []); - const [stagedTypeText, setStagedTypeText] = useState(''); + const [stagedProbeText, setStagedProbeText] = useState(''); + + const onChangeOperation = useCallback( + (operationText: string) => { + setStagedOperationText(operationText); + const selectedOperationTypes = props.operationTypes.find( + ({ operation }) => operationText === operation.value + ); + const selectedTypeAvailable = selectedOperationTypes?.types.some( + ({ value }) => stagedTypeText === value + ); + if (!selectedTypeAvailable) { + setStagedTypeText(selectedOperationTypes?.types[0].value ?? ''); + } + }, + [props.operationTypes, stagedTypeText] + ); + const onChangeType = useCallback((operationText: string) => { setStagedTypeText(operationText); + if (operationText === DISCOVERY_RULE_TYPE_ALL) { + setStagedProbeText(''); + } }, []); - const [stagedProbeText, setStagedProbeText] = useState(''); const onChangeProbe = useCallback((operationText: string) => { setStagedProbeText(operationText); }, []); @@ -125,8 +151,9 @@ export function RuntimeAttachment(props: Props) { ]); const onAddRule = useCallback(() => { - const operationText = props.operations[0]; - const typeText = props.types[0]; + const firstOperationType = props.operationTypes[0]; + const operationText = firstOperationType.operation.value; + const typeText = firstOperationType.types[0].value; const valueText = ''; setStagedOperationText(operationText); setStagedTypeText(typeText); @@ -163,8 +190,7 @@ export function RuntimeAttachment(props: Props) { onCancel={onCancel} onSubmit={onSubmit} onAddRule={onAddRule} - operations={props.operations} - types={props.types} + operationTypes={props.operationTypes} toggleDescription={props.toggleDescription} discoveryRulesDescription={props.discoveryRulesDescription} showUnsavedWarning={props.showUnsavedWarning} diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.stories.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.stories.tsx index 56dce86e67add..341e5284b82d1 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.stories.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.stories.tsx @@ -25,11 +25,26 @@ const stories: Meta<{}> = { }; export default stories; +const excludeOptions = [ + { value: 'main', label: 'main class / jar name' }, + { value: 'vmarg', label: 'vmarg' }, + { value: 'user', label: 'user' }, +]; +const includeOptions = [{ value: 'all', label: 'All' }, ...excludeOptions]; + export const RuntimeAttachmentExample: Story = () => { return ( {}} toggleDescription="Attach the Java agent to running and starting Java applications." discoveryRulesDescription="For every running JVM, the discovery rules are evaluated in the order they are provided. The first matching rule determines the outcome. Learn more in the docs" diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx index 3392708022d95..1be1f9d15ca7f 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx @@ -24,7 +24,7 @@ import React, { ReactNode } from 'react'; import { DiscoveryRule } from './discovery_rule'; import { DefaultDiscoveryRule } from './default_discovery_rule'; import { EditDiscoveryRule } from './edit_discovery_rule'; -import { IDiscoveryRuleList } from '.'; +import { IDiscoveryRuleList, Operation } from '.'; interface Props { isEnabled: boolean; @@ -43,8 +43,7 @@ interface Props { onCancel: () => void; onSubmit: () => void; onAddRule: () => void; - operations: string[]; - types: string[]; + operationTypes: Operation[]; toggleDescription: ReactNode; discoveryRulesDescription: ReactNode; showUnsavedWarning?: boolean; @@ -67,8 +66,7 @@ export function RuntimeAttachment({ onCancel, onSubmit, onAddRule, - operations, - types, + operationTypes, toggleDescription, discoveryRulesDescription, showUnsavedWarning, @@ -157,8 +155,7 @@ export function RuntimeAttachment({ probe={stagedProbeText} onCancel={onCancel} onSubmit={onSubmit} - operations={operations} - types={types} + operationTypes={operationTypes} /> ) : ( ) } diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx index 9fe2d4c419177..7a902929cfb98 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx @@ -12,11 +12,27 @@ interface Props { // onChange: PackagePolicyEditExtensionComponentProps['onChange']; onChange?: () => void; } + +const excludeOptions = [ + { value: 'main', label: 'main class / jar name' }, + { value: 'vmarg', label: 'vmarg' }, + { value: 'user', label: 'user' }, +]; +const includeOptions = [{ value: 'all', label: 'All' }, ...excludeOptions]; + export function JavaRuntimeAttachment(props: Props) { return ( { if (props.onChange) { props.onChange(...args); @@ -27,13 +43,13 @@ export function JavaRuntimeAttachment(props: Props) { showUnsavedWarning={true} initialDiscoveryRules={[ { - operation: 'Include', + operation: 'include', type: 'main', probe: 'java-opbeans-10010', }, { - operation: 'Exclude', - type: 'pid', + operation: 'exclude', + type: 'vmarg', probe: '10948653898867', }, ]} From 24f8b9b3dcd4e17c73ad3b2832d55d87d73d95e6 Mon Sep 17 00:00:00 2001 From: Oliver Gupte Date: Thu, 18 Nov 2021 23:04:30 -0500 Subject: [PATCH 06/25] wip --- .../apm_agents/runtime_attachment/index.tsx | 58 +++++++++++++++++-- .../runtime_attachment.stories.tsx | 56 ++++++++++++------ .../runtime_attachment/runtime_attachment.tsx | 14 +---- .../java_runtime_attachment.tsx | 3 +- 4 files changed, 95 insertions(+), 36 deletions(-) diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx index 43f08748a04f5..87c4baeb79a6f 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx @@ -1,4 +1,4 @@ -import { htmlIdGenerator } from '@elastic/eui'; +import { htmlIdGenerator, euiDragDropReorder, DropResult } from '@elastic/eui'; import React, { useState, useCallback, ReactNode } from 'react'; import { RuntimeAttachment as RuntimeAttachmentStateless } from './runtime_attachment'; @@ -16,11 +16,17 @@ export type IDiscoveryRuleList = Array<{ discoveryRule: IDiscoveryRule; }>; +export interface RuntimeAttachmentSettings { + enabled: boolean; + discoveryRules: IDiscoveryRule[]; +} + interface Props { - onChange?: () => void; + onChange?: (runtimeAttachmentSettings: RuntimeAttachmentSettings) => void; toggleDescription: ReactNode; discoveryRulesDescription: ReactNode; showUnsavedWarning?: boolean; + initialIsEnabled?: boolean; initialDiscoveryRules?: IDiscoveryRule[]; operationTypes: Operation[]; } @@ -36,8 +42,8 @@ export interface Operation { } export function RuntimeAttachment(props: Props) { - const { initialDiscoveryRules = [] } = props; - const [isEnabled, setIsEnabled] = useState(true); + const { initialDiscoveryRules = [], onChange = () => {} } = props; + const [isEnabled, setIsEnabled] = useState(Boolean(props.initialIsEnabled)); const [discoveryRuleList, setDiscoveryRuleList] = useState( initialDiscoveryRules.map((discoveryRule) => ({ @@ -52,7 +58,11 @@ export function RuntimeAttachment(props: Props) { const onToggleEnable = useCallback(() => { setIsEnabled(!isEnabled); setDiscoveryRuleList([]); - }, [isEnabled]); + onChange({ + enabled: !isEnabled, + discoveryRules: [], + }); + }, [isEnabled, onChange]); const onDelete = useCallback( (discoveryRuleId: string) => { @@ -60,8 +70,14 @@ export function RuntimeAttachment(props: Props) { ({ id }) => id !== discoveryRuleId ); setDiscoveryRuleList(filteredDiscoveryRuleList); + onChange({ + enabled: isEnabled, + discoveryRules: filteredDiscoveryRuleList.map( + ({ discoveryRule }) => discoveryRule + ), + }); }, - [discoveryRuleList] + [isEnabled, discoveryRuleList, onChange] ); const onEdit = useCallback( @@ -142,12 +158,20 @@ export function RuntimeAttachment(props: Props) { ]; setDiscoveryRuleList(nextDiscoveryRuleList); setEditDiscoveryRuleId(null); + onChange({ + enabled: isEnabled, + discoveryRules: nextDiscoveryRuleList.map( + ({ discoveryRule }) => discoveryRule + ), + }); }, [ + isEnabled, editDiscoveryRuleId, stagedOperationText, stagedTypeText, stagedProbeText, discoveryRuleList, + onChange, ]); const onAddRule = useCallback(() => { @@ -172,6 +196,27 @@ export function RuntimeAttachment(props: Props) { setDiscoveryRuleList(nextDiscoveryRuleList); setEditDiscoveryRuleId(STAGED_DISCOVERY_RULE_ID); }, [discoveryRuleList]); + + const onDragEnd = useCallback( + ({ source, destination }: DropResult) => { + if (source && destination) { + const nextDiscoveryRuleList = euiDragDropReorder( + discoveryRuleList, + source.index, + destination.index + ); + setDiscoveryRuleList(nextDiscoveryRuleList); + onChange({ + enabled: isEnabled, + discoveryRules: nextDiscoveryRuleList.map( + ({ discoveryRule }) => discoveryRule + ), + }); + } + }, + [isEnabled, discoveryRuleList, onChange] + ); + return ( ); } diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.stories.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.stories.tsx index 341e5284b82d1..6ea11b6320a87 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.stories.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.stories.tsx @@ -6,7 +6,7 @@ */ import { Meta, Story } from '@storybook/react'; -import React from 'react'; +import React, { useState } from 'react'; import { RuntimeAttachment } from '.'; import { JavaRuntimeAttachment } from './supported_agents/java_runtime_attachment'; @@ -33,23 +33,45 @@ const excludeOptions = [ const includeOptions = [{ value: 'all', label: 'All' }, ...excludeOptions]; export const RuntimeAttachmentExample: Story = () => { + const [runtimeAttachmentSettings, setRuntimeAttachmentSettings] = useState( + {} + ); return ( - {}} - toggleDescription="Attach the Java agent to running and starting Java applications." - discoveryRulesDescription="For every running JVM, the discovery rules are evaluated in the order they are provided. The first matching rule determines the outcome. Learn more in the docs" - showUnsavedWarning={true} - /> + <> + { + setRuntimeAttachmentSettings(settings); + }} + toggleDescription="Attach the Java agent to running and starting Java applications." + discoveryRulesDescription="For every running JVM, the discovery rules are evaluated in the order they are provided. The first matching rule determines the outcome. Learn more in the docs" + showUnsavedWarning={true} + initialIsEnabled={true} + initialDiscoveryRules={[ + { + operation: 'include', + type: 'main', + probe: 'java-opbeans-10010', + }, + { + operation: 'exclude', + type: 'vmarg', + probe: '10948653898867', + }, + ]} + /> +
+
{JSON.stringify(runtimeAttachmentSettings, null, 4)}
+ ); }; RuntimeAttachmentExample.storyName = 'RuntimeAttachment'; diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx index 1be1f9d15ca7f..f7eea7de2798c 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx @@ -18,7 +18,6 @@ import { EuiDroppable, EuiDraggable, EuiIcon, - euiDragDropReorder, } from '@elastic/eui'; import React, { ReactNode } from 'react'; import { DiscoveryRule } from './discovery_rule'; @@ -47,6 +46,7 @@ interface Props { toggleDescription: ReactNode; discoveryRulesDescription: ReactNode; showUnsavedWarning?: boolean; + onDragEnd: (dropResult: DropResult) => void; } export function RuntimeAttachment({ @@ -70,18 +70,8 @@ export function RuntimeAttachment({ toggleDescription, discoveryRulesDescription, showUnsavedWarning, + onDragEnd, }: Props) { - const onDragEnd = ({ source, destination }: DropResult) => { - if (source && destination) { - const items = euiDragDropReorder( - discoveryRuleList, - source.index, - destination.index - ); - - setDiscoveryRuleList(items); - } - }; return (
{showUnsavedWarning && ( diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx index 7a902929cfb98..e41cd3086b206 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx @@ -10,7 +10,7 @@ interface Props { // policy: PackagePolicy; // newPolicy: NewPackagePolicy; // onChange: PackagePolicyEditExtensionComponentProps['onChange']; - onChange?: () => void; + onChange?: (settings: any) => void; } const excludeOptions = [ @@ -41,6 +41,7 @@ export function JavaRuntimeAttachment(props: Props) { toggleDescription="Attach the Java agent to running and starting Java applications." discoveryRulesDescription="For every running JVM, the discovery rules are evaluated in the order they are provided. The first matching rule determines the outcome. Learn more in the docs" showUnsavedWarning={true} + initialIsEnabled={true} initialDiscoveryRules={[ { operation: 'include', From 8556e410588558ef342188087944e718922dff3d Mon Sep 17 00:00:00 2001 From: Oliver Gupte Date: Thu, 18 Nov 2021 23:45:09 -0500 Subject: [PATCH 07/25] wip --- .../agent_instructions_accordion.tsx | 105 +++-- .../apm_agents/agent_instructions_mappings.ts | 15 + .../fleet_integration/apm_agents/index.tsx | 15 +- .../runtime_attachment.stories.tsx | 402 +++++++++++++++++- .../java_runtime_attachment.tsx | 26 +- 5 files changed, 506 insertions(+), 57 deletions(-) diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx index 64ca630691d78..1be36e9947b08 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx @@ -16,18 +16,24 @@ import { EuiBetaBadge, } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import React from 'react'; -import { CreateAgentInstructions } from './agent_instructions_mappings'; +import React, { ReactElement } from 'react'; +import { + AgentRuntimeAttachmentProps, + CreateAgentInstructions, +} from './agent_instructions_mappings'; import { Markdown, useKibana, } from '../../../../../../../src/plugins/kibana_react/public'; import { AgentName } from '../../../../typings/es_schemas/ui/fields/agent'; import { AgentIcon } from '../../shared/agent_icon'; -import { NewPackagePolicy } from '../apm_policy_form/typings'; +import { + NewPackagePolicy, + PackagePolicy, + PackagePolicyEditExtensionComponentProps, +} from '../apm_policy_form/typings'; import { getCommands } from '../../../tutorial/config_agent/commands/get_commands'; import { replaceTemplateStrings } from './replace_template_strings'; -import { JavaRuntimeAttachment } from './runtime_attachment/supported_agents/java_runtime_attachment'; function AccordionButtonContent({ agentName, @@ -100,19 +106,25 @@ function TutorialConfigAgent({ } interface Props { + policy: PackagePolicy; newPolicy: NewPackagePolicy; + onChange: PackagePolicyEditExtensionComponentProps['onChange']; agentName: AgentName; title: string; variantId: string; createAgentInstructions: CreateAgentInstructions; + AgentRuntimeAttachment?: (props: AgentRuntimeAttachmentProps) => ReactElement; } export function AgentInstructionsAccordion({ + policy, newPolicy, + onChange, agentName, title, createAgentInstructions, variantId, + AgentRuntimeAttachment, }: Props) { const docLinks = useKibana().services.docLinks; const vars = newPolicy?.inputs?.[0]?.vars; @@ -176,6 +188,14 @@ export function AgentInstructionsAccordion({ ); } ); + + const manualInstrumentationContent = ( + <> + + {stepsElements} + + ); + return ( } > - - - - {stepsElements} - - ), - }, - { - id: 'auto-attachment', - name: ( - - Auto-Attachment - - - - - ), - content: ( - <> - - - - ), - }, - ]} - /> + {AgentRuntimeAttachment ? ( + <> + + + Auto-Attachment + + + + + ), + content: ( + <> + + + + ), + }, + ]} + /> + + ) : ( + manualInstrumentationContent + )} ); } diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_mappings.ts b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_mappings.ts index 8bfdafe61d44e..6fdfa147b77c5 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_mappings.ts +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_mappings.ts @@ -5,6 +5,7 @@ * 2.0. */ +import { ReactElement } from 'react'; import { createDotNetAgentInstructions, createDjangoAgentInstructions, @@ -18,6 +19,18 @@ import { createRackAgentInstructions, } from '../../../../common/tutorial/instructions/apm_agent_instructions'; import { AgentName } from '../../../../typings/es_schemas/ui/fields/agent'; +import { JavaRuntimeAttachment } from './runtime_attachment/supported_agents/java_runtime_attachment'; +import { + NewPackagePolicy, + PackagePolicy, + PackagePolicyEditExtensionComponentProps, +} from '../apm_policy_form/typings'; + +export interface AgentRuntimeAttachmentProps { + policy: PackagePolicy; + newPolicy: NewPackagePolicy; + onChange: PackagePolicyEditExtensionComponentProps['onChange']; +} export type CreateAgentInstructions = ( apmServerUrl?: string, @@ -35,12 +48,14 @@ export const ApmAgentInstructionsMappings: Array<{ title: string; variantId: string; createAgentInstructions: CreateAgentInstructions; + AgentRuntimeAttachment?: (props: AgentRuntimeAttachmentProps) => ReactElement; }> = [ { agentName: 'java', title: 'Java', variantId: 'java', createAgentInstructions: createJavaAgentInstructions, + AgentRuntimeAttachment: JavaRuntimeAttachment, }, { agentName: 'rum-js', diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/index.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/index.tsx index d6a43a1e1268a..09b638fb184df 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/index.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/index.tsx @@ -21,19 +21,28 @@ interface Props { onChange: PackagePolicyEditExtensionComponentProps['onChange']; } -export function ApmAgents({ newPolicy }: Props) { +export function ApmAgents({ policy, newPolicy, onChange }: Props) { return (
{ApmAgentInstructionsMappings.map( - ({ agentName, title, createAgentInstructions, variantId }) => ( + ({ + agentName, + title, + createAgentInstructions, + variantId, + AgentRuntimeAttachment, + }) => ( diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.stories.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.stories.tsx index 6ea11b6320a87..a9abc965fccce 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.stories.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.stories.tsx @@ -77,6 +77,406 @@ export const RuntimeAttachmentExample: Story = () => { RuntimeAttachmentExample.storyName = 'RuntimeAttachment'; export const JavaRuntimeAttachmentExample: Story = () => { - return {}} />; + return ( + {}} + /> + ); }; JavaRuntimeAttachmentExample.storyName = 'JavaRuntimeAttachment'; + +const policy = { + id: 'cc380ec5-d84e-40e1-885a-d706edbdc968', + version: 'WzM0MzA2LDJd', + name: 'apm-1', + description: '', + namespace: 'default', + policy_id: 'policy-elastic-agent-on-cloud', + enabled: true, + output_id: '', + inputs: [ + { + type: 'apm', + policy_template: 'apmserver', + enabled: true, + streams: [], + vars: { + host: { + value: 'localhost:8200', + type: 'text', + }, + url: { + value: 'http://localhost:8200', + type: 'text', + }, + secret_token: { + type: 'text', + }, + api_key_enabled: { + value: false, + type: 'bool', + }, + enable_rum: { + value: true, + type: 'bool', + }, + anonymous_enabled: { + value: true, + type: 'bool', + }, + anonymous_allow_agent: { + value: ['rum-js', 'js-base', 'iOS/swift'], + type: 'text', + }, + anonymous_allow_service: { + value: [], + type: 'text', + }, + anonymous_rate_limit_event_limit: { + value: 10, + type: 'integer', + }, + anonymous_rate_limit_ip_limit: { + value: 10000, + type: 'integer', + }, + default_service_environment: { + type: 'text', + }, + rum_allow_origins: { + value: ['"*"'], + type: 'text', + }, + rum_allow_headers: { + value: [], + type: 'text', + }, + rum_response_headers: { + type: 'yaml', + }, + rum_library_pattern: { + value: '"node_modules|bower_components|~"', + type: 'text', + }, + rum_exclude_from_grouping: { + value: '"^/webpack"', + type: 'text', + }, + api_key_limit: { + value: 100, + type: 'integer', + }, + max_event_bytes: { + value: 307200, + type: 'integer', + }, + capture_personal_data: { + value: true, + type: 'bool', + }, + max_header_bytes: { + value: 1048576, + type: 'integer', + }, + idle_timeout: { + value: '45s', + type: 'text', + }, + read_timeout: { + value: '3600s', + type: 'text', + }, + shutdown_timeout: { + value: '30s', + type: 'text', + }, + write_timeout: { + value: '30s', + type: 'text', + }, + max_connections: { + value: 0, + type: 'integer', + }, + response_headers: { + type: 'yaml', + }, + expvar_enabled: { + value: false, + type: 'bool', + }, + tls_enabled: { + value: false, + type: 'bool', + }, + tls_certificate: { + type: 'text', + }, + tls_key: { + type: 'text', + }, + tls_supported_protocols: { + value: ['TLSv1.0', 'TLSv1.1', 'TLSv1.2'], + type: 'text', + }, + tls_cipher_suites: { + value: [], + type: 'text', + }, + tls_curve_types: { + value: [], + type: 'text', + }, + tail_sampling_policies: { + type: 'yaml', + }, + tail_sampling_interval: { + type: 'text', + }, + }, + config: { + 'apm-server': { + value: { + rum: { + source_mapping: { + metadata: [], + }, + }, + agent_config: [], + }, + }, + }, + compiled_input: { + 'apm-server': { + auth: { + anonymous: { + allow_agent: ['rum-js', 'js-base', 'iOS/swift'], + allow_service: null, + enabled: true, + rate_limit: { + event_limit: 10, + ip_limit: 10000, + }, + }, + api_key: { + enabled: false, + limit: 100, + }, + secret_token: null, + }, + capture_personal_data: true, + idle_timeout: '45s', + default_service_environment: null, + 'expvar.enabled': false, + host: 'localhost:8200', + max_connections: 0, + max_event_size: 307200, + max_header_size: 1048576, + read_timeout: '3600s', + response_headers: null, + rum: { + allow_headers: null, + allow_origins: ['*'], + enabled: true, + exclude_from_grouping: '^/webpack', + library_pattern: 'node_modules|bower_components|~', + response_headers: null, + }, + shutdown_timeout: '30s', + write_timeout: '30s', + }, + }, + }, + ], + package: { + name: 'apm', + title: 'Elastic APM', + version: '7.16.0', + }, + elasticsearch: { + privileges: { + cluster: ['cluster:monitor/main'], + }, + }, + revision: 1, + created_at: '2021-11-18T02:14:55.758Z', + created_by: 'admin', + updated_at: '2021-11-18T02:14:55.758Z', + updated_by: 'admin', +}; + +const newPolicy = { + version: 'WzM0MzA2LDJd', + name: 'apm-1', + description: '', + namespace: 'default', + policy_id: 'policy-elastic-agent-on-cloud', + enabled: true, + output_id: '', + package: { + name: 'apm', + title: 'Elastic APM', + version: '8.0.0-dev2', + }, + elasticsearch: { + privileges: { + cluster: ['cluster:monitor/main'], + }, + }, + inputs: [ + { + type: 'apm', + policy_template: 'apmserver', + enabled: true, + vars: { + host: { + value: 'localhost:8200', + type: 'text', + }, + url: { + value: 'http://localhost:8200', + type: 'text', + }, + secret_token: { + type: 'text', + }, + api_key_enabled: { + value: false, + type: 'bool', + }, + enable_rum: { + value: true, + type: 'bool', + }, + anonymous_enabled: { + value: true, + type: 'bool', + }, + anonymous_allow_agent: { + value: ['rum-js', 'js-base', 'iOS/swift'], + type: 'text', + }, + anonymous_allow_service: { + value: [], + type: 'text', + }, + anonymous_rate_limit_event_limit: { + value: 10, + type: 'integer', + }, + anonymous_rate_limit_ip_limit: { + value: 10000, + type: 'integer', + }, + default_service_environment: { + type: 'text', + }, + rum_allow_origins: { + value: ['"*"'], + type: 'text', + }, + rum_allow_headers: { + value: [], + type: 'text', + }, + rum_response_headers: { + type: 'yaml', + }, + rum_library_pattern: { + value: '"node_modules|bower_components|~"', + type: 'text', + }, + rum_exclude_from_grouping: { + value: '"^/webpack"', + type: 'text', + }, + api_key_limit: { + value: 100, + type: 'integer', + }, + max_event_bytes: { + value: 307200, + type: 'integer', + }, + capture_personal_data: { + value: true, + type: 'bool', + }, + max_header_bytes: { + value: 1048576, + type: 'integer', + }, + idle_timeout: { + value: '45s', + type: 'text', + }, + read_timeout: { + value: '3600s', + type: 'text', + }, + shutdown_timeout: { + value: '30s', + type: 'text', + }, + write_timeout: { + value: '30s', + type: 'text', + }, + max_connections: { + value: 0, + type: 'integer', + }, + response_headers: { + type: 'yaml', + }, + expvar_enabled: { + value: false, + type: 'bool', + }, + tls_enabled: { + value: false, + type: 'bool', + }, + tls_certificate: { + type: 'text', + }, + tls_key: { + type: 'text', + }, + tls_supported_protocols: { + value: ['TLSv1.0', 'TLSv1.1', 'TLSv1.2'], + type: 'text', + }, + tls_cipher_suites: { + value: [], + type: 'text', + }, + tls_curve_types: { + value: [], + type: 'text', + }, + tail_sampling_policies: { + type: 'yaml', + }, + tail_sampling_interval: { + type: 'text', + }, + }, + config: { + 'apm-server': { + value: { + rum: { + source_mapping: { + metadata: [], + }, + }, + agent_config: [], + }, + }, + }, + streams: [], + }, + ], +}; diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx index e41cd3086b206..99b5ed358f164 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx @@ -1,16 +1,15 @@ import React from 'react'; import { RuntimeAttachment } from '..'; -// import { -// NewPackagePolicy, -// PackagePolicy, -// PackagePolicyEditExtensionComponentProps, -// } from '../apm_policy_form/typings'; +import { + NewPackagePolicy, + PackagePolicy, + PackagePolicyEditExtensionComponentProps, +} from '../../../apm_policy_form/typings'; interface Props { - // policy: PackagePolicy; - // newPolicy: NewPackagePolicy; - // onChange: PackagePolicyEditExtensionComponentProps['onChange']; - onChange?: (settings: any) => void; + policy: PackagePolicy; + newPolicy: NewPackagePolicy; + onChange: PackagePolicyEditExtensionComponentProps['onChange']; } const excludeOptions = [ @@ -21,6 +20,7 @@ const excludeOptions = [ const includeOptions = [{ value: 'all', label: 'All' }, ...excludeOptions]; export function JavaRuntimeAttachment(props: Props) { + console.log(props); return ( { - if (props.onChange) { - props.onChange(...args); - } + // if (props.onChange) { + // props.onChange(...args); + // } }} toggleDescription="Attach the Java agent to running and starting Java applications." - discoveryRulesDescription="For every running JVM, the discovery rules are evaluated in the order they are provided. The first matching rule determines the outcome. Learn more in the docs" + discoveryRulesDescription="For every running JVM, the discovery rules are evaluated in the order they are provided. The first matching rule determines the outcome. Learn more in the docs." showUnsavedWarning={true} initialIsEnabled={true} initialDiscoveryRules={[ From c44577971db27868a26096ae8668f8d7b00fec40 Mon Sep 17 00:00:00 2001 From: Oliver Gupte Date: Fri, 19 Nov 2021 02:03:19 -0500 Subject: [PATCH 08/25] wip --- .../java_runtime_attachment.tsx | 81 +++++++++++++------ 1 file changed, 58 insertions(+), 23 deletions(-) diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx index 99b5ed358f164..953ec414c1aae 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx @@ -1,5 +1,5 @@ -import React from 'react'; -import { RuntimeAttachment } from '..'; +import React, { useCallback, useState } from 'react'; +import { RuntimeAttachment, RuntimeAttachmentSettings } from '..'; import { NewPackagePolicy, PackagePolicy, @@ -19,8 +19,45 @@ const excludeOptions = [ ]; const includeOptions = [{ value: 'all', label: 'All' }, ...excludeOptions]; -export function JavaRuntimeAttachment(props: Props) { - console.log(props); +export function JavaRuntimeAttachment({ newPolicy, onChange }: Props) { + const [isDirty, setIsDirty] = useState(false); + const onChangePolicy = useCallback( + (runtimeAttachmentSettings: RuntimeAttachmentSettings) => { + const apmInputIdx = newPolicy.inputs.findIndex( + ({ type }) => type === 'apm' + ); + onChange({ + isValid: true, + updatedPolicy: { + ...newPolicy, + inputs: [ + ...newPolicy.inputs.slice(0, apmInputIdx), + { + ...newPolicy.inputs[apmInputIdx], + vars: { + ...newPolicy.inputs[apmInputIdx].vars, + java_attacher_enabled: { + value: runtimeAttachmentSettings.enabled, + type: 'bool', + }, + java_attacher_discovery_rules: { + type: 'yaml', + value: runtimeAttachmentSettings.discoveryRules.map( + ({ operation, type, probe }) => ({ + [`${operation}-${type}`]: probe, + }) + ), + }, + }, + }, + ...newPolicy.inputs.slice(apmInputIdx + 1), + ], + }, + }); + setIsDirty(true); + }, + [newPolicy] + ); return ( { - // if (props.onChange) { - // props.onChange(...args); - // } - }} + onChange={onChangePolicy} toggleDescription="Attach the Java agent to running and starting Java applications." discoveryRulesDescription="For every running JVM, the discovery rules are evaluated in the order they are provided. The first matching rule determines the outcome. Learn more in the docs." - showUnsavedWarning={true} - initialIsEnabled={true} - initialDiscoveryRules={[ - { - operation: 'include', - type: 'main', - probe: 'java-opbeans-10010', - }, - { - operation: 'exclude', - type: 'vmarg', - probe: '10948653898867', - }, - ]} + showUnsavedWarning={isDirty} + initialIsEnabled={ + newPolicy.inputs.find(({ type }) => type === 'apm')?.vars + ?.java_attacher_enabled?.value + } + initialDiscoveryRules={( + newPolicy.inputs.find(({ type }) => type === 'apm')?.vars + ?.java_attacher_discovery_rules?.value ?? [] + ).map((discoveryRuleMap: Record) => { + const [operationType, probe] = Object.entries(discoveryRuleMap)[0]; + return { + operation: operationType.split('-')[0], + type: operationType.split('-')[1], + probe, + }; + })} /> ); } From 105af2f3fc4b10c6b2519d1f841bb960ea5ca12b Mon Sep 17 00:00:00 2001 From: Oliver Gupte Date: Thu, 2 Dec 2021 00:15:57 -0500 Subject: [PATCH 09/25] adds initial discovery rule for `include-vmargs elastic.apm.attach=true` --- .../apm_agents/runtime_attachment/index.tsx | 12 +++++++----- .../supported_agents/java_runtime_attachment.tsx | 4 +++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx index 87c4baeb79a6f..e5e6dd4afb420 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx @@ -56,13 +56,15 @@ export function RuntimeAttachment(props: Props) { ); const onToggleEnable = useCallback(() => { - setIsEnabled(!isEnabled); - setDiscoveryRuleList([]); + const nextIsEnabled = !isEnabled; + setIsEnabled(nextIsEnabled); onChange({ - enabled: !isEnabled, - discoveryRules: [], + enabled: nextIsEnabled, + discoveryRules: nextIsEnabled + ? discoveryRuleList.map(({ discoveryRule }) => discoveryRule) + : [], }); - }, [isEnabled, onChange]); + }, [isEnabled, onChange, discoveryRuleList]); const onDelete = useCallback( (discoveryRuleId: string) => { diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx index 953ec414c1aae..b68b3b16826b9 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx @@ -80,7 +80,7 @@ export function JavaRuntimeAttachment({ newPolicy, onChange }: Props) { } initialDiscoveryRules={( newPolicy.inputs.find(({ type }) => type === 'apm')?.vars - ?.java_attacher_discovery_rules?.value ?? [] + ?.java_attacher_discovery_rules?.value ?? [initialDiscoveryRule] ).map((discoveryRuleMap: Record) => { const [operationType, probe] = Object.entries(discoveryRuleMap)[0]; return { @@ -92,3 +92,5 @@ export function JavaRuntimeAttachment({ newPolicy, onChange }: Props) { /> ); } + +const initialDiscoveryRule = { 'include-vmarg': 'elastic.apm.attach=true' }; From 4497c91830bd24bc454d992a948d942aa5238e9b Mon Sep 17 00:00:00 2001 From: Oliver Gupte Date: Thu, 2 Dec 2021 01:28:00 -0500 Subject: [PATCH 10/25] adds support for type descriptions --- .../default_discovery_rule.tsx | 7 +- .../edit_discovery_rule.tsx | 77 +++++++++++-------- .../apm_agents/runtime_attachment/index.tsx | 1 + .../java_runtime_attachment.tsx | 30 +++++++- 4 files changed, 75 insertions(+), 40 deletions(-) diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/default_discovery_rule.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/default_discovery_rule.tsx index 9ac2547ec47de..c8b2d45afa1c3 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/default_discovery_rule.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/default_discovery_rule.tsx @@ -11,14 +11,11 @@ export function DefaultDiscoveryRule() { return ( - - Everything else - - + Exclude - All + Everything else diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx index 3c1e34a51b7ee..7ce6a995c05d1 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx @@ -8,6 +8,8 @@ import { EuiSelect, EuiFieldText, EuiFormRow, + EuiSuperSelect, + EuiText, } from '@elastic/eui'; import React from 'react'; import { @@ -44,7 +46,7 @@ export function EditDiscoveryRule({ return ( - + ({ @@ -58,44 +60,57 @@ export function EditDiscoveryRule({ /> + + - - - definedOperation.value === operation - ) - ?.types.map((type) => ({ - text: type.label, - value: type.value, - }))} - value={type} - onChange={(e) => { - onChangeType(e.target.value); + + + definedOperation.value === operation + ) + ?.types.map((type) => ({ + inputDisplay: type.label, + value: type.value, + dropdownDisplay: ( + <> + {type.label} + +

{type.description}

+
+ + ), + })) ?? [] + } + valueOfSelected={type} + onChange={(value) => { + onChangeType(value); }} />
- - - - onChangeProbe(e.target.value)} - /> - - -
+ {type !== DISCOVERY_RULE_TYPE_ALL && ( + + + + + onChangeProbe(e.target.value)} + /> + + + + + )} Cancel diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx index e5e6dd4afb420..768abc4c5778a 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx @@ -34,6 +34,7 @@ interface Props { interface Option { value: string; label: string; + description?: string; } export interface Operation { diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx index b68b3b16826b9..0dde02a5044ca 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx @@ -13,11 +13,33 @@ interface Props { } const excludeOptions = [ - { value: 'main', label: 'main class / jar name' }, - { value: 'vmarg', label: 'vmarg' }, - { value: 'user', label: 'user' }, + { + value: 'main', + label: 'main', + description: + 'A regular expression of fully qualified main class names or paths to JARs of applications the java agent should be attached to. Performs a partial match so that foo matches /bin/foo.jar.', + }, + { + value: 'vmarg', + label: 'vmarg', + description: + 'A regular expression matched against the arguments passed to the JVM, such as system properties. Performs a partial match so that attach=true matches the system property -Dattach=true.', + }, + { + value: 'user', + label: 'user', + description: + 'A username that is matched against the operating system user that runs the JVM. For included users, make sure that the Elastic Agent user is either the same user or has permissions to switch to the user that runs the target JVM.', + }, +]; +const includeOptions = [ + { + value: 'all', + label: 'All', + description: 'Includes all JVMs for attachment.', + }, + ...excludeOptions, ]; -const includeOptions = [{ value: 'all', label: 'All' }, ...excludeOptions]; export function JavaRuntimeAttachment({ newPolicy, onChange }: Props) { const [isDirty, setIsDirty] = useState(false); From 42adcaf7cee0eca5400c17460ac4a2e1cac5fab2 Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Thu, 2 Dec 2021 15:17:56 -0500 Subject: [PATCH 11/25] adding java_attacher_agent_version field --- .../apm_agents/runtime_attachment/index.tsx | 85 ++++++++++++++++++- .../runtime_attachment/runtime_attachment.tsx | 56 +++++++++--- .../java_runtime_attachment.tsx | 46 ++++++++++ 3 files changed, 173 insertions(+), 14 deletions(-) diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx index 768abc4c5778a..8c7c3f524dc68 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx @@ -1,4 +1,16 @@ -import { htmlIdGenerator, euiDragDropReorder, DropResult } from '@elastic/eui'; +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { + htmlIdGenerator, + euiDragDropReorder, + DropResult, + EuiComboBoxOptionOption, +} from '@elastic/eui'; import React, { useState, useCallback, ReactNode } from 'react'; import { RuntimeAttachment as RuntimeAttachmentStateless } from './runtime_attachment'; @@ -19,6 +31,7 @@ export type IDiscoveryRuleList = Array<{ export interface RuntimeAttachmentSettings { enabled: boolean; discoveryRules: IDiscoveryRule[]; + version: string; } interface Props { @@ -29,6 +42,8 @@ interface Props { initialIsEnabled?: boolean; initialDiscoveryRules?: IDiscoveryRule[]; operationTypes: Operation[]; + selectedVersion: string; + versions: string[]; } interface Option { @@ -42,6 +57,11 @@ export interface Operation { types: Option[]; } +const versionRegex = new RegExp(/^\d+\.\d+\.\d+$/); +function validateVersion(version: string) { + return versionRegex.test(version); +} + export function RuntimeAttachment(props: Props) { const { initialDiscoveryRules = [], onChange = () => {} } = props; const [isEnabled, setIsEnabled] = useState(Boolean(props.initialIsEnabled)); @@ -55,6 +75,11 @@ export function RuntimeAttachment(props: Props) { const [editDiscoveryRuleId, setEditDiscoveryRuleId] = useState( null ); + const [version, setVersion] = useState(props.selectedVersion); + const [versions, setVersions] = useState(props.versions); + const [isValidVersion, setIsValidVersion] = useState( + validateVersion(version) + ); const onToggleEnable = useCallback(() => { const nextIsEnabled = !isEnabled; @@ -64,8 +89,9 @@ export function RuntimeAttachment(props: Props) { discoveryRules: nextIsEnabled ? discoveryRuleList.map(({ discoveryRule }) => discoveryRule) : [], + version, }); - }, [isEnabled, onChange, discoveryRuleList]); + }, [isEnabled, onChange, discoveryRuleList, version]); const onDelete = useCallback( (discoveryRuleId: string) => { @@ -78,9 +104,10 @@ export function RuntimeAttachment(props: Props) { discoveryRules: filteredDiscoveryRuleList.map( ({ discoveryRule }) => discoveryRule ), + version, }); }, - [isEnabled, discoveryRuleList, onChange] + [isEnabled, discoveryRuleList, onChange, version] ); const onEdit = useCallback( @@ -166,6 +193,7 @@ export function RuntimeAttachment(props: Props) { discoveryRules: nextDiscoveryRuleList.map( ({ discoveryRule }) => discoveryRule ), + version, }); }, [ isEnabled, @@ -175,6 +203,7 @@ export function RuntimeAttachment(props: Props) { stagedProbeText, discoveryRuleList, onChange, + version, ]); const onAddRule = useCallback(() => { @@ -214,12 +243,50 @@ export function RuntimeAttachment(props: Props) { discoveryRules: nextDiscoveryRuleList.map( ({ discoveryRule }) => discoveryRule ), + version, }); } }, - [isEnabled, discoveryRuleList, onChange] + [isEnabled, discoveryRuleList, onChange, version] ); + function onChangeVersion(nextVersion?: string) { + if (!nextVersion) { + return; + } + setVersion(nextVersion); + onChange({ + enabled: isEnabled, + discoveryRules: isEnabled + ? discoveryRuleList.map(({ discoveryRule }) => discoveryRule) + : [], + version: nextVersion, + }); + } + + function onCreateNewVersion( + newVersion: string, + flattenedOptions: Array> + ) { + const normalizedNewVersion = newVersion.trim().toLowerCase(); + const isNextVersionValid = validateVersion(normalizedNewVersion); + setIsValidVersion(isNextVersionValid); + if (!normalizedNewVersion || !isNextVersionValid) { + return; + } + + // Create the option if it doesn't exist. + if ( + flattenedOptions.findIndex( + (option) => option.label.trim().toLowerCase() === normalizedNewVersion + ) === -1 + ) { + setVersions([...versions, newVersion]); + } + + onChangeVersion(newVersion); + } + return ( { + const nextVersion: string | undefined = selectedVersions[0]?.label; + const isNextVersionValid = validateVersion(nextVersion); + setIsValidVersion(isNextVersionValid); + onChangeVersion(nextVersion); + }} + onCreateNewVersion={onCreateNewVersion} + isValidVersion={isValidVersion} /> ); } diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx index f7eea7de2798c..379699156cf24 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx @@ -5,7 +5,6 @@ * 2.0. */ -import { DropResult } from '@elastic/eui'; import { EuiCallOut, EuiSpacer, @@ -18,6 +17,10 @@ import { EuiDroppable, EuiDraggable, EuiIcon, + DropResult, + EuiComboBox, + EuiComboBoxProps, + EuiFormRow, } from '@elastic/eui'; import React, { ReactNode } from 'react'; import { DiscoveryRule } from './discovery_rule'; @@ -47,6 +50,11 @@ interface Props { discoveryRulesDescription: ReactNode; showUnsavedWarning?: boolean; onDragEnd: (dropResult: DropResult) => void; + selectedVersion: string; + versions: string[]; + onChangeVersion: EuiComboBoxProps['onChange']; + onCreateNewVersion: EuiComboBoxProps['onCreateOption']; + isValidVersion: boolean; } export function RuntimeAttachment({ @@ -71,6 +79,11 @@ export function RuntimeAttachment({ discoveryRulesDescription, showUnsavedWarning, onDragEnd, + selectedVersion, + versions, + onChangeVersion, + onCreateNewVersion, + isValidVersion, }: Props) { return (
@@ -87,15 +100,38 @@ export function RuntimeAttachment({ )} - - - -

{toggleDescription}

-
+ + + + + +

{toggleDescription}

+
+
+ {isEnabled && versions && ( + + + ({ label: _version }))} + onChange={onChangeVersion} + onCreateOption={onCreateNewVersion} + singleSelection + isClearable={false} + /> + + + )} +
{isEnabled && ( <> diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx index 0dde02a5044ca..2a86244ef77ff 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx @@ -1,3 +1,10 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + import React, { useCallback, useState } from 'react'; import { RuntimeAttachment, RuntimeAttachmentSettings } from '..'; import { @@ -41,6 +48,39 @@ const includeOptions = [ ...excludeOptions, ]; +const versions = [ + '1.27.1', + '1.27.0', + '1.26.0', + '1.25.0', + '1.24.0', + '1.23.0', + '1.22.0', + '1.21.0', + '1.20.0', + '1.19.0', + '1.18.1', + '1.18.0', + '1.18.0.RC1', + '1.17.0', + '1.16.0', + '1.15.0', + '1.14.0', + '1.13.0', + '1.12.0', + '1.11.0', + '1.10.0', + '1.9.0', + '1.8.0', + '1.7.0', + '1.6.1', + '1.6.0', + '1.5.0', + '1.4.0', + '1.3.0', + '1.2.0', +]; + export function JavaRuntimeAttachment({ newPolicy, onChange }: Props) { const [isDirty, setIsDirty] = useState(false); const onChangePolicy = useCallback( @@ -70,6 +110,10 @@ export function JavaRuntimeAttachment({ newPolicy, onChange }: Props) { }) ), }, + java_attacher_agent_version: { + type: 'text', + value: runtimeAttachmentSettings.version, + }, }, }, ...newPolicy.inputs.slice(apmInputIdx + 1), @@ -111,6 +155,8 @@ export function JavaRuntimeAttachment({ newPolicy, onChange }: Props) { probe, }; })} + selectedVersion={versions[0]} + versions={versions} /> ); } From 9315aa10fb82efdbfaed64af95b3bcc94385e4db Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Thu, 2 Dec 2021 15:35:43 -0500 Subject: [PATCH 12/25] fixing some stuff --- .../default_discovery_rule.tsx | 7 ++++++ .../runtime_attachment/discovery_rule.tsx | 15 ++++++++---- .../edit_discovery_rule.tsx | 23 ++++++++++++------- .../apm_agents/runtime_attachment/index.tsx | 6 ++--- .../runtime_attachment.stories.tsx | 4 ++++ .../java_runtime_attachment.tsx | 2 +- 6 files changed, 41 insertions(+), 16 deletions(-) diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/default_discovery_rule.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/default_discovery_rule.tsx index c8b2d45afa1c3..125e3952462b6 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/default_discovery_rule.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/default_discovery_rule.tsx @@ -1,3 +1,10 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + import { EuiText, EuiFlexGroup, diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx index 661ebb88338d0..ed3e1a596e4ab 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx @@ -1,3 +1,10 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + import { EuiText, EuiFlexGroup, @@ -34,12 +41,12 @@ export function DiscoveryRule({ operationTypes, }: Props) { const operationTypesLabels = useMemo(() => { - return operationTypes.reduce((acc, { operation, types }) => { + return operationTypes.reduce((acc, current) => { return { ...acc, - [operation.value]: { - label: operation.label, - types: types.reduce((memo, { value, label }) => { + [current.operation.value]: { + label: current.operation.label, + types: current.types.reduce((memo, { value, label }) => { return { ...memo, [value]: label }; }, {}), }, diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx index 7ce6a995c05d1..b41aec067f735 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx @@ -1,3 +1,10 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + import { EuiFlexGroup, EuiFlexItem, @@ -49,9 +56,9 @@ export function EditDiscoveryRule({ ({ - text: operation.label, - value: operation.value, + options={operationTypes.map((item) => ({ + text: item.operation.label, + value: item.operation.value, }))} value={operation} onChange={(e) => { @@ -74,14 +81,14 @@ export function EditDiscoveryRule({ ({ operation: definedOperation }) => definedOperation.value === operation ) - ?.types.map((type) => ({ - inputDisplay: type.label, - value: type.value, + ?.types.map((item) => ({ + inputDisplay: item.label, + value: item.value, dropdownDisplay: ( <> - {type.label} + {item.label} -

{type.description}

+

{item.description}

), diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx index 8c7c3f524dc68..559a51b8f8d52 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx @@ -89,9 +89,9 @@ export function RuntimeAttachment(props: Props) { discoveryRules: nextIsEnabled ? discoveryRuleList.map(({ discoveryRule }) => discoveryRule) : [], - version, + version: nextIsEnabled ? version : props.selectedVersion, }); - }, [isEnabled, onChange, discoveryRuleList, version]); + }, [isEnabled, onChange, discoveryRuleList, version, props.selectedVersion]); const onDelete = useCallback( (discoveryRuleId: string) => { @@ -227,7 +227,7 @@ export function RuntimeAttachment(props: Props) { ]; setDiscoveryRuleList(nextDiscoveryRuleList); setEditDiscoveryRuleId(STAGED_DISCOVERY_RULE_ID); - }, [discoveryRuleList]); + }, [discoveryRuleList, props.operationTypes]); const onDragEnd = useCallback( ({ source, destination }: DropResult) => { diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.stories.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.stories.tsx index a9abc965fccce..12d48c0cb3b73 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.stories.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.stories.tsx @@ -32,6 +32,8 @@ const excludeOptions = [ ]; const includeOptions = [{ value: 'all', label: 'All' }, ...excludeOptions]; +const versions = ['1.27.1', '1.27.0', '1.26.0', '1.25.0']; + export const RuntimeAttachmentExample: Story = () => { const [runtimeAttachmentSettings, setRuntimeAttachmentSettings] = useState( {} @@ -68,6 +70,8 @@ export const RuntimeAttachmentExample: Story = () => { probe: '10948653898867', }, ]} + versions={versions} + selectedVersion={versions[0]} />
{JSON.stringify(runtimeAttachmentSettings, null, 4)}
diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx index 2a86244ef77ff..f0f35e2405c4b 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx @@ -122,7 +122,7 @@ export function JavaRuntimeAttachment({ newPolicy, onChange }: Props) { }); setIsDirty(true); }, - [newPolicy] + [newPolicy, onChange] ); return ( Date: Thu, 2 Dec 2021 16:36:46 -0500 Subject: [PATCH 13/25] adding link to doc --- .../java_runtime_attachment.tsx | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx index f0f35e2405c4b..4e55caa62ec56 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx @@ -5,6 +5,8 @@ * 2.0. */ +import { i18n } from '@kbn/i18n'; +import { FormattedMessage } from '@kbn/i18n-react'; import React, { useCallback, useState } from 'react'; import { RuntimeAttachment, RuntimeAttachmentSettings } from '..'; import { @@ -138,7 +140,25 @@ export function JavaRuntimeAttachment({ newPolicy, onChange }: Props) { ]} onChange={onChangePolicy} toggleDescription="Attach the Java agent to running and starting Java applications." - discoveryRulesDescription="For every running JVM, the discovery rules are evaluated in the order they are provided. The first matching rule determines the outcome. Learn more in the docs." + discoveryRulesDescription={ + + {i18n.translate( + 'xpack.apm.fleetIntegration.javaRuntime.discoveryRulesDescription.docLink', + { defaultMessage: 'docs' } + )} + + ), + }} + /> + } showUnsavedWarning={isDirty} initialIsEnabled={ newPolicy.inputs.find(({ type }) => type === 'apm')?.vars From e40d6e9a6c4e8449760d882f55ebc8987500e6af Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Fri, 3 Dec 2021 09:10:20 -0500 Subject: [PATCH 14/25] adding internationalization --- .../edit_discovery_rule.tsx | 31 +++++++- .../runtime_attachment/runtime_attachment.tsx | 33 ++++++-- .../java_runtime_attachment.tsx | 76 +++++++++++++++---- 3 files changed, 116 insertions(+), 24 deletions(-) diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx index b41aec067f735..152cb298bf19a 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx @@ -18,6 +18,7 @@ import { EuiSuperSelect, EuiText, } from '@elastic/eui'; +import { i18n } from '@kbn/i18n'; import React from 'react'; import { Operation, @@ -71,7 +72,15 @@ export function EditDiscoveryRule({ - + - + - {id === STAGED_DISCOVERY_RULE_ID ? 'Add' : 'Save'} + {id === STAGED_DISCOVERY_RULE_ID + ? i18n.translate( + 'xpack.apm.fleetIntegration.apmAgent.runtimeAttachment.editRule.add', + { defaultMessage: 'Add' } + ) + : i18n.translate( + 'xpack.apm.fleetIntegration.apmAgent.runtimeAttachment.editRule.save', + { defaultMessage: 'Save' } + )} diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx index 379699156cf24..5b496a2102156 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx @@ -23,6 +23,7 @@ import { EuiFormRow, } from '@elastic/eui'; import React, { ReactNode } from 'react'; +import { i18n } from '@kbn/i18n'; import { DiscoveryRule } from './discovery_rule'; import { DefaultDiscoveryRule } from './default_discovery_rule'; import { EditDiscoveryRule } from './edit_discovery_rule'; @@ -90,9 +91,13 @@ export function RuntimeAttachment({ {showUnsavedWarning && ( <> @@ -117,11 +125,17 @@ export function RuntimeAttachment({ ({ label: _version }))} onChange={onChangeVersion} onCreateOption={onCreateNewVersion} @@ -136,7 +150,12 @@ export function RuntimeAttachment({ <> -

Discovery rules

+

+ {i18n.translate( + 'xpack.apm.fleetIntegration.apmAgent.runtimeAttachment.discoveryRules', + { defaultMessage: 'Discovery rules' } + )} +

diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx index 4e55caa62ec56..a3a7529ac6aa6 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx @@ -24,28 +24,58 @@ interface Props { const excludeOptions = [ { value: 'main', - label: 'main', - description: - 'A regular expression of fully qualified main class names or paths to JARs of applications the java agent should be attached to. Performs a partial match so that foo matches /bin/foo.jar.', + label: i18n.translate( + 'xpack.apm.fleetIntegration.javaRuntime.operationType.exclude.options.main', + { defaultMessage: 'main' } + ), + description: i18n.translate( + 'xpack.apm.fleetIntegration.javaRuntime.operationType.exclude.options.mainDescription', + { + defaultMessage: + 'A regular expression of fully qualified main class names or paths to JARs of applications the java agent should be attached to. Performs a partial match so that foo matches /bin/foo.jar.', + } + ), }, { value: 'vmarg', - label: 'vmarg', - description: - 'A regular expression matched against the arguments passed to the JVM, such as system properties. Performs a partial match so that attach=true matches the system property -Dattach=true.', + label: i18n.translate( + 'xpack.apm.fleetIntegration.javaRuntime.operationType.exclude.options.vmarg', + { defaultMessage: 'vmarg' } + ), + description: i18n.translate( + 'xpack.apm.fleetIntegration.javaRuntime.operationType.exclude.options.vmargDescription', + { + defaultMessage: + 'A regular expression matched against the arguments passed to the JVM, such as system properties. Performs a partial match so that attach=true matches the system property -Dattach=true.', + } + ), }, { value: 'user', - label: 'user', - description: - 'A username that is matched against the operating system user that runs the JVM. For included users, make sure that the Elastic Agent user is either the same user or has permissions to switch to the user that runs the target JVM.', + label: i18n.translate( + 'xpack.apm.fleetIntegration.javaRuntime.operationType.exclude.options.user', + { defaultMessage: 'user' } + ), + description: i18n.translate( + 'xpack.apm.fleetIntegration.javaRuntime.operationType.exclude.options.vmargDescription', + { + defaultMessage: + 'A username that is matched against the operating system user that runs the JVM. For included users, make sure that the Elastic Agent user is either the same user or has permissions to switch to the user that runs the target JVM.', + } + ), }, ]; const includeOptions = [ { value: 'all', - label: 'All', - description: 'Includes all JVMs for attachment.', + label: i18n.translate( + 'xpack.apm.fleetIntegration.javaRuntime.operationType.include.options.all', + { defaultMessage: 'All' } + ), + description: i18n.translate( + 'xpack.apm.fleetIntegration.javaRuntime.operationType.include.options.allDescription', + { defaultMessage: 'Includes all JVMs for attachment.' } + ), }, ...excludeOptions, ]; @@ -130,16 +160,34 @@ export function JavaRuntimeAttachment({ newPolicy, onChange }: Props) { Date: Fri, 3 Dec 2021 09:26:17 -0500 Subject: [PATCH 15/25] updating user description --- .../supported_agents/java_runtime_attachment.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx index a3a7529ac6aa6..b68a1b47fa588 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx @@ -60,7 +60,7 @@ const excludeOptions = [ 'xpack.apm.fleetIntegration.javaRuntime.operationType.exclude.options.vmargDescription', { defaultMessage: - 'A username that is matched against the operating system user that runs the JVM. For included users, make sure that the Elastic Agent user is either the same user or has permissions to switch to the user that runs the target JVM.', + 'A username that is matched against the operating system user that runs the JVM.', } ), }, From 21d298a01036aaed4208f856fa397236a44ca461 Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Fri, 3 Dec 2021 15:17:40 -0500 Subject: [PATCH 16/25] fixing default version --- .../java_runtime_attachment.tsx | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx index b68a1b47fa588..ef534c9b5421c 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx @@ -7,7 +7,7 @@ import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; -import React, { useCallback, useState } from 'react'; +import React, { useCallback, useState, useMemo } from 'react'; import { RuntimeAttachment, RuntimeAttachmentSettings } from '..'; import { NewPackagePolicy, @@ -113,6 +113,10 @@ const versions = [ '1.2.0', ]; +function getApmVars(newPolicy: NewPackagePolicy) { + return newPolicy.inputs.find(({ type }) => type === 'apm')?.vars; +} + export function JavaRuntimeAttachment({ newPolicy, onChange }: Props) { const [isDirty, setIsDirty] = useState(false); const onChangePolicy = useCallback( @@ -156,6 +160,9 @@ export function JavaRuntimeAttachment({ newPolicy, onChange }: Props) { }, [newPolicy, onChange] ); + + const apmVars = useMemo(() => getApmVars(newPolicy), [newPolicy]); + return ( } showUnsavedWarning={isDirty} - initialIsEnabled={ - newPolicy.inputs.find(({ type }) => type === 'apm')?.vars - ?.java_attacher_enabled?.value - } + initialIsEnabled={apmVars?.java_attacher_enabled?.value} initialDiscoveryRules={( - newPolicy.inputs.find(({ type }) => type === 'apm')?.vars - ?.java_attacher_discovery_rules?.value ?? [initialDiscoveryRule] + apmVars?.java_attacher_discovery_rules?.value ?? [initialDiscoveryRule] ).map((discoveryRuleMap: Record) => { const [operationType, probe] = Object.entries(discoveryRuleMap)[0]; return { @@ -223,7 +226,9 @@ export function JavaRuntimeAttachment({ newPolicy, onChange }: Props) { probe, }; })} - selectedVersion={versions[0]} + selectedVersion={ + apmVars?.java_attacher_agent_version?.value || versions[0] + } versions={versions} /> ); From da4b6138738b8797fe4bed31169dca5138543f91 Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Fri, 3 Dec 2021 16:02:08 -0500 Subject: [PATCH 17/25] setting to null when disabled --- .../apm_agents/runtime_attachment/index.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx index 559a51b8f8d52..fa9c47d1f767b 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx @@ -31,7 +31,7 @@ export type IDiscoveryRuleList = Array<{ export interface RuntimeAttachmentSettings { enabled: boolean; discoveryRules: IDiscoveryRule[]; - version: string; + version: string | null; } interface Props { @@ -89,9 +89,9 @@ export function RuntimeAttachment(props: Props) { discoveryRules: nextIsEnabled ? discoveryRuleList.map(({ discoveryRule }) => discoveryRule) : [], - version: nextIsEnabled ? version : props.selectedVersion, + version: nextIsEnabled ? version : null, }); - }, [isEnabled, onChange, discoveryRuleList, version, props.selectedVersion]); + }, [isEnabled, onChange, discoveryRuleList, version]); const onDelete = useCallback( (discoveryRuleId: string) => { From 569ad958b7da1b8e012b5f869c8e89d7f7075054 Mon Sep 17 00:00:00 2001 From: Oliver Gupte Date: Fri, 3 Dec 2021 16:59:54 -0500 Subject: [PATCH 18/25] - fixes encoding and decoding discovery rules yaml - adds workaround for extra 'elasticsearch' field on integration policy updates - updates migration package version from 7.16.0 to 8.0.0-dev4 --- x-pack/plugins/apm/common/fleet.ts | 2 +- .../apm_agents/runtime_attachment/index.tsx | 2 +- .../java_runtime_attachment.tsx | 71 ++++++++++++++----- .../edit_package_policy_page/index.tsx | 3 +- 4 files changed, 59 insertions(+), 19 deletions(-) diff --git a/x-pack/plugins/apm/common/fleet.ts b/x-pack/plugins/apm/common/fleet.ts index 00a958952d2de..bd8c6cf2653c2 100644 --- a/x-pack/plugins/apm/common/fleet.ts +++ b/x-pack/plugins/apm/common/fleet.ts @@ -8,7 +8,7 @@ import semverParse from 'semver/functions/parse'; export const POLICY_ELASTIC_AGENT_ON_CLOUD = 'policy-elastic-agent-on-cloud'; -export const SUPPORTED_APM_PACKAGE_VERSION = '7.16.0'; +export const SUPPORTED_APM_PACKAGE_VERSION = '8.0.0-dev4'; // TODO update to just '8.0.0' once published export function isPrereleaseVersion(version: string) { return semverParse(version)?.prerelease?.length ?? 0 > 0; diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx index fa9c47d1f767b..8f2a1d3d1dea1 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/index.tsx @@ -17,7 +17,7 @@ import { RuntimeAttachment as RuntimeAttachmentStateless } from './runtime_attac export const STAGED_DISCOVERY_RULE_ID = 'STAGED_DISCOVERY_RULE_ID'; export const DISCOVERY_RULE_TYPE_ALL = 'all'; -interface IDiscoveryRule { +export interface IDiscoveryRule { operation: string; type: string; probe: string; diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx index ef534c9b5421c..c39d95b9bf58d 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx @@ -5,10 +5,15 @@ * 2.0. */ +import yaml from 'js-yaml'; import { i18n } from '@kbn/i18n'; import { FormattedMessage } from '@kbn/i18n-react'; import React, { useCallback, useState, useMemo } from 'react'; -import { RuntimeAttachment, RuntimeAttachmentSettings } from '..'; +import { + RuntimeAttachment, + RuntimeAttachmentSettings, + IDiscoveryRule, +} from '..'; import { NewPackagePolicy, PackagePolicy, @@ -140,10 +145,8 @@ export function JavaRuntimeAttachment({ newPolicy, onChange }: Props) { }, java_attacher_discovery_rules: { type: 'yaml', - value: runtimeAttachmentSettings.discoveryRules.map( - ({ operation, type, probe }) => ({ - [`${operation}-${type}`]: probe, - }) + value: encodeDiscoveryRulesYaml( + runtimeAttachmentSettings.discoveryRules ), }, java_attacher_agent_version: { @@ -216,16 +219,10 @@ export function JavaRuntimeAttachment({ newPolicy, onChange }: Props) { } showUnsavedWarning={isDirty} initialIsEnabled={apmVars?.java_attacher_enabled?.value} - initialDiscoveryRules={( - apmVars?.java_attacher_discovery_rules?.value ?? [initialDiscoveryRule] - ).map((discoveryRuleMap: Record) => { - const [operationType, probe] = Object.entries(discoveryRuleMap)[0]; - return { - operation: operationType.split('-')[0], - type: operationType.split('-')[1], - probe, - }; - })} + initialDiscoveryRules={decodeDiscoveryRulesYaml( + apmVars?.java_attacher_discovery_rules?.value ?? '[]\n', + [initialDiscoveryRule] + )} selectedVersion={ apmVars?.java_attacher_agent_version?.value || versions[0] } @@ -234,4 +231,46 @@ export function JavaRuntimeAttachment({ newPolicy, onChange }: Props) { ); } -const initialDiscoveryRule = { 'include-vmarg': 'elastic.apm.attach=true' }; +const initialDiscoveryRule = { + operation: 'include', + type: 'vmarg', + probe: 'elastic.apm.attach=true', +}; + +type DiscoveryRulesParsedYaml = Array<{ [operationType: string]: string }>; + +function decodeDiscoveryRulesYaml( + discoveryRulesYaml: string, + defaultDiscoveryRules: IDiscoveryRule[] = [] +): IDiscoveryRule[] { + try { + const parsedYaml: DiscoveryRulesParsedYaml = + yaml.load(discoveryRulesYaml) ?? []; + + if (parsedYaml.length === 0) { + return defaultDiscoveryRules; + } + + // transform into array of discovery rules + return parsedYaml.map((discoveryRuleMap) => { + const [operationType, probe] = Object.entries(discoveryRuleMap)[0]; + return { + operation: operationType.split('-')[0], + type: operationType.split('-')[1], + probe, + }; + }); + } catch (error) { + return defaultDiscoveryRules; + } +} + +function encodeDiscoveryRulesYaml(discoveryRules: IDiscoveryRule[]): string { + // transform into list of key,value objects for expected yaml result + const mappedDiscoveryRules: DiscoveryRulesParsedYaml = discoveryRules.map( + ({ operation, type, probe }) => ({ + [`${operation}-${type}`]: probe, + }) + ); + return yaml.dump(mappedDiscoveryRules); +} diff --git a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/edit_package_policy_page/index.tsx b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/edit_package_policy_page/index.tsx index c0914e41872b1..a7dd682384748 100644 --- a/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/edit_package_policy_page/index.tsx +++ b/x-pack/plugins/fleet/public/applications/fleet/sections/agent_policy/edit_package_policy_page/index.tsx @@ -348,7 +348,8 @@ export const EditPackagePolicyForm = memo<{ const [formState, setFormState] = useState('INVALID'); const savePackagePolicy = async () => { setFormState('LOADING'); - const result = await sendUpdatePackagePolicy(packagePolicyId, packagePolicy); + const { elasticsearch, ...restPackagePolicy } = packagePolicy; // ignore 'elasticsearch' property since it fails route validation + const result = await sendUpdatePackagePolicy(packagePolicyId, restPackagePolicy); setFormState('SUBMITTED'); return result; }; From 9f952bf8209669849636d43b43ddbeba71b823b4 Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Mon, 6 Dec 2021 13:21:48 -0500 Subject: [PATCH 19/25] addressing pr comments --- .../apm_agents/runtime_attachment/default_discovery_rule.tsx | 2 +- .../apm_agents/runtime_attachment/discovery_rule.tsx | 4 ++-- .../apm_agents/runtime_attachment/edit_discovery_rule.tsx | 2 +- .../apm_agents/runtime_attachment/runtime_attachment.tsx | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/default_discovery_rule.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/default_discovery_rule.tsx index 125e3952462b6..848582bb3feb6 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/default_discovery_rule.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/default_discovery_rule.tsx @@ -16,7 +16,7 @@ import React from 'react'; export function DefaultDiscoveryRule() { return ( - + Exclude diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx index ed3e1a596e4ab..7473044ed5449 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx @@ -55,8 +55,8 @@ export function DiscoveryRule({ }, [operationTypes]); return ( - - + +
diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx index 152cb298bf19a..4d07ce5f4e2fd 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx @@ -52,7 +52,7 @@ export function EditDiscoveryRule({ operationTypes, }: Props) { return ( - + diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx index 5b496a2102156..01b4750780410 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx @@ -163,7 +163,7 @@ export function RuntimeAttachment({ - +

{discoveryRulesDescription}

From d21eefae3fb34573f8e72dacf724c892426ae714 Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Mon, 6 Dec 2021 13:22:37 -0500 Subject: [PATCH 20/25] fixing ci --- .../supported_agents/java_runtime_attachment.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx index c39d95b9bf58d..beb2db14ee902 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx @@ -62,7 +62,7 @@ const excludeOptions = [ { defaultMessage: 'user' } ), description: i18n.translate( - 'xpack.apm.fleetIntegration.javaRuntime.operationType.exclude.options.vmargDescription', + 'xpack.apm.fleetIntegration.javaRuntime.operationType.exclude.options.userDescription', { defaultMessage: 'A username that is matched against the operating system user that runs the JVM.', From 5302978109c2a3a5a00bc3439d13670903b39e26 Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Mon, 6 Dec 2021 14:25:26 -0500 Subject: [PATCH 21/25] fixing elements not visible while dragging --- .../apm_agents/agent_instructions_accordion.tsx | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx index 1be36e9947b08..e4e55d5ff7283 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx @@ -17,6 +17,7 @@ import { } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; import React, { ReactElement } from 'react'; +import styled from 'styled-components'; import { AgentRuntimeAttachmentProps, CreateAgentInstructions, @@ -116,6 +117,14 @@ interface Props { AgentRuntimeAttachment?: (props: AgentRuntimeAttachmentProps) => ReactElement; } +const StyledEuiAccordion = styled(EuiAccordion)` + //This is an alternative fix suggested by the EUI team to fix drag elements inside EuiAccordion + //This Issue tracks the fix on the Eui side https://github.com/elastic/eui/issues/3548#issuecomment-639041283 + .euiAccordion__childWrapper { + transform: none; + } +`; + export function AgentInstructionsAccordion({ policy, newPolicy, @@ -197,7 +206,7 @@ export function AgentInstructionsAccordion({ ); return ( - @@ -244,6 +253,6 @@ export function AgentInstructionsAccordion({ ) : ( manualInstrumentationContent )} - + ); } From a7b74cde4cd872c37019dfb3098dd84b1cc5648b Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Mon, 6 Dec 2021 15:13:57 -0500 Subject: [PATCH 22/25] addressing PR changes --- .../apm_agents/agent_instructions_accordion.tsx | 17 ++++++++++------- ...e_template_strings.ts => render_mustache.ts} | 17 +++++++++++------ 2 files changed, 21 insertions(+), 13 deletions(-) rename x-pack/plugins/apm/public/components/fleet_integration/apm_agents/{replace_template_strings.ts => render_mustache.ts} (65%) diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx index e4e55d5ff7283..f5ac16adbd503 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx @@ -34,7 +34,7 @@ import { PackagePolicyEditExtensionComponentProps, } from '../apm_policy_form/typings'; import { getCommands } from '../../../tutorial/config_agent/commands/get_commands'; -import { replaceTemplateStrings } from './replace_template_strings'; +import { renderMustache } from './render_mustache'; function AccordionButtonContent({ agentName, @@ -145,10 +145,13 @@ export function AgentInstructionsAccordion({ { title: stepTitle, textPre, textPost, customComponentName, commands }, index ) => { - const commandBlock = replaceTemplateStrings( - Array.isArray(commands) ? commands.join('\n') : commands || '', - docLinks - ); + const commandBlock = commands + ? renderMustache({ + text: commands, + docLinks, + }) + : ''; + return (
@@ -158,7 +161,7 @@ export function AgentInstructionsAccordion({ {textPre && ( )} {commandBlock && ( @@ -187,7 +190,7 @@ export function AgentInstructionsAccordion({ <> )} diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/replace_template_strings.ts b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/render_mustache.ts similarity index 65% rename from x-pack/plugins/apm/public/components/fleet_integration/apm_agents/replace_template_strings.ts rename to x-pack/plugins/apm/public/components/fleet_integration/apm_agents/render_mustache.ts index d36d76d466308..ebf5fea7f2b85 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/replace_template_strings.ts +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/render_mustache.ts @@ -10,12 +10,17 @@ import Mustache from 'mustache'; const TEMPLATE_TAGS = ['{', '}']; -export function replaceTemplateStrings( - text: string, - docLinks?: CoreStart['docLinks'] -) { - Mustache.parse(text, TEMPLATE_TAGS); - return Mustache.render(text, { +export function renderMustache({ + text, + docLinks, +}: { + text: string | string[]; + docLinks?: CoreStart['docLinks']; +}) { + const template = Array.isArray(text) ? text.join('\n') : text; + + Mustache.parse(template, TEMPLATE_TAGS); + return Mustache.render(template, { config: { docs: { base_url: docLinks?.ELASTIC_WEBSITE_URL, From f57c62770a9d91bb9ba8a1fcf8d1cf2bf4d3a3aa Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Tue, 7 Dec 2021 09:19:02 -0500 Subject: [PATCH 23/25] beta --- .../apm_agents/agent_instructions_accordion.tsx | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx index f5ac16adbd503..21b47b59e2c26 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx @@ -235,7 +235,12 @@ export function AgentInstructionsAccordion({ > Auto-Attachment - + ), From 29f735909938a1fbf2b7b5f89f247511386a3a0c Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Tue, 7 Dec 2021 11:14:10 -0500 Subject: [PATCH 24/25] adding tooltip back --- .../apm_agents/agent_instructions_accordion.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx index 21b47b59e2c26..6757db1fe3580 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx @@ -240,6 +240,13 @@ export function AgentInstructionsAccordion({ 'xpack.apm.fleetIntegration.apmAgent.runtimeAttachment.betaBadge.label', { defaultMessage: 'BETA' } )} + tooltipContent={i18n.translate( + 'xpack.apm.fleetIntegration.apmAgent.runtimeAttachment.betaBadge.tooltipContent', + { + defaultMessage: + 'Auto-attachment for Java is not GA. Please help us by reporting any bugs.', + } + )} /> From 5c93cbfb1c9ea9e649d724335b43c2a09176433e Mon Sep 17 00:00:00 2001 From: cauemarcondes Date: Tue, 7 Dec 2021 15:30:35 -0500 Subject: [PATCH 25/25] addressing pr comments --- .../agent_instructions_accordion.tsx | 22 +++++++++---- .../apm_agents/agent_instructions_mappings.ts | 4 +-- .../runtime_attachment/discovery_rule.tsx | 31 ++++++++++------- .../edit_discovery_rule.tsx | 33 +++++++++++++++---- .../runtime_attachment.stories.tsx | 2 -- .../runtime_attachment/runtime_attachment.tsx | 10 ++++-- .../java_runtime_attachment.tsx | 2 +- 7 files changed, 72 insertions(+), 32 deletions(-) diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx index 6757db1fe3580..a82fa3121bb3b 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/agent_instructions_accordion.tsx @@ -16,7 +16,7 @@ import { EuiBetaBadge, } from '@elastic/eui'; import { i18n } from '@kbn/i18n'; -import React, { ReactElement } from 'react'; +import React, { ComponentType } from 'react'; import styled from 'styled-components'; import { AgentRuntimeAttachmentProps, @@ -28,7 +28,7 @@ import { } from '../../../../../../../src/plugins/kibana_react/public'; import { AgentName } from '../../../../typings/es_schemas/ui/fields/agent'; import { AgentIcon } from '../../shared/agent_icon'; -import { +import type { NewPackagePolicy, PackagePolicy, PackagePolicyEditExtensionComponentProps, @@ -114,12 +114,12 @@ interface Props { title: string; variantId: string; createAgentInstructions: CreateAgentInstructions; - AgentRuntimeAttachment?: (props: AgentRuntimeAttachmentProps) => ReactElement; + AgentRuntimeAttachment?: ComponentType; } const StyledEuiAccordion = styled(EuiAccordion)` - //This is an alternative fix suggested by the EUI team to fix drag elements inside EuiAccordion - //This Issue tracks the fix on the Eui side https://github.com/elastic/eui/issues/3548#issuecomment-639041283 + // This is an alternative fix suggested by the EUI team to fix drag elements inside EuiAccordion + // This Issue tracks the fix on the Eui side https://github.com/elastic/eui/issues/3548#issuecomment-639041283 .euiAccordion__childWrapper { transform: none; } @@ -222,7 +222,10 @@ export function AgentInstructionsAccordion({ tabs={[ { id: 'manual-instrumentation', - name: 'Manual instrumentation', + name: i18n.translate( + 'xpack.apm.fleetIntegration.apmAgent.runtimeAttachment.manualInstrumentation', + { defaultMessage: 'Manual instrumentation' } + ), content: manualInstrumentationContent, }, { @@ -233,7 +236,12 @@ export function AgentInstructionsAccordion({ alignItems="baseline" gutterSize="s" > - Auto-Attachment + + {i18n.translate( + 'xpack.apm.fleetIntegration.apmAgent.runtimeAttachment.autoAttachment', + { defaultMessage: 'Auto-Attachment' } + )} + ReactElement; + AgentRuntimeAttachment?: ComponentType; }> = [ { agentName: 'java', diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx index 7473044ed5449..f7b1b3db3a4c4 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/discovery_rule.tsx @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ - +import { i18n } from '@kbn/i18n'; import { EuiText, EuiFlexGroup, @@ -13,6 +13,7 @@ import { EuiBadge, EuiPanel, DraggableProvidedDragHandleProps, + EuiButtonIcon, } from '@elastic/eui'; import React, { useMemo } from 'react'; import { Operation } from '.'; @@ -41,7 +42,12 @@ export function DiscoveryRule({ operationTypes, }: Props) { const operationTypesLabels = useMemo(() => { - return operationTypes.reduce((acc, current) => { + return operationTypes.reduce<{ + [operationValue: string]: { + label: string; + types: { [typeValue: string]: string }; + }; + }>((acc, current) => { return { ...acc, [current.operation.value]: { @@ -51,14 +57,19 @@ export function DiscoveryRule({ }, {}), }, }; - }, {} as { [operationValue: string]: { label: string; types: { [typeValue: string]: string } } }); + }, {}); }, [operationTypes]); - return ( -
+
@@ -87,23 +98,21 @@ export function DiscoveryRule({ - { onEdit(id); }} - style={{ cursor: 'pointer' }} /> - { onDelete(id); }} - style={{ cursor: 'pointer' }} /> diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx index 4d07ce5f4e2fd..5059bbabfce91 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/edit_discovery_rule.tsx @@ -55,7 +55,14 @@ export function EditDiscoveryRule({ - + ({ text: item.operation.label, @@ -71,13 +78,20 @@ export function EditDiscoveryRule({ - + @@ -104,9 +118,7 @@ export function EditDiscoveryRule({ })) ?? [] } valueOfSelected={type} - onChange={(value) => { - onChangeType(value); - }} + onChange={onChangeType} /> @@ -115,7 +127,14 @@ export function EditDiscoveryRule({ {type !== DISCOVERY_RULE_TYPE_ALL && ( - + { ); }; -RuntimeAttachmentExample.storyName = 'RuntimeAttachment'; export const JavaRuntimeAttachmentExample: Story = () => { return ( @@ -89,7 +88,6 @@ export const JavaRuntimeAttachmentExample: Story = () => { /> ); }; -JavaRuntimeAttachmentExample.storyName = 'JavaRuntimeAttachment'; const policy = { id: 'cc380ec5-d84e-40e1-885a-d706edbdc968', diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx index 01b4750780410..3592eb4f04745 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/runtime_attachment.tsx @@ -123,7 +123,10 @@ export function RuntimeAttachment({ {isEnabled && versions && ( - Add rule + {i18n.translate( + 'xpack.apm.fleetIntegration.apmAgent.runtimeAttachment.addRule', + { defaultMessage: 'Add rule' } + )} diff --git a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx index beb2db14ee902..2284315d4a6ba 100644 --- a/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx +++ b/x-pack/plugins/apm/public/components/fleet_integration/apm_agents/runtime_attachment/supported_agents/java_runtime_attachment.tsx @@ -14,7 +14,7 @@ import { RuntimeAttachmentSettings, IDiscoveryRule, } from '..'; -import { +import type { NewPackagePolicy, PackagePolicy, PackagePolicyEditExtensionComponentProps,