Skip to content

Commit

Permalink
Merge branch 'main' into fix-certs-filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 authored Jun 21, 2023

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 382ded6 + 1149fe4 commit d4adbbc
Showing 57 changed files with 1,920 additions and 274 deletions.
2 changes: 1 addition & 1 deletion docs/api-generated/cases/case-apis-passthru.asciidoc
Original file line number Diff line number Diff line change
@@ -556,7 +556,7 @@ Any modifications made to this file will be overwritten.
<div class="param-desc"><span class="param-type">Query Parameter</span> &mdash; The page number to return. default: 1 </div><div class="param">perPage (optional)</div>
<div class="param-desc"><span class="param-type">Query Parameter</span> &mdash; The number of items to return. default: 20 </div><div class="param">sortOrder (optional)</div>
<div class="param-desc"><span class="param-type">Query Parameter</span> &mdash; The number of items to return. Limited to 100 items. default: 20 </div><div class="param">sortOrder (optional)</div>
<div class="param-desc"><span class="param-type">Query Parameter</span> &mdash; Determines the sort order. default: desc </div>
</div> <!-- field-items -->
Original file line number Diff line number Diff line change
@@ -51,7 +51,7 @@ const action: Action = {
execute: () => Promise.resolve(),
};

const dataViewMock = { id: '1', toSpec: () => ({}) } as DataView;
const dataViewMock = { id: '1', toSpec: () => ({}), isTimeBased: () => true } as DataView;

