Skip to content

Commit

Permalink
[8.x] [Onboarding] Remove retrying when fetch index API query fails (e…
Browse files Browse the repository at this point in the history
…lastic#193634) (elastic#194173)

# Backport

This will backport the following commits from `main` to `8.x`:
- [[Onboarding] Remove retrying when fetch index API query fails
(elastic#193634)](elastic#193634)

<!--- Backport version: 9.4.3 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT [{"author":{"name":"Saarika
Bhasi","email":"[email protected]"},"sourceCommit":{"committedDate":"2024-09-26T15:08:32Z","message":"[Onboarding]
Remove retrying when fetch index API query fails (elastic#193634)\n\n##
Summary\r\n\r\nThis Pr set retrying to `false` when fetch Index api
returns 404 status.\r\nFor all other status code, the fetch index api is
retried until failure\r\ncount is 3.\r\n\r\nAlso updated error component
to show error message returned from\r\nelasticsearch\r\n\r\n###
screenshot\r\n\r\n**Status code: 404** \r\n\r\n<img width=\"1286\"
alt=\"Screenshot 2024-09-25 at 11 07
20 AM\"\r\nsrc=\"https://github.com/user-attachments/assets/982b5037-b8a5-43d7-bd5f-874929a74ede\">\r\n\r\n**Status
code: 500** \r\n<img width=\"1286\" alt=\"Screenshot 2024-09-25 at 11 16
26 AM\"\r\nsrc=\"https://github.com/user-attachments/assets/7b7ecbbe-14af-4d9d-8107-bcee9fa384bf\">\r\n\r\n**How
to test:** \r\n1. Enable searchIndices plugin in `kibana.dev.yml` as
this plugin is\r\nbehind Feature
flag\r\n```\r\nxpack.searchIndices.enabled: true\r\n\r\n```\r\n2.
[Create
new\r\nindex](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html)\r\n3.
Navigate
to\r\n`/app/elasticsearch/indices/index_details/${indexName}/data`\r\n4.
[
Delete\r\nindex](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html)\r\n5.
Wait for the error screen to appear. Note error message is
shown\r\nafter one `/internal/index_management/indices/my-index` API is
failed\r\n\r\n### Checklist\r\n\r\nDelete any items that are not
applicable to this PR.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests
changed","sha":"2583b961bb37e9f498157efbe1710b8661272eba","branchLabelMapping":{"^v9.0.0$":"main","^v8.16.0$":"8.x","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["release_note:skip","v9.0.0","Team:Search","backport:prev-minor","v8.16.0"],"title":"[Onboarding]
Remove retrying when fetch index API query
fails","number":193634,"url":"https://github.com/elastic/kibana/pull/193634","mergeCommit":{"message":"[Onboarding]
Remove retrying when fetch index API query fails (elastic#193634)\n\n##
Summary\r\n\r\nThis Pr set retrying to `false` when fetch Index api
returns 404 status.\r\nFor all other status code, the fetch index api is
retried until failure\r\ncount is 3.\r\n\r\nAlso updated error component
to show error message returned from\r\nelasticsearch\r\n\r\n###
screenshot\r\n\r\n**Status code: 404** \r\n\r\n<img width=\"1286\"
alt=\"Screenshot 2024-09-25 at 11 07
20 AM\"\r\nsrc=\"https://github.com/user-attachments/assets/982b5037-b8a5-43d7-bd5f-874929a74ede\">\r\n\r\n**Status
code: 500** \r\n<img width=\"1286\" alt=\"Screenshot 2024-09-25 at 11 16
26 AM\"\r\nsrc=\"https://github.com/user-attachments/assets/7b7ecbbe-14af-4d9d-8107-bcee9fa384bf\">\r\n\r\n**How
to test:** \r\n1. Enable searchIndices plugin in `kibana.dev.yml` as
this plugin is\r\nbehind Feature
flag\r\n```\r\nxpack.searchIndices.enabled: true\r\n\r\n```\r\n2.
[Create
new\r\nindex](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html)\r\n3.
Navigate
to\r\n`/app/elasticsearch/indices/index_details/${indexName}/data`\r\n4.
[
Delete\r\nindex](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html)\r\n5.
Wait for the error screen to appear. Note error message is
shown\r\nafter one `/internal/index_management/indices/my-index` API is
failed\r\n\r\n### Checklist\r\n\r\nDelete any items that are not
applicable to this PR.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests
changed","sha":"2583b961bb37e9f498157efbe1710b8661272eba"}},"sourceBranch":"main","suggestedTargetBranches":["8.x"],"targetPullRequestStates":[{"branch":"main","label":"v9.0.0","branchLabelMappingKey":"^v9.0.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/193634","number":193634,"mergeCommit":{"message":"[Onboarding]
Remove retrying when fetch index API query fails (elastic#193634)\n\n##
Summary\r\n\r\nThis Pr set retrying to `false` when fetch Index api
returns 404 status.\r\nFor all other status code, the fetch index api is
retried until failure\r\ncount is 3.\r\n\r\nAlso updated error component
to show error message returned from\r\nelasticsearch\r\n\r\n###
screenshot\r\n\r\n**Status code: 404** \r\n\r\n<img width=\"1286\"
alt=\"Screenshot 2024-09-25 at 11 07
20 AM\"\r\nsrc=\"https://github.com/user-attachments/assets/982b5037-b8a5-43d7-bd5f-874929a74ede\">\r\n\r\n**Status
code: 500** \r\n<img width=\"1286\" alt=\"Screenshot 2024-09-25 at 11 16
26 AM\"\r\nsrc=\"https://github.com/user-attachments/assets/7b7ecbbe-14af-4d9d-8107-bcee9fa384bf\">\r\n\r\n**How
to test:** \r\n1. Enable searchIndices plugin in `kibana.dev.yml` as
this plugin is\r\nbehind Feature
flag\r\n```\r\nxpack.searchIndices.enabled: true\r\n\r\n```\r\n2.
[Create
new\r\nindex](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html)\r\n3.
Navigate
to\r\n`/app/elasticsearch/indices/index_details/${indexName}/data`\r\n4.
[
Delete\r\nindex](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-delete-index.html)\r\n5.
Wait for the error screen to appear. Note error message is
shown\r\nafter one `/internal/index_management/indices/my-index` API is
failed\r\n\r\n### Checklist\r\n\r\nDelete any items that are not
applicable to this PR.\r\n\r\n- [x] [Unit or
functional\r\ntests](https://www.elastic.co/guide/en/kibana/master/development-tests.html)\r\nwere
updated or added to match the most common scenarios\r\n- [x] [Flaky
Test\r\nRunner](https://ci-stats.kibana.dev/trigger_flaky_test_runner/1)
was\r\nused on any tests
changed","sha":"2583b961bb37e9f498157efbe1710b8661272eba"}},{"branch":"8.x","label":"v8.16.0","branchLabelMappingKey":"^v8.16.0$","isSourceBranch":false,"state":"NOT_CREATED"}]}]
BACKPORT-->

Co-authored-by: Saarika Bhasi <[email protected]>
  • Loading branch information
kibanamachine and saarikabhasi authored Sep 26, 2024
1 parent 9c3af40 commit 8125595
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,18 @@ export const SearchIndexDetailsPage = () => {
const tabId = decodeURIComponent(useParams<{ tabId: string }>().tabId);

const { console: consolePlugin, docLinks, application, history } = useKibana().services;
const { data: index, refetch, isError: isIndexError, isInitialLoading } = useIndex(indexName);
const {
data: index,
refetch,
isError: isIndexError,
isInitialLoading,
error: indexLoadingError,
} = useIndex(indexName);
const {
data: mappings,
isError: isMappingsError,
isInitialLoading: isMappingsInitialLoading,
error: mappingsError,
} = useIndexMapping(indexName);

const detailsPageTabs: EuiTabbedContentTab[] = useMemo(() => {
Expand Down Expand Up @@ -103,6 +110,19 @@ export const SearchIndexDetailsPage = () => {
const refetchIndex = useCallback(() => {
refetch();
}, [refetch]);
const indexError = useMemo(
() =>
isIndexError
? {
title: indexLoadingError ? indexLoadingError.body?.error : '',
message: indexLoadingError ? indexLoadingError.body?.message : '',
}
: {
title: mappingsError ? mappingsError.body?.error : '',
message: mappingsError ? mappingsError.body?.message : '',
},
[isIndexError, indexLoadingError, mappingsError]
);
const [showMoreOptions, setShowMoreOptions] = useState<boolean>(false);
const [isShowingDeleteModal, setShowDeleteIndexModal] = useState<boolean>(false);
const moreOptionsPopover = (
Expand Down Expand Up @@ -165,7 +185,7 @@ export const SearchIndexDetailsPage = () => {
>
{isIndexError || isMappingsError || !index || !mappings ? (
<IndexloadingError
indexName={indexName}
error={indexError}
navigateToIndexListPage={navigateToIndexListPage}
reloadFunction={refetchIndex}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,15 @@ import {
import React from 'react';
import { FormattedMessage } from '@kbn/i18n-react';
interface IndexloadingErrorProps {
indexName: string;
error: {
title: string;
message: string;
};
navigateToIndexListPage: () => void;
reloadFunction: () => void;
}
export const IndexloadingError = ({
indexName,
error: { title, message },
navigateToIndexListPage,
reloadFunction,
}: IndexloadingErrorProps) => (
Expand All @@ -31,18 +34,21 @@ export const IndexloadingError = ({
title={
<h2>
<FormattedMessage
id="xpack.searchIndices.pageLoaError.errorTitle"
defaultMessage="Unable to load index details"
id="xpack.searchIndices.pageLoadError.errorTitle"
defaultMessage="{error}"
values={{
error: title,
}}
/>
</h2>
}
body={
<EuiText color="subdued">
<FormattedMessage
id="xpack.searchIndices.pageLoadError.description"
defaultMessage="We encountered an error loading data for index {indexName}. Make sure that the index name in the URL is correct and try again."
defaultMessage="{message}"
values={{
indexName,
message,
}}
/>
</EuiText>
Expand Down
6 changes: 4 additions & 2 deletions x-pack/plugins/search_indices/public/hooks/api/use_index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ const POLLING_INTERVAL = 15 * 1000;
export const useIndex = (indexName: string) => {
const { http } = useKibana().services;
const queryKey = [QueryKeys.FetchIndex, indexName];
const result = useQuery({
const result = useQuery<Index, { body: { statusCode: number; message: string; error: string } }>({
queryKey,
refetchInterval: POLLING_INTERVAL,
refetchIntervalInBackground: true,
refetchOnWindowFocus: 'always',
retry: 3,
retry: (failureCount, error) => {
return !(error?.body?.statusCode === 404 || failureCount === 3);
},
queryFn: () =>
http.fetch<Index>(`/internal/index_management/indices/${encodeURIComponent(indexName)}`),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { Mappings } from '../../types';
export const useIndexMapping = (indexName: string) => {
const { http } = useKibana().services;
const queryKey = ['fetchMapping', indexName];
const result = useQuery({
const result = useQuery<Mappings, { body: { message: string; error: string } }>({
queryKey,
refetchOnWindowFocus: 'always',
queryFn: () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ export function SvlSearchIndexDetailPageProvider({ getService }: FtrProviderCont
await testSubjects.existOrFail('loadingErrorBackToIndicesButton');
await testSubjects.existOrFail('reloadButton');
},
async expectIndexNotFoundErrorExists() {
const pageLoadErrorElement = await (
await testSubjects.find('pageLoadError')
).findByClassName('euiTitle');
expect(await pageLoadErrorElement.getVisibleText()).to.contain('Not Found');
},
async clickPageReload() {
await retry.tryForTime(60 * 1000, async () => {
await testSubjects.click('reloadButton', 2000);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ export default function ({ getPageObjects, getService }: FtrProviderContext) {
});
it('has page load error section', async () => {
await pageObjects.svlSearchIndexDetailPage.expectPageLoadErrorExists();
await pageObjects.svlSearchIndexDetailPage.expectIndexNotFoundErrorExists();
});
it('reload button shows details page again', async () => {
await es.indices.create({ index: indexName });
Expand Down

0 comments on commit 8125595

Please sign in to comment.