Add implementation of the Elasticsearch Python client integration (#144967)

This commit is contained in:
Miriam Eid 2022-11-14 11:14:01 +02:00 committed by GitHub
parent b2ebf68914
commit 8619d513b0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 176 additions and 5 deletions

View file

@ -20,7 +20,7 @@ pageLoadAssetSize:
controls: 40000
core: 435325
crossClusterReplication: 65408
customIntegrations: 28810
customIntegrations: 44305
dashboard: 82025
dashboardEnhanced: 65646
data: 454087

View file

@ -115,9 +115,9 @@ export const languageIntegrations: LanguageIntegration[] = [
description: i18n.translate('customIntegrations.languageclients.PythonDescription', {
defaultMessage: 'Index data to Elasticsearch with the Python client.',
}),
docUrlTemplate: `${ELASTICSEARCH_CLIENT_URL}/python-api/{branch}/index.html`,
docUrlTemplate: '',
integrationsAppUrl: `/app/integrations/language_clients/python/overview`,
exportLanguageUiComponent: false,
exportLanguageUiComponent: true,
},
{
id: 'rust',

View file

@ -0,0 +1,170 @@
/*
* 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';
// eslint-disable-next-line @kbn/eslint/module_migration
import styled from 'styled-components';
import {
EuiCode,
EuiCodeBlock,
EuiFlexGroup,
EuiFlexItem,
EuiPage,
EuiPageBody,
EuiPageHeader,
EuiPageSection,
EuiSpacer,
EuiText,
EuiTitle,
EuiPanel,
EuiImage,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { euiThemeVars } from '@kbn/ui-theme';
import icon from '../../../assets/language_clients/python.svg';
const CenterColumn = styled(EuiFlexItem)`
max-width: 740px;
`;
const FixedHeader = styled.div`
width: 100%;
height: 196px;
border-bottom: 1px solid ${euiThemeVars.euiColorLightShade};
`;
const IconPanel = styled(EuiPanel)`
padding: ${(props) => props.theme.eui.euiSizeXL};
width: ${(props) =>
parseFloat(props.theme.eui.euiSize) * 6 + parseFloat(props.theme.eui.euiSizeXL) * 2}px;
svg,
img {
height: ${(props) => parseFloat(props.theme.eui.euiSize) * 6}px;
width: ${(props) => parseFloat(props.theme.eui.euiSize) * 6}px;
}
.euiFlexItem {
height: ${(props) => parseFloat(props.theme.eui.euiSize) * 6}px;
justify-content: center;
}
`;
const TopFlexGroup = styled(EuiFlexGroup)`
max-width: 1150px;
margin-left: auto;
margin-right: auto;
padding: calc(${euiThemeVars.euiSizeXL} * 2) ${euiThemeVars.euiSizeM} 0 ${euiThemeVars.euiSizeM};
`;
export const ElasticsearchPyClientReadme = () => {
return (
<>
<FixedHeader>
<TopFlexGroup alignItems="center" justifyContent="flexStart">
<EuiFlexItem grow={false}>
<IconPanel>
<EuiImage size="fullWidth" src={icon} alt="icon" />
</IconPanel>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<EuiTitle size="l">
<h1>
<FormattedMessage
id="customIntegrations.languageClients.PythonElasticsearch.readme.title"
defaultMessage="Elasticsearch Python Client"
/>
</h1>
</EuiTitle>
</EuiFlexItem>
</TopFlexGroup>
</FixedHeader>
<EuiFlexGroup alignItems="flexStart" justifyContent="center">
<CenterColumn>
<EuiPage paddingSize="m">
<EuiPageBody panelled>
<EuiPageSection>
<EuiPageHeader
description={
<EuiText>
<FormattedMessage
id="customIntegrations.languageClients.PythonElasticsearch.readme.intro"
defaultMessage="Getting started with the Elasticsearch Python Client requires a few steps."
/>
</EuiText>
}
/>
</EuiPageSection>
<EuiPageSection>
<EuiTitle>
<h2>
<FormattedMessage
id="customIntegrations.languageClients.PythonElasticsearch.readme.install"
defaultMessage="Install the Elasticsearch Python Client"
/>
</h2>
</EuiTitle>
<EuiSpacer size="s" />
<EuiCodeBlock language="shell" isCopyable>
{`# The Python client for Elasticsearch can be installed with pip: \n`}
{`$ python -m pip install elasticsearch`}
</EuiCodeBlock>
</EuiPageSection>
<EuiPageSection>
<EuiTitle>
<h2>
<FormattedMessage
id="customIntegrations.languageClients.PythonElasticsearch.readme.connecting"
defaultMessage="Connecting to Elastic cloud"
/>
</h2>
</EuiTitle>
<EuiText>
<FormattedMessage
id="customIntegrations.languageClients.PythonElasticsearch.readme.connectingText"
defaultMessage="You can connect to Elastic Cloud using an {api_key} and a {cloud_id}:"
values={{
api_key: <EuiCode>API key</EuiCode>,
cloud_id: <EuiCode>Cloud ID</EuiCode>,
}}
/>
</EuiText>
<EuiSpacer size="s" />
<EuiCodeBlock isCopyable language="python">
{`
from elasticsearch import Elasticsearch
# Found in the 'Manage this deployment' page
CLOUD_ID = "deployment-name:dXMtZWFzdDQuZ2Nw..."
# Found in the 'Management' page under the section 'Security'
API_KEY = "YOUR_API_KEY"
# Create the client instance
client = Elasticsearch(
cloud_id=CLOUD_ID,
api_key=API_KEY,
)
`}
</EuiCodeBlock>
</EuiPageSection>
</EuiPageBody>
</EuiPage>
</CenterColumn>
</EuiFlexGroup>
</>
);
};

View file

@ -24,6 +24,7 @@ import { CustomIntegrationsServicesProvider } from './services';
import { servicesFactory } from './services/kibana';
import { SampleClientReadme } from './components/fleet_integration/sample/sample_client_readme';
import { ElasticsearchJsClientReadme } from './components/fleet_integration/elasticsearch_js/elasticsearch_js_readme';
import { ElasticsearchPyClientReadme } from './components/fleet_integration/elasticsearch_py/elasticsearch_py_readme';
export class CustomIntegrationsPlugin
implements Plugin<CustomIntegrationsSetup, CustomIntegrationsStart>
@ -50,6 +51,7 @@ export class CustomIntegrationsPlugin
const languageClientsUiComponents = {
sample: SampleClientReadme,
javascript: ElasticsearchJsClientReadme,
python: ElasticsearchPyClientReadme,
};
const ContextProvider: React.FC = ({ children }) => (

View file

@ -108,8 +108,7 @@ describe('CustomIntegrationsPlugin', () => {
description: 'Index data to Elasticsearch with the Python client.',
type: 'ui_link',
shipper: 'language_clients',
uiInternalPath:
'https://www.elastic.co/guide/en/elasticsearch/client/python-api/branch/index.html',
uiInternalPath: '/app/integrations/language_clients/python/overview',
isBeta: false,
icons: [{ type: 'svg', src: undefined }],
categories: ['elastic_stack', 'custom', 'language_client'],