Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Cloud] ES endpoint discovery #167122

Merged
merged 32 commits into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d1ec4cd
Add cloud package to expose deployment details component
sebelga Sep 22, 2023
836413e
Update the fleet plugin to consume the package
sebelga Sep 25, 2023
5189129
Update cloud integration links to open modal
sebelga Sep 25, 2023
584bb54
Update jest test
sebelga Sep 25, 2023
462038b
Update docs
sebelga Sep 25, 2023
8092db4
[CI] Auto-commit changed files from 'node scripts/lint_ts_projects --…
kibanamachine Sep 25, 2023
a2dcc69
[CI] Auto-commit changed files from 'node scripts/generate codeowners'
kibanamachine Sep 25, 2023
d69e76a
Add cloud functional test
sebelga Sep 25, 2023
23a0201
Merge branch 'es-endpoint-discovery' of github.com:sebelga/kibana int…
sebelga Sep 25, 2023
c269ca6
Change folder name to snake_case
sebelga Sep 25, 2023
8f41014
Merge branch 'main' into es-endpoint-discovery
sebelga Sep 25, 2023
d453c20
Merge branch 'main' into es-endpoint-discovery
kibanamachine Sep 25, 2023
15cdb95
Merge branch 'main' into es-endpoint-discovery
kibanamachine Sep 25, 2023
b06adf7
Fix jest test
sebelga Sep 26, 2023
bbcddfb
Merge branch 'es-endpoint-discovery' of github.com:sebelga/kibana int…
sebelga Sep 26, 2023
be6f5e4
Merge remote-tracking branch 'upstream/main' into es-endpoint-discovery
sebelga Sep 26, 2023
3a403e0
Fix TS issue
sebelga Sep 26, 2023
b46d1eb
Merge branch 'main' into es-endpoint-discovery
kibanamachine Sep 26, 2023
cfbed55
Merge branch 'main' into es-endpoint-discovery
sebelga Sep 26, 2023
4667486
Merge branch 'main' into es-endpoint-discovery
sebelga Sep 26, 2023
6817726
Merge branch 'main' into es-endpoint-discovery
sebelga Sep 26, 2023
39d422e
Merge branch 'main' into es-endpoint-discovery
sebelga Sep 26, 2023
c63854d
Merge branch 'main' into es-endpoint-discovery
sebelga Sep 27, 2023
112a0a3
Merge branch 'main' into es-endpoint-discovery
sebelga Sep 27, 2023
4eb0f4e
Remove unused barrel file
sebelga Sep 27, 2023
241e22d
Allow cmd+click to open "manage API keys" link
sebelga Sep 27, 2023
9d46281
Address CR changes
sebelga Sep 27, 2023
6a25ade
Merge branch 'main' into es-endpoint-discovery
sebelga Sep 27, 2023
3828297
Merge branch 'main' into es-endpoint-discovery
sebelga Sep 27, 2023
204aa34
Merge branch 'main' into es-endpoint-discovery
sebelga Sep 27, 2023
f585492
Merge branch 'main' into es-endpoint-discovery
sebelga Sep 28, 2023
defa39d
Merge branch 'main' into es-endpoint-discovery
sebelga Sep 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ packages/kbn-ci-stats-performance-metrics @elastic/kibana-operations
packages/kbn-ci-stats-reporter @elastic/kibana-operations
packages/kbn-ci-stats-shipper-cli @elastic/kibana-operations
packages/kbn-cli-dev-mode @elastic/kibana-operations
packages/cloud @elastic/kibana-core
x-pack/plugins/cloud_integrations/cloud_chat @elastic/kibana-core
x-pack/plugins/cloud_integrations/cloud_chat_provider @elastic/kibana-core
x-pack/plugins/cloud_integrations/cloud_data_migration @elastic/platform-onboarding
Expand Down
1 change: 1 addition & 0 deletions .i18nrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"customIntegrations": "src/plugins/custom_integrations",
"customIntegrationsPackage": "packages/kbn-custom-integrations",
"dashboard": "src/plugins/dashboard",
"cloud": "packages/cloud",
"domDragDrop": "packages/kbn-dom-drag-drop",
"controls": "src/plugins/controls",
"data": "src/plugins/data",
Expand Down
3 changes: 2 additions & 1 deletion docs/setup/connect-to-elasticsearch.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ Details for each programming language library that Elastic provides are in the
https://www.elastic.co/guide/en/elasticsearch/client/index.html[{es} Client documentation].

If you are running {kib} on our hosted {es} Service,
click *View deployment details* on the *Integrations* view
click *Endpoints* on the *Integrations* view
to verify your {es} endpoint and Cloud ID, and create API keys for integration.
Alternatively, the *Endpoints* are also accessible through the top bar help menu.

