-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ObsInfra][APM] Extract agent utils and custom icons (#170968)
## 📓 Summary Closes #170728 This work comes from the need to use agent and cloud provider icons in the new Log Detail flyout. Since those icons were already used across the `infra` and `apm` plugins, this was a good opportunity to extract the shared logic into packages. The results of this refactoring are two new packages: - **@kbn/elastic-agent-utils**: exports small utilities and type definition used to parse the icon to render and exploits also across the APM plugin. - **@kbn/custom-icons**: exports custom icons built on top of EuiIcon, encapsulating logic related to mapping from data to the relative icon. Apart from creating the new plugins, this also applies their usage to the `infra` and `apm` plugins, while the Log Explorer flyout will benefit from these working on #170721. ## 🧪 How to test ### Infra - Navigate to `Infrastructure -> Hosts` - Verify the hosts table correctly renders the cloud provider icon for each table entry. ### APM - Navigate to `APM -> Services`. - Verify each table entry correctly displays the related agent icon. - Navigate to `APM -> Services`. - Click on a service where t a cloud provider icon is expected to appear next to the service name. - Verify the icon is correctly displayed. - Navigate to `APM -> Services -> Service Map`. - Create a new group. - Verify the agent icon is correctly displayed for each entry in the preview list. - Navigate to `APM -> Traces`. - Verify each table entry correctly displays the related agent icon. - Navigate to `APM -> Settings -> Agent Explorer`. - Verify each table entry correctly displays the related agent icon. --------- Co-authored-by: Marco Antonio Ghiani <[email protected]> Co-authored-by: kibanamachine <[email protected]>
- Loading branch information
1 parent
a968a2e
commit b83b495
Showing
82 changed files
with
886 additions
and
589 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
module.exports = require('@kbn/storybook').defaultConfig; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# @kbn/custom-icons | ||
|
||
A utility package, `@kbn/custom-icons`, that provides components for rendering icons related to Elastic Agents, Cloud Providers and more. | ||
|
||
## Components | ||
|
||
### `<AgentIcon />` | ||
|
||
```jsx | ||
<AgentIcon agentName={agentName} /> | ||
``` | ||
|
||
This component renders an icon corresponding to the specified Elastic Agent name (`agentName`). | ||
|
||
#### Props | ||
|
||
- **`agentName`**: The name of the Elastic Agent for which the icon should be rendered. | ||
|
||
### `<CloudProviderIcon />` | ||
|
||
```jsx | ||
<CloudProviderIcon cloudProvider={cloudProvider} /> | ||
``` | ||
|
||
This component renders an icon associated with the specified Cloud Provider (`cloudProvider`). | ||
|
||
#### Props | ||
|
||
- **`cloudProvider`**: The name of the Cloud Provider for which the icon should be rendered. |
File renamed without changes
File renamed without changes
File renamed without changes
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
export { getAgentIcon } from './src/components/agent_icon/get_agent_icon'; | ||
export { getServerlessIcon } from './src/components/agent_icon/get_serverless_icon'; | ||
export { AgentIcon } from './src/components/agent_icon'; | ||
export type { AgentIconProps } from './src/components/agent_icon'; | ||
|
||
export { getCloudProviderIcon } from './src/components/cloud_provider_icon/get_cloud_provider_icon'; | ||
export type { CloudProvider } from './src/components/cloud_provider_icon/get_cloud_provider_icon'; | ||
export { CloudProviderIcon } from './src/components/cloud_provider_icon'; | ||
export type { CloudProviderIconProps } from './src/components/cloud_provider_icon'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
module.exports = { | ||
preset: '@kbn/test', | ||
rootDir: '../..', | ||
roots: ['<rootDir>/packages/kbn-custom-icons'], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"type": "shared-common", | ||
"id": "@kbn/custom-icons", | ||
"owner": "@elastic/obs-ux-logs-team" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"name": "@kbn/custom-icons", | ||
"private": true, | ||
"version": "1.0.0", | ||
"license": "SSPL-1.0 OR Elastic License 2.0", | ||
"sideEffects": false | ||
} |
53 changes: 53 additions & 0 deletions
53
packages/kbn-custom-icons/src/components/agent_icon/agent_icon.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { EuiCard, EuiFlexGroup, EuiFlexItem, EuiImage, EuiToolTip } from '@elastic/eui'; | ||
import type { Story } from '@storybook/react'; | ||
import React from 'react'; | ||
import { AGENT_NAMES } from '@kbn/elastic-agent-utils'; | ||
import { EuiThemeProvider } from '@kbn/kibana-react-plugin/common'; | ||
import { getAgentIcon } from './get_agent_icon'; | ||
import { AgentIcon } from '.'; | ||
|
||
export default { | ||
title: 'Custom Icons/AgentIcon', | ||
component: AgentIcon, | ||
}; | ||
|
||
export const List: Story = () => { | ||
return ( | ||
<EuiThemeProvider darkMode={false}> | ||
<EuiFlexGroup gutterSize="l" wrap={true}> | ||
{AGENT_NAMES.map((agentName) => { | ||
return ( | ||
<EuiFlexItem key={agentName} grow={false}> | ||
<EuiCard | ||
icon={ | ||
<EuiToolTip position="top" content="Icon rendered with `EuiImage`"> | ||
<EuiImage | ||
size="s" | ||
hasShadow | ||
alt={agentName} | ||
src={getAgentIcon(agentName, false)} | ||
/> | ||
</EuiToolTip> | ||
} | ||
title={agentName} | ||
description={ | ||
<EuiToolTip position="bottom" content="Icon rendered with `AgentIcon`"> | ||
<AgentIcon agentName={agentName} /> | ||
</EuiToolTip> | ||
} | ||
/> | ||
</EuiFlexItem> | ||
); | ||
})} | ||
</EuiFlexGroup> | ||
</EuiThemeProvider> | ||
); | ||
}; |
5 changes: 3 additions & 2 deletions
5
.../shared/agent_icon/get_agent_icon.test.ts → ...ponents/agent_icon/get_agent_icon.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
packages/kbn-custom-icons/src/components/agent_icon/get_serverless_icon.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
import { ServerlessType } from '@kbn/elastic-agent-utils'; | ||
import defaultIcon from '../../../assets/default.svg'; | ||
import lambdaIcon from '../../../assets/lambda.svg'; | ||
import azureFunctionsIcon from '../../../assets/functions.svg'; | ||
|
||
const serverlessIcons: Record<ServerlessType, string> = { | ||
'aws.lambda': lambdaIcon, | ||
'azure.functions': azureFunctionsIcon, | ||
} as const; | ||
|
||
export function getServerlessIcon(serverlessType?: ServerlessType) { | ||
if (!serverlessType) { | ||
return defaultIcon; | ||
} | ||
return serverlessIcons[serverlessType] ?? defaultIcon; | ||
} |
23 changes: 23 additions & 0 deletions
23
packages/kbn-custom-icons/src/components/agent_icon/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import React from 'react'; | ||
import { EuiIcon, EuiIconProps, useEuiTheme } from '@elastic/eui'; | ||
import { AgentName } from '@kbn/elastic-agent-utils'; | ||
import { getAgentIcon } from './get_agent_icon'; | ||
|
||
export interface AgentIconProps extends Omit<EuiIconProps, 'type'> { | ||
agentName?: AgentName; | ||
} | ||
|
||
export function AgentIcon({ agentName, size = 'l', ...props }: AgentIconProps) { | ||
const theme = useEuiTheme(); | ||
const icon = getAgentIcon(agentName, theme.colorMode === 'DARK'); | ||
|
||
return <EuiIcon type={icon} size={size} title={agentName} {...props} />; | ||
} |
41 changes: 41 additions & 0 deletions
41
packages/kbn-custom-icons/src/components/cloud_provider_icon/cloud_provider_icon.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* 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 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
import { EuiCard, EuiFlexGroup, EuiFlexItem, EuiToolTip } from '@elastic/eui'; | ||
import type { Story } from '@storybook/react'; | ||
import React from 'react'; | ||
import { CloudProviderIcon } from '.'; | ||
import { CloudProvider } from './get_cloud_provider_icon'; | ||
|
||
export default { | ||
title: 'Custom Icons/CloudProviderIcon', | ||
component: CloudProviderIcon, | ||
}; | ||
|
||
const providers: CloudProvider[] = ['gcp', 'aws', 'azure', 'unknownProvider']; | ||
|
||
export const List: Story = () => { | ||
return ( | ||
<EuiFlexGroup gutterSize="l" wrap={true}> | ||
{providers.map((cloudProvider) => { | ||
return ( | ||
<EuiFlexItem key={cloudProvider} grow={false}> | ||
<EuiCard | ||
title={cloudProvider as string} | ||
description={ | ||
<EuiToolTip position="bottom" content="Icon rendered with `CloudProviderIcon`"> | ||
<CloudProviderIcon cloudProvider={cloudProvider} size="xxl" /> | ||
</EuiToolTip> | ||
} | ||
/> | ||
</EuiFlexItem> | ||
); | ||
})} | ||
</EuiFlexGroup> | ||
); | ||
}; |
Oops, something went wrong.