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

[Ingest Manager] Surface saved object client 10,000 limitation to bulk actions UI #78520

Merged
merged 4 commits into from
Sep 28, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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
11 changes: 3 additions & 8 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,26 +41,20 @@ 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);

savedObjectResults = initialSOs;

// The saved object client can't actually page through more than the first 10,000
// The saved object client can't actually page through more than the first 10000
jen-huang marked this conversation as resolved.
Show resolved Hide resolved
// results, due to the same `index.max_result_window` constraint. The commented out
// code below is an example of paging through rest of results when the SO client
// offers that kind of support.
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