Skip to content

Commit

Permalink
[Ingest Manager] Surface saved object client 10,000 limitation to bul…
Browse files Browse the repository at this point in the history
…k actions UI (#78520)

* Surface saved object client 10,000 limitation to UI

* Update x-pack/plugins/ingest_manager/server/services/saved_object.ts

Co-authored-by: John Schulz <github.com@jfsiii.org>

Co-authored-by: John Schulz <github.com@jfsiii.org>
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
3 people committed Sep 28, 2020
1 parent 9017d50 commit 26f2bd2
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 17 deletions.
6 changes: 6 additions & 0 deletions x-pack/plugins/ingest_manager/common/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ export * from './epm';
export * from './output';
export * from './enrollment_api_key';
export * from './settings';

// TODO: This is the default `index.max_result_window` ES setting, which dictates
// the maximum amount of results allowed to be returned from a search. It's possible
// for the actual setting to differ from the default. Can we retrieve the real
// setting in the future?
export const SO_SEARCH_LIMIT = 10000;
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export {
PLUGIN_ID,
EPM_API_ROUTES,
AGENT_API_ROUTES,
SO_SEARCH_LIMIT,
AGENT_POLICY_SAVED_OBJECT_TYPE,
AGENT_EVENT_SAVED_OBJECT_TYPE,
AGENT_SAVED_OBJECT_TYPE,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
EuiIcon,
EuiPortal,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { FormattedMessage, FormattedNumber } from '@kbn/i18n/react';
import { SO_SEARCH_LIMIT } from '../../../../constants';
import { Agent } from '../../../../types';
import { AgentReassignAgentPolicyFlyout, AgentUnenrollAgentModal } from '../../components';

Expand Down Expand Up @@ -153,11 +154,22 @@ export const AgentBulkActions: React.FunctionComponent<{
<EuiFlexGroup gutterSize="m" alignItems="center">
<EuiFlexItem grow={false}>
<EuiText size="xs" color="subdued">
<FormattedMessage
id="xpack.ingestManager.agentBulkActions.totalAgents"
defaultMessage="Showing {count, plural, one {# agent} other {# agents}}"
values={{ count: totalAgents }}
/>
{totalAgents > SO_SEARCH_LIMIT ? (
<FormattedMessage
id="xpack.ingestManager.agentBulkActions.totalAgentsWithLimit"
defaultMessage="Showing {count} of {total} agents"
values={{
count: <FormattedNumber value={SO_SEARCH_LIMIT} />,
total: <FormattedNumber value={totalAgents} />,
}}
/>
) : (
<FormattedMessage
id="xpack.ingestManager.agentBulkActions.totalAgents"
defaultMessage="Showing {count, plural, one {# agent} other {# agents}}"
values={{ count: totalAgents }}
/>
)}
</EuiText>
</EuiFlexItem>
{(selectionMode === 'manual' && selectedAgents.length) ||
Expand All @@ -184,7 +196,7 @@ export const AgentBulkActions: React.FunctionComponent<{
count:
selectionMode === 'manual'
? selectedAgents.length
: totalAgents - totalInactiveAgents,
: Math.min(totalAgents - totalInactiveAgents, SO_SEARCH_LIMIT),
}}
/>
</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import React, { useState, useEffect } from 'react';
import { i18n } from '@kbn/i18n';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiSelect, EuiSpacer, EuiText, EuiButtonEmpty } from '@elastic/eui';
import { SO_SEARCH_LIMIT } from '../../../../constants';
import { AgentPolicy, GetEnrollmentAPIKeysResponse } from '../../../../types';
import { sendGetEnrollmentAPIKeys, useCore } from '../../../../hooks';
import { AgentPolicyPackageBadges } from '../agent_policy_package_badges';
Expand Down Expand Up @@ -98,7 +99,7 @@ export const EnrollmentStepAgentPolicy: React.FC<Props> = (props) => {
try {
const res = await sendGetEnrollmentAPIKeys({
page: 1,
perPage: 10000,
perPage: SO_SEARCH_LIMIT,
});
if (res.error) {
throw res.error;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from '@elastic/eui';
import { OverviewPanel } from './overview_panel';
import { OverviewStats } from './overview_stats';
import { SO_SEARCH_LIMIT } from '../../../constants';
import { useLink, useGetPackagePolicies } from '../../../hooks';
import { AgentPolicy } from '../../../types';
import { Loading } from '../../fleet/components';
Expand All @@ -25,7 +26,7 @@ export const OverviewPolicySection: React.FC<{ agentPolicies: AgentPolicy[] }> =
const { getHref } = useLink();
const packagePoliciesRequest = useGetPackagePolicies({
page: 1,
perPage: 10000,
perPage: SO_SEARCH_LIMIT,
});

return (
Expand Down
1 change: 1 addition & 0 deletions x-pack/plugins/ingest_manager/server/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ export {
SETTINGS_API_ROUTES,
APP_API_ROUTES,
// Saved object types
SO_SEARCH_LIMIT,
AGENT_SAVED_OBJECT_TYPE,
AGENT_EVENT_SAVED_OBJECT_TYPE,
AGENT_ACTION_SAVED_OBJECT_TYPE,
Expand Down
9 changes: 2 additions & 7 deletions x-pack/plugins/ingest_manager/server/services/saved_object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* you may not use this file except in compliance with the Elastic License.
*/
import { SavedObjectsClientContract, SavedObjectsFindResponse } from 'src/core/server';
import { SO_SEARCH_LIMIT } from '../constants';
import { ListWithKuery } from '../types';

/**
Expand Down Expand Up @@ -40,19 +41,13 @@ export const findAllSOs = async <T = unknown>(
const { type, sortField, sortOrder, kuery } = options;
let savedObjectResults: SavedObjectsFindResponse<T>['saved_objects'] = [];

// TODO: This is the default `index.max_result_window` ES setting, which dictates
// the maximum amount of results allowed to be returned from a search. It's possible
// for the actual setting to differ from the default. Can we retrieve the real
// setting in the future?
const searchLimit = 10000;

const query = {
type,
sortField,
sortOrder,
filter: kuery,
page: 1,
perPage: searchLimit,
perPage: SO_SEARCH_LIMIT,
};

const { saved_objects: initialSOs, total } = await soClient.find<T>(query);
Expand Down
3 changes: 2 additions & 1 deletion x-pack/plugins/ingest_manager/server/services/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
Output,
DEFAULT_AGENT_POLICIES_PACKAGES,
} from '../../common';
import { SO_SEARCH_LIMIT } from '../constants';
import { getPackageInfo } from './epm/packages';
import { packagePolicyService } from './package_policy';
import { generateEnrollmentAPIKey } from './api_keys';
Expand Down Expand Up @@ -159,7 +160,7 @@ export async function setupFleet(
});

const { items: agentPolicies } = await agentPolicyService.list(soClient, {
perPage: 10000,
perPage: SO_SEARCH_LIMIT,
});

await Promise.all(
Expand Down

0 comments on commit 26f2bd2

Please sign in to comment.