[float]
=== Add sample data
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
"@kbn/chart-expressions-common": "link:src/plugins/chart_expressions/common",
"@kbn/chart-icons": "link:packages/kbn-chart-icons",
"@kbn/charts-plugin": "link:src/plugins/charts",
"@kbn/cloud": "link:packages/cloud",
"@kbn/cloud-chat-plugin": "link:x-pack/plugins/cloud_integrations/cloud_chat",
"@kbn/cloud-chat-provider-plugin": "link:x-pack/plugins/cloud_integrations/cloud_chat_provider",
"@kbn/cloud-data-migration-plugin": "link:x-pack/plugins/cloud_integrations/cloud_data_migration",
Expand Down
3 changes: 3 additions & 0 deletions packages/cloud/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# @kbn/cloud

Empty package generated by @kbn/generate
132 changes: 132 additions & 0 deletions packages/cloud/deployment_details/deployment_details.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
/*
* 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 {
EuiForm,
EuiFormRow,
EuiFieldText,
EuiCopy,
EuiButtonIcon,
EuiFlexGroup,
EuiFlexItem,
EuiLink,
EuiButtonEmpty,
EuiSpacer,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { useDeploymentDetails } from './services';

export const DeploymentDetails = ({ closeModal }: { closeModal?: () => void }) => {
const { cloudId, elasticsearchUrl, managementUrl, learnMoreUrl, navigateToUrl } =
useDeploymentDetails();
const isInsideModal = !!closeModal;

if (!cloudId) {
return null;
}

return (
<>
sebelga marked this conversation as resolved.
Show resolved Hide resolved
<EuiForm component="div">
{/* Elastic endpoint */}
{elasticsearchUrl && (
<EuiFormRow
label={i18n.translate('cloud.deploymentDetails.elasticEndpointLabel', {
defaultMessage: 'Elastic endpoint',
})}
fullWidth
>
<EuiFlexGroup gutterSize="s">
<EuiFlexItem>
<EuiFieldText
value={elasticsearchUrl}
fullWidth
disabled
data-test-subj="deploymentDetailsEsEndpoint"
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiCopy textToCopy={elasticsearchUrl}>
{(copy) => (
<EuiButtonIcon
onClick={copy}
iconType="copyClipboard"
display="base"
size="m"
/>
)}
</EuiCopy>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFormRow>
sebelga marked this conversation as resolved.
Show resolved Hide resolved
)}

{/* Cloud ID */}
<EuiFormRow
label={i18n.translate('cloud.deploymentDetails.cloudIDLabel', {
defaultMessage: 'Cloud ID',
})}
fullWidth
>
<EuiFlexGroup gutterSize="s">
<EuiFlexItem>
<EuiFieldText
value={cloudId}
fullWidth
disabled
data-test-subj="deploymentDetailsCloudID"
/>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiCopy textToCopy={cloudId}>
{(copy) => (
<EuiButtonIcon onClick={copy} iconType="copyClipboard" display="base" size="m" />
)}
</EuiCopy>
</EuiFlexItem>
</EuiFlexGroup>
</EuiFormRow>

<EuiSpacer size="m" />

{managementUrl && (
<EuiFlexGroup gutterSize="m" justifyContent="spaceBetween" alignItems="center">
<EuiFlexItem grow={false}>
{/* eslint-disable-next-line @elastic/eui/href-or-on-click */}
<EuiButtonEmpty
href={managementUrl}
onClick={(e: any) => {
sebelga marked this conversation as resolved.
Show resolved Hide resolved
e.preventDefault();
navigateToUrl(managementUrl);
if (closeModal) {
closeModal();
}
}}
sebelga marked this conversation as resolved.
Show resolved Hide resolved
flush="left"
>
{i18n.translate('cloud.deploymentDetails.createManageApiKeysButtonLabel', {
defaultMessage: 'Create and manage API keys',
})}
</EuiButtonEmpty>
</EuiFlexItem>
{!isInsideModal && (
<EuiFlexItem grow={false}>
<EuiLink external href={learnMoreUrl} target="_blank">
{i18n.translate('cloud.deploymentDetails.learnMoreButtonLabel', {
defaultMessage: 'Learn more',
})}
</EuiLink>
</EuiFlexItem>
)}
</EuiFlexGroup>
)}
</EuiForm>
</>
);
};
69 changes: 69 additions & 0 deletions packages/cloud/deployment_details/deployment_details_modal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* 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, { type FC } from 'react';
import { i18n } from '@kbn/i18n';
import {
EuiButton,
EuiFlexGroup,
EuiFlexItem,
EuiLink,
EuiModal,
EuiModalBody,
EuiModalFooter,
EuiModalHeader,
EuiModalHeaderTitle,
} from '@elastic/eui';
import { useDeploymentDetails } from './services';
import { DeploymentDetails } from './deployment_details';

