Skip to content

Commit

Permalink
Merge branch 'main' into 135874-change-infrastructure-pages-titles-to…
Browse files Browse the repository at this point in the history
…-use-breadcrumbs
  • Loading branch information
jennypavlova authored Sep 27, 2022
2 parents 98b9124 + d41e5ab commit b084fb7
Show file tree
Hide file tree
Showing 264 changed files with 3,809 additions and 3,328 deletions.
4 changes: 2 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -1314,15 +1314,15 @@ module.exports = {
{
// typescript for front and back end
files: [
'x-pack/plugins/{alerting,stack_alerts,stack_connectors,actions,task_manager,event_log}/**/*.{ts,tsx}',
'x-pack/plugins/{alerting,stack_alerts,actions,task_manager,event_log}/**/*.{ts,tsx}',
],
rules: {
'@typescript-eslint/no-explicit-any': 'error',
},
},
{
// typescript only for back end
files: ['x-pack/plugins/triggers_actions_ui/server/**/*.ts'],
files: ['x-pack/plugins/{stack_connectors,triggers_actions_ui}/server/**/*.ts'],
rules: {
'@typescript-eslint/no-explicit-any': 'error',
},
Expand Down
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,9 @@ x-pack/examples/files_example @elastic/kibana-app-services
/x-pack/plugins/event_log/ @elastic/response-ops
/x-pack/plugins/task_manager/ @elastic/response-ops
/x-pack/plugins/stack_connectors/ @elastic/response-ops
/x-pack/plugins/stack_connectors/public/connector_types/stack/ @elastic/response-ops-execution
/x-pack/plugins/stack_connectors/server/connector_types/stack/ @elastic/response-ops-execution
/x-pack/plugins/stack_connectors/public/connector_types/cases/ @elastic/response-ops-cases
/x-pack/plugins/stack_connectors/server/connector_types/cases/ @elastic/response-ops-cases
/x-pack/test/alerting_api_integration/ @elastic/response-ops
/x-pack/test/plugin_api_integration/test_suites/task_manager/ @elastic/response-ops
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@
"@types/nock": "^10.0.3",
"@types/node": "16.11.41",
"@types/node-fetch": "^2.6.0",
"@types/node-forge": "^1.0.4",
"@types/node-forge": "^1.3.0",
"@types/nodemailer": "^6.4.0",
"@types/normalize-path": "^3.0.0",
"@types/object-hash": "^1.3.0",
Expand Down
1 change: 1 addition & 0 deletions packages/kbn-optimizer/limits.yml
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ pageLoadAssetSize:
snapshotRestore: 79032
spaces: 57868
stackAlerts: 29684
stackConnectors: 36314
synthetics: 40958
telemetry: 51957
telemetryManagementSection: 38586
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { left } from 'fp-ts/lib/Either';
import { TimeDuration } from '.';
import { foldLeftRight, getPaths } from '@kbn/securitysolution-io-ts-utils';

describe('time_unit', () => {
describe('TimeDuration', () => {
test('it should validate a correctly formed TimeDuration with time unit of seconds', () => {
const payload = '1s';
const decoded = TimeDuration.decode(payload);
Expand Down Expand Up @@ -39,6 +39,17 @@ describe('time_unit', () => {
expect(message.schema).toEqual(payload);
});

test('it should NOT validate a TimeDuration of 0 length', () => {
const payload = '0s';
const decoded = TimeDuration.decode(payload);
const message = pipe(decoded, foldLeftRight);

expect(getPaths(left(message.errors))).toEqual([
'Invalid value "0s" supplied to "TimeDuration"',
]);
expect(message.schema).toEqual({});
});

test('it should NOT validate a negative TimeDuration', () => {
const payload = '-10s';
const decoded = TimeDuration.decode(payload);
Expand All @@ -50,6 +61,17 @@ describe('time_unit', () => {
expect(message.schema).toEqual({});
});

test('it should NOT validate a decimal TimeDuration', () => {
const payload = '1.5s';
const decoded = TimeDuration.decode(payload);
const message = pipe(decoded, foldLeftRight);

expect(getPaths(left(message.errors))).toEqual([
'Invalid value "1.5s" supplied to "TimeDuration"',
]);
expect(message.schema).toEqual({});
});

test('it should NOT validate a TimeDuration with some other time unit', () => {
const payload = '10000000w';
const decoded = TimeDuration.decode(payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ export const TimeDuration = new t.Type<string, string, unknown>(
if (typeof input === 'string' && input.trim() !== '') {
try {
const inputLength = input.length;
const time = parseInt(input.trim().substring(0, inputLength - 1), 10);
const unit = input.trim().at(-1);
const time = parseFloat(input.trim().substring(0, inputLength - 1));

if (!Number.isInteger(time)) {
return t.failure(input, context);
}
if (
time >= 1 &&
Number.isSafeInteger(time) &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ export function registerIndexRoutes({
pipelineName,
modelId,
sourceField,
destinationField || modelId,
destinationField,
client.asCurrentUser
);
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,23 @@ import {
getPrefixedInferencePipelineProcessorName,
} from './ml_inference_pipeline_utils';

const mockClient = {
ingest: {
getPipeline: jest.fn(),
putPipeline: jest.fn(),
},
ml: {
getTrainedModels: jest.fn(),
},
};

describe('createMlInferencePipeline util function', () => {
const pipelineName = 'my-pipeline';
const modelId = 'my-model-id';
const sourceField = 'my-source-field';
const destinationField = 'my-dest-field';
const inferencePipelineGeneratedName = getPrefixedInferencePipelineProcessorName(pipelineName);

const mockClient = {
ingest: {
getPipeline: jest.fn(),
putPipeline: jest.fn(),
},
ml: {
getTrainedModels: jest.fn(),
},
};

mockClient.ml.getTrainedModels.mockImplementation(() =>
Promise.resolve({
trained_model_configs: [
Expand Down Expand Up @@ -86,6 +86,32 @@ describe('createMlInferencePipeline util function', () => {
);
});

it('should default the destination field to the pipeline name', async () => {
mockClient.ingest.getPipeline.mockImplementation(() => Promise.reject({ statusCode: 404 })); // Pipeline does not exist
mockClient.ingest.putPipeline.mockImplementation(() => Promise.resolve({ acknowledged: true }));

await createMlInferencePipeline(
pipelineName,
modelId,
sourceField,
undefined, // Omitted destination field
mockClient as unknown as ElasticsearchClient
);

// Verify the object passed to pipeline creation contains the default target field name
expect(mockClient.ingest.putPipeline).toHaveBeenCalledWith(
expect.objectContaining({
processors: expect.arrayContaining([
expect.objectContaining({
inference: expect.objectContaining({
target_field: `ml.inference.${pipelineName}`,
}),
}),
]),
})
);
});

it('should throw an error without creating the pipeline if it already exists', () => {
mockClient.ingest.getPipeline.mockImplementation(() =>
Promise.resolve({
Expand All @@ -111,13 +137,6 @@ describe('addSubPipelineToIndexSpecificMlPipeline util function', () => {
const parentPipelineId = getInferencePipelineNameFromIndexName(indexName);
const pipelineName = 'ml-inference-my-pipeline';

const mockClient = {
ingest: {
getPipeline: jest.fn(),
putPipeline: jest.fn(),
},
};

beforeEach(() => {
jest.clearAllMocks();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { formatMlPipelineBody } from '../lib/pipelines/create_pipeline_definitio
import {
getInferencePipelineNameFromIndexName,
getPrefixedInferencePipelineProcessorName,
formatPipelineName,
} from './ml_inference_pipeline_utils';

/**
Expand All @@ -41,14 +42,14 @@ export const createAndReferenceMlInferencePipeline = async (
pipelineName: string,
modelId: string,
sourceField: string,
destinationField: string,
destinationField: string | null | undefined,
esClient: ElasticsearchClient
): Promise<CreatedPipeline> => {
const createPipelineResult = await createMlInferencePipeline(
pipelineName,
modelId,
sourceField,
destinationField || modelId,
destinationField,
esClient
);

Expand Down Expand Up @@ -76,7 +77,7 @@ export const createMlInferencePipeline = async (
pipelineName: string,
modelId: string,
sourceField: string,
destinationField: string,
destinationField: string | null | undefined,
esClient: ElasticsearchClient
): Promise<CreatedPipeline> => {
const inferencePipelineGeneratedName = getPrefixedInferencePipelineProcessorName(pipelineName);
Expand All @@ -99,7 +100,7 @@ export const createMlInferencePipeline = async (
inferencePipelineGeneratedName,
modelId,
sourceField,
destinationField,
destinationField || formatPipelineName(pipelineName),
esClient
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const getPrefixedInferencePipelineProcessorName = (pipelineName: string)
? formatPipelineName(pipelineName)
: `ml-inference-${formatPipelineName(pipelineName)}`;

const formatPipelineName = (rawName: string) =>
export const formatPipelineName = (rawName: string) =>
rawName
.trim()
.replace(/\s+/g, '_') // Convert whitespaces to underscores
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/fleet/dev_docs/fleet_ui_extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ export class Plugin {
component: LazyEndpointPolicyCreateExtension,
});

registerExtension({
package: 'endpoint',
view: 'package-policy-create-multi-step',
component: LazyEndpointPolicyCreateMultiStepExtension,
});

registerExtension({
package: 'endpoint',
view: 'package-detail-custom',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* 2.0.
*/

import React, { useCallback, useState, useEffect } from 'react';
import React, { useCallback, useState, useEffect, useMemo } from 'react';
import { FormattedMessage } from '@kbn/i18n-react';
import { EuiSpacer, EuiButtonEmpty, EuiFlexItem, EuiFlexGroup } from '@elastic/eui';
import { safeLoad } from 'js-yaml';
Expand All @@ -19,9 +19,9 @@ import { isVerificationError } from '../../../../../../../../services';
import type { MultiPageStepLayoutProps } from '../../types';
import type { PackagePolicyFormState } from '../../../types';
import type { NewPackagePolicy } from '../../../../../../types';
import { sendCreatePackagePolicy, useStartServices } from '../../../../../../hooks';
import { sendCreatePackagePolicy, useStartServices, useUIExtension } from '../../../../../../hooks';
import type { RequestError } from '../../../../../../hooks';
import { Error } from '../../../../../../components';
import { Error, ExtensionWrapper } from '../../../../../../components';
import { sendGeneratePackagePolicy } from '../../hooks';
import { CreatePackagePolicyBottomBar, StandaloneModeWarningCallout } from '..';
import type { PackagePolicyValidationResults } from '../../../services';
Expand Down Expand Up @@ -212,6 +212,55 @@ export const AddIntegrationPageStep: React.FC<MultiPageStepLayoutProps> = (props
getBasePolicy();
}, []); // eslint-disable-line react-hooks/exhaustive-deps

const extensionView = useUIExtension(packageInfo.name ?? '', 'package-policy-create-multi-step');
const addIntegrationExtensionView = useMemo(() => {
return (
extensionView && (
<ExtensionWrapper>
<extensionView.Component newPolicy={packagePolicy} />
</ExtensionWrapper>
)
);
}, [packagePolicy, extensionView]);

const content = useMemo(() => {
if (packageInfo.name !== 'endpoint') {
return (
<>
<EuiSpacer size={'l'} />
<StepConfigurePackagePolicy
packageInfo={packageInfo}
showOnlyIntegration={integrationInfo?.name}
packagePolicy={packagePolicy}
updatePackagePolicy={updatePackagePolicy}
validationResults={validationResults!}
submitAttempted={formState === 'INVALID'}
noTopRule={true}
/>
{validationResults && (
<ExpandableAdvancedSettings>
<StepDefinePackagePolicy
packageInfo={packageInfo}
packagePolicy={packagePolicy}
updatePackagePolicy={updatePackagePolicy}
validationResults={validationResults!}
submitAttempted={formState === 'INVALID'}
noAdvancedToggle={true}
/>
</ExpandableAdvancedSettings>
)}
</>
);
}
}, [
formState,
integrationInfo?.name,
packageInfo,
packagePolicy,
updatePackagePolicy,
validationResults,
]);

if (!agentPolicy) {
return (
<AddIntegrationError
Expand All @@ -228,28 +277,8 @@ export const AddIntegrationPageStep: React.FC<MultiPageStepLayoutProps> = (props
return (
<>
{isManaged ? null : <StandaloneModeWarningCallout setIsManaged={setIsManaged} />}
<EuiSpacer size={'l'} />
<StepConfigurePackagePolicy
packageInfo={packageInfo}
showOnlyIntegration={integrationInfo?.name}
packagePolicy={packagePolicy}
updatePackagePolicy={updatePackagePolicy}
validationResults={validationResults!}
submitAttempted={formState === 'INVALID'}
noTopRule={true}
/>
{validationResults && (
<ExpandableAdvancedSettings>
<StepDefinePackagePolicy
packageInfo={packageInfo}
packagePolicy={packagePolicy}
updatePackagePolicy={updatePackagePolicy}
validationResults={validationResults!}
submitAttempted={formState === 'INVALID'}
noAdvancedToggle={true}
/>
</ExpandableAdvancedSettings>
)}
{content}
{addIntegrationExtensionView}
<NotObscuredByBottomBar />
<CreatePackagePolicyBottomBar
cancelClickHandler={isManaged ? onBack : () => setIsManaged(true)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ describe('getInstallPkgRouteOptions', () => {

expect(getInstallPkgRouteOptions(opts)).toEqual(['fleet', expectedOptions]);
});
it('should not navigate to steps app for endpoint', () => {
it('should navigate to steps app for endpoint', () => {
const opts = {
currentPath: 'currentPath',
integration: 'myintegration',
Expand All @@ -144,7 +144,7 @@ describe('getInstallPkgRouteOptions', () => {
const expectedRedirectURl = '/detail/endpoint-1.0.0/policies?integration=myintegration';

const expectedOptions = {
path: '/integrations/endpoint-1.0.0/add-integration/myintegration',
path: '/integrations/endpoint-1.0.0/add-integration/myintegration?useMultiPageLayout',
state: {
onCancelUrl: 'currentPath',
onCancelNavigateTo: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ const EXCLUDED_PACKAGES = [
'apm',
'cloud_security_posture',
'dga',
'endpoint',
'fleet_server',
'kubernetes',
'osquery_manager',
Expand Down
Loading

0 comments on commit b084fb7

Please sign in to comment.