From 3630057dabe57f65c707977d17e5ccdecec18a54 Mon Sep 17 00:00:00 2001 From: Jedr Blaszyk Date: Mon, 18 Nov 2024 11:13:19 +0100 Subject: [PATCH] [Ent Search Plugin] Fix loading initial plugin data, save kbn version in kea, fix connector img version (#199777) ## Summary PR is a bugfix to dynamically populate the `version` of the connectors docker image shown in the onboarding. It's hardcoded to `8.15.0` now .... Ideally we want to backport this to 8.16.1 + Changes: - Given that we are already getting [kibanaVersion](https://github.com/elastic/kibana/blob/main/x-pack/plugins/enterprise_search/public/applications/index.tsx#L65) from the [backend](https://github.com/elastic/kibana/blob/main/x-pack/plugins/enterprise_search/public/plugin.ts#L212), I'm saving the version in `KibanaLogic` reducer and use it to popuale the docker image version - I realised that because of [this change](https://github.com/elastic/kibana/commit/664c1a0a08003f82cb88c9b4a51f194fbb42cd84#diff-19a48c92980fd550e48c5e1d4d1f9a2bec4d309909b7cfa693264c92b387fe3dR95) ~10 months ago, we stopped passing plugin data, due to `if (!this.config.host) return; // No API to call` therefore I removed this line to fix this. Why I think it's safe to merge? - It was only added 10 months ago, before things were working without this extra if statement - The backend logic handles the non-existent host: see [here](https://github.com/elastic/kibana/blob/main/x-pack/plugins/enterprise_search/server/lib/enterprise_search_config_api.ts#L45-L61) - We are guaranteed that other config fields exist, see [config schema](https://github.com/elastic/kibana/blob/d276b4899533b0bde2038c7fedfed7c30a74a80b/x-pack/plugins/enterprise_search/server/index.ts#L16-L42) Screenshot 2024-11-13 at 10 51 36 ### Checklist Delete any items that are not applicable to this PR. - [ ] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios - [ ] If a plugin configuration key changed, check if it needs to be allowlisted in the cloud and added to the [docker list](https://github.com/elastic/kibana/blob/main/src/dev/build/tasks/os_packages/docker_generator/resources/base/bin/kibana-docker) --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Elastic Machine (cherry picked from commit 5d00a0a098930b2292ea7777cd1ee9f46a91a778) --- .../applications/__mocks__/kea_logic/kibana_logic.mock.ts | 1 + .../connector_detail/components/docker_instructions_step.tsx | 4 +++- .../components/connector_detail/deployment.tsx | 3 +++ .../plugins/enterprise_search/public/applications/index.tsx | 1 + .../public/applications/shared/kibana/kibana_logic.ts | 3 +++ x-pack/plugins/enterprise_search/public/plugin.ts | 1 - 6 files changed, 11 insertions(+), 2 deletions(-) diff --git a/x-pack/plugins/enterprise_search/public/applications/__mocks__/kea_logic/kibana_logic.mock.ts b/x-pack/plugins/enterprise_search/public/applications/__mocks__/kea_logic/kibana_logic.mock.ts index cca5523ded681..38b2d42f4a4d0 100644 --- a/x-pack/plugins/enterprise_search/public/applications/__mocks__/kea_logic/kibana_logic.mock.ts +++ b/x-pack/plugins/enterprise_search/public/applications/__mocks__/kea_logic/kibana_logic.mock.ts @@ -46,6 +46,7 @@ export const mockKibanaValues = { indexMappingComponent: null, isCloud: false, isSidebarEnabled: true, + kibanaVersion: null, lens: { EmbeddableComponent: jest.fn(), stateHelperApi: jest.fn().mockResolvedValue({ diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/connector_detail/components/docker_instructions_step.tsx b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/connector_detail/components/docker_instructions_step.tsx index 46e7998444729..ea5b59c4d3263 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/connector_detail/components/docker_instructions_step.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/connector_detail/components/docker_instructions_step.tsx @@ -34,12 +34,14 @@ export interface DockerInstructionsStepProps { hasApiKey: boolean; isWaitingForConnector: boolean; serviceType: string; + connectorVersion: string; } export const DockerInstructionsStep: React.FC = ({ connectorId, isWaitingForConnector, serviceType, apiKeyData, + connectorVersion, }) => { const [isOpen, setIsOpen] = React.useState('open'); const { elasticsearchUrl } = useCloudDetails(); @@ -163,7 +165,7 @@ export const DockerInstructionsStep: React.FC = ({ showTopBar={false} languageType="bash" codeSnippet={getRunFromDockerSnippet({ - version: '8.15.0', + version: connectorVersion, })} /> diff --git a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/connector_detail/deployment.tsx b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/connector_detail/deployment.tsx index 2a617a87df8bc..7bf1f101cc71a 100644 --- a/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/connector_detail/deployment.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/enterprise_search_content/components/connector_detail/deployment.tsx @@ -30,6 +30,7 @@ import { ConnectorStatus } from '@kbn/search-connectors'; import { Status } from '../../../../../common/types/api'; +import { KibanaLogic } from '../../../shared/kibana'; import { GetApiKeyByIdLogic } from '../../api/api_key/get_api_key_by_id_api_logic'; import { GenerateConnectorApiKeyApiLogic } from '../../api/connector/generate_connector_api_key_api_logic'; @@ -48,6 +49,7 @@ export const ConnectorDeployment: React.FC = () => { const [selectedDeploymentMethod, setSelectedDeploymentMethod] = useState<'docker' | 'source'>( 'docker' ); + const { kibanaVersion } = useValues(KibanaLogic); const { generatedData, isGenerateLoading } = useValues(DeploymentLogic); const { index, isLoading, connector, connectorId } = useValues(ConnectorViewLogic); const { fetchConnector } = useActions(ConnectorViewLogic); @@ -199,6 +201,7 @@ export const ConnectorDeployment: React.FC = () => { serviceType={connector.service_type ?? ''} isWaitingForConnector={isWaitingForConnector} apiKeyData={apiKey} + connectorVersion={kibanaVersion ?? ''} /> )} diff --git a/x-pack/plugins/enterprise_search/public/applications/index.tsx b/x-pack/plugins/enterprise_search/public/applications/index.tsx index eafa8827869d8..cd42372d838d0 100644 --- a/x-pack/plugins/enterprise_search/public/applications/index.tsx +++ b/x-pack/plugins/enterprise_search/public/applications/index.tsx @@ -118,6 +118,7 @@ export const renderApp = ( history, indexMappingComponent, isSidebarEnabled, + kibanaVersion, lens, ml, navigateToUrl, diff --git a/x-pack/plugins/enterprise_search/public/applications/shared/kibana/kibana_logic.ts b/x-pack/plugins/enterprise_search/public/applications/shared/kibana/kibana_logic.ts index f74345a1c75c1..933e25a6dd68e 100644 --- a/x-pack/plugins/enterprise_search/public/applications/shared/kibana/kibana_logic.ts +++ b/x-pack/plugins/enterprise_search/public/applications/shared/kibana/kibana_logic.ts @@ -59,6 +59,7 @@ export interface KibanaLogicProps { history: ScopedHistory; indexMappingComponent?: React.FC; isSidebarEnabled: boolean; + kibanaVersion?: string; lens?: LensPublicStart; ml?: MlPluginStart; navigateToUrl: RequiredFieldsOnly; @@ -92,6 +93,7 @@ export interface KibanaValues { indexMappingComponent: React.FC | null; isCloud: boolean; isSidebarEnabled: boolean; + kibanaVersion: string | null; lens: LensPublicStart | null; ml: MlPluginStart | null; navigateToUrl(path: string, options?: CreateHrefOptions): Promise; @@ -130,6 +132,7 @@ export const KibanaLogic = kea>({ history: [props.history, {}], indexMappingComponent: [props.indexMappingComponent || null, {}], isSidebarEnabled: [props.isSidebarEnabled, {}], + kibanaVersion: [props.kibanaVersion || null, {}], lens: [props.lens || null, {}], ml: [props.ml || null, {}], navigateToUrl: [ diff --git a/x-pack/plugins/enterprise_search/public/plugin.ts b/x-pack/plugins/enterprise_search/public/plugin.ts index 06f14ba3d7037..80d7840501d3a 100644 --- a/x-pack/plugins/enterprise_search/public/plugin.ts +++ b/x-pack/plugins/enterprise_search/public/plugin.ts @@ -199,7 +199,6 @@ export class EnterpriseSearchPlugin implements Plugin { this.esConfig = { elasticsearch_host: ELASTICSEARCH_URL_PLACEHOLDER }; } - if (!this.config.host) return; // No API to call if (this.hasInitialized) return; // We've already made an initial call try {