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

[Fleet] Show callout when EPR unavailable #117598

Merged
merged 16 commits into from
Nov 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ readonly links: {
fleetServerAddFleetServer: string;
settings: string;
settingsFleetServerHostSettings: string;
settingsFleetServerProxySettings: string;
troubleshooting: string;
elasticAgent: string;
datastreams: string;
Expand All @@ -252,6 +253,7 @@ readonly links: {
upgradeElasticAgent712lower: string;
learnMoreBlog: string;
apiKeysLearnMore: string;
onPremRegistry: string;
}>;
readonly ecs: {
readonly guide: string;
Expand Down
4 changes: 4 additions & 0 deletions src/core/public/doc_links/doc_links_service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ export class DocLinksService {
fleetServerAddFleetServer: `${FLEET_DOCS}fleet-server.html#add-fleet-server`,
settings: `${FLEET_DOCS}fleet-settings.html#fleet-server-hosts-setting`,
settingsFleetServerHostSettings: `${FLEET_DOCS}fleet-settings.html#fleet-server-hosts-setting`,
settingsFleetServerProxySettings: `${KIBANA_DOCS}fleet-settings-kb.html#fleet-data-visualizer-settings`,
troubleshooting: `${FLEET_DOCS}fleet-troubleshooting.html`,
elasticAgent: `${FLEET_DOCS}elastic-agent-installation.html`,
beatsAgentComparison: `${FLEET_DOCS}beats-agent-comparison.html`,
Expand All @@ -500,6 +501,7 @@ export class DocLinksService {
upgradeElasticAgent712lower: `${FLEET_DOCS}upgrade-elastic-agent.html#upgrade-7.12-lower`,
learnMoreBlog: `${ELASTIC_WEBSITE_URL}blog/elastic-agent-and-fleet-make-it-easier-to-integrate-your-systems-with-elastic`,
apiKeysLearnMore: `${KIBANA_DOCS}api-keys.html`,
onPremRegistry: `${ELASTIC_WEBSITE_URL}guide/en/integrations-developer/${DOC_LINK_VERSION}/air-gapped.html`,
},
ecs: {
guide: `${ELASTIC_WEBSITE_URL}guide/en/ecs/current/index.html`,
Expand Down Expand Up @@ -765,6 +767,7 @@ export interface DocLinksStart {
fleetServerAddFleetServer: string;
settings: string;
settingsFleetServerHostSettings: string;
settingsFleetServerProxySettings: string;
troubleshooting: string;
elasticAgent: string;
datastreams: string;
Expand All @@ -774,6 +777,7 @@ export interface DocLinksStart {
upgradeElasticAgent712lower: string;
learnMoreBlog: string;
apiKeysLearnMore: string;
onPremRegistry: string;
}>;
readonly ecs: {
readonly guide: string;
Expand Down
2 changes: 2 additions & 0 deletions src/core/public/public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,7 @@ export interface DocLinksStart {
fleetServerAddFleetServer: string;
settings: string;
settingsFleetServerHostSettings: string;
settingsFleetServerProxySettings: string;
troubleshooting: string;
elasticAgent: string;
datastreams: string;
Expand All @@ -720,6 +721,7 @@ export interface DocLinksStart {
upgradeElasticAgent712lower: string;
learnMoreBlog: string;
apiKeysLearnMore: string;
onPremRegistry: string;
}>;
readonly ecs: {
readonly guide: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@
* 2.0.
*/

import type { FunctionComponent } from 'react';
import React, { memo, useMemo, useState } from 'react';
import { useLocation, useHistory, useParams } from 'react-router-dom';
import _ from 'lodash';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import {
EuiHorizontalRule,
EuiFlexItem,
EuiFlexGrid,
EuiSpacer,
EuiCard,
EuiIcon,
EuiCallOut,
EuiLink,
} from '@elastic/eui';

import { useStartServices } from '../../../../hooks';
Expand Down Expand Up @@ -52,6 +56,76 @@ import type { CategoryFacet } from './category_facets';
import type { CategoryParams } from '.';
import { getParams, categoryExists, mapToCard } from '.';

const NoEprCallout: FunctionComponent<{ statusCode?: number }> = ({
statusCode,
}: {
statusCode?: number;
}) => {
let titleMessage;
let descriptionMessage;
if (statusCode === 502) {
titleMessage = i18n.translate('xpack.fleet.epmList.eprUnavailableBadGatewayCalloutTitle', {
defaultMessage:
'Kibana cannot reach the Elastic Package Registry, which provides Elastic Agent integrations\n',
});
descriptionMessage = (
<FormattedMessage
id="xpack.fleet.epmList.eprUnavailableCallouBdGatewaytTitleMessage"
defaultMessage="To view these integrations, configure a {registryproxy} or host {onpremregistry}."
values={{
registryproxy: <ProxyLink />,
onpremregistry: <OnPremLink />,
}}
/>
);
} else {
titleMessage = i18n.translate('xpack.fleet.epmList.eprUnavailable400500CalloutTitle', {
defaultMessage:
'Kibana cannot connect to the Elastic Package Registry, which provides Elastic Agent integrations\n',
});
descriptionMessage = (
<FormattedMessage
id="xpack.fleet.epmList.eprUnavailableCallout400500TitleMessage"
defaultMessage="Ensure the {registryproxy} or {onpremregistry} is configured correctly, or try again later."
values={{
registryproxy: <ProxyLink />,
onpremregistry: <OnPremLink />,
}}
/>
);
}

return (
<EuiCallOut title={titleMessage} iconType="iInCircle" color={'warning'}>
<p>{descriptionMessage}</p>
</EuiCallOut>
);
};

function ProxyLink() {
const { docLinks } = useStartServices();

return (
<EuiLink href={docLinks.links.fleet.settingsFleetServerProxySettings} target="_blank">
{i18n.translate('xpack.fleet.epmList.proxyLinkSnippedText', {
defaultMessage: 'proxy server',
})}
</EuiLink>
);
}

function OnPremLink() {
const { docLinks } = useStartServices();

return (
<EuiLink href={docLinks.links.fleet.onPremRegistry} target="_blank">
{i18n.translate('xpack.fleet.epmList.onPremLinkSnippetText', {
defaultMessage: 'your own registry',
})}
</EuiLink>
);
}

function getAllCategoriesFromIntegrations(pkg: PackageListItem) {
if (!doesPackageHaveIntegrations(pkg)) {
return pkg.categories;
Expand Down Expand Up @@ -133,10 +207,13 @@ export const AvailablePackages: React.FC = memo(() => {
history.replace(pagePathGetters.integrations_all({ searchTerm: search })[1]);
}

const { data: eprPackages, isLoading: isLoadingAllPackages } = useGetPackages({
const {
data: eprPackages,
isLoading: isLoadingAllPackages,
error: eprPackageLoadingError,
} = useGetPackages({
category: '',
});

const eprIntegrationList = useMemo(
() => packageListToIntegrationsList(eprPackages?.response || []),
[eprPackages]
Expand Down Expand Up @@ -166,18 +243,23 @@ export const AvailablePackages: React.FC = memo(() => {
return a.title.localeCompare(b.title);
});

const { data: eprCategories, isLoading: isLoadingCategories } = useGetCategories({
const {
data: eprCategories,
isLoading: isLoadingCategories,
error: eprCategoryLoadingError,
} = useGetCategories({
include_policy_templates: true,
});

const categories = useMemo(() => {
const eprAndCustomCategories: CategoryFacet[] =
isLoadingCategories || !eprCategories
? []
: mergeCategoriesAndCount(
eprCategories.response as Array<{ id: string; title: string; count: number }>,
cards
);
const eprAndCustomCategories: CategoryFacet[] = isLoadingCategories
? []
: mergeCategoriesAndCount(
eprCategories
? (eprCategories.response as Array<{ id: string; title: string; count: number }>)
: [],
cards
);
return [
{
...ALL_CATEGORY,
Expand Down Expand Up @@ -281,6 +363,12 @@ export const AvailablePackages: React.FC = memo(() => {
</>
);

let noEprCallout;
if (eprPackageLoadingError || eprCategoryLoadingError) {
const error = eprPackageLoadingError || eprCategoryLoadingError;
noEprCallout = <NoEprCallout statusCode={error?.statusCode} />;
}

return (
<PackageListGrid
featuredList={featuredList}
Expand All @@ -291,6 +379,7 @@ export const AvailablePackages: React.FC = memo(() => {
setSelectedCategory={setSelectedCategory}
onSearchChange={setSearchTerm}
showMissingIntegrationMessage
callout={noEprCallout}
/>
);
});
9 changes: 8 additions & 1 deletion x-pack/plugins/fleet/server/errors/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ import {
IngestManagerError,
PackageNotFoundError,
PackageUnsupportedMediaTypeError,
RegistryConnectionError,
RegistryError,
RegistryResponseError,
} from './index';

type IngestErrorHandler = (
Expand All @@ -40,7 +42,12 @@ interface IngestErrorHandlerParams {
// this type is based on BadRequest values observed while debugging https://github.com/elastic/kibana/issues/75862

const getHTTPResponseCode = (error: IngestManagerError): number => {
if (error instanceof RegistryError) {
if (error instanceof RegistryResponseError) {
// 4xx/5xx's from EPR
return 500;
}
if (error instanceof RegistryConnectionError || error instanceof RegistryError) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding explicit check on both, even though RegistryConnectionError subclasses from RegistryError. It may help as in-code documentation, and doesn't tie it as much to class-hierarchy.

// Connection errors (ie. RegistryConnectionError) / fallback (RegistryError) from EPR
return 502; // Bad Gateway
}
if (error instanceof PackageNotFoundError) {
Expand Down