Skip to content

Commit

Permalink
Merge branch 'main' into cases-custom-fields-feature-branch
Browse files Browse the repository at this point in the history
  • Loading branch information
kibanamachine authored Oct 2, 2023
2 parents c56cc31 + 274139e commit 4122735
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 23 deletions.
22 changes: 22 additions & 0 deletions x-pack/plugins/apm/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
Logger,
Plugin,
PluginInitializerContext,
SavedObjectsClient,
} from '@kbn/core/server';
import { isEmpty, mapValues } from 'lodash';
import { Dataset } from '@kbn/rule-registry-plugin/server';
Expand Down Expand Up @@ -48,6 +49,7 @@ import { scheduleSourceMapMigration } from './routes/source_maps/schedule_source
import { createApmSourceMapIndexTemplate } from './routes/source_maps/create_apm_source_map_index_template';
import { addApiKeysToEveryPackagePolicyIfMissing } from './routes/fleet/api_keys/add_api_keys_to_policies_if_missing';
import { apmTutorialCustomIntegration } from '../common/tutorial/tutorials';
import { APM_STATIC_DATA_VIEW_ID } from '../common/data_view_constants';

export class APMPlugin
implements
Expand Down Expand Up @@ -119,6 +121,26 @@ export class APMPlugin
],
});

// ensure that the APM data view is globally available
getCoreStart()
.then(async (coreStart) => {
const soClient = new SavedObjectsClient(
coreStart.savedObjects.createInternalRepository()
);

await soClient.updateObjectsSpaces(
[{ id: APM_STATIC_DATA_VIEW_ID, type: 'index-pattern' }],
['*'],
[]
);
})
.catch((e) => {
this.logger?.error(
'Failed to make APM data view available globally',
e
);
});