interface Props {
closeModal: () => void;
}

export const DeploymentDetailsModal: FC<Props> = ({ closeModal }) => {
const { learnMoreUrl } = useDeploymentDetails();

return (
<EuiModal
onClose={() => {
closeModal();
}}
style={{ width: 600 }}
data-test-subj="deploymentDetailsModal"
>
<EuiModalHeader>
<EuiModalHeaderTitle>
{i18n.translate('cloud.deploymentDetails.helpMenuLinks.endpoints', {
defaultMessage: 'Endpoints',
})}
</EuiModalHeaderTitle>
</EuiModalHeader>
<EuiModalBody>
<DeploymentDetails closeModal={closeModal} />
</EuiModalBody>
<EuiModalFooter>
<EuiFlexGroup alignItems="baseline" justifyContent="flexEnd">
<EuiFlexItem grow={false}>
<EuiLink external href={learnMoreUrl} target="_blank">
{i18n.translate('cloud.deploymentDetails.modal.learnMoreButtonLabel', {
defaultMessage: 'Learn more',
})}
</EuiLink>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiButton onClick={closeModal} fill>
{i18n.translate('cloud.deploymentDetails.modal.closeButtonLabel', {
defaultMessage: 'Close',
})}
</EuiButton>
</EuiFlexItem>
</EuiFlexGroup>
</EuiModalFooter>
</EuiModal>
);
};
11 changes: 11 additions & 0 deletions packages/cloud/deployment_details/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* 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 { DeploymentDetailsKibanaProvider, DeploymentDetailsProvider } from './services';
export { DeploymentDetails } from './deployment_details';
export { DeploymentDetailsModal } from './deployment_details_modal';
120 changes: 120 additions & 0 deletions packages/cloud/deployment_details/services.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* 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, { FC, useContext } from 'react';

export interface Services {
sebelga marked this conversation as resolved.
Show resolved Hide resolved
cloudId?: string;
elasticsearchUrl?: string;
managementUrl?: string;
learnMoreUrl: string;
navigateToUrl(url: string): Promise<void>;
}

const DeploymentDetailsContext = React.createContext<Services | null>(null);

/**
* Abstract external service Provider.
*/
export const DeploymentDetailsProvider: FC<Services> = ({ children, ...services }) => {
return (
<DeploymentDetailsContext.Provider value={services}>
{children}
</DeploymentDetailsContext.Provider>
);
};

/**
* Kibana-specific service types.
*/
export interface DeploymentDetailsKibanaDependencies {
/** CoreStart contract */
core: {
application: {
navigateToUrl(url: string): Promise<void>;
};
};
/** SharePluginStart contract */
share: {
url: {
locators: {
get(
id: string
): undefined | { useUrl: (params: { sectionId: string; appId: string }) => string };
};
};
};
/** CloudSetup contract */
cloud: {
isCloudEnabled: boolean;
cloudId?: string;
elasticsearchUrl?: string;
};
/** DocLinksStart contract */
docLinks: {
links: {
fleet: {
apiKeysLearnMore: string;
};
};
};
}

/**
* Kibana-specific Provider that maps to known dependency types.
*/
export const DeploymentDetailsKibanaProvider: FC<DeploymentDetailsKibanaDependencies> = ({
children,
...services
}) => {
const {
core: {
application: { navigateToUrl },
},
cloud: { isCloudEnabled, cloudId, elasticsearchUrl },
share: {
url: { locators },
},
docLinks: {
links: {
fleet: { apiKeysLearnMore },
},
},
} = services;

const managementUrl = locators
.get('MANAGEMENT_APP_LOCATOR')
?.useUrl({ sectionId: 'security', appId: 'api_keys' });

return (
<DeploymentDetailsProvider
cloudId={isCloudEnabled ? cloudId : undefined}
elasticsearchUrl={elasticsearchUrl}
managementUrl={managementUrl}
learnMoreUrl={apiKeysLearnMore}
navigateToUrl={navigateToUrl}
>
{children}
</DeploymentDetailsProvider>
);
};

/**
* React hook for accessing pre-wired services.
*/
export function useDeploymentDetails() {
const context = useContext(DeploymentDetailsContext);

if (!context) {
throw new Error(
'DeploymentDetailsContext is missing. Ensure your component or React root is wrapped with <DeploymentDetailsProvider /> or <DeploymentDetailsKibanaProvider />.'
);
}

return context;
}
11 changes: 11 additions & 0 deletions packages/cloud/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* 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 function foo() {
return 'hello world';
}
Loading