-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Enterprise Search] Add stats overview to indices page (#145282)
- Loading branch information
Showing
7 changed files
with
340 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
export interface SyncJobsStats { | ||
connected: number; | ||
errors: number; | ||
in_progress: number; | ||
incomplete: number; | ||
long_running: number; | ||
orphaned_jobs: number; | ||
} |
23 changes: 23 additions & 0 deletions
23
...ublic/applications/enterprise_search_content/api/stats/fetch_sync_jobs_stats_api_logic.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { SyncJobsStats } from '../../../../../common/stats'; | ||
|
||
import { createApiLogic } from '../../../shared/api_logic/create_api_logic'; | ||
import { HttpLogic } from '../../../shared/http'; | ||
|
||
export type FetchSyncJobsStatsResponse = SyncJobsStats; | ||
|
||
export const fetchSyncJobsStats = async () => { | ||
const route = '/internal/enterprise_search/stats/sync_jobs'; | ||
return await HttpLogic.values.http.get<FetchSyncJobsStatsResponse>(route); | ||
}; | ||
|
||
export const FetchSyncJobsStatsApiLogic = createApiLogic( | ||
['enterprise_search_content', 'fetch_sync_jobs_stats_api_logic'], | ||
fetchSyncJobsStats | ||
); |
141 changes: 141 additions & 0 deletions
141
...public/applications/enterprise_search_content/components/search_indices/indices_stats.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import React, { useEffect } from 'react'; | ||
|
||
import { useActions, useValues } from 'kea'; | ||
|
||
import { EuiFlexGroup, EuiFlexItem, EuiPanel, EuiStat } from '@elastic/eui'; | ||
|
||
import { i18n } from '@kbn/i18n'; | ||
|
||
import { Status } from '../../../../../common/types/api'; | ||
|
||
import { FetchSyncJobsStatsApiLogic } from '../../api/stats/fetch_sync_jobs_stats_api_logic'; | ||
|
||
export const IndicesStats: React.FC = () => { | ||
const { makeRequest } = useActions(FetchSyncJobsStatsApiLogic); | ||
const { data, status } = useValues(FetchSyncJobsStatsApiLogic); | ||
const isLoading = status === Status.LOADING; | ||
|
||
useEffect(() => { | ||
makeRequest({}); | ||
}, []); | ||
|
||
return ( | ||
<EuiFlexGroup direction="column"> | ||
<EuiFlexItem> | ||
<EuiFlexGroup> | ||
<EuiFlexItem> | ||
<EuiPanel | ||
color={data?.connected ? 'success' : 'subdued'} | ||
hasShadow={false} | ||
paddingSize="l" | ||
> | ||
<EuiStat | ||
description={i18n.translate( | ||
'xpack.enterpriseSearch.content.searchIndices.jobStats.connectedMethods', | ||
{ | ||
defaultMessage: 'Connected ingest methods', | ||
} | ||
)} | ||
isLoading={isLoading} | ||
title={data?.connected} | ||
/> | ||
</EuiPanel> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<EuiPanel | ||
color={data?.incomplete ? 'warning' : 'subdued'} | ||
hasShadow={false} | ||
paddingSize="l" | ||
> | ||
<EuiStat | ||
description={i18n.translate( | ||
'xpack.enterpriseSearch.content.searchIndices.jobStats.incompleteMethods', | ||
{ | ||
defaultMessage: 'Incomplete ingest methods', | ||
} | ||
)} | ||
isLoading={isLoading} | ||
title={data?.incomplete} | ||
/> | ||
</EuiPanel> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<EuiFlexGroup> | ||
<EuiFlexItem> | ||
<EuiPanel color="subdued" hasShadow={false} paddingSize="l"> | ||
<EuiStat | ||
description={i18n.translate( | ||
'xpack.enterpriseSearch.content.searchIndices.jobStats.runningSyncs', | ||
{ | ||
defaultMessage: 'Running syncs', | ||
} | ||
)} | ||
isLoading={isLoading} | ||
title={data?.in_progress} | ||
/> | ||
</EuiPanel> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<EuiPanel | ||
color={data?.long_running ? 'warning' : 'subdued'} | ||
hasShadow={false} | ||
paddingSize="l" | ||
> | ||
<EuiStat | ||
description={i18n.translate( | ||
'xpack.enterpriseSearch.content.searchIndices.jobStats.longRunningSyncs', | ||
{ | ||
defaultMessage: 'Long running syncs', | ||
} | ||
)} | ||
isLoading={isLoading} | ||
title={data?.long_running} | ||
/> | ||
</EuiPanel> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<EuiPanel | ||
color={data?.orphaned_jobs ? 'warning' : 'subdued'} | ||
hasShadow={false} | ||
paddingSize="l" | ||
> | ||
<EuiStat | ||
description={i18n.translate( | ||
'xpack.enterpriseSearch.content.searchIndices.jobStats.orphanedSyncs', | ||
{ | ||
defaultMessage: 'Orphaned syncs', | ||
} | ||
)} | ||
isLoading={isLoading} | ||
title={data?.orphaned_jobs} | ||
/> | ||
</EuiPanel> | ||
</EuiFlexItem> | ||
<EuiFlexItem> | ||
<EuiPanel color={data?.errors ? 'danger' : 'subdued'} hasShadow={false} paddingSize="l"> | ||
<EuiStat | ||
description={i18n.translate( | ||
'xpack.enterpriseSearch.content.searchIndices.jobStats.errorSyncs', | ||
{ | ||
defaultMessage: 'Syncs errors', | ||
} | ||
)} | ||
isLoading={isLoading} | ||
title={data?.errors} | ||
/> | ||
</EuiPanel> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
</EuiFlexItem> | ||
</EuiFlexGroup> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
131 changes: 131 additions & 0 deletions
131
x-pack/plugins/enterprise_search/server/lib/stats/get_sync_jobs.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import moment from 'moment'; | ||
|
||
import { IScopedClusterClient } from '@kbn/core/server'; | ||
|
||
import { CONNECTORS_INDEX, CONNECTORS_JOBS_INDEX } from '../..'; | ||
import { SyncJobsStats } from '../../../common/stats'; | ||
|
||
import { ConnectorStatus, SyncStatus } from '../../../common/types/connectors'; | ||
|
||
export const fetchSyncJobsStats = async (client: IScopedClusterClient): Promise<SyncJobsStats> => { | ||
const connectorIdsResult = await client.asCurrentUser.search({ | ||
index: CONNECTORS_INDEX, | ||
scroll: '10s', | ||
stored_fields: [], | ||
}); | ||
const ids = connectorIdsResult.hits.hits.map((hit) => hit._id); | ||
const orphanedJobsCountResponse = await client.asCurrentUser.count({ | ||
index: CONNECTORS_JOBS_INDEX, | ||
query: { | ||
terms: { | ||
'connector.id': ids, | ||
}, | ||
}, | ||
}); | ||
|
||
const inProgressJobsCountResponse = await client.asCurrentUser.count({ | ||
index: CONNECTORS_JOBS_INDEX, | ||
query: { | ||
term: { | ||
status: SyncStatus.IN_PROGRESS, | ||
}, | ||
}, | ||
}); | ||
|
||
const longRunningProgressJobsCountResponse = await client.asCurrentUser.count({ | ||
index: CONNECTORS_JOBS_INDEX, | ||
query: { | ||
bool: { | ||
filter: [ | ||
{ | ||
term: { | ||
status: SyncStatus.IN_PROGRESS, | ||
}, | ||
}, | ||
{ | ||
range: { | ||
last_seen: { | ||
lt: moment().subtract(1, 'day').toISOString(), | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}); | ||
|
||
const errorResponse = await client.asCurrentUser.count({ | ||
index: CONNECTORS_JOBS_INDEX, | ||
query: { | ||
term: { | ||
status: SyncStatus.ERROR, | ||
}, | ||
}, | ||
}); | ||
|
||
const connectedResponse = await client.asCurrentUser.count({ | ||
index: CONNECTORS_INDEX, | ||
query: { | ||
bool: { | ||
filter: [ | ||
{ | ||
term: { | ||
status: ConnectorStatus.CONNECTED, | ||
}, | ||
}, | ||
{ | ||
range: { | ||
last_seen: { | ||
gte: moment().subtract(30, 'minutes').toISOString(), | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}); | ||
|
||
const incompleteResponse = await client.asCurrentUser.count({ | ||
index: CONNECTORS_INDEX, | ||
query: { | ||
bool: { | ||
should: [ | ||
{ | ||
bool: { | ||
must_not: { | ||
terms: { | ||
status: [ConnectorStatus.CONNECTED, ConnectorStatus.ERROR], | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
range: { | ||
last_seen: { | ||
gt: moment().subtract(30, 'minutes').toISOString(), | ||
}, | ||
}, | ||
}, | ||
], | ||
}, | ||
}, | ||
}); | ||
|
||
const response = { | ||
connected: connectedResponse.count, | ||
errors: errorResponse.count, | ||
in_progress: inProgressJobsCountResponse.count, | ||
incomplete: incompleteResponse.count, | ||
long_running: longRunningProgressJobsCountResponse.count, | ||
orphaned_jobs: orphanedJobsCountResponse.count, | ||
}; | ||
|
||
return response; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
x-pack/plugins/enterprise_search/server/routes/enterprise_search/stats.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
/* | ||
* 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; you may not use this file except in compliance with the Elastic License | ||
* 2.0. | ||
*/ | ||
|
||
import { fetchSyncJobsStats } from '../../lib/stats/get_sync_jobs'; | ||
import { RouteDependencies } from '../../plugin'; | ||
import { elasticsearchErrorHandler } from '../../utils/elasticsearch_error_handler'; | ||
|
||
export function registerStatsRoutes({ router, log }: RouteDependencies) { | ||
router.get( | ||
{ | ||
path: '/internal/enterprise_search/stats/sync_jobs', | ||
validate: {}, | ||
}, | ||
elasticsearchErrorHandler(log, async (context, request, response) => { | ||
const { client } = (await context.core).elasticsearch; | ||
const body = await fetchSyncJobsStats(client); | ||
return response.ok({ body }); | ||
}) | ||
); | ||
} |