const resourcePlugins = mapValues(plugins, (value, key) => {
return {
setup: value,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import { validateNonExact } from '@kbn/securitysolution-io-ts-utils';
import { ESQL_RULE_TYPE_ID } from '@kbn/securitysolution-rules';
import { DEFAULT_APP_CATEGORIES } from '@kbn/core-application-common';

import { SERVER_APP_ID } from '../../../../../common/constants';
import type { EsqlRuleParams } from '../../rule_schema';
Expand Down Expand Up @@ -47,6 +48,7 @@ export const createEsqlAlertType = (
},
minimumLicenseRequired: 'basic',
isExportable: false,
category: DEFAULT_APP_CATEGORIES.security.id,
producer: SERVER_APP_ID,
executor: (params) => esqlExecutor({ ...params, version }),
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import React from 'react';

import React, { Ref } from 'react';
import { FormattedMessage } from '@kbn/i18n-react';
import {
EuiFieldText,
Expand All @@ -14,21 +15,22 @@ import {
EuiCallOut,
EuiCode,
EuiLink,
EuiFieldTextProps,
} from '@elastic/eui';
import { useSelector } from 'react-redux';
import { i18n } from '@kbn/i18n';
import { useFormContext, useFormState } from 'react-hook-form';
import { TagsField } from '../components/tags_field';
import { PrivateLocation } from '../../../../../../common/runtime_types';
import { AgentPolicyNeeded } from './agent_policy_needed';
import { PolicyHostsField } from './policy_hosts';
import { PolicyHostsField, AGENT_POLICY_FIELD_NAME } from './policy_hosts';
import { selectAgentPolicies } from '../../../state/private_locations';

export const LocationForm = ({ privateLocations }: { privateLocations: PrivateLocation[] }) => {
const { data } = useSelector(selectAgentPolicies);
const { control, register, watch } = useFormContext<PrivateLocation>();
const { control, register, getValues } = useFormContext<PrivateLocation>();
const { errors } = useFormState();
const selectedPolicyId = watch('agentPolicyId');
const selectedPolicyId = getValues(AGENT_POLICY_FIELD_NAME);
const selectedPolicy = data?.find((item) => item.id === selectedPolicyId);

const tagsList = privateLocations.reduce((acc, item) => {
Expand All @@ -46,7 +48,7 @@ export const LocationForm = ({ privateLocations }: { privateLocations: PrivateLo
isInvalid={Boolean(errors?.label)}
error={errors?.label?.message}
>
<EuiFieldText
<FieldText
data-test-subj="syntheticsLocationFormFieldText"
fullWidth
aria-label={LOCATION_NAME_LABEL}
Expand All @@ -64,7 +66,7 @@ export const LocationForm = ({ privateLocations }: { privateLocations: PrivateLo
/>
</EuiFormRow>
<EuiSpacer />
<PolicyHostsField errors={errors} control={control} privateLocations={privateLocations} />
<PolicyHostsField privateLocations={privateLocations} />
<EuiSpacer />
<TagsField tagsList={tagsList} control={control} errors={errors} />
<EuiSpacer />
Expand Down Expand Up @@ -133,6 +135,12 @@ export const LocationForm = ({ privateLocations }: { privateLocations: PrivateLo
);
};

const FieldText = React.forwardRef<HTMLInputElement, EuiFieldTextProps>(
(props, ref: Ref<HTMLInputElement>) => (
<EuiFieldText data-test-subj="syntheticsFieldTextFieldText" {...props} inputRef={ref} />
)
);

export const AGENT_CALLOUT_TITLE = i18n.translate(
'xpack.synthetics.monitorManagement.agentCallout.title',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
*/

import React from 'react';
import { Controller, FieldErrors, Control } from 'react-hook-form';
import { Controller, useFormContext } from 'react-hook-form';
import { useSelector } from 'react-redux';

import {
EuiFlexGroup,
EuiFlexItem,
EuiFormRow,
EuiHealth,
EuiSuperSelectProps,
EuiSuperSelect,
EuiText,
EuiToolTip,
Expand All @@ -23,16 +23,17 @@ import { i18n } from '@kbn/i18n';
import { PrivateLocation } from '../../../../../../common/runtime_types';
import { selectAgentPolicies } from '../../../state/private_locations';

export const PolicyHostsField = ({
errors,
control,
privateLocations,
}: {
errors: FieldErrors;
control: Control<PrivateLocation, any>;
privateLocations: PrivateLocation[];
}) => {
export const AGENT_POLICY_FIELD_NAME = 'agentPolicyId';

export const PolicyHostsField = ({ privateLocations }: { privateLocations: PrivateLocation[] }) => {
const { data } = useSelector(selectAgentPolicies);
const {
control,
formState: { isSubmitted },
trigger,
} = useFormContext<PrivateLocation>();
const { isTouched, error } = control.getFieldState(AGENT_POLICY_FIELD_NAME);
const showFieldInvalid = (isSubmitted || isTouched) && !!error;

const policyHostsOptions = data?.map((item) => {
const hasLocation = privateLocations.find((location) => location.agentPolicyId === item.id);
Expand Down Expand Up @@ -91,26 +92,29 @@ export const PolicyHostsField = ({
<EuiFormRow
fullWidth
label={POLICY_HOST_LABEL}
helpText={!errors?.agentPolicyId ? SELECT_POLICY_HOSTS_HELP_TEXT : undefined}
isInvalid={!!errors?.agentPolicyId}
error={SELECT_POLICY_HOSTS}
helpText={showFieldInvalid ? SELECT_POLICY_HOSTS_HELP_TEXT : undefined}
isInvalid={showFieldInvalid}
error={showFieldInvalid ? SELECT_POLICY_HOSTS : undefined}
>
<Controller
name="agentPolicyId"
name={AGENT_POLICY_FIELD_NAME}
control={control}
rules={{ required: true }}
render={({ field }) => (
<EuiSuperSelect
<SuperSelect
fullWidth
aria-label={SELECT_POLICY_HOSTS}
placeholder={SELECT_POLICY_HOSTS}
valueOfSelected={field.value}
itemLayoutAlign="top"
popoverProps={{ repositionOnScroll: true }}
hasDividers
isInvalid={!!errors?.agentPolicyId}
isInvalid={showFieldInvalid}
options={policyHostsOptions ?? []}
{...field}
onBlur={async () => {
await trigger();
}}
/>
)}
/>
Expand All @@ -136,3 +140,11 @@ const SELECT_POLICY_HOSTS_HELP_TEXT = i18n.translate(
const POLICY_HOST_LABEL = i18n.translate('xpack.synthetics.monitorManagement.policyHost', {
defaultMessage: 'Agent policy',
});

export const SuperSelect = React.forwardRef<HTMLSelectElement, EuiSuperSelectProps<string>>(
(props, ref) => (
<span ref={ref} tabIndex={-1}>
<EuiSuperSelect data-test-subj="syntheticsAgentPolicySelect" {...props} />
</span>
)
);
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,14 @@ export default function (providerContext: FtrProviderContext) {
})
.expect(200);

await supertest
.post(`/api/fleet/epm/packages/endpoint/8.10.2`)
.set('kbn-xsrf', 'xxxx')
.send({
force: true,
})
.expect(200);

// add endpoint package policy, which is required for tamper protection
await supertest
.post(`/api/fleet/package_policies`)
Expand Down

0 comments on commit 4122735

Please sign in to comment.