describe('categorize_trigger_utils', () => {
afterEach(() => {
Original file line number Diff line number Diff line change
@@ -46,7 +46,12 @@ export async function canCategorize(
field: DataViewField,
dataView: DataView | undefined
): Promise<boolean> {
if (field.name === '_id' || !dataView?.id || !field.esTypes?.includes('text')) {
if (
field.name === '_id' ||
!dataView?.id ||
!dataView.isTimeBased() ||
!field.esTypes?.includes('text')
) {
return false;
}

1 change: 1 addition & 0 deletions x-pack/plugins/actions/server/mocks.ts
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ const createSetupMock = () => {
getSubActionConnectorClass: jest.fn(),
getCaseConnectorClass: jest.fn(),
getActionsHealth: jest.fn(),
getActionsConfigurationUtilities: jest.fn(),
};
return mock;
};
4 changes: 3 additions & 1 deletion x-pack/plugins/actions/server/plugin.ts
Original file line number Diff line number Diff line change
@@ -67,7 +67,7 @@ import {
ActionsRequestHandlerContext,
} from './types';

import { getActionsConfigurationUtilities } from './actions_config';
import { ActionsConfigurationUtilities, getActionsConfigurationUtilities } from './actions_config';

import { defineRoutes } from './routes';
import { initializeActionsTelemetry, scheduleActionsTelemetry } from './usage/task';
@@ -129,6 +129,7 @@ export interface PluginSetupContract {
getSubActionConnectorClass: <Config, Secrets>() => IServiceAbstract<Config, Secrets>;
getCaseConnectorClass: <Config, Secrets>() => IServiceAbstract<Config, Secrets>;
getActionsHealth: () => { hasPermanentEncryptionKey: boolean };
getActionsConfigurationUtilities: () => ActionsConfigurationUtilities;
}

export interface PluginStartContract {
@@ -370,6 +371,7 @@ export class ActionsPlugin implements Plugin<PluginSetupContract, PluginStartCon
hasPermanentEncryptionKey: plugins.encryptedSavedObjects.canEncrypt,
};
},
getActionsConfigurationUtilities: () => actionsConfigUtils,
};
}

1 change: 1 addition & 0 deletions x-pack/plugins/cases/common/constants/index.ts
Original file line number Diff line number Diff line change
@@ -104,6 +104,7 @@ export const MAX_DOCS_PER_PAGE = 10000 as const;
export const MAX_BULK_GET_ATTACHMENTS = MAX_DOCS_PER_PAGE;
export const MAX_CONCURRENT_SEARCHES = 10 as const;
export const MAX_BULK_GET_CASES = 1000 as const;
export const MAX_COMMENTS_PER_PAGE = 100 as const;
export const MAX_CATEGORY_FILTER_LENGTH = 100 as const;

/**
10 changes: 9 additions & 1 deletion x-pack/plugins/cases/docs/openapi/bundled.json
Original file line number Diff line number Diff line change
@@ -1852,7 +1852,15 @@
"$ref": "#/components/parameters/page_index"
},
{
"$ref": "#/components/parameters/page_size"
"name": "perPage",
"in": "query",
"description": "The number of items to return. Limited to 100 items.",
"required": false,
"schema": {
"type": "integer",
"default": 20,
"maximum": 100
}
},
{
"$ref": "#/components/parameters/sort_order"
9 changes: 8 additions & 1 deletion x-pack/plugins/cases/docs/openapi/bundled.yaml
Original file line number Diff line number Diff line change
@@ -1156,7 +1156,14 @@ paths:
parameters:
- $ref: '#/components/parameters/case_id'
- $ref: '#/components/parameters/page_index'
- $ref: '#/components/parameters/page_size'
- name: perPage
in: query
description: The number of items to return. Limited to 100 items.
required: false
schema:
type: integer
default: 20
maximum: 100
- $ref: '#/components/parameters/sort_order'
- $ref: '#/components/parameters/space_id'
responses:
Original file line number Diff line number Diff line change
@@ -10,7 +10,14 @@ get:
parameters:
- $ref: '../components/parameters/case_id.yaml'
- $ref: '../components/parameters/page_index.yaml'
- $ref: '../components/parameters/page_size.yaml'
- name: perPage
in: query
description: The number of items to return. Limited to 100 items.
required: false
schema:
type: integer
default: 20
maximum: 100
- $ref: '../components/parameters/sort_order.yaml'
- $ref: '../components/parameters/space_id.yaml'
responses:
10 changes: 9 additions & 1 deletion x-pack/plugins/cases/server/client/attachments/get.test.ts
Original file line number Diff line number Diff line change
@@ -18,12 +18,20 @@ describe('get', () => {

it('Invalid total items results in error', async () => {
await expect(() =>
findComment({ caseID: 'mock-id', findQueryParams: { page: 2, perPage: 9001 } }, clientArgs)
findComment({ caseID: 'mock-id', findQueryParams: { page: 209, perPage: 100 } }, clientArgs)
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Failed to find comments case id: mock-id: Error: The number of documents is too high. Paginating through more than 10,000 documents is not possible."`
);
});

it('Invalid perPage items results in error', async () => {
await expect(() =>
findComment({ caseID: 'mock-id', findQueryParams: { page: 2, perPage: 9001 } }, clientArgs)
).rejects.toThrowErrorMatchingInlineSnapshot(
`"Failed to find comments case id: mock-id: Error: The provided perPage value was too high. The maximum allowed perPage value is 100."`
);
});

it('throws with excess fields', async () => {
await expect(
findComment(
19 changes: 16 additions & 3 deletions x-pack/plugins/cases/server/client/attachments/validators.test.ts
Original file line number Diff line number Diff line change
@@ -6,10 +6,13 @@
*/

import { validateFindCommentsPagination } from './validators';
import { MAX_COMMENTS_PER_PAGE } from '../../../common/constants';

const ERROR_MSG =
'The number of documents is too high. Paginating through more than 10,000 documents is not possible.';

const ERROR_MSG_PER_PAGE = `The provided perPage value was too high. The maximum allowed perPage value is ${MAX_COMMENTS_PER_PAGE}.`;

describe('validators', () => {
describe('validateFindCommentsPagination', () => {
it('does not throw if only page is undefined', () => {
@@ -20,20 +23,30 @@ describe('validators', () => {
expect(() => validateFindCommentsPagination({ page: 100 })).not.toThrowError();
});

it('does not throw if page and perPage are defined and valid', () => {
expect(() => validateFindCommentsPagination({ page: 2, perPage: 100 })).not.toThrowError();
});

it('returns if page and perPage are undefined', () => {
expect(() => validateFindCommentsPagination({})).not.toThrowError();
});

it('returns if perPage < 0', () => {
expect(() => validateFindCommentsPagination({ perPage: -1 })).not.toThrowError();
});

it('throws if page > 10k', () => {
expect(() => validateFindCommentsPagination({ page: 10001 })).toThrow(ERROR_MSG);
});

it('throws if perPage > 10k', () => {
expect(() => validateFindCommentsPagination({ perPage: 10001 })).toThrowError(ERROR_MSG);
it('throws if perPage > 100', () => {
expect(() =>
validateFindCommentsPagination({ perPage: MAX_COMMENTS_PER_PAGE + 1 })
).toThrowError(ERROR_MSG_PER_PAGE);
});

it('throws if page * perPage > 10k', () => {
expect(() => validateFindCommentsPagination({ page: 10, perPage: 1001 })).toThrow(ERROR_MSG);
expect(() => validateFindCommentsPagination({ page: 101, perPage: 100 })).toThrow(ERROR_MSG);
});
});
});
10 changes: 8 additions & 2 deletions x-pack/plugins/cases/server/client/attachments/validators.ts
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
*/

import Boom from '@hapi/boom';
import { MAX_DOCS_PER_PAGE } from '../../../common/constants';
import { MAX_DOCS_PER_PAGE, MAX_COMMENTS_PER_PAGE } from '../../../common/constants';
import {
isCommentRequestTypeExternalReference,
isCommentRequestTypePersistableState,
@@ -51,7 +51,13 @@ export const validateFindCommentsPagination = (params?: FindCommentsQueryParams)
const pageAsNumber = params.page ?? 0;
const perPageAsNumber = params.perPage ?? 0;

if (Math.max(pageAsNumber, perPageAsNumber, pageAsNumber * perPageAsNumber) > MAX_DOCS_PER_PAGE) {
if (perPageAsNumber > MAX_COMMENTS_PER_PAGE) {
throw Boom.badRequest(
`The provided perPage value was too high. The maximum allowed perPage value is ${MAX_COMMENTS_PER_PAGE}.`
);
}

if (Math.max(pageAsNumber, pageAsNumber * perPageAsNumber) > MAX_DOCS_PER_PAGE) {
throw Boom.badRequest(
'The number of documents is too high. Paginating through more than 10,000 documents is not possible.'
);
Original file line number Diff line number Diff line change
@@ -9,6 +9,8 @@ import React, { useState, useMemo } from 'react';

import { useActions, useValues } from 'kea';

import useLocalStorage from 'react-use/lib/useLocalStorage';

import {
EuiButtonEmpty,
EuiContextMenuItem,
@@ -24,6 +26,7 @@ import {
EuiText,
EuiTextColor,
EuiTitle,
EuiTourStep,
} from '@elastic/eui';
import {
PagingInfo,
@@ -128,6 +131,11 @@ const ConfigurationPopover: React.FC<ConfigurationPopOverProps> = ({
const { engineData } = useValues(EngineViewLogic);
const { openDeleteEngineModal } = useActions(EngineViewLogic);
const { sendEnterpriseSearchTelemetry } = useActions(TelemetryLogic);
const [isTourClosed, setTourClosed] = useLocalStorage<boolean>(
'search-application-tour-closed',
false
);

return (
<>
<EuiPopover
@@ -137,20 +145,66 @@ const ConfigurationPopover: React.FC<ConfigurationPopOverProps> = ({
closePopover={setCloseConfiguration}
button={
<EuiFlexGroup alignItems="center" gutterSize="xs">
{hasSchemaConflicts && <EuiIcon type="alert" color="danger" />}
<EuiButtonEmpty
color="primary"
iconType="arrowDown"
iconSide="right"
onClick={setCloseConfiguration}
>
{i18n.translate(
'xpack.enterpriseSearch.content.engine.searchPreview.configuration.buttonTitle',
{
defaultMessage: 'Configuration',
{hasSchemaConflicts && (
<>
<EuiFlexItem>
<EuiIcon type="alert" color="danger" />
</EuiFlexItem>
{!isTourClosed && <EuiSpacer size="xs" />}
</>
)}
<EuiFlexItem>
<EuiTourStep
display="block"
decoration="beacon"
content={
<EuiText>
<p>
{i18n.translate(
'xpack.enterpriseSearch.content.searchApplication.searchPreview.configuration.tourContent',
{
defaultMessage:
'Create your API key, learn about using language clients and find more resources in Connect.',
}
)}
</p>
</EuiText>
}
)}
</EuiButtonEmpty>
isStepOpen={!isTourClosed}
maxWidth={360}
hasArrow
step={1}
onFinish={() => {
setTourClosed(true);
}}
stepsTotal={1}
anchorPosition="downCenter"
title={i18n.translate(
'xpack.enterpriseSearch.content.searchApplication.searchPreview.configuration.tourTitle',
{
defaultMessage: 'Review our API page to start using your search application',
}
)}
>
<></>
</EuiTourStep>
</EuiFlexItem>

<EuiFlexItem>
<EuiButtonEmpty
color="primary"
iconType="arrowDown"
iconSide="right"
onClick={setCloseConfiguration}
>
{i18n.translate(
'xpack.enterpriseSearch.content.engine.searchPreview.configuration.buttonTitle',
{
defaultMessage: 'Configuration',
}
)}
</EuiButtonEmpty>
</EuiFlexItem>
</EuiFlexGroup>
}
>
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ import { useUnifiedSearchContext } from '../../hooks/use_unified_search';
import { HostsLensMetricChartFormulas } from '../../../../../common/visualizations';
import { useHostsViewContext } from '../../hooks/use_hosts_view';
import { LensWrapper } from '../chart/lens_wrapper';
import { createHostsFilter } from '../../utils';
import { buildCombinedHostsFilter } from '../../utils';
import { useHostCountContext } from '../../hooks/use_host_count';
import { useAfterLoadedState } from '../../hooks/use_after_loaded_state';
import { TooltipContent } from '../metric_explanation/tooltip_content';
@@ -83,10 +83,11 @@ export const Tile = ({

const filters = useMemo(() => {
return [
createHostsFilter(
hostNodes.map((p) => p.name),
dataView
),
buildCombinedHostsFilter({
field: 'host.name',
values: hostNodes.map((p) => p.name),
dataView,
}),
];
}, [hostNodes, dataView]);

Original file line number Diff line number Diff line change
@@ -15,7 +15,7 @@ import { useUnifiedSearchContext } from '../../../hooks/use_unified_search';
import { useLogsSearchUrlState } from '../../../hooks/use_logs_search_url_state';
import { LogsLinkToStream } from './logs_link_to_stream';
import { LogsSearchBar } from './logs_search_bar';
import { createHostsFilter } from '../../../utils';
import { buildCombinedHostsFilter } from '../../../utils';
import { useLogViewReference } from '../../../hooks/use_log_view_reference';

export const LogsTabContent = () => {
@@ -25,7 +25,11 @@ export const LogsTabContent = () => {
const { hostNodes, loading } = useHostsViewContext();

const hostsFilterQuery = useMemo(
() => createHostsFilter(hostNodes.map((p) => p.name)),
() =>
buildCombinedHostsFilter({
field: 'host.name',
values: hostNodes.map((p) => p.name),
}),
[hostNodes]
);

Original file line number Diff line number Diff line change
@@ -22,7 +22,7 @@ import { useMetricsDataViewContext } from '../../../hooks/use_data_view';
import { useUnifiedSearchContext } from '../../../hooks/use_unified_search';
import { HostsLensLineChartFormulas } from '../../../../../../common/visualizations';
import { useHostsViewContext } from '../../../hooks/use_hosts_view';
import { createHostsFilter } from '../../../utils';
import { buildCombinedHostsFilter } from '../../../utils';
import { useHostsTableContext } from '../../../hooks/use_hosts_table';
import { LensWrapper } from '../../chart/lens_wrapper';
import { useAfterLoadedState } from '../../../hooks/use_after_loaded_state';
@@ -62,10 +62,11 @@ export const MetricChart = ({ title, type, breakdownSize }: MetricChartProps) =>

const filters = useMemo(() => {
return [
createHostsFilter(
currentPage.map((p) => p.name),
dataView
),
buildCombinedHostsFilter({
field: 'host.name',
values: currentPage.map((p) => p.name),
dataView,
}),
];
}, [currentPage, dataView]);

Loading

0 comments on commit d4adbbc

Please sign in to